Repository navigation
Description
Description
In OpenCode v1, apply_patch includes movePath: undefined in permission metadata for add, update, and delete operations. The request is accepted in memory, but GET /permission fails while encoding it:
BadRequest: Expected JSON value
This is easy to miss because permission.asked SSE serialization omits the undefined property, so the normal interactive flow can still work. It becomes a hang when a client misses the SSE event and relies on the permission-list endpoint for recovery.
Reproduced with v1.17.4 for add and update operations. The implementation remains unchanged in v1.18.23 and the current dev branch at 830aaf2059e87eab3105dda4c19556206d60c443.
opencode/packages/opencode/src/tool/apply_patch.ts
Lines 193 to 202 in 830aaf2
| // Build per-file metadata for UI rendering (used for both permission and result) | |
| const files = fileChanges.map((change) => ({ | |
| filePath: change.filePath, | |
| relativePath: path.relative(instance.worktree, change.movePath ?? change.filePath).replaceAll("\\", "/"), | |
| type: change.type, | |
| patch: change.diff, | |
| additions: change.additions, | |
| deletions: change.deletions, | |
| movePath: change.movePath, | |
| })) |
Permission metadata accepts arbitrary values rather than requiring JSON-safe data:
opencode/packages/schema/src/v1/permission.ts
Lines 27 to 35 in 830aaf2
| export const Request = Schema.Struct({ | |
| id: ID, | |
| sessionID: SessionID, | |
| permission: Schema.String, | |
| patterns: Schema.Array(Schema.String), | |
| metadata: Schema.Record(Schema.String, Schema.Unknown), | |
| always: Schema.Array(Schema.String), | |
| tool: Schema.optional(Schema.Struct({ messageID: Schema.String, callID: Schema.String })), | |
| }).annotate({ identifier: "PermissionRequest" }) |
At minimum, v1 should omit movePath when it is undefined so pending apply-patch permissions remain listable.
Plugins
None required. The failure occurs through the server API directly.
OpenCode version
Reproduced with v1.17.4. Source inspection indicates v1.4.4 through v1.18.23 and current dev are affected.
Steps to reproduce
- Start OpenCode v1 with edit permission configured to ask.
- Use a model that selects
apply_patch. - Ask it to add or update a file.
- While the permission request is pending, call
GET /permission. - Observe HTTP 400 with
BadRequest: Expected JSON value.
The failure also follows from the same metadata construction for deletes and mixed patches. A move-only patch may avoid this exact error because its movePath is a string.
Screenshot and/or share link
Not applicable. Reproduced through the HTTP permission API.
Operating System
Linux 7.0.0-29-generic x86_64
Terminal
Not terminal-specific; reproduced at the server API boundary.
Activity
github-actions commentedon Aug 26, 2026
This issue might be a duplicate of existing issues. Please check:
undefined, causingGET /permissionto fail with HTTP 400; bug: undefined in v1 permission metadata breaks GET /permission #38912 already coversapply_patchspecifically atapply_patch.ts:201.