Repository navigation
fix(prompt_agent): a re-run closes the conversations a dead run of the step left active - #937
psinghal20 wants to merge 4 commits into
Conversation
|
🤖 Automated Claude routine — Env Pod PR Context Review. This is a bot, not Edgar Arakelyan; not a human review. Context from a newer open PR: #951 ( Generated by Claude Code |
A step that raises mid-turn leaves the conversation active and pending, a failed agent turn is recorded completed, a closed conversation still takes a new task, and a retried step's reply completes the dead attempt's turn. A conversation closed before the first turn must fail the step without sending anything. A retry after a run killed before its close must cancel the task that run left and complete its own. Two runs racing to create the conversation must share one record, and a close that fails in the step's cleanup must not replace the step's own exception.
The step closed its conversation only after the loop returned normally, so a
timeout, cancellation or any other exception left it active, and pending when
the turn was recorded, for list_pending to keep listing. The close now runs in
the loop's finally, and the conversation is created just before that try. A
store error in that close is logged, so it never replaces the step's own
exception.
add_a2a_task appended to a closed conversation, so a turn recorded after a
peer closed it, or a peer recording a message after the step closed it, left a
working task no one would end. It now refuses unless the conversation is
active, read under the same rev swap, and returns None. The step then stops
without sending the turn. A refusal of the first turn fails the step, since
the agent was sent nothing and an empty answer must not pass as one.
complete_a2a_task recorded every reply as completed. It takes the state the
responder's task ended in, and the step passes the agent's.
A re-run of the step under the same instance id (a retry, or a later step
continuing the same context_id) found its conversation through
create_conversation raising DuplicateKeyError. Only the unique index that
conversation_store.ensure_indexes creates raises it, and nothing in this
repository calls ensure_indexes, so on a store without the index a re-run
inserted a second document with the same conversation_id. The step now calls
reopen first, which reactivates the conversation and cancels any task an
earlier run left working, and creates it only when reopen finds none. If two
runs race to create it, the loser's DuplicateKeyError leads to reopen too.
Tests that stub the store return {} from add_a2a_task, a recorded turn, and
stub reopen with the other calls. The user-side test that pinned a failed turn
as completed now expects failed.
tst/formal/a2a_conversation holds a TLA+ model of a prompt_agent step's A2A conversation record, the step that owns it, a retry of the step, a process that dies mid-step, and a human peer's endpoint writing the same store. check.sh runs the fixed code, the code before the fix, six mutants and one known gap against six invariants, with the TLC jar pinned by sha256. AGENTS.md says which code the model covers, when to run it and how to read a failure. The known gap: an earlier run's ask that the peer's endpoint records after a retry reopened the conversation sits ahead of the retry's turn, and the retry's reply ends it, because complete_a2a_task ends the oldest working task.
…e step left active A step without context_id mints a new conversation id on every run, so when its worker dies and the step is re-run, the earlier conversation stays active and reopen never finds it. The record now carries the step_id that created it, and the step closes the active conversations an earlier run of it left for the same task instance before anything reaches the agent (close_active_for_step). A step with context_id shares its conversation across runs and is left to reopen. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
73e19d8 to
cbc10d5
Compare
|
|
66f45fa to
fb1f009
Compare
Stacked on #951, which closes a prompt step's conversation however the step ends and
reopens it on a re-run with the same conversation id.A step without
context_idmints a new conversation id on every run. When its worker dies mid-step, nothing in that process closes the conversation, and the re-run'sreopennever finds it, so it staysactiveand pending in the hub worklist.The record now carries the
step_idthat created it, and the step closes the active conversations an earlier run of it left for the same task instance (close_active_for_step) at the start of_execute, before anything reaches the agent, so a re-run that fails early still closes them. A step withcontext_idshares its conversation across runs, gets nostep_idand is left to #951'sreopen. Records written before this have nostep_idand are never swept.Not covered: a worker that dies with no later run of the step, and cancelling the earlier agent turn. An earlier run that is stuck but alive when the step is re-run has its conversation closed, and #951's guard refuses its next turn.
Validation: 3 step tests (re-run closes the leftover, a re-run failing before its own conversation still closes it,
context_idnot swept), the first two failing with the sweep disabled; 2 store tests; with #951's 11 conversation tests, 16 pass;ruff checkclean. Thetst/unit/task_step,a2a_agentandstoresuites pass except 6 failures incomputer_exec_test.pyandtest_mcp_cli_builder.pythat also fail onmain.Once #951 lands, this branch is rebased onto
main.🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no new actionable issues remain.Summary
Adds
step_idto conversations owned byprompt_agentand closes active leftovers before a new attempt contacts the agent.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Start prompt step] --> B{Fixed context_id?} B -->|No| C[Close active leftovers for this task instance and step] B -->|Yes| D[Keep shared conversation behavior] C --> E[Configure agent and start conversation] D --> EReviews (3) · Last reviewed commit: "fix(prompt_agent): a re-run closes the c..." · Reviewed by Greptile