Repository navigation
feat(conn-server): commit effects with their command in an outbox - #261
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]>
…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
added a commit
that referenced
this pull request
Nov 23, 2026
… and replay follow T3 - Receipts name their owner (owner_kind thread or project, owner_id), chosen by command type as T3's commandThreadId: a fork's and a merge-back's is the target thread. Migration 5 names older receipts' owners from their own events; one nothing proves is kept and refused, never run twice. A project receipt never answers for a thread. - A replayed queue.resume or queued-run.start checks the queue again and answers the recorded sequence. A command that writes nothing answers its own thread's latest sequence. Thread setters record their event even when nothing changes (a re-pin keeps updatedAt). - thread.auto-settle refuses a thread set active or changed after its snapshot, then settles with the archive guard first. - thread.visit keeps the later visit, compared as times, and records thread.visit-recorded. - The first message after a merge-back names its instance on the handoff and transfer events. - The receipts' high-water mark reads an index. Opening the engine off the runtime thread is #261's. - thread-cli-diff excuses only the expired question after its session's release, row by row. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This was referenced Nov 23, 2026
…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]>
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]>
… 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]>
nckrtl
added a commit
that referenced
this pull request
Nov 23, 2026
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]>
nckrtl
added a commit
that referenced
this pull request
Nov 24, 2026
…#260) * fix(conn-server): thread.unsettle restores the Active anchor an undone settle cleared The engine ignored restoreUnsettledAt, so undoing a settle moved the thread to the top of Active. It now sets unsettledAt to the given time, to null for null, and refuses a time that does not parse, as T3's Orchestrator does. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(conn-server): thread.unsettle follows T3 for archived threads, retries and wire times - An archived thread refuses thread.unsettle before its anchor is read. - The anchor parses as T3's DateTime.make: a time without a zone is UTC. - A fresh command on a thread already active records thread.unsettled and keeps the anchor and updatedAt; a retry of the same command id records nothing. The shell row keeps its updatedAt, as T3's projection does. - The event envelope carries providerInstanceId, from the updated thread. - Wire times outside years 0000-9999 get toISOString's signed six-digit year, so T3's client decoder reads them. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(conn-server): thread commands follow T3's guards, times, receipts and envelopes - Command times (restoreUnsettledAt, snoozedUntil, visitedAt) parse as T3's DateTime.make: a port of V8's Date.parse, legacy forms included, with Effect's zone rule and the server's zone for local times. Checked against T3's own answers for 1683 strings in five zones (gen-date-cases.mjs). - An archived thread refuses settle, auto-settle, unsettle, snooze, unsnooze, auto-settle set, pin, unpin and both reorders first, as T3. - The thread's updatedAt follows T3's ProjectionStore: a thread event writes its payload's, every other event its own time, in the row and the stored thread (list generated from T3). Pin and settle keep updatedAt as T3 does. - The event envelope names providerInstanceId wherever T3's does, mapped flow by flow; thread-cli-diff compares it with the T3 server. - Command receipts are kept for good and record refusals: a retry gets the recorded refusal, a receipt answers only for its own thread, and an old retry after an undo changes nothing (T3's receipt tests, ported). Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(conn-server): receipts answer for their owner; auto-settle, visit and replay follow T3 - Receipts name their owner (owner_kind thread or project, owner_id), chosen by command type as T3's commandThreadId: a fork's and a merge-back's is the target thread. Migration 5 names older receipts' owners from their own events; one nothing proves is kept and refused, never run twice. A project receipt never answers for a thread. - A replayed queue.resume or queued-run.start checks the queue again and answers the recorded sequence. A command that writes nothing answers its own thread's latest sequence. Thread setters record their event even when nothing changes (a re-pin keeps updatedAt). - thread.auto-settle refuses a thread set active or changed after its snapshot, then settles with the archive guard first. - thread.visit keeps the later visit, compared as times, and records thread.visit-recorded. - The first message after a merge-back names its instance on the handoff and transfer events. - The receipts' high-water mark reads an index. Opening the engine off the runtime thread is #261's. - thread-cli-diff excuses only the expired question after its session's release, row by row. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(conn-server): a settle for a stale run is refused, as T3 thread.settle with an expectedLatestRunId that is not the thread's latest run (every run by ordinal, queued ones too; or no run at all) is refused with T3's "The thread received another run before settlement." instead of returning quietly. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(conn-server): receipt owners from their own execution; project and queue admission as T3 - Migration 5 names an older receipt's owner only from its own execution: the event at the receipt's sequence must carry its command id, so an older run of a reused id (main pruned receipts, not events) never decides it. A delegation's parent is the thread whose task row names the created child. The upgrade pages receipts and commits columns, owners and the version in one transaction. - The queue start holds the queue when the run's provider is off for its project (T3's startNextQueuedRun), so a replayed queue.resume starts nothing then. - A project write reads its receipt in its own transaction and records its project and command type: a thread command's id, or another project's or command's, is refused with T3's text and the receipt kept. - thread.visit reads the stored read mark as a command time, so main's stored forms compare correctly. - thread-cli-diff excuses the expired question only when it pairs with exactly one T3 question for the same native request, thread, run and request. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(conn-server): legacy receipts name no owner; project receipts and queue start as T3 - Migration 5 only adds the receipt columns (one transaction). A receipt from before keeps no owner, so a retry across the upgrade is refused, never run twice. The evidence-based backfill and its tests are gone. - A project command takes its id inside its write (insert-if-absent) and validates a receipt another write holds there; a receipt is never replaced. A refusal from planning is recorded under the project and T3's command type (project.update is project.meta.update) and replayed; folder and store failures stay retryable. A replay with no project row is T3's typed read error. - The queue start resolves the run's effective selection (a message that follows the conversation takes the thread's) and checks it with T3's queue rule: only an explicit project override or a machine entry disables. The server reads it from the settings under the lock, without a copy. - thread-cli-diff binds its one exception to the thread and run of the scenario's asked step, with the pending row before its terminal row. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(conn-server): a command id keeps its outcome across a reopen Moved from fix/conn-server-rejected-receipts (4bbd2ac, audit 1.6 and 1.7): after the store reopens, a refused id is refused again though its precondition now holds, an accepted archive replays with its original sequence after an undo and 4,400 later writes, and the same command under a new id runs. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(conn-server): queued runs follow the thread, offline folders retry, monograms count graphemes - An unpinned scheduled dispatch sets followsThreadSelection, and the queue start recognises Conn's delegated-completion wakes by their id, so both run on the thread's current selection, as T3's followsCurrentConversation. - project.create checks the folder before it plans, as T3's ProjectService.create: an offline folder another project holds is a retryable ProjectOperationError, not a recorded conflict. - A monogram counts extended grapheme clusters, as T3's Intl.Segmenter. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(conn-server): settle waits for queued messages, queue start moves the thread, wakes reach their conversation - thread.settle refuses a thread with a queued user message, as T3's settle; queued server, agent or scheduled messages do not block it. - Starting a queued run on another selection moves the thread to it in the same transaction, as T3's startNextQueuedRun, so an unpinned scheduled run queued behind it starts on the same model. - The runner recognises delegated-completion wakes with the queue's is_delegated_completion, so a fresh scheduled run's result reaches the conversation that delegated it. Co-Authored-By: Claude Opus 5.5 <[email protected]> * fix(conn-server): settling cancels queued automatic runs A settle refused a queued user message but left a queued scheduled, agent or server run in place, so a later queue resume still started it. The settle now cancels those runs before it writes thread.settled, as T3's settle cancels its automatic cohort. Co-Authored-By: Claude Opus 5.5 <[email protected]> * test(conn-server): compare date parsing from 1970 on, where system tzdata matches ICU Linux tzdata merges backzone local mean times (Amsterdam reads Brussels), so pre-1970 cases differ from the TypeScript server's ICU values on the CI runner, not in this code. Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- 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
This was referenced Nov 24, 2026
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.
If a client's socket closed while Conn Server committed a command, the aborted handler dropped the command's effects: they started only after the commit returned. A thread launch then kept its message and receipt, but the provider start was lost, and the run stayed
startingforever.Fix: port T3's effect outbox. Effects are rows written in the same transaction as their command, and one worker runs them later.
outbox.rs: theeffect_outboxtable, claim, settle and prune (T3EffectOutbox.ts). EveryEffectvariant is serialized under T3's effect type name where T3 has one.EventSink):dispatch_claimed,project_write, the run's end (end_run), the checkpoint capture, and the restart inopen.effect_worker.rs(T3EffectWorker.ts): claims rows in commit order, one running row per thread lane, and settles each one. It wakes on commit and polls every 30 s. An hourly loop prunes rows settled more than 7 days ago.effect_lanes,ReservedEffect) are gone.Gate fixes (two astra-high gates on 1598b2d), all in
conn-engine:engine_epochlease inmetaat open. Every write checks the lease and the drop flag inside its own transaction:Tx::commit, claim, settle and prune. An effect already running when its engine drops now fails its next write instead of committing into the new engine's store with a stale sequence. The drop flag at claim time and before execution stays. T3 gets the same from the scope that owns its workers and the database.retryWhileLocked, a settlement retries every 100 ms while the store is locked. Any other failure settles the rowfailed(T3'sterminalizeClaim), so the lane frees and the effect does not run again.EventSinkpublishes after its transaction). An aborted caller can no longer hide a committed change from connected clients.Second gate fixes (BLOCK on 2b73e02), in
conn-engine, plusserve.rsinconn-server. Each test failed on 2b73e02 first:advance_rollback(from, to): one write checks the lease and the expected phase. The provider is contacted only when exactly one row moved; otherwise the rollback stops (Fenced) and writes nothing. A retry by the same run goes on from its ownprovider.a_replaced_engine_cannot_move_a_rollback_on: the replaced store moves nothing, the owner moves once, and a second move fromadmittedmoves nothing.NOT_OWNER, andopenaborts.a_stale_open_cancels_nothingrunninga_failed_settlement_frees_the_thread_without_running_the_effect_again, now with 1 and with 2 injected failuresSqliteEngine::startopens, migrates (including the sequence read) and recovers onspawn_blocking. The worker starts after recovery commits.serve.rsuses it, so #260 can drop this item.opening_the_engine_does_not_block_the_runtime: a second connection holds the write lock during the open, and a ticker task ran 0 ticks with the old inline open.Third gate fixes (BLOCK on 8c27e3a), in
conn-engine. Each test failed on 8c27e3a first:Ok(false)from theprovider → provider_donemove returnsFenced. After it takes the workspace lock, the rollback checks ownership again before it restores files or deletes refs.a_replaced_engine_s_rollback_touches_no_files: the engine is replaced while the provider rollback is in flight (the old engine deletedb.txt).start()marks its open abandoned when its future is dropped.take_ownershipreads that flag inside its immediate lease transaction and takes nothing.an_abandoned_start_never_takes_the_lease_of_a_newer_engine: queue start A, drop it, open B, release A (B's next command failed withNOT_OWNER).a_settlement_stops_retrying_once_another_engine_owns_the_store(the injected-fault counter kept falling after the epoch moved).One engine per store (round 4). The fourth gate found two more races between two engines on one store:
Instead of patching a fifth race,
SqliteEngine::opennow makes the production invariant its own. Only one engine may own a store:serveholds the state-directory lock, and T3 is one process.opentakes an exclusive advisory lock on<database>.lock(stdFile::try_lock), before it reads, migrates or recovers the store. Understart, that runs on the blocking pool. The engine holds the lock until it drops.STORE_IN_USEand touches nothing.Both round-4 scenarios are unreachable under the lock. A second engine cannot open while the first lives. A cancelled start now ends in "store in use", or in a dropped engine that frees the lock, never in two owners. In the server, an engine drops only as its process ends, so none of its tasks outlive it.
Tests and overlap. Tests that run two engines on one store open the second only after dropping the first. All of the engine's tests already did. The lock found none that overlapped, and none was removed. After a drop, a test's lingering task is still fenced by the epoch, which
a_replaced_engine_s_*cover. The store-level tests that use twoStorevalues on one file test that fencing directly, and they stay. New:a_second_engine_on_a_live_store_is_refused: "store in use"; the epoch and events are unchanged, and the first engine goes on.a_store_opens_again_after_its_engine_drops_and_recovers: the reopen continues the cut turn.Fifth gate fixes (on 5305e0d), in
conn-engine. Each test failed on 5305e0d first:a_store_opened_through_a_symlink_is_refusedopens both spellings in one process, each first in turn (the second open succeeded)Arc, andInnerkeeps aWeak. The rollback upgrades it after it takes the workspace lock and holds it until files and refs are done. A failed upgrade means the engine is gone, so the rollback stops (Fenced) and touches nothing.a_store_stays_locked_while_a_dropped_engine_restores_files: the engine drops during a paused restore; a reopen getsSTORE_IN_USE, and succeeds once the restore ends (the reopen succeeded at once)The gate suggested moving the lock into
Inner. That would never release it: a session's event pump holdsArc<Inner>andInnerholds the session that feeds the pump, soInnerlives until the session closes. Every restart test drops an engine with a turn in flight and reopens it. Only the restore holds the lock now. The provider half of a rollback stays fenced by the epoch andadvance_rollback, as before (a_replaced_engine_s_rollback_touches_no_filesstill passes).Known deviations from T3
succeeded. For the same reason, a row whose settlement write fails is settledfailed, where T3 requeues a replay-safe effect. Porting T3's retries is a planned follow-up.AbandonStartandRemoteTaskChangedrun at once: T3 has no such effects.pending_rollbacksinto the outbox row.Tests (each gate probe fails on 1598b2d)
a_dropped_engine_s_running_effect_writes_nothinganda_replaced_engine_s_running_effect_writes_nothing(T3: "does not reclaim a running effect after its process-local lease expires"). Before the fix, the old task committed its title and the new engine's next command failed withUNIQUE constraint failed: events.seq.a_failed_settlement_frees_the_thread_without_running_the_effect_again(T3: "terminalizes a process-bound claim when success settlement fails") anda_settlement_waits_out_a_locked_store(T3: "keeps requeueing a failed claim while the database is locked"; a second connection holds the write lock).an_aborted_archive_still_closes_the_threadnow observes a shell subscriber: it gets the archive at seq 3.a_read_gets_in_between_prune_batches, and the outbox store tests (T3FoundationPersistence.test.ts) now include the lease.lane_order_is_commit_ordernow waits on the host's event instead of a 50 ms sleep, which flaked under load.Checks (Mac, at 5305e0d):
cargo fmt --checkpasses.-D warningspasses for conn-engine and conn-server.cargo test --locked --workspace --no-fail-fastpasses: 50 test binaries, none failed.tools/check.shwas not run locally: the disk was under 60 GB free. CI runs all its groups on Linux.Note for the rebase onto #262:
an_aborted_launch_still_starts_its_committed_runhangs there. Inengine_tests.rs, pause on"A"instead of"A:initial-message", and update the doc comment to "…while its thread and first message commit…". With that, all 228 engine tests pass.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.Follow-up: a replaced engine whose blocking database task outlives its cancellation can still insert a refusal receipt after it lost ownership (
store.rs:583), and a retry on the new engine replays that refusal.🤖 Generated with Claude Code