Repository navigation
Description
AI-authorship disclosure
This issue was researched and drafted by an AI coding assistant, then submitted under the account owner's direction. The observed symptom was supplied by the human reporter. The source-code findings are linked below; the affected local database has not yet been inspected, and all hypotheses are explicitly marked as such.
Summary
OpenCode Desktop shows the following error whenever it reloads a project/session:
Expected JSON value, got [[{"filePath":...,"type":"update","patch":"Index: ..."}]]
The workload continues to run and files continue to update. The failure is observed specifically during Desktop project/session reload.
Environment
- Client: OpenCode Desktop
- Workload: large, long-lived sessions; multiple sessions used for the same project
- Exact Desktop version, OS/arch, active plugins/MCP configuration: to be added
Observed behavior
- Reopening/reloading the same project reproduces the error.
- The payload resembles patch history.
- Its leading
[[{suggests a nested array. - The visible object has
filePath,type: "update", and a stringpatchbeginning withIndex: .... - Current work is not stopped: tool execution and file writes continue.
Source investigation
Confirmed
- The built-in legacy
apply_patchtool emits a flatfilesarray whose items have the observed shape:{ filePath, relativePath, type, patch, additions, deletions, movePath }. - Snapshot
PatchPartis not this shape: it is{ type: "patch", hash: string, files: string[] }. The snapshot implementation returns a flat list of file path strings.- https://github.com/anomalyco/opencode/blob/dev/packages/schema/src/v1/session.ts#L94-L100
- https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/snapshot/index.ts#L349-L380
- Session
part.datais persisted as JSON text. On legacy message hydration, rows are reconstructed by type assertion rather than a per-row schema decode.- https://github.com/anomalyco/opencode/blob/dev/packages/core/src/session/sql.ts#L82-L98
- https://github.com/anomalyco/opencode/blob/dev/packages/opencode/src/session/message-v2.ts#L80-L121
- Desktop starts a bundled local sidecar server, and the app fetches legacy session messages as a fallback path during reload.
- https://github.com/anomalyco/opencode/blob/dev/packages/desktop/src/main/sidecar.ts#L51-L69
- https://github.com/anomalyco/opencode/blob/dev/packages/app/src/context/server-session.ts#L526-L560
Hypothesis, not yet verified against the affected DB
A historical tool part, likely tool.state.metadata.files, may contain Patch[][] / FileChange[][] rather than the flat FileChange[] written by the current apply_patch tool. Reload then reaches an HTTP response JSON/schema boundary that rejects the persisted value.
This is not yet evidence that snapshot PatchPart itself is nested. The source has no declared Patch[][] in the snapshot/revert path.
Related reports
- tools: optional search metadata breaks pending permission listing #37650 / fix(core): drop undefined metadata values from permission requests #37679 show the same general failure class: a permissive metadata field later fails JSON response encoding.
- Parallel terminal sessions overlap when running in the same project directory #28249 reports shared snapshot corruption when multiple OpenCode processes edit the same project concurrently.
- fix(session): prevent cross-session patch contamination #20560 is an unmerged proposal addressing cross-session patch contamination and specifically consumes
files[].filePathfromapply_patchmetadata.
Expected behavior
A malformed or legacy persisted tool part must not prevent a whole session/project from reloading. At minimum, the response should identify the failing part.id and safely isolate or omit that part rather than failing session message retrieval.
Requested guidance
- Is there a known migration/schema incompatibility for legacy
apply_patchmetadata orPatch[][]? - What is the supported non-destructive recovery path for one malformed session part?
- Is
snapshot: falseexpected only to prevent future snapshot generation, rather than repair existing persisted metadata? - Is there a recommended export/query that maintainers want attached to identify the exact bad row?
I can attach a sanitized session export, relevant part/session_message query results, and a Desktop debug-log archive after guidance on the preferred redaction format.
Activity
[-]Desktop reload fails with Expected JSON value for nested apply_patch metadata[/-][+][AI-assisted] Desktop reload fails with Expected JSON value for nested apply_patch metadata[/+]github-actions commentedon Jul 24, 2026
This issue doesn't fully meet our contributing guidelines.
What needs to be fixed:
Please edit this issue to address the above within 2 hours, or it will be automatically closed.
This issue might be a duplicate of existing issues. Please check:
part.dataJSON rows that fail HTTP response schema encoding, making sessions/messages unloadable. Covers the same code paths inmessage-v2.tsand includes a detailed workaround and fix proposal.Expected JSON value, got ...error class from permissive metadata fields failing schema encoding at an HTTP response boundary.If you believe this was flagged incorrectly, please let a maintainer know.
su-351917 commentedon Jul 24, 2026
Closing after further local investigation. A verified SQLite backup and read-only scan found no nested Patch[][] values and no malformed persisted rows covered by #29908. The matching server-log failures instead appear closer to #37650/#37679: apply_patch live metadata contains an optional movePath nested under metadata.files[], which may be undefined before JSON persistence removes it. I will add the factual reproduction evidence to the existing related report rather than continue this non-compliant duplicate issue.