openwork icon indicating copy to clipboard operation
openwork copied to clipboard

[Bug]: CRITICAL - Invalid V1/V2 config syntax causes workspace deletion, silent data orphaning, and masked 502 errors

Open thetalmid opened this issue 1 month ago • 2 comments

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

  1. Have an existing workspace with a populated chat history.
  2. Edit your .opencode/openwork.json and add a model to the V1 "provider" block using the V2 "reasoning" object syntax (e.g., "reasoning": { "supported": true, "effort": ["low", "high"] }).
  3. Launch OpenWork. The engine throws a fatal ConfigInvalidError and refuses to start.
  4. Check the OpenWork audit logs. The server attempts to recover by firing a workspace.delete event, followed immediately by a workspace.create event.
  5. 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

  1. The workspace.delete event empties the workspace table in SQLite and clears openwork-workspaces.json.
  2. The subsequent workspace.create fails to insert a valid workspace row (likely related to locale initialization bugs, see context below).
  3. All sessions are orphaned with workspace_id = NULL.
  4. The OpenWork UI explicitly filters out sessions with NULL workspace IDs, creating the illusion of a total data wipe.
  5. 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 generic 502 Bad Gateway to 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 the workspace table. This appears heavily correlated with non-English locales (Issue #28083 confirms similar behavior on pt-BR systems).
  • The Proxy Masking: The engine returns a specific 500 Workspace not found: wrk_... error when queried directly. However, the OpenWork server intercepts this and returns 502 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_id column 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_id of subagent chats no longer matched the root hierarchy, causing the sidebar to hide them entirely.

Suggested Fixes:

  1. Do not use workspace.delete as a fallback for a config parse error. Isolate the bad config and boot the engine with defaults.
  2. Implement a migration/backfill. If workspace.create runs, it must UPDATE session SET workspace_id = ? WHERE workspace_id IS NULL.
  3. Expose the true error. If the engine returns 500 Workspace not found, the proxy should return 500, not 502.
  4. UI fallback. The UI should not strictly hide NULL workspace sessions if the session directory matches the active workspace path.

(Filed with AI assistance.)

thetalmid avatar Oct 21 '26 03:10 thetalmid

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

OmarMcAdam avatar Oct 29 '26 01:10 OmarMcAdam

I'd like to work on this! @benjaminshafii @OmarMcAdam please assign me.

user-Param avatar Oct 31 '26 10:10 user-Param