Skip to content

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

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

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

Conversation

@IbrahimKhan12

@IbrahimKhan12 IbrahimKhan12 commented Jul 20, 2026

Copy link
Copy Markdown

Issue for this PR

Fixes #37650

Type of change

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

What does this PR do?

glob and grep copied omitted optional inputs into pending permission metadata as explicit undefined values. Permission metadata must be JSON, so session.permission.list could fail schema encoding while one of those requests was waiting for approval.

This change conditionally includes path, include, and limit only when callers provide them. The required metadata remains unchanged, and supplied optional values are still preserved for permission display and persistence.

How did you verify your code works?

  • bun test test/tool-glob.test.ts test/tool-grep.test.ts from packages/core: 4 tests pass. The tests execute the real tools and verify both omitted and supplied optional metadata fields.
  • bun typecheck from packages/core: passes.

Screenshots / recordings

N/A, this changes permission metadata encoding only.

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
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tools: optional search metadata breaks pending permission listing

1 participant