Skip to content

[feat] agent: take back a queued message and continue a stalled queue - #384

Draft
wtz2333 wants to merge 2 commits into
ThinkFlowLab:mainfrom
wtz2333:feat/midturn-retract
Draft

wtz2333 wants to merge 2 commits into
ThinkFlowLab:mainfrom
wtz2333:feat/midturn-retract

Conversation

@wtz2333

@wtz2333 wtz2333 commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

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 gets 409 telling it to stop the reply instead of pretending the message can vanish.
  • POST /assistant/queue/dispatch continues 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.
  • Retracting also emits a retracted frame 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 on main and it will show only the retract/dispatch commit.

Linked issue

Refs #379

  • Refs #379 is included

Labels

  • Not applied: wtz2333 cannot add labels here. Suggested: type:feat, area:agent, area:harness.

Test plan

  • tests/test_assistant_retract.py (new, 3 cases):
    • a queued message is withdrawn while the running turn keeps going and nothing runs after it;
    • a message that already started answers 409 and an unknown id answers 404;
    • a failed turn leaves the queue in queued, POST /queue/dispatch then runs it, and a second call answers 409.
  • Regression: 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

  • Media attached, or N/A because: this is an API contract; the three cases above pin the behaviour, and the UI for it is a separate change.

Provider verification

  • Real-provider calls are described honestly, or none were made: none; the tests replace the runtime stream.

Bilingual UI

  • No user-facing copy changes in this PR; the English copy for the error messages is served by the existing localized_error_for_language table when the client sends Accept-Language.

@wtz2333
wtz2333 force-pushed the feat/midturn-retract branch 2 times, most recently from 2539f5f to 6248578 Compare November 20, 2026 07:00
config = await asyncio.to_thread(configs.resolve, message['modelConfigId'], 'agent')
except Exception:
logger.warning('agent.queue.model_missing project_id=%s message_id=%s',
project_id, message.get('id'))
@wtz2333
wtz2333 force-pushed the feat/midturn-retract branch from 6248578 to af7eb9c Compare November 23, 2026 02:02
wtz2333 and others added 2 commits November 26, 2026 11:09
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
wtz2333 force-pushed the feat/midturn-retract branch from af7eb9c to 48bdcf0 Compare November 26, 2026 03:10

This branch has not been deployed

No deployments
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.

2 participants