Skip to content

fix(server): count deferred archive and switch supersession from request time - #233

Merged
pandec merged 4 commits into
devfrom
fix/deferred-run-start-order
Oct 7, 2026
Merged

pandec merged 4 commits into
devfrom
fix/deferred-run-start-order

Conversation

@pandec

@pandec pandec commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

Deferred thread archive and deferred worktree switch decided "superseded by new work" by comparing run creation ordinals against the requesting run. Reordering the queue past an edit-held message runs messages out of creation order. An archive or switch requested by the older run was then cancelled because a newer-created run had already finished before the request. A switch requested by the newer run while the older one was held could also apply later, while the older run was active, detaching its provider session.

Fix:

  • Archive and switch requests record latestRunOrdinal, the thread's highest run ordinal at request time (optional key in the thread payload_json). Only runs created after it count as new work, so a later-created run that already ran before the request no longer cancels. Archive keeps its wake lineage, and requests from before this change fall back to the old comparison.
  • Any queued run cancels a pending switch. A message waiting behind the requester, even an edit-held older one, would otherwise start in the old checkout's checkpoint scope or race the switch scheduler.
  • A sent (non-wake) message now cancels a pending switch immediately, as it already did for an archive. A prepared-run retry cancels both.
  • When a wake is withdrawn, the archive now falls back past runs that had already settled before the request. Restart-continuation detection now selects the run the same way restart recovery does (runRanAfter), so neither depends on creation order.

Tests: decider unit tests for reordered history, legacy requests, withdrawn-wake fallback and restart continuation. Orchestrator integration tests cover a reordered, edit-held queue (switch cancel and apply, archive apply), steering that cancels a switch, and a retry that cancels both.

Model: Claude Opus 5.5 (Claude Code via T3 Code)

pandec added 3 commits October 7, 2026 09:49
…art order

Deferred archive and worktree switch compared run creation ordinals, so a
queue reordered past an edit-held message cancelled requests wrongly or
applied a switch while the older run was active. Runs now record a per-thread
startSequence when they enter execution, requests record the latest one, and a
sent message explicitly cancels a pending switch.
…tart stamps

Review follow-up: any queued run cancels a pending switch (it would start in
the old checkout's scope, and racing the scheduler otherwise), the boundary
replaces per-run start sequences, and a prepared-run retry cancels a pending
archive or switch.
@pandec pandec changed the title fix(server): judge deferred archive and switch supersession by run start order fix(server): count deferred archive and switch supersession from request time Oct 7, 2026
@pandec
pandec marked this pull request as ready for review October 7, 2026 08:02
@coderabbitai

coderabbitai Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Path: .coderabbit.config.ts
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 234684fb-aacc-4f14-abf9-a51a7da542a5
📥 Commits

Reviewing files that changed from the base of the PR and between 824f33f and 5fdfe35.

📒 Files selected for processing (8)
  • apps/server/src/orchestration-v2/DeferredArchive.test.ts
  • apps/server/src/orchestration-v2/DeferredArchive.ts
  • apps/server/src/orchestration-v2/DeferredWorktreeSwitch.test.ts
  • apps/server/src/orchestration-v2/DeferredWorktreeSwitch.ts
  • apps/server/src/orchestration-v2/Orchestrator.ts
  • apps/server/src/orchestration-v2/QueuedRunEditHold.integration.test.ts
  • apps/server/src/orchestration-v2/ThreadLaunchService.test.ts
  • packages/contracts/src/orchestrationV2.ts
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pandec
pandec merged commit 3d18ad0 into dev Oct 7, 2026
@pandec
pandec deleted the fix/deferred-run-start-order branch October 7, 2026 08:04
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