Repository navigation
Conversation
## summary
- Replace the single-per-project `active` slot with a `Chain` that covers the
running turn together with the messages queued behind it, so the moment
between one turn ending and the next starting stays closed.
- Accept a supplementary message while a turn runs: `POST /assistant/messages`
starts a turn when the project is idle and answers 202 with the queued
message when one is running. The message is stored in the conversation at
once, shows up as `queued`, and starts when the active turn ends.
- Give every event a `seq`, let `GET /turns/{id}/events?after=` resume from a
cursor, and keep one stream across turns: an `end` frame that carries
`nextTurnId` means the next reply continues on the same connection.
- Stopping ends the whole chain and marks messages that never started as
`cancelled`, so a stopped run cannot leave work that begins later by surprise.
## validation
- `python -m pytest tests/test_assistant_queue.py tests/test_assistant_conversations.py -q`
→ 35 passed.
- Full `tests/` run against the same environment: the failures that remain
(missing libx264 / ffmpeg options on this host) are identical with and
without this change.
- `lint-imports` and `python scripts/generate_contracts.py --check` pass.
Refs: ThinkFlowLab#379
4 of 5 tasks
A viewer that lost the connection between two turns holds the turn it saw last, which is already finished while its chain keeps writing. Asking for that turn's stream answered 404, so the only way back was a reload. The turn is looked up in the conversation it belongs to and compared with the running chain's conversation, so a stale turn of the same thread finds the stream while a turn from anywhere else is still refused.
A message waiting behind the active turn could be changed by nothing but sending it: withdrawing it meant stopping the whole chain, which also threw away the turn that was running. Retracting removes a message that has not started, under the same lock the chain takes when it picks the next one up, so it is either still waiting and goes away or it has started and the caller is told to stop it instead. A failure leaves the queue waiting rather than spending it, and continuing by hand starts the oldest message without retyping it. Refs ThinkFlowLab#379
wtz2333
force-pushed
the
feat/midturn-retract
branch
from
November 17, 2026 03:47
478bfb0 to
2539f5f
Compare
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.
Summary
DELETE /assistant/messages/{id}takes back a message that is still waiting behind the active turn. It runs under the same admission lock the chain takes when it picks the next message up, so a message is either still waiting and goes away, or it has already started and the caller gets409telling it to stop the reply instead of pretending the message can vanish.POST /assistant/queue/dispatchcontinues the queue when nothing is running. A queued message outlives a restart, and a turn that failed leaves the queue waiting rather than spending it, so there has to be an explicit way to start the oldest one without retyping it.retractedframe on the chain's stream, so another open viewer drops the bubble instead of showing a message that is no longer there.Stacked on #381 (
feat/midturn-queue): this branch contains that commit too, because both touch the queue. Please review #381 first; once it lands I will rebase this one onmainand it will show only the retract/dispatch commit.Linked issue
Refs #379Refs #379is includedLabels
wtz2333cannot add labels here. Suggested:type:feat,area:agent,area:harness.Test plan
tests/test_assistant_retract.py(new, 3 cases):409and an unknown id answers404;queued,POST /queue/dispatchthen runs it, and a second call answers409.pytest tests/test_assistant_retract.py tests/test_assistant_queue.py tests/test_assistant_conversations.py -q→ 38 passed.lint-imports→ 4 contracts kept.Evidence that it works
Provider verification
Bilingual UI
localized_error_for_languagetable when the client sendsAccept-Language.