Files
ben f368943099 fix: use upstream v2 migration; remove custom history copy/lock (#6979)
* fix(engine): use upstream in-place v2 history migration

Remove OpenWork's history-copy worker, transfer stages, disk budget, mutex/leases, resume jobs, startup gates and migration UI/API. A stuck worker could outlive cancellation/quit, hold the history fence and leave v2 unavailable with 503s and an unrelated disk estimate.

Start vanilla 2.2.0 on the original database unless a populated legacy separate v2 store exists. Save the chosen path in engine state so deleting the last chat cannot switch databases. Preserve all original databases, partial copies, staging, backups and stale artifacts; split history is not silently merged.

Use the existing engine handoff fence and idle check before adoption. Once the shared store belongs to v2, refuse v1 chat writes and reverting to v1: upstream retains v1 tables but never reimports later writes. Keep existing v2-only policy and external-engine ownership.

* test(engine): await the independent local provider mirror

The live Gateway catalog can be ready before the unrelated local provider mirror has settled. Wait for the actual mirror before asserting ownership in the native 2.2.0 regression. Also remove a remote-workspace comparison that the server's local-only workspace type cannot represent.

* fix(engine): never infer v1 safety from a failed v2 start

Binary resolution can fail before this process reads the adopted history path, even when an earlier boot already migrated that database. Keep forced v2 selected and use normal restart handling on every start failure instead of reviving a potentially stale v1 projection.

* test(engine): isolate restart profiles from the host history

Give the restart fixture its own OPENCODE_DB and OPENCODE_CONFIG_DIR so an agent running inside OpenWork cannot inject its real profile into the fake engine's provider mirror. The inherited-profile run timed out; an empty environment and this explicit fixture both pass.
2026-11-04 08:35:58 -08:00
..

OpenCode v2 only (opencodeV2Only)

  • Feature key: opencodeV2Only
  • Deployments: cloud and self-hosted
  • Default: off
  • Author: benjaminshafii

What a person gets

On a signed-in desktop whose organization has the rollout on:

  • Every chat runs on OpenCode v2. If the desktop was still on OpenCode v1, it moves to v2 as soon as v1 has no running task (it never strands a running v1 turn; it waits and tries again on the next policy check).
  • Switching to OpenCode v1 is turned off. The command palette and Settings › Advanced › OpenCode engine still show OpenCode v1, locked, with "Your organization runs every chat on OpenCode v2." The server refuses a v1 switch with 409 engine_v2_only.
  • OpenCode v2 starts directly and upstream migrates the selected database in place. Existing populated separate v2 stores remain selected. There is no custom history copy, migration command, disk preflight or history lock.

This is the user-visible half of making OpenCode v2 the only engine. The v1 engine still ships and still backs provider sign-in on this release; removing it is a separate change once this rollout is on everywhere.

How it is resolved

The server reads the flag from the same verified /v1/me/desktop-config response as liveProviderSync (opencodeV2Only: true|false). It is never saved locally: signed out, an older Den without the field, or Den unreachable all mean off. The renderer only reads the server's effective state (GET /experimental/engine-v2-preview/status → v2Only).

How to try it

  1. In /admin, turn opencodeV2Only on for one organization.
  2. Sign in to the desktop app as a member of that organization.
  3. Within one provider-sync pass (on sign-in, then every interval) the status reports v2Only: true, chats route to v2, and the v1 option is locked.

Turning it off (kill switch)

Turning it off only unlocks the v1 option. It does not move anyone back to OpenCode v1 or change saved routing: the engine state file keeps enabled: true, chatRouting: true and engineOrigin: "forced", which older desktop builds also read as "v2". People can switch engines manually again afterwards.

Safety guarantees it relies on (always on, not behind the flag)

  • The engine state file always includes enabled, chatRouting and engineOrigin, so older builds keep selecting v2 after a downgrade. A state file written by the reverted v2-only build (no enabled) is read as v2.
  • Stale copy fences, leases, staging files and receipts from older builds do not gate startup. They are preserved for recovery, not deleted or resumed.
  • Split or partially copied histories are not merged. Existing v2 chats remain available; uncopied v1 data remains in its original database and backups.

See docs/opencode-engine-migration.md for the full lifecycle.

What to watch

  • Normal engine startup errors in lastError, including upstream conversion failures.
  • Server warnings prefixed OpenCode v2 only: (for example waiting for v1 tasks) in lastWarning.
  • 409 engine_v2_only responses mean something still tried to select v1.