Repository navigation
fix(prompt_agent): close the A2A conversation however the step ends - #951
Conversation
002b4a8 to
efb6747
Compare
|
🤖 Automated Claude routine — Env Pod PR Context Review. This is a bot, not Edgar Arakelyan; not a human review. Context from another open PR: #937 (
Probably simplest to decide whether #937 folds into this PR or lands first. Generated by Claude Code |
efb6747 to
66f45fa
Compare
|
The close in |
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.
66f45fa to
fb1f009
Compare
|
Thanks for the probes. On On fencing |
psinghal20
left a comment
There was a problem hiding this comment.
Looks good, I don't have much context on the TLA+ changes, but they are not part of the CI so should be good.
Why
A
prompt_agentstep could leave its A2A conversation open forever. The step closed the conversation only on its normal path, so a timeout, cancel, or exception left itactive, andpendingif a turn was in flight. Nothing else closes it, solist_pendingkept listing it. Two related writes were also wrong:add_a2a_taskappended to a closed conversation, andcomplete_a2a_taskrecorded a failed agent turn ascompleted.What changed
finally. A store error during that close is logged and does not hide why the step failed.add_a2a_taskreturnsNoneunless the conversation is stillactive. It checks under the samerevcompare-and-swap as the write. The step then stops without sending. A refusal before the first turn fails the step instead of recording an empty answer.complete_a2a_task(state=...)records the agent task's real end state.reopen, which cancels tasks an earlier run left working, before it creates the conversation. If another run creates it first, the step reopens and continues.tst/formal/a2a_conversation/, withAGENTS.mdand acheck.shthat pins TLC.Scope
context_id. Only those steps keep one conversation id across the runs of an instance, so only their re-run reopens a killed run's conversation. A step withoutcontext_idgets a new id on each run, and the killed run's record staysactive; fix(prompt_agent): a re-run closes the conversations a dead run of the step left active #937 closes it when the step runs again.reopencancels working tasks, andcomplete_a2a_taskends the oldest one, without checking which attempt owns it. A superseded attempt that is still running, or a sibling step that shares thecontext_id, can end the other's task. Fencing it needs an attempt id on each A2A task, so it is left for a follow-up.add_a2a_taskon a closed conversation now getsNone. The docstring already allowedNone.Blast Radius
always_onignores the return ofadd_a2a_taskand closes its own conversation last, so it behaves as before. On a retry, the step now shares one conversation record with the earlier attempt on every store. Before, stores without the unique index got a second record.Verification
tst/unit/task_step/test_prompt_agent_conversation_close.py: 8 of its 10 tests fail onmain(for example('active', True) != ('closed', False)), and all 10 pass here.tst/unit/task_stepandtst/unit/a2a_agentgive 4998 passed.make lintpasses.tst/formal/a2a_conversation/check.shexits 0 with 66 checks as expected. The fixed config holds all six rules (39,211 states). Each guard has a mutant config that breaks its rule.Confidence Score: 5/5

The PR appears safe to merge; no new actionable issues were found.Summary
prompt_agentnow closes its conversation infinally, refuses turns after closure, and records each agent task’s actual end state. Retries reopen the existing conversation and cancel tasks left working.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Finish setup] --> B{Existing conversation?} B -->|Yes| C[Reopen and cancel leftover tasks] B -->|No| D[Create conversation] C --> E{Record turn accepted?} D --> E E -->|Yes| F[Send message and wait] E -->|No, first turn| G[Fail step] E -->|No, later turn| H[End loop] F --> I[Record actual end state] I --> J[Continue or end loop] F -->|Timeout, cancellation, or error| K[Finally: close conversation] G --> K H --> K J --> K K --> L[End live trajectory]Reviews (7) · Last reviewed commit: "chore: model-check a prompt step's A2A c..." · Reviewed by Greptile