Skip to content

fix(core): omit undefined optional keys from glob/grep permission metadata#37965

Open
IbrahimKhan12 wants to merge 1 commit into
anomalyco:devfrom
IbrahimKhan12:search-metadata-omit
Open

fix(core): omit undefined optional keys from glob/grep permission metadata#37965
IbrahimKhan12 wants to merge 1 commit into
anomalyco:devfrom
IbrahimKhan12:search-metadata-omit

Conversation

@IbrahimKhan12

Copy link
Copy Markdown

Issue for this PR

Closes #37650

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

glob and grep build their permission metadata by reading optional inputs directly:

metadata: { root: input.path ?? ".", path: input.path, limit: input.limit }

The decoded tool input is exact-optional, so when path/limit/include are omitted the key is absent and input.path reads back as undefined. Assigning it still materializes an own property with an undefined value ({ root: ".", path: undefined, limit: undefined }).

Permission metadata is Schema.Record(Schema.String, Schema.Unknown), and Unknown keeps that undefined as a real own property through schema encoding (verified: the encoded object still has the path key; only JSON.stringify later hides it). Serializing session.permission.list as a strict JSON value then chokes on it, so a single pending glob/grep permission with omitted optional inputs can fail the whole listing.

Fix: only add the optional keys when their value is defined. This matches webfetch/websearch, which spread the exact-optional decoded input and so never introduce undefined keys.

Related: #37679 fixes the same issue on the v2 branch by stripping undefined centrally in permission.ts. This PR targets dev and fixes it at the source (the tools produce clean metadata), leaving the Record<string, unknown> bag untouched.

How did you verify your code works?

Added test/tool-glob.test.ts and test/tool-grep.test.ts that execute each tool without the optional inputs and assert the metadata passed to permission.assert has no undefined-valued keys (checking Object.keys, since toEqual ignores undefined properties). Both fail on dev (keys path/include/limit present) and pass with the fix; a second case confirms provided optional fields are still recorded.

bun typecheck and the packages/core permission/tool suites pass locally.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Potential Related PR Found:

Why they're related:
Both PRs address the same underlying issue of undefined values in permission metadata. PR #37679 fixes it on the v2 branch by stripping undefined values centrally in permission.ts, while PR #37965 (the current PR) targets the dev branch and fixes it at the source by preventing glob/grep tools from creating undefined-valued keys in the first place. These are complementary fixes for different branches but solving the same problem.

…adata

The glob and grep tools built their permission metadata by assigning
input.path/input.limit/input.include directly. When those optional
inputs are omitted, the decoded input has no such key, so reading it
yields undefined and materializes undefined-valued keys in the metadata
bag (e.g. { root: ".", path: undefined, limit: undefined }).

Permission metadata is Schema.Record(String, Unknown) and is serialized
as JSON for session.permission.list. The undefined entries survive
schema encoding as own properties and break strict JSON encoding of the
response, so a single pending glob/grep permission with omitted optional
inputs can make the whole listing fail.

Only include the optional keys when their value is defined, matching the
webfetch/websearch tools which spread the exact-optional decoded input
and never introduce undefined keys.

Refs anomalyco#37650
@IbrahimKhan12
IbrahimKhan12 force-pushed the search-metadata-omit branch from 9bb6dae to 7be147b Compare July 20, 2026 19:14
@IbrahimKhan12
IbrahimKhan12 marked this pull request as ready for review July 20, 2026 19:14
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.

tools: optional search metadata breaks pending permission listing

1 participant