Skip to content

Leave the trash out of Google Drive search and recent files - #588

Merged
davidmckayv merged 2 commits into
CopilotKit:mainfrom
kevin9327:drive-leave-out-trash
Sep 16, 2026
Merged

davidmckayv merged 2 commits into
CopilotKit:mainfrom
kevin9327:drive-leave-out-trash

Conversation

@kevin9327

Copy link
Copy Markdown
Contributor

What this changes

Google's reference for files.list says:

This method returns all files by default, including trashed files. If you don't want trashed files to appear in the list, use the trashed=false query parameter to remove trashed files from the results.

The Drive connector's two listings did not do that:

Tool Request on main
search_files q=name contains '…' or fullText contains '…'
list_recent_files no q, orderBy=modifiedTime desc

A document somebody moved to the trash (an outdated plan, or a draft replaced by a newer one) still came back to the Bot as a match or as a recently changed file. fileLine shows name, type, modified time, link and id, and Drive was not asked for anything that would say the file was trashed. The Bot had no way to tell it apart from a live document and could answer from it.

After this change:

  • search_files sends (name contains '…' or fullText contains '…') and trashed = false. The brackets make trashed = false apply to both halves of the or. The escaping of ' and \ is unchanged.
  • list_recent_files sends q=trashed = false with the same orderBy.

get_file_metadata and read_file_content are unchanged. A file read by its id is still read whether or not it is trashed, because that is a request for that particular file.

Where it runs

  • New state that outlives a request? None. This only changes the query string sent to Google.
  • What happens on the second replica? The same request.
  • Anything serialised? No.
  • Anything fanned out to a browser? No.
  • New listener, port, or schedule? No.

Boundary and audit

  • Every acting call still goes through the gateway: resolve, decide, audit, then act. Grants, policy and the audit row around callTool are untouched.
  • New refusals and new failures each write a row. None are added.
  • Nothing new is trusted from the client that the server can resolve itself. The search term is escaped exactly as before.

Changelog

  • A line in CHANGELOG.md under Unreleased.

Proof

server/tests/google-drive-rest.test.ts already asserts the exact request each listing becomes, so three existing assertions change and no test is added:

  • the search clause, in "the query is sent as a Drive q clause" and in the apostrophe case;
  • "recent files are ordered by Drive rather than filtered" becomes "…and filtered only by the trash". It used to assert that no q was sent, and now asserts q=trashed = false. A comment on it says why.

With google-drive-rest.ts from main (only the tests changed):

Expected: "(name contains 'roadmap' or fullText contains 'roadmap') and trashed = false"
Received: "name contains 'roadmap' or fullText contains 'roadmap'"
(fail) a search becomes the right Drive request > the query is sent as a Drive q clause, with the caller's token
Expected: "(name contains 'don\'t ship' or fullText contains 'don\'t ship') and trashed = false"
Received: "name contains 'don\'t ship' or fullText contains 'don\'t ship'"
(fail) a search becomes the right Drive request > an apostrophe in the query cannot break out of the clause
Expected: "trashed = false"
Received: null
(fail) a search becomes the right Drive request > recent files are ordered by Drive, and filtered only by the trash
 15 pass
 3 fail

With the fix:

  • bun test --coverage server/tests/google-drive-rest.test.ts: 18 pass, 0 fail. The only uncovered lines in google-drive-rest.ts are 160–166, the network-error branch of request, which this change does not touch.
  • bun test server/tests/tool-selection-environment-restoration-driver.test.ts: 3 pass. Nothing else in the repo asserts on these query strings.
  • bun run typecheck (app, server, worker): exit 0. bunx biome check and biome lint --error-on-warnings on the changed files: clean.

I have no Google account wired to a deployment here, so this was not driven against live Drive. The claim rests on Google's documented default quoted above, and on the tests pinning the request this connector sends.

This PR adds its entry at the top of ## Unreleased, where other open PRs add theirs, so the changelog may conflict. I can rebase if it does.

🤖 Generated with Claude Code

files.list returns trashed files unless the query excludes them, and
neither search_files nor list_recent_files did, so a document somebody had
thrown away came back to the Bot as a match or a recent file with nothing
to say it was in the trash.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@davidmckayv davidmckayv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code-verified clean; CI green on this sha.

@davidmckayv
davidmckayv merged commit 0b40968 into CopilotKit:main Sep 16, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants