14 Commits
Author SHA1 Message Date
ben 4fe991da8d chore(engine): update OpenCode to 2.2.6 (#7168) 2026-11-09 12:54:45 -08:00
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
benandHugo Alves 312cbc6303 fix(engine): make the v2 history copy crash-safe and recoverable, and gate v2-only behind a rollout (#6583)
* fix(engine): make the v2 history copy crash-safe and recoverable, and gate v2-only behind a rollout

Redo the intent of the reverted v2-only engine change safely:

Downgrade-safe history copy lifecycle (always on):
- The history-copy.pending fence is published only immediately before the
  first target write, after every refusal check (other copies, running and
  orphaned engines, disk). A refused copy leaves no fence behind, so a long
  interrupted copy never locks a person out of their intact v2 history.
- A copy that fails after writing the target undoes only the chats it left
  half-written (rows it owns through an unfinished openwork_history_copy
  checkpoint) and lifts its own fence; only a pause (closing OpenWork) or
  process death keeps the fence and start marker for the next start to resume.
- An engine start that finds an abandoned fence lifts it when the target has
  no unfinished checkpoint, and otherwise resumes that copy once (or undoes
  its unfinished chats) before opening v2.
- An engine left running by an OpenWork that exited is stopped only when a
  copy needs exclusive access and the process is positively identified as
  that lease's opencode serve, re-checked before each signal; a reused pid
  is never signalled, and a running OpenWork's engine (including another
  installed app sharing the history) is never stopped.
- Disk preflight (profile match, room for the rest of the copy) runs before
  anything is written or v2 is stopped.
- Start errors suggest OPENWORK_OPENCODE2_BIN only for executable failures
  (spawn, exit, health), never for history copy states.
- The engine state file always keeps enabled, chatRouting and engineOrigin,
  and a state saved by the reverted v2-only build (no enabled) is read as v2,
  so an older build keeps selecting v2 after a downgrade.

opencodeV2Only rollout (cloud and self-hosted, off):
- Desktop chats always run on OpenCode v2: v1 is selected away once idle,
  switching back answers 409 engine_v2_only, and earlier chats are copied in
  the background after v2 is selected, never holding v2's own history back.
- Turning it off only unlocks the switch; it never moves anyone back to v1 or
  stops a copy. The v1 engine still ships and still backs provider sign-in.

Tests: fence/lease/orphan/interrupted-copy/disk-preflight/downgrade behavior
run in CI without a native engine; a repro using only pre-fix APIs fails on
the previous dev and passes here; a native-engine proof passes locally and
fails on the previous dev with the reported lockout error.

Disk-space budget (additional):

The preflight's source multiplier is tightened from 5× to a justified 4×
source + target. The two SQLite WALs (the conversion engine's WAL and the
target's WAL) do not peak simultaneously: conversion finishes and
checkpoints before the copy opens the target, so only one WAL is live at a
time. SQLite's default wal_autocheckpoint (1000 pages ~ 4 MB) bounds each
WAL to a few megabytes in practice; 1× source per WAL is the conservative
worst case. The source is read-only and the target's existing allocation is
already on disk, so neither is counted as new.

A long-time v2 user with all v1 chats already copied needs no copy at all:
v1ChatsToCopy checks hasV1ChatsSince(source, v1HistoryCopiedAt) and returns
false when v1 has nothing newer than the last finished copy. No preflight,
no fence, no disk check — v2 just serves.

The v2-only rollout starts v2 first and copies in the background, so even a
copy that cannot fit on disk (the reported ~105 GB estimate, which was an
unverified preflight estimate, not a measured requirement) never keeps v2
from serving the history it already has.

Tests added: the budget covers the actual files a copy creates (no double
counting); low disk refuses the copy and preserves every existing v2 chat; a
v2 user with nothing to copy starts v2 and copies nothing; the v1 source is
never written.

* fix(engine): retry v2-only selection after v1 becomes idle

Signed-off-by: Hugo Alves <goninja@gmail.com>
(cherry picked from commit ecd27b87d5)

* refactor(engine): clarify pending v2 selection and test setup

Signed-off-by: Hugo Alves <goninja@gmail.com>
(cherry picked from commit 49f778f3e0)

---------

Signed-off-by: Hugo Alves <goninja@gmail.com>
Co-authored-by: Hugo Alves <goninja@gmail.com>
2026-11-02 18:32:26 -08:00
ben cd4a46751e refactor(features): remove completed GA rollout flags (#6771)
* refactor(features): retire completed GA rollout gates

* fix(evals): repair inherited proof type errors

* test(den): pin the upload relay fixture clock and verify expiry

* test(den): arrange API security fixtures with hashed sessions

* test(library): verify compact lists and wait for detail breadcrumbs
2026-10-30 10:46:16 -07:00
ben f3a45d8d29 Revert "refactor(engine): remove OpenCode v1 and run only OpenCode v2 (#6515)" (#6559)
This reverts commit cdc2184384.
2026-10-27 11:05:54 -07:00
ben cdc2184384 refactor(engine): remove OpenCode v1 and run only OpenCode v2 (#6515)
* refactor(server): run only OpenCode v2 and copy earlier chats automatically

The server no longer starts, proxies or selects the OpenCode v1 engine.
OpenCode v2 is its only engine: v1 routes answer 410, engine switching
routes are gone, and earlier v1 chats are copied from the v1 database on
start with the existing staged migration. A failed copy restores v2's
own pre-copy history, keeps the original database, backs off between
starts and still lets v2 serve new chats.

API keys added on this computer are saved by OpenWork in the same
credential file the v1 engine used, and provider metadata comes from the
model catalog instead of a running v1 engine.

* docs: describe OpenCode v2 as the only engine and automatic history copy

* refactor(desktop): ship and start only OpenCode v2

Desktop, hosted images, CI and headless clients no longer download,
bundle, verify or select the OpenCode v1 binary. Images built from
source bake the pinned, integrity-checked opencode2; the cloud runtime
requires it and drops the retired engine policy variables. Remote
session runners and headless threads talk only to OpenCode v2.

The OpenCode CLI used as a CI agent tool is pinned inline in its
workflows; it is not the product engine.

* refactor(app): talk only to OpenCode v2 and drop engine switching

Every chat, session, model and settings client uses the workspace's
OpenCode v2 mount. The engine routing poller, Switch to OpenCode v1/v2
and Migrate chats commands, the Advanced engine section and their
analytics are gone. A small observer shows the host's automatic copy of
earlier chats, reloads chat lists when it finishes and offers Try again
after a failure.

Provider API keys save through OpenWork's compat routes; provider OAuth,
the v1 MCP engine sign-in modal, session archive and the effective
permissions panel depended on the v1 engine and are removed. The legacy
scripts that drove a raw v1 opencode serve are deleted.

* test(evals): run every world on OpenCode v2 and prove earlier chats copy over

Remove the --engine lane, parity tooling and v1 benchmark results. Worlds
use v2 routes and custom mock providers (no OpenCode Zen models). The
force-policy proof, which needed a real v1 binary and the removed force
route, is replaced by v1-history-copied-to-v2: a headless app opens a
chat from a seeded v1 database, finds no engine switch commands and
sends a new message.

* chore: drop remaining references to the removed v1 smoke scripts

* fix: read runtime providers from OpenWork instead of the removed engine config route

Den's provider materialization read and verified providers through the
worker's /opencode/config, which only the v1 engine served. It now uses
the OpenWork server's host-token GET /runtime-config/providers, which
workers have exposed alongside the PATCH route it already uses. The v2
context bridge no longer falls back to reading the removed v1 mount.

* test: fix CI checks for the OpenCode v2-only engine

- ci-tests no longer runs the deleted v1 title-recovery test.
- The outbound-access manifest drops mcp.slack.com: only the removed v1
  MCP sign-in modal referenced it on desktop.
- thread-continues-after-restart reads a v2 user turn from its text field.
- workspace-write-outcome creates its conversations on the witness model,
  closes a model list that opens while loading, and no longer expects the
  destination label that v2 tool rows do not show yet.

* test(evals): read every OpenCode v2 context entry in the restart journey

* fix(den-gateway): do not proxy host-token runtime-config routes

Den's provider materialization reaches the worker the same way its
existing PATCH /runtime-config/providers does; the gateway must not
inject the host token for members on these routes.

* test(smoke): assert startup readiness without deferred vision judgments
2026-10-27 07:57:07 -07:00
ben 810bd6e37f fix(engine): migrate to v2 without a rollout flag (#6358)
* fix(engine): migrate to v2 without a rollout flag

* fix(engine): preserve externally supplied engine ownership

* test(engine): prove default migration preserves a real v1 chat

* test(engine): compare independent MCP registrations without incidental order
2026-10-22 15:42:21 -07:00
ben 60c6c3fc39 feat(engine): new desktop versions move everyone to OpenCode v2 in the background (#6350)
- Desktop starts its local server with engineAutoUpgrade on: installs still on
  v1 copy their chats with a backup and switch when idle, signed in or not.
  A pinned engine (OPENWORK_ENGINE_V2_PREVIEW / OPENWORK_ENGINE_AUTO_UPGRADE,
  used by test harnesses and support) keeps today's behavior.
- engineV2ForceUpgrade now defaults to on and is the off switch: kill switch,
  org/member override or Helm lock tells desktops to stop and returns
  force-moved installs to v1. Signed-out desktops read it from /v1/features.
- A person's explicit switch back to v1 (manual, with a recorded time) sticks;
  installs that never chose are moved.
- The automation runner applies the engine policy in the background, so a
  local server that is still starting no longer fails the work poll
  ('runner polling failed: OpenWork engine policy service unavailable').
2026-10-21 21:31:37 -07:00
ben 01168ad307 chore(features): fold and retire Workbot, headless and other rollout switches (#6261)
Signed-off-by: Benjamin Shafii <ben@prologe.io>
2026-10-20 15:56:09 -07:00
ben 2e72bbf56f feat(engine): manage v2 upgrades with one org policy (#6119)
* feat(engine): manage automatic v2 upgrades with one org policy

* fix(engine): recover failed forced fresh starts safely

* fix(engine): retire fresh-start errors after a successful retry
2026-10-17 14:27:52 -07:00
ben 5a50d147ea feat(desktop): sync v2 provider models live from Den (#6111)
* feat(features): declare live provider sync rollout off

* feat(den): stream member inventory revisions behind live sync

* feat(plugin): reconcile provider inventory over shared live streams

* feat(app): consume live v2 provider events without sync pokes

* test(providers): prove native reload and document ownership boundaries

* feat(server): give live v2 gateway state one plugin owner

* test(evals): prove live Den changes reach an open model picker

* fix(den): scope live revisions to caller-visible inventory

* fix(providers): secure shared live sync and prove lifecycle recovery

* fix(providers): keep Den bearer outside the engine and repair CI

* fix(providers): isolate reusable keys and shared subscription credentials
2026-10-17 07:53:50 -07:00
Jalil fcf44f8fe9 fix(engine): migrate full chat history in resumable stages (#6081)
* fix(engine): migrate full chat history in resumable stages

Signed-off-by: Jalil <reachjalil@gmail.com>

* refactor(engine): focus staged copies on new migrations

Signed-off-by: Jalil <reachjalil@gmail.com>

---------

Signed-off-by: Jalil <reachjalil@gmail.com>
2026-10-16 21:58:51 +00:00
ben a806557059 fix(app): stop engine-switch request storms; guide chat migration (#5506)
* fix(app): stop engine-switch request storms and guide chat migration

Switching chat engines (and migrating v1 history, which keeps session ids)
left the app polling the engine it had moved away from, and the two engines'
pollers fought over run state that is keyed by workspace and session only.

What a desktop showed: ~9 status reads/s for 40 minutes, 503s at 4-5/s from
a stopped v2 engine, and a loop that reloaded a running chat's whole
transcript (two ~400 KB pages plus artifact resolution) every ~270 ms.

Session sync (apps/app):
- seedSessionStatus adopts a live run only into syncs of the engine the
  status was read from. A v1 sync used to adopt a v2 run, read v1 status
  (which cannot list it), settle it idle, invalidate the transcript, and
  adopt it again from the refetch.
- Ensuring a sync for one engine disposes released syncs of the other
  engine for that workspace instead of letting retained sessions keep them
  polling for 10+ minutes (re-retained forever via shared activity records).
- A reconnect reconcile no longer settles the whole workspace's records
  while another engine's sync is in use.
- Failed status reads keep the 250 ms cadence until the read is degraded
  (3 failures), then back off to at most 15 s.

Server (apps/server):
- The v2 pending-request list skips one conversation the engine cannot
  read (e.g. moved into a deleted folder) instead of failing every call
  with 500 "Conversation could not be read".
- Task recovery reads only the session's own forms, backs off records whose
  observation keeps failing, drops expired watches, and skips records for a
  stopped engine.
- New GET /experimental/engine-v2-preview/activity (counts only). Migration
  answers 409 engine_migration_active_sessions while v1 tasks run unless
  allowActiveSessions is set; engine switches during a migration answer
  409 engine_migration_running instead of a 500.
- Migration status reports phase and startedAt.

Migration UX (apps/app):
- One app-wide owner (shell/engine-migration.tsx) for the switch check,
  migration consent, and progress, shared by the palette and settings.
- Switching away from an engine with running tasks asks first.
- Consent names running v1 tasks and requires "Migrate anyway".
- A modal shows progress (indeterminate until copying starts, then a
  count and elapsed time) with "Continue using OpenWork", which leaves a
  banner; completion offers "Switch to OpenCode v2"; failure offers
  "Try again".

Signed-off-by: Benjamin Shafii <ben@prologe.io>

* test(evals): find v2 routing spec model rows by data-model-key

Model picker rows became native context-menu triggers in the shared picker,
so their data-slot is no longer command-item and the spec's picker step
timed out with no rows on dev as well.

Signed-off-by: Benjamin Shafii <ben@prologe.io>

---------

Signed-off-by: Benjamin Shafii <ben@prologe.io>
2026-09-30 22:16:43 -07:00
ben 18bae4bd17 feat(desktop): switch OpenCode engines and migrate v1 chats (#5319)
* feat(desktop): switch OpenCode engines and migrate v1 chats

* test(desktop): wait for engine inventory before creating a task

* fix(connect): inspect and repair the selected OpenCode engine

* fix(sessions): hide unavailable v2 archive controls

* test(sessions): record archive regression evidence
2026-09-24 12:59:33 -07:00