Skip to content

feat(wsl-mover): rewrite a moved project's orchestration history on the desktop (D1b-7e) - #31232

Closed
nwparker wants to merge 2 commits into
nwparker/wsl-mover-d1b-7d-renderer-storesfrom
nwparker/wsl-mover-d1b-7e-orchestration-history
Closed

nwparker wants to merge 2 commits into
nwparker/wsl-mover-d1b-7d-renderer-storesfrom
nwparker/wsl-mover-d1b-7e-orchestration-history

Conversation

@nwparker

@nwparker nwparker commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​344 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​344
Prod 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​269 $\color{#cf222e}{\Huge{\mathbf{−}}}$​24 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​245

Stacked on #29827 (D1b-7d). For owner review only — please do not merge. Dark-gated behind the internal WSL hosts gate; nothing runs with the gate closed.

ELI5

When a user moves a project from "this Windows computer, reaching into WSL" to "the WSL host itself", the project's folders get new names (a Windows \\wsl.localhost\Ubuntu\... path becomes /home/...). Orca's record of past agent work ("this worker ran in that worktree") still pointed at the old name. This PR updates those records once, after the move commits, so past work points at where the project lives now. Everything else in that history is left exactly as it was.

What Changed

Before: after a move, the desktop's orchestration history (orchestration.db) kept listing finished workers against the project's old Windows-side worktree id. That id belongs to a hidden, retained copy of the project, so the history pointed at something the user can no longer open.

After: once the move reaches destination-committed, a new desktop rewrite store, orchestration-history, gives every settled local worker dispatch in a moved project, and its worker-terminal row, the host's worktree id. Nothing else changes.

Mechanism (it follows the 7b/7c store pattern exactly):

  • Registration. registerWslMoveOrchestrationHistoryStore(path) registers {id: 'orchestration-history', side: 'main', run, flush}. It is called at startup next to the 7c main stores. WSL_MOVE_DESKTOP_REWRITE_REGISTRY_COMPLETE stays false (7f flips it).
  • What run does.
    • Opens orchestration.db on its own connection. It never creates or migrates the file, so it can run at startup before the runtime exists.
    • In one BEGIN IMMEDIATE transaction, it rewrites worker_dispatches.worktree_id and worker_terminal_resources.worktree_id. A row is rewritten only if both hold:
      • its repo is one of the move's repos;
      • its path is a UNC path of the moved distro (\\wsl.localhost or \\wsl$).
    • The commit runs with synchronous = FULL, so it is on disk before the ledger entry. flush is therefore a no-op.
  • Rows it leaves alone.
    • Rows on other hosts: SSH, other distros, other repos.
    • Structured (chat) workers. Chats stay on the desktop (decision C).
    • Federated dispatches, and resources owned by a remote attachment.
    • updated_at, so history order does not change.
    • JSON receipts.
  • Live workers in scope. If any worker in scope is still live (starting, ready, start_unknown, stopping, stop_unknown), the store throws. It gets no ledger entry, and a later pass rewrites the row once it settles. That way it never records a half-rewritten project. The move's dispatch gate must refuse the same set, so the set is exported as WSL_MOVE_LIVE_WORKER_STATES. The gate's activeDispatchIds producer is not wired yet; it belongs to the gate/quiesce wiring, not this PR.
  • Idempotent. A rewritten id is no longer a UNC path, so a re-run after a crash finds nothing.
  • Dispositions. SQLITE_TABLE_DISPOSITIONS for orchestration was split per table: two tables are rewrite-desktop and the rest are N/A, each with its reason. The automations and automationRuns notes now say the desktop's copy is left as it is.
  • Small refactor. orchestrationDbFile(userData) is now shared by the runtime and the store.

Disposition table (desktop stores of orchestration, dispatch, automation-run and coordinator history)

Store 7e disposition Why
orchestration.db worker_dispatches.worktree_id Rewritten to host id (settled, non-chat, non-federated rows) Decision 4: rewrite in place; the desktop keeps coordinating. This is the column the worker list, worker show and observation read.
orchestration.db worker_terminal_resources.worktree_id Rewritten to host id (same rules; rows owned by a remote attachment excluded) Feeds COALESCE(w.worktree_id, r.worktree_id) in the worker list; must agree with its dispatch.
worker_terminal_resources.host_scope, dispatch_contexts.host_scope Stays (N/A) A fact about where that process ran, which stays true. The host-scope type has no runtime-host kind.
pane keys (runs.coordinator_pane_key, tasks.created_by_pane_key, dispatch_contexts.*_pane_key, resource pane_key) Stays (N/A) Tab and leaf ids are kept by the move, so pane keys don't change.
remote_dispatch_attachments Stays (N/A) It records what this computer told a remote home as that home's worker. The home reaches this runtime, which doesn't serve the WSL host's ids. Rewriting would publish an id the home can't resolve (wire compatibility).
federated_dispatches, federation_relay_items Stays (N/A) Another host's worktree ids and relayed messages.
worker_dispatches.start_options / effects / residual_resources, mutation_receipts, legacy_*_receipts Stays (N/A) Recorded answers: a replay must return the bytes first answered. Readers only parse and echo them, never resolve a worktree from them.
runs, tasks, coordinator_runs, run_coordinator_handles, messages, deliveries, question_threads, decision_gates, attempt_observation_facts, archives Stays (N/A) Keyed by run, task, dispatch, message or terminal handle; no repo, worktree or path. @worktree: group addresses are resolved to handles at send time.
Structured (chat) worker rows Stays local, read-only (N/A) Decision C: existing chats stay on the desktop and resume under their local id.
automations (profile state) Stays local, unchanged (N/A for 7e) The manifest (D1b-3/D1b-6 dormantState.automations) carries the host's copy, and the host runs it. The desktop scheduler treats the retained copy as owned by the host and only advances nextRunAt (5c-3). Rewriting it could make the desktop resolve it to the host (a double run) and would break undo-if-unchanged, which compares the frozen source digest, automations included.
automationRuns (profile state SQLite) Stays local, unchanged (N/A for 7e) The manifest carries the host's copy (dormantState.automationRuns). The desktop history sits beside its retained automation; an in-flight run in scope blocks the move.
Renderer state / localStorage N/A No persisted orchestration history in the renderer: worker lists are live RPC projections of orchestration.db. orchestration-setup-state.ts is global, already in the localStorage census.
Automation in-memory caches (external manager cache, retained-run reconciler) N/A In memory only; rebuilt on start.

Why

  • Rewrite in place, not move to the host: owner decision 4. The desktop stays the home of its own orchestration runs.
  • Only the indexed worktree columns: they are the only place a reader resolves a worktree. The JSON receipts are idempotency answers, and the pane keys and host scopes are still accurate.
  • Own connection, without the runtime's OrchestrationDb: the startup pass runs before the runtime is constructed. Opening through OrchestrationDb would also migrate and backfill the file as a side effect of a move.
  • Throw on a live row instead of skipping it: skipping would record the store and leave that row on the old id forever. Throwing keeps the ledger honest.
  • Automations left alone: 5c-3 already makes the retained copy inert but still advancing. Touching it is the only way 7e could cause a double run or a lost run.

Linked Issue

Internal WSL mover track (D1b-7e); no public issue.

Visual Proof

N/A: no UI change, and the feature is dark-gated. The visible effect is the worktree id in orca orchestration worker lists after a move, which tests cover.

Testing

  • I manually tested these changes locally (gated feature; covered by real-SQLite tests)
  • Automated tests added/updated

New wsl-move-orchestration-history-rewrite.test.ts (real SQLite, listed in vitest-sqlite-runtime-files.mjs):

  • Scope: the moved repo's \\wsl.localhost and \\wsl$ ids are rewritten. Other repos, other distros, SSH-style paths, chat workers, federated dispatches, remote-attachment resources and null ids are not.
  • Timestamps and JSON are unchanged.
  • Crash after rewrite, before ledger: the re-run changes nothing, and the function returns 0.
  • No move journal: the database file is byte-identical. A move that has not committed changes nothing either.
  • No database: the store is recorded and the file is not created.
  • Live worker in scope: no ledger entry and no change; it is rewritten after it settles.
  • Older schemas: without the resource or attachment tables, dispatches are still rewritten. Without a worktree_id column, the store is recorded and nothing changes.

automation-wsl-move-refusal.test.ts gets one new case. It runs the real desktop rewrite pass at destination-committed: the 7c main stores, plus 7e with an in-scope dispatch that does get rewritten. It then checks three things:

  • the local automation is byte-identical;
  • a scheduler tick creates no run;
  • nextRunAt advances to the next occurrence, so nothing double-runs and nothing is dropped.

Commands run:

  • pnpm tc
  • pnpm test on src/main/persistence/moving-wsl-projects, src/shared/wsl-move, src/main/startup/main-process-ready* and src/main/automations (65 files, 588 tests)
  • pnpm run check:code-quality:changed
  • check-focus-read-ratchet and check-layout-writer-ratchets: both OK, no baseline changes

An adversarial review pass was run. It found one MEDIUM: a skipped live row would never be revisited. That is fixed by making the store throw instead. The LOWs fixed in the same pass:

  • federated rows are now excluded;
  • the NOT IN against a nullable column became NOT EXISTS;
  • the busy timeout is shorter;
  • the tests are stronger.

Review

Shared paths touched:

  • dispatch history (orchestration.db rewrite, new store);
  • src/main/runtime/workspaces/persisted-surfaces/automation-operations.ts (path helper only);
  • src/main/startup/main-process-ready-foundation.ts (store registration);
  • the shared WSL-move disposition tables;
  • the automation tests.

No automation runtime code changed.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: no new inputs. Only parameterised SQL; the table names in the SQL are constants.
  • Cross-platform: the move is Windows-only. The path rewrite is the existing UNC→Linux rewriter.
  • SSH: SSH rows never match (they have no UNC path of the distro).
  • Folder workspaces: their ids carry no path, so they are unchanged.
  • Backwards compatibility: older schemas are read as they stand, and nothing is published to peers.
  • Performance: a one-shot scan of two bounded tables, only for a committed move.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

🤖 Generated with Claude Code

@nwparker
nwparker force-pushed the nwparker/wsl-mover-d1b-7d-renderer-stores branch from 589c670 to 16fbe29 Compare October 20, 2026 23:17
@nwparker
nwparker requested a review from brennanb2025 as a October 20, 2026 23:17
@nwparker
nwparker force-pushed the nwparker/wsl-mover-d1b-7e-orchestration-history branch from e07ff55 to 033b672 Compare October 20, 2026 23:17
@nwparker
nwparker force-pushed the nwparker/wsl-mover-d1b-7d-renderer-stores branch from 16fbe29 to d82cf50 Compare October 21, 2026 00:46
@nwparker
nwparker force-pushed the nwparker/wsl-mover-d1b-7e-orchestration-history branch from 033b672 to b8bf5c6 Compare October 21, 2026 00:46
nwparker and others added 2 commits October 20, 2026 22:10
…he desktop (D1b-7e)

Settled local worker dispatches and their worker-terminal rows in a moved
project take the WSL host's worktree id, in one ledgered, idempotent store.
Chat workers, live rows, federated attachments and JSON receipts stay as
written; automations keep their unchanged local copy (the scheduler only
advances it). Per-table dispositions for orchestration.db.

Co-Authored-By: Claude <[email protected]>
…is live; skip federated rows (D1b-7e review)

Co-Authored-By: Claude <[email protected]>
@nwparker

Copy link
Copy Markdown
Contributor Author

Contained in the dark landing PR #34059 (its head commit is an ancestor of the landing branch). Closing in favour of it; branch kept.

@nwparker nwparker closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant