Skip to content

fix(opencode): drop undefined from v1 permission metadata - #38918

Closed
rvaccone wants to merge 1 commit into
anomalyco:devfrom
rvaccone:fix/v1-permission-metadata-undefined
Closed

rvaccone wants to merge 1 commit into
anomalyco:devfrom
rvaccone:fix/v1-permission-metadata-undefined

Conversation

@rvaccone

Copy link
Copy Markdown

Issue for this PR

Closes #38912

Type of change

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

What does this PR do?

v1 tools write absent optional inputs into permission metadata as undefined, because path: params.path creates the key instead of omitting it. Metadata is Schema.Record(Schema.String, Schema.Unknown), and Unknown encodes through Schema.Json, whose guard rejects undefined and recurses. One pending request therefore breaks the whole GET /permission response, not just its own entry.

Five tools hit it: glob, grep, webfetch and websearch flat, plus apply_patch, which nests movePath inside metadata.files[].

Fixed where the pending request is built, the only place one is constructed, so it covers both the listing and the Event.Asked publish. Recursive because apply_patch nests, and because plugin tools feed the same bag (AskInput.metadata is { [key: string]: any }), so the producer set is open. Plain objects and arrays only, so a Date is not flattened to {} by Object.entries, and ancestors are tracked the way SchemaAST.isJson does, so genuine cycles still fail instead of looping forever.

How did you verify your code works?

Three tests boot the real Permission service and encode list() through the schema GET /permission declares, so they assert the operation that actually fails rather than a proxy. Reverting only the source change makes the flat and nested tests fail while the negative one still passes. 145 tests pass across the permission, acp and apply_patch suites, tsgo --noEmit is clean, and oxlint reports the same 3 warnings as before.

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:

I found two related PRs that appear to address similar issues with undefined values in permission metadata:

  1. PR fix(core): drop undefined metadata values from permission requests #37679: fix(core): drop undefined metadata values from permission requests

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

These PRs likely addressed similar problems in the core layer, while the current PR (38918) is fixing the same issue in the opencode (v1) layer. You may want to verify whether these earlier PRs should have also covered the v1 tools, or if there's overlap in the fixes.

@rvaccone

Copy link
Copy Markdown
Author

Related, no overlap. Both of those change v2 code in packages/core: #37679 the v2 permission service, #37965 the v2 glob and grep tools. This PR changes v1's own permission service in packages/opencode. v1 has separate implementations of both the service and these tools, so a fix in one does not reach the other.

Scope differs too. #37650 was reported against v2 glob and grep. On v1 the same defect additionally affects webfetch, websearch and apply_patch, the last nesting undefined inside metadata.files[] where a top level strip does not reach. Details in #38912.

@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.

bug: undefined in v1 permission metadata breaks GET /permission

1 participant