Repository navigation
feat(conn-server): reconcile the effect outbox after a process loss, as T3 - #268
Merged
Merged
Conversation
Effects now commit in the same transaction as their command, as T3's EventSink and EffectOutbox do, and one worker claims and runs them (T3's EffectWorker). A closed socket that aborts a handler after the commit can no longer lose a committed provider start. The in-memory effect lanes are gone. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The restart tests open a second engine on the store while the first engine's tasks still run. The first engine's worker could still claim the new engine's rows, such as the continuation's turn start, and write events with its own stale sequence counter: "UNIQUE constraint failed: events.seq" (1 in 30 runs on Linux, 9 in 120 under load). Dropping the engine now stops its worker and prune loop. The claim checks the flag while it holds the write lock, and the worker checks it again before it runs what it claimed, so a claim in flight at the drop takes nothing the next engine wrote. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 23, 2026
…h on commit Three gate findings on the effect outbox: - A dropped or replaced engine still wrote: an effect already running committed into the next engine's store with a stale sequence. The engine now takes an engine_epoch lease at open, and every write checks the lease and the drop flag inside its own transaction (Tx::commit, claim, settle, prune). The drop flag at claim and before execution stays. - One failed settlement write held the thread's lane until a restart. As T3's worker does, a settlement retries while the store is locked (100 ms), and any other failure settles the row failed instead, so the lane frees without running the effect again. - A commit published its sequence only when its caller lived, so an aborted caller hid the change from connected clients. Tx::commit now sends it, for every command path, as T3's EventSink publishes after its transaction. Also: pruning lets the store go between 500-row batches, and the lane order test waits on the host's event instead of a 50 ms sleep. Co-Authored-By: Claude Opus 5.5 <[email protected]>
An outbox row outlives a server update. Fields a later build adds to CleanupHtmlAttachments take #[serde(default)], so a row stored before them still decodes (audit 6.7 adds one). Co-Authored-By: Claude Opus 5.5 <[email protected]>
…runtime Four gate findings on the outbox: - A replaced engine could send a rollback twice: its phase update checked only the command id and took zero changed rows as success. The move from admitted to provider is now one write that checks the engine's lease and the expected phase, and the provider is contacted only when exactly one row moved. Otherwise the rollback stops and writes nothing. - Overlapping opens: engine A's late startup cancel could cancel engine B's committed start. The ownership check and the cancel are one immediate transaction; a stale open gets NOT_OWNER and aborts. - Two failed settlement writes left a row running. The settlement is kept and tried again with backoff (100 ms, doubling, 30 s at most) for as long as the engine owns the store; the effect ran once. - The server opened the store, ran its migrations and recovery on the runtime thread. SqliteEngine::start opens on the blocking pool; the worker starts once recovery committed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl
force-pushed
the
feat/conn-server-effect-outbox-reconcile
branch
from
November 23, 2026 19:05
3934265 to
bf696e8
Compare
…t, and settlement Three gate findings (round 3): - A rollback fenced after the provider answered still restored files and deleted refs. Ok(false) from the provider_done move now stops it, and the rollback checks ownership again after it takes the workspace lock, before it touches Git. - A start the server gave up on still ran on the blocking pool and took the lease after a newer engine opened. start() marks the open abandoned when its future drops; take_ownership reads that flag under the lease's write lock and takes nothing. - A settlement kept retrying after another engine took the store. After any failed write, both retry paths read the durable epoch and stop on a mismatch; the write keeps its epoch predicate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl
force-pushed
the
feat/conn-server-effect-outbox-reconcile
branch
from
November 23, 2026 20:22
bf696e8 to
4982214
Compare
Four gate rounds found races between two engines on one store. In production only one may exist: serve holds the state-directory lock, and T3 is one process. SqliteEngine::open now makes that the engine's own invariant: it takes an exclusive advisory lock on <database>.lock before it reads, migrates or recovers the store (on the blocking pool under start), and holds it until the engine drops. A second open, in this process or another, gets STORE_IN_USE and touches nothing. A child process forked elsewhere in the process keeps a copy of the lock's file until its exec, so an open retries the lock for up to 2 s before it reports the store in use. The epoch fencing stays as defence in depth. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl
force-pushed
the
feat/conn-server-effect-outbox-reconcile
branch
from
November 23, 2026 21:13
4982214 to
76c6734
Compare
… restore A symlink to a live store took its own lock file, so a second engine opened beside the first. The lock path now comes from the resolved database path, a file not created yet through its folder and any symlink naming it. A dropped engine released the lock while its rollback still restored files. The rollback now upgrades the engine's lock before it touches the workspace and holds it until files and refs are done; a failed upgrade fences it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…as T3 A restart now follows T3's reconcileAfterProcessLoss. Process-bound effects (turn start, steer, Stop, answers, model changes) are cancelled, and the restart decides again from the stored runs. Replay-safe effects (capture, session close, cleanups, titles, host notices) run again. A rollback row is still cancelled and enqueued again from pending_rollbacks; the next change folds that journal into the row. A running run with no provider turn for its attempt never got its prompt, so the restart sends it again (T3's rewindUnacceptedRuns) instead of asking the agent to continue. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Seven gate findings on the process-loss reconcile, and audit 5.1: - A prompt a provider never confirmed was sent again on its own. Codex gets turn/start before its reply is stored, and our Claude adapter reports its turn before a cold SDK host has the prompt, so neither a missing nor a present provider-turn row proves anything. A start now counts as accepted only when its provider-turn.start row settled (start_turn returned); a store without start rows falls back to provider turns. As T3's reconcileProjection: a user's prompt waits at the head of the held queue, unattended work (scheduled, MCP) is sent again at most 3 times and never to an archived, deleted, settled or snoozed thread, and anything else is cancelled. - A replayed checkpoint capture woke the parent again. The capture ends the run, and wakes its parent, only when it finds the run waiting. - A replayed thread.closed ran before the server's scheduled tasks were ready. EngineConfig::hold_effects keeps the worker stopped until the server calls start_effects after its host services. - A rollback row was cancelled and enqueued again at the lane's end, so later work overtook it. It now stays in place: the journal moves it on from its phase, and a row whose entry is gone (result committed) settles. - A dropped worker settling a replayed row: already fenced by the engine lease (#261); a store test now proves it. - Audit 5.1: nothing read continueThreadsAfterServerUpdate, so a restart continued cut turns after the user opted out. The server resolves it per project (an override wins either way, as T3's resolveProjectSettings) into EngineConfig::restart_policy, and the restart checks it before a continuation or an unattended resend. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…and Stops Seven gate findings on the process-loss recovery: - A strong provider turn of the run's attempt (Codex's turn/started, Claude's first usage) now counts as acceptance next to a settled start row. Claude's weak cold-start turn still proves nothing. - A child with a checkpoint scope that was interrupted or cancelled got no parent wake: the capture only ended runs it found waiting. The first capture to commit now writes the run's end for every outcome and marks its row; a replay of that row finds the mark. - A restart continuation cut off by a second crash was cancelled. It is now sent again under the project policy and the chain limit. - A resend now skips a run with a stored Stop, on itself or on the task that delegated its thread, and a run with a waiting request. - Queued prompts behind a cut run are held before the continuation decision, so an opted-out project no longer starts them. - Dead sessions are stopped, and the attempt and node reset, on the hold and resend paths too. - EngineHost::thread_closed returns a future the effect awaits, so a replayed delete finishes its schedule cleanup before it settles. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… families Nine gate findings on the restart recovery: - A continuation sent again keeps its run id; its claimed resends now count toward the chain limit, so crash after crash ends at 3. - A Stop stored on the run or its delegating task now blocks the continuation too, not only the resend. - A capture row from an older build has no mark: a terminal run whose checkpoint committed counts as already ended, so a replay wakes the parent once. - A run recovery cancels without a continuation (an opted-out project) ends for its parent: the family completion commits then. - Sessions are stopped and the queue held before every exit, the resend and the waiting capture included. - A store without start rows takes only a provider-confirmed turn as acceptance, not Claude's weak cold-start turn. - Terminal teardown runs on the blocking pool. thread_closed returns its error; the close tries again with T3's backoff (5 attempts) and then settles its row failed with that error. Device release has a 30 s deadline. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…reports device errors A replayed checkpoint capture started a prompt queued behind an interrupted run, in a project that opted out of restart continuation: only threads with an active run had their queue held. The start now holds the queue of every thread with an unfinished run, queued-only ones included, before any replayed effect can run. Devices::cleanup_thread dropped close errors, so a reconnecting SSH device host reported success and the close was never retried. It now returns the first failure after trying every session. The host's thread close runs the terminal close, the scheduled-task delete and the device release each on its own, so a device timeout no longer skips the schedules, and returns their errors together. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nckrtl
force-pushed
the
feat/conn-server-effect-outbox-reconcile
branch
from
November 23, 2026 22:29
76c6734 to
274edac
Compare
…tions A Claude background-task notification queued behind a run that waits for its checkpoint lost its buffered output with the old process. Recovery now cancels it before holding the rest of the queue, as ProviderRuntimeRecoveryService does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oval A queued run never started, so it owns no runtime request. Cancelling a buffered notification at restart cancelled the active run's pending approval too, and recovery then continued that run without it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # apps/conn-server/crates/conn-engine/src/commands.rs # apps/conn-server/crates/conn-engine/src/engine.rs # apps/conn-server/crates/conn-engine/src/engine_tests.rs # apps/conn-server/crates/conn-engine/src/lib.rs # apps/conn-server/crates/conn-engine/src/projects.rs
…into HEAD # Conflicts: # apps/conn-server/crates/conn-engine/src/engine.rs # apps/conn-server/crates/conn-engine/src/restart.rs # apps/conn-server/crates/conn-engine/src/store.rs # apps/conn-server/crates/conn-server/src/host.rs # apps/conn-server/crates/conn-server/src/serve.rs # apps/conn-server/crates/conn-server/src/settings.rs
…estart; old settle closes decode - A settle close returns before its script runs, so a restart could requeue the close and start the script again. The engine now records, durably, which settlement's script started (settle_scripts), and run_settle_script starts nothing for a settlement it already recorded. - A settle close stored by the earlier #268 build holds "reason": "settled". It now decodes as ThreadClose::SettledUnnamed: the host closes the thread's terminals for its current settlement and runs no script, since nothing shows whether it ran. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #261. After a crash or restart, Conn Server cancelled every unsettled outbox row, as it lost in-memory effects before. T3 instead splits them by whether they can safely run twice, and decides from evidence whether the provider took a prompt.
Change: port T3's
reconcileAfterProcessLossand its recovery (ProviderRuntimeRecoveryService.reconcileProjection). All of it is inconn-engine, except the settings resolution inconn-server.PROCESS_BOUND_EFFECT_TYPES).restart.rsthen decides again from the stored runs.pendingand run again, in place: session close, checkpoint capture, title, HTML attachment cleanup, thread closed, remote task changed, and rollback. Awaitingrun whose capture row is still queued leaves the capture to that row.provider_doneresumes from the stored answer, andproviderfails withROLLBACK_INTERRUPTED_MESSAGE. An unsettled row whose journal entry is gone committed its result already, so it settles. refactor(conn-server): keep the rollback phase in its outbox row #269 moves the phase into the row.provider-turn.startrow settled, which happens afterSession::start_turnreturned. T3 reads a provider turn of the run's attempt. Here a provider turn proves nothing either way: Codex getsturn/startbefore its reply is stored, and our Claude adapter reports its turn about 3.5 s before a cold SDK host has the prompt. A store without start rows (from before the outbox) falls back to T3's provider-turn rule.reconcileProjection):MAX_RESENDS). It is never sent to an archived, deleted, settled or snoozed thread.preparingincluded, is cancelled.continueThreadsAfterServerUpdate(audit 5.1): nothing read it before. conn-server resolves it per project, with an override winning either way, as T3'sresolveProjectSettingsdoes. It passes the result asEngineConfig::restart_policy, and the restart checks it before a continuation or an unattended resend.waiting.EngineConfig::hold_effects, rows wait until the server callsstart_effects, after its scheduled tasks, devices and/mcpare up. A replayedthread.closed(Deleted)then deletes the thread's schedules.recover_runsoff) still cancels every unsettled row.reconcile_after_process_losschecks ownership and writes in one immediate transaction, as feat(conn-server): commit effects with their command in an outbox #261's startup cancel does. A stale open getsNOT_OWNERand aborts.a_stale_open_cancels_nothingcovers it.Second gate fixes (BLOCK on bf696e8bc4), in
conn-engine, plus the host inconn-server. Each test failed on the reviewed head first:RunningConfirmedTurn(the run was held instead of cancelled)progress.runEnded). A replayed row finds the mark.an_interrupted_child_with_a_checkpoint_wakes_its_parent_once(0 wakes)restartContinuationOfRunIdis sent again under the project policy and the chain limit.Continuation(0 starts)run_interrupt_request, or when a request of the run is pending (T3'srestartStopRequested).McpStopped(sent again)an_opted_out_restart_holds_the_queued_prompt(B ran)ready)thread.closed(Deleted)settled before its schedule cleanupEngineHost::thread_closedreturns a future that the effect awaits. The host awaits device cleanup anddelete_for_thread.a_close_settles_after_its_host_cleanup. Proof: with the host future dropped instead of awaited, the row settled during the cleanup.Third gate fixes (BLOCK on 4982214bec), in
conn-engine, plus the host inconn-server. Each test failed before its fix:a_continuation_cut_off_again_and_again_stops_at_the_chain_limit(round 4 stillstarting)may_continueapplies the run and delegating-task Stop checks, as the resend does.a_stopped_run_is_not_continued_after_a_restart(a continuation ran)an_unmarked_capture_row_replayed_wakes_the_parent_once(2 wakes)on_run_end).an_opted_out_child_ends_for_its_parent_at_a_restart(the task stayedrunning)hold_queuea_resend_holds_the_prompt_queued_behind_it(B ran)spawn_blockingand awaits it.LegacyEarlyTurn(not held)stop_sessionsa_restart_finishes_a_run_left_waiting_for_its_checkpointnow checks the session (it stayedready)thread_closedreturns its error. The close retries with T3's backoff, up to 5 attempts, then the worker settles the rowfailedwith the error. Device release has a 30 s overall deadline.a_failed_close_cleanup_is_retried_then_recorded. Proof: with the error dropped, there was no retry and the row settledsucceeded.Fifth gate fixes (on 76c6734b49), in
conn-engine,conn-devicesand the host inconn-server. Each test failed on 76c6734b49 first:restart::recoverno longer holds it itself.a_replayed_capture_does_not_start_a_queued_prompt: A is interrupted with B queued, and the store is copied while A's capture is unsettled. After the restart, B wasstarting; now it staysqueuedand held.cleanup_threaddroppedDevices::closeerrors, and a device timeout skipped deleting the thread's schedulescleanup_threadtries every session and returns the first error. The host runs the terminal close, the schedule delete and the device release each on its own, and returns their errors together, so the close effect retries.a_thread_cleanup_reports_a_device_it_could_not_close(conn-devices): a session on a reconnecting SSH host returned(); now it returns the "reconnecting" error and the session stays. The host's step order has no test seam: conn-server cannot make a device session.Known deviations from T3
Tests. Each gate probe fails on 3934265f9a:
a_prompt_the_provider_never_accepted_is_held_resent_or_cancelledports T3's "recovers $0 work after restart" table. It covers starting, running, running with an early provider turn, scheduled, MCP, MCP capped, MCP snoozed, MCP archived and user archived.a_held_prompt_runs_when_the_user_sends_itanda_restart_holds_an_undelivered_message_for_the_user, which replaces the test that expected an automatic resend.a_replayed_capture_wakes_the_parent_once, where the probe got 2 parent messages.held_effects_wait_for_the_host.a_restart_keeps_a_rollback_ahead_of_later_work. The probe left rollback 1 and detach 2; the restart produced detach 2, then rollback 3.a_replaced_worker_cannot_settle_the_new_claim_of_a_replayed_rowis a store test. It passes on the base too: feat(conn-server): commit effects with their command in an outbox #261's lease covers it.a_project_override_decides_whether_a_restart_continuescovers both directions, global off with the project on, and global on with the project off. The opt-out direction fails on the base. conn-server also hasrestart_policy_follows_the_project_override.Checks (Mac):
-D warningspass; conn-engine passes 252 tests and conn-server 367.cargo test --workspace(see the refactor(conn-server): keep the rollback phase in its outbox row #269 body).tools/check.shwas not run locally: the disk was under 60 GB free. CI runs everything on Linux.Rebase onto #260 (still being fixed; not rebased yet).
engine.rsandprojects.rs. The stack tip (refactor(conn-server): keep the rollback phase in its outbox row #269) also conflicts inrestart.rsandstore.rs.store.rs, keep fix(conn-server): an undone settle keeps the thread's place in Active #260's receipt index and leave the retiredpending_rollbackstable out. Recreating it empty would make refactor(conn-server): keep the rollback phase in its outbox row #269's migration settle unfinished rollbacks as committed.ProviderRuntimeRecoveryServicedoes.Follow-up: a restart after a settlement whose settle script had not started yet skips the script. This matches the TypeScript server, which does not persist settle cleanup.
🤖 Generated with Claude Code