[Bug]: CRITICAL - Invalid V1/V2 config syntax causes workspace deletion, silent data orphaning, and masked 502 errors
Summary
A simple schema mismatch in openwork.json (using V2 reasoning object syntax inside a V1 provider block) causes a fatal ConfigInvalidError. Instead of gracefully rejecting the bad model, the OpenWork server attempts to recover by deleting and recreating the workspace. The recreate process fails to backfill the workspace_id in the SQLite database, silently orphaning all existing sessions. The UI then filters out these sessions (making 100% of chat history invisible), and the proxy masks the underlying engine error with a generic 502 Bad Gateway.
To Reproduce
- Have an existing workspace with a populated chat history.
- Edit your
.opencode/openwork.jsonand add a model to the V1"provider"block using the V2"reasoning"object syntax (e.g.,"reasoning": { "supported": true, "effort": ["low", "high"] }). - Launch OpenWork. The engine throws a fatal
ConfigInvalidErrorand refuses to start. - Check the OpenWork audit logs. The server attempts to recover by firing a
workspace.deleteevent, followed immediately by aworkspace.createevent. - Observe the UI: The chat history is completely empty. Clicking into the workspace throws a
502 Bad Gateway.
Expected behavior
The app should catch the invalid model configuration, isolate or drop the bad model, throw a validation warning to the user, and keep the workspace and chat history fully intact.
Actual behavior
- The
workspace.deleteevent empties theworkspacetable in SQLite and clearsopenwork-workspaces.json. - The subsequent
workspace.createfails to insert a valid workspace row (likely related to locale initialization bugs, see context below). - All sessions are orphaned with
workspace_id = NULL. - The OpenWork UI explicitly filters out sessions with
NULLworkspace IDs, creating the illusion of a total data wipe. - When the OpenWork server proxies a request to the engine, the engine throws a 500
Workspace not found: wrk_.... The OpenWork server swallows this error and returns a generic502 Bad Gatewayto the frontend, providing zero diagnostic clues.
Screenshots (optional)
No response
OW version & Desktop info (optional)
- OS: Windows 11 (System Locale:
pt-BR) - OpenWork Version: 0.18.58
- OpenCode Version: 1.18.30
- Terminal: Windows PowerShell
Additional context (optional)
This failure mode is catastrophic because a simple JSON typo results in a total UI data wipe. Recovering the data required direct SQLite surgery. Here is the exact forensic breakdown discovered during recovery:
- The Locale Trigger: The workspace recreation step (
workspace.create) silently fails to populate theworkspacetable. This appears heavily correlated with non-English locales (Issue #28083 confirms similar behavior onpt-BRsystems). - The Proxy Masking: The engine returns a specific
500 Workspace not found: wrk_...error when queried directly. However, the OpenWork server intercepts this and returns502 Bad Gateway(as seen in the OpenWork server logs:error="OpenCode request failed"). This completely obscures the actual problem. - The Schema Rejection: Because the engine refused to start with the bad config, the user is trapped. Even manually patching the config and restarting leaves the user stuck, because the
workspace_idcolumn on all sessions was permanently wiped by the delete/recreate cycle. - Subagent Hiding: When attempting to re-import the orphaned sessions, the UI further hid them because the
parent_idof subagent chats no longer matched the root hierarchy, causing the sidebar to hide them entirely.
Suggested Fixes:
- Do not use
workspace.deleteas a fallback for a config parse error. Isolate the bad config and boot the engine with defaults. - Implement a migration/backfill. If
workspace.createruns, it mustUPDATE session SET workspace_id = ? WHERE workspace_id IS NULL. - Expose the true error. If the engine returns
500 Workspace not found, the proxy should return500, not502. - UI fallback. The UI should not strictly hide
NULLworkspace sessions if the sessiondirectorymatches the active workspace path.
(Filed with AI assistance.)
#6680 makes an invalid opencode.json show the file and field to fix instead of an empty workspace or a 502. I couldn't find any OpenWork path that deletes or recreates a workspace on a config error (only Remove workspace does), so that part stays open.
I'd like to work on this! @benjaminshafii @OmarMcAdam please assign me.