Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(google-vault): error handling improvement and more params #2735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aadamgough wants to merge 9 commits into staging
base: staging
Choose a base branch
Loading
from fix/google-vault

Conversation

@aadamgough
Copy link
Contributor

@aadamgough aadamgough commented Jan 9, 2026

Summary

Added better error handling for vault specifically. Google Cloud by default has a limit for token expiration, and they throw invalid_grant after the token expires, and the only workaround to this is disconneting and reconnecting credential, or, as an admin, disabling reauth for Sim.

Also added additional params for dates

Type of Change

  • Bug fix
  • New feature

Testing

Tested manually

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Copy link

vercel bot commented Jan 9, 2026
edited
Loading

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Review Updated (UTC)
docs Skipped Skipped Jan 9, 2026 7:31am

@aadamgough aadamgough marked this pull request as ready for review January 9, 2026 04:42
Copy link
Collaborator

greptile-apps[bot] reacted with thumbs up emoji

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Greptile Overview

Greptile Summary

Adds specialized error handling for Google Vault credential expiration issues by creating a dedicated block handler that detects RAPT and invalid_grant errors, providing users with actionable reconnection instructions. Extends Google Vault functionality with date filtering (startTime, endTime) and search terms for both exports and holds, plus shared drive support for DRIVE corpus holds. Removes the unused timeZone parameter from export operations.

Confidence Score: 3/5

  • Generally safe to merge with minor validation concerns
  • The PR improves error handling and adds useful functionality, but has duplicate field IDs in the block configuration that could cause form rendering issues. The query object construction in create_matters_holds.ts should be verified to ensure empty query objects are handled correctly by the Google Vault API. The error handling logic itself is well-implemented with comprehensive pattern matching.
  • apps/sim/blocks/blocks/google_vault.ts needs duplicate field ID resolution; apps/sim/tools/google_vault/create_matters_holds.ts needs API validation for empty query objects

Important Files Changed

File Analysis

Filename Score Overview
apps/sim/executor/handlers/google-vault/google-vault-handler.ts 4/5 Adds specialized handler for Google Vault blocks with enhanced credential error detection and user-friendly error messages
apps/sim/tools/google_vault/create_matters_holds.ts 3/5 Adds query parameters for MAIL/GROUPS date filtering and DRIVE shared drive support; query object construction needs validation
apps/sim/blocks/blocks/google_vault.ts 3/5 Adds extensive UI configuration for date filtering and search terms with wand AI prompts; duplicate field IDs need attention

Sequence Diagram

sequenceDiagram
 participant Client
 participant GoogleVaultHandler
 participant executeTool
 participant GoogleVaultAPI
 
 Client->>GoogleVaultHandler: execute(block, inputs)
 GoogleVaultHandler->>GoogleVaultHandler: Transform inputs & parse JSON
 GoogleVaultHandler->>executeTool: Execute with credentials
 executeTool->>GoogleVaultAPI: API Request
 
 alt Success
 GoogleVaultAPI-->>executeTool: Valid response
 executeTool-->>GoogleVaultHandler: result.success = true
 GoogleVaultHandler-->>Client: Return output
 else Credential Error
 GoogleVaultAPI-->>executeTool: invalid_grant/RAPT error
 executeTool-->>GoogleVaultHandler: result.success = false
 GoogleVaultHandler->>GoogleVaultHandler: isCredentialRefreshError()
 GoogleVaultHandler->>GoogleVaultHandler: enhanceCredentialError()
 GoogleVaultHandler-->>Client: User-friendly error with reconnection guidance
 else Other Error
 GoogleVaultAPI-->>executeTool: Other error
 executeTool-->>GoogleVaultHandler: Throws error
 GoogleVaultHandler->>GoogleVaultHandler: Check if credential error
 GoogleVaultHandler-->>Client: Enhanced or standard error message
 end
Loading

Comment on lines +162 to +184
// Date filtering for exports (works with all corpus types)
{
id: 'startTime',
title: 'Start Time',
type: 'short-input',
placeholder: 'YYYY-MM-DDTHH:mm:ssZ',
condition: { field: 'operation', value: 'create_matters_export' },
wandConfig: {
enabled: true,
prompt: `Generate an ISO 8601 timestamp in GMT based on the user's description for Google Vault date filtering.
The timestamp should be in the format: YYYY-MM-DDTHH:mm:ssZ (UTC timezone).
Note: Google Vault rounds times to 12 AM on the specified date.
Examples:
- "yesterday" -> Calculate yesterday's date at 00:00:00Z
- "last week" -> Calculate 7 days ago at 00:00:00Z
- "beginning of this month" -> Calculate the 1st of current month at 00:00:00Z
- "January 1, 2024" -> 2024年01月01日T00:00:00Z
Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
placeholder: 'Describe the start date (e.g., "last month", "January 1, 2024")...',
generationType: 'timestamp',
},
},
Copy link
Contributor

@greptile-apps greptile-apps bot Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate field ID startTime defined. This field already exists for create_matters_export operation (lines 162-184) and is redefined for create_matters_holds operation (lines 186-208). The UI form system may not handle duplicate field IDs correctly, potentially causing configuration conflicts or only one field being recognized.

Consider using unique field IDs like export_startTime and hold_startTime, or refactor to use a single field definition with more complex conditions if the behavior should be identical.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/blocks/blocks/google_vault.ts
Line: 162:184
Comment:
Duplicate field ID `startTime` defined. This field already exists for create_matters_export operation (lines 162-184) and is redefined for create_matters_holds operation (lines 186-208). The UI form system may not handle duplicate field IDs correctly, potentially causing configuration conflicts or only one field being recognized.
Consider using unique field IDs like `export_startTime` and `hold_startTime`, or refactor to use a single field definition with more complex conditions if the behavior should be identical.
How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +186 to +208
id: 'endTime',
title: 'End Time',
type: 'short-input',
placeholder: 'YYYY-MM-DDTHH:mm:ssZ',
condition: { field: 'operation', value: 'create_matters_export' },
wandConfig: {
enabled: true,
prompt: `Generate an ISO 8601 timestamp in GMT based on the user's description for Google Vault date filtering.
The timestamp should be in the format: YYYY-MM-DDTHH:mm:ssZ (UTC timezone).
Note: Google Vault rounds times to 12 AM on the specified date.
Examples:
- "now" -> Current timestamp
- "today" -> Today's date at 23:59:59Z
- "end of last month" -> Last day of previous month at 23:59:59Z
- "December 31, 2024" -> 2024年12月31日T23:59:59Z
Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
placeholder: 'Describe the end date (e.g., "today", "end of last quarter")...',
generationType: 'timestamp',
},
},
// Date filtering for holds (only works with MAIL and GROUPS corpus)
{
Copy link
Contributor

@greptile-apps greptile-apps bot Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate field ID endTime defined. This field is already defined for create_matters_export (lines 186-208) and is redefined for create_matters_holds (lines 210-232). Similar to startTime, duplicate IDs may cause issues with the form rendering system.

Consider using unique field IDs to avoid potential conflicts.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/blocks/blocks/google_vault.ts
Line: 186:208
Comment:
Duplicate field ID `endTime` defined. This field is already defined for create_matters_export (lines 186-208) and is redefined for create_matters_holds (lines 210-232). Similar to `startTime`, duplicate IDs may cause issues with the form rendering system.
Consider using unique field IDs to avoid potential conflicts.
How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +234 to +256
{
id: 'endTime',
title: 'End Time',
type: 'short-input',
placeholder: 'YYYY-MM-DDTHH:mm:ssZ',
condition: {
field: 'operation',
value: 'create_matters_holds',
and: { field: 'corpus', value: ['MAIL', 'GROUPS'] },
},
wandConfig: {
enabled: true,
prompt: `Generate an ISO 8601 timestamp in GMT based on the user's description for Google Vault date filtering.
The timestamp should be in the format: YYYY-MM-DDTHH:mm:ssZ (UTC timezone).
Note: Google Vault rounds times to 12 AM on the specified date.
Examples:
- "now" -> Current timestamp
- "today" -> Today's date at 23:59:59Z
- "end of last month" -> Last day of previous month at 23:59:59Z
- "December 31, 2024" -> 2024年12月31日T23:59:59Z
Return ONLY the timestamp string - no explanations, no quotes, no extra text.`,
placeholder: 'Describe the end date (e.g., "today", "end of last quarter")...',
Copy link
Contributor

@greptile-apps greptile-apps bot Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate field ID terms defined. This field appears twice - once for exports (lines 234-256) and once for holds (lines 258-278). Like the date fields, duplicate field IDs may cause form rendering or data binding issues.

Consider using unique identifiers for each operation's search terms field.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/blocks/blocks/google_vault.ts
Line: 234:256
Comment:
Duplicate field ID `terms` defined. This field appears twice - once for exports (lines 234-256) and once for holds (lines 258-278). Like the date fields, duplicate field IDs may cause form rendering or data binding issues.
Consider using unique identifiers for each operation's search terms field.
How can I resolve this? If you propose a fix, please make it concise.

Comment on lines 101 to 119
// Build corpus-specific query for date filtering
if (params.corpus === 'MAIL' || params.corpus === 'GROUPS') {
const hasQueryParams = params.terms || params.startTime || params.endTime
if (hasQueryParams) {
const queryObj: any = {}
if (params.terms) queryObj.terms = params.terms
if (params.startTime) queryObj.startTime = params.startTime
if (params.endTime) queryObj.endTime = params.endTime

if (params.corpus === 'MAIL') {
body.query = { mailQuery: queryObj }
} else {
body.query = { groupsQuery: queryObj }
}
}
} else if (params.corpus === 'DRIVE' && params.includeSharedDrives) {
body.query = { driveQuery: { includeSharedDriveFiles: params.includeSharedDrives } }
}

Copy link
Contributor

@greptile-apps greptile-apps bot Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verify that the Google Vault API accepts empty query objects when no filtering parameters are provided. The current code creates { mailQuery: {} } or { groupsQuery: {} } structures when the corpus is MAIL or GROUPS but no terms or dates are specified. Check if the query field should be omitted entirely in this case to avoid potential API errors. Does the Google Vault API require the query field to be omitted when no filters are specified, or does it accept empty query objects?

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/tools/google_vault/create_matters_holds.ts
Line: 101:119
Comment:
Verify that the Google Vault API accepts empty query objects when no filtering parameters are provided. The current code creates `{ mailQuery: {} }` or `{ groupsQuery: {} }` structures when the corpus is MAIL or GROUPS but no terms or dates are specified. Check if the `query` field should be omitted entirely in this case to avoid potential API errors. Does the Google Vault API require the query field to be omitted when no filters are specified, or does it accept empty query objects?
How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +116 to +118
} else if (params.corpus === 'DRIVE' && params.includeSharedDrives) {
body.query = { driveQuery: { includeSharedDriveFiles: params.includeSharedDrives } }
}
Copy link
Contributor

@greptile-apps greptile-apps bot Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition params.includeSharedDrives only adds the driveQuery when truthy. If explicitly set to false, no query is added. Consider whether false should explicitly set includeSharedDriveFiles: false in the API request.

Suggested change
} else if (params.corpus === 'DRIVE' && params.includeSharedDrives) {
body.query = { driveQuery: { includeSharedDriveFiles: params.includeSharedDrives } }
}
} else if (params.corpus === 'DRIVE' && params.includeSharedDrives!==undefined) {
body.query = { driveQuery: { includeSharedDriveFiles: params.includeSharedDrives } }
}
Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/tools/google_vault/create_matters_holds.ts
Line: 116:118
Comment:
The condition `params.includeSharedDrives` only adds the driveQuery when truthy. If explicitly set to `false`, no query is added. Consider whether `false` should explicitly set `includeSharedDriveFiles: false` in the API request.
```suggestion
 } else if (params.corpus === 'DRIVE' && params.includeSharedDrives !== undefined) {
 body.query = { driveQuery: { includeSharedDriveFiles: params.includeSharedDrives } }
 }
```
How can I resolve this? If you propose a fix, please make it concise.

Comment on lines 24 to 32
function isCredentialRefreshError(errorMessage: string): boolean {
const lowerMessage = errorMessage.toLowerCase()
return (
lowerMessage.includes('invalid_rapt') ||
lowerMessage.includes('reauth related error') ||
(lowerMessage.includes('invalid_grant') && lowerMessage.includes('rapt')) ||
lowerMessage.includes('failed to refresh token') ||
(lowerMessage.includes('failed to fetch access token') && lowerMessage.includes('401'))
)
Copy link
Contributor

@greptile-apps greptile-apps bot Jan 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented comprehensive error detection for Google Vault authentication issues, covering multiple error patterns including RAPT errors, invalid_grant with rapt, token refresh failures, and 401 access token errors

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/sim/executor/handlers/google-vault/google-vault-handler.ts
Line: 24:32
Comment:
Implemented comprehensive error detection for Google Vault authentication issues, covering multiple error patterns including RAPT errors, invalid_grant with rapt, token refresh failures, and 401 access token errors
How can I resolve this? If you propose a fix, please make it concise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer

@greptile-apps greptile-apps[bot] greptile-apps[bot] left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /