Skip to content

fix(queue): settle interrupted turns before draining - #390

Closed
0xSolarPunk wants to merge 9 commits into
cfal:mainfrom
0xSolarPunk:fix/send-now-turn-settlement
Closed

fix(queue): settle interrupted turns before draining#390
0xSolarPunk wants to merge 9 commits into
cfal:mainfrom
0xSolarPunk:fix/send-now-turn-settlement

Conversation

@0xSolarPunk

@0xSolarPunk 0xSolarPunk commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Before

  • Send now could drain a successor while the interrupted predecessor still awaited terminal settlement.
  • Active-input delivery published successor turn metadata before durable input persistence completed, so concurrent predecessor output could be attributed to the successor and then rolled back inconsistently.
flowchart LR
  A[Active turn A] --> B[Send now]
  B --> C[Abort acknowledged]
  C --> D[Drain successor B]
  D --> E[Publish B metadata]
  E --> F[Persist accepted input]
  A -. concurrent output or terminal .-> G[Mixed ownership]
  F -. failure .-> H[Partial rollback]
Loading

After

flowchart LR
  A[Active turn A] --> B[Send now]
  B --> C[Abort acknowledged]
  C --> D[Await A settlement]
  D --> E[Reserve A to B handoff]
  E --> F[Persist accepted input while A remains active]
  F --> G[Validate every owner]
  G --> H[Commit B synchronously]
  H --> I[Drain and settle exactly once]
Loading

The server now retains interrupted execution ownership until exact settlement, rejects accidental live-turn replacement, and stages active-input identity handoff across the queue attempt, event bus, provider operation tracker, and Codex runtime. Durable persistence completes before successor metadata becomes observable; the final handoff and abortability transfer commit synchronously.

Pre-commit failure leaves predecessor ownership unchanged. Post-commit delivery ambiguity retains successor ownership for reconciliation. This closes the server ownership gap that remained after #362 fixed stale client processing state.

Files

  • server/chat-execution/ coordinates exact predecessor settlement and staged active-input ownership.
  • server/agents/ guards event routing and composes synchronous handoff participants.
  • server-agents/codex/ transfers operation, runtime metadata, and abortability at the delivery boundary.
  • Regression suites cover delayed and duplicate terminals, persistence failure, cross-layer atomicity, command locking, restart, and native-history recovery.

Tests

  • PR-focused server, Codex, command, architecture, and restart suite: 386 passed.
  • bun run check: passed with no Svelte errors or warnings.
  • Web logic: 83 files, 611 tests passed.
  • Web UI partitions: 235 files, 2,278 tests passed.
  • Production build and random-port startup completed; the server remained healthy until the expected smoke-test timeout.

Closes #388.

Prompted by: yk (@chiayong)

yongkangc added 6 commits July 24, 2026 03:27
Prevents stale predecessor restoration during active-input admission.
Persist accepted input before publishing successor turn ownership across the queue, event bus, operation tracker, and Codex runtime. Transfer abortability at the same synchronous boundary and cover failure, restart, and settlement races deterministically.
@0xSolarPunk
0xSolarPunk force-pushed the fix/send-now-turn-settlement branch from a7c45e3 to 8ff0fbf Compare July 24, 2026 03:29
@yongkangc
yongkangc enabled auto-merge (squash) July 25, 2026 05:01
auto-merge was automatically disabled July 25, 2026 06:33

Head branch was pushed to by a user without write access

@yongkangc yongkangc closed this Jul 28, 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.

Send now can overwrite active turn metadata and leave chat permanently in-flight

2 participants