Skip to content

fix(server): a queued /v1 run no longer takes over the running one's cancel and asks - #515

Merged
mrnasil merged 1 commit into
mainfrom
fix/server-queued-run-ownership
Nov 27, 2026
Merged

mrnasil merged 1 commit into
mainfrom
fix/server-queued-run-ownership

Conversation

@mrnasil

@mrnasil mrnasil commented Nov 27, 2026

Copy link
Copy Markdown
Member

Problem

POST /v1/sessions/:id/run registered its cancel flag and event sink in per-session maps before its task took the session lock. With a run in flight, a second run for the same session replaced those entries:

  • cancel stopped the queued run instead of the running one.
  • The running turn's permission asks and questions went to the second client's stream.
  • When the first run ended, its cleanup removed the queued run's entries by session id. The queued run could then not be cancelled, and its asks reached nobody (each waited out the 300 s timeout and was denied).

Fix

A run registers once it holds the session and unregisters before releasing it (own_run). An uncontended run still takes the lock inside the handler, so cancel works as soon as run has answered, as before. Runs on one session still queue; that is unchanged.

A queued run cannot be cancelled until it starts. Before this change a cancel in that window hit the queued run by accident; now it reaches the running one.

Verification

  • a_queued_run_does_not_take_over_the_running_one fails on main (cancel does not reach the running run's flag) and passes here.
  • cargo test -p whycodes-server: 95 passed. Clippy, fmt, budget scripts: green.
  • Coverage: server crate measured locally after cargo llvm-cov clean, no uncovered lines. The full scripts/coverage.sh workspace run was not done locally.
  • docs/knowhow.md has the entry.

🤖 Generated with Claude Code

…cancel and asks

run registered its cancel flag and event sink per session id before the
task took the session lock. A second run for the same session replaced
the running one's entries: cancel stopped the queued run instead of the
running one, the running turn's permission asks went to the second
client's stream, and the first run's cleanup then removed the queued
run's entries, leaving it uncancellable with asks nobody received.

A run now registers once it holds the session and unregisters before
releasing it. An uncontended run still takes the lock in the handler,
so cancel works as soon as run has answered.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@mrnasil
mrnasil merged commit 9438044 into main Nov 27, 2026
7 checks passed
@mrnasil
mrnasil deleted the fix/server-queued-run-ownership branch November 27, 2026 19:45
@mrnasil mrnasil mentioned this pull request Nov 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.

1 participant