Repository navigation
feat(session-control): session_retry re-runs a failed turn like Resume - #15436
Conversation
|
Intent: give an agent the Resume button's action for a session it created whose last turn failed, so a timed-out or errored turn can be restarted without re-sending the prompt. |
|
👋 Hi! This PR is currently in draft status. Workflow runs won't be auto-approved until it's marked as ready for review. When you're ready, click "Ready for review" and the workflows will be approved on the next cycle automatically. |
Design Review (Opus 5.5, fork) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that [DESIGN-REVIEWED] d0d28e0 Description read[DESCRIPTION-READ] ed1611bd25e6c54aa36c9daffdc11d22e32bc39627adcee7de144a5d7d94ab82 That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5, fork) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Check before merge: crew-member DM sessions get What this change shipsInventory (6 items) — 6 justifiedIntent: an agent restarts a failed turn in a session it created the way Resume does, without sending the prompt a second time (Fixes #15431). This is an ADDITION.
[FIRST-PRINCIPLES-REVIEWED] d0d28e0 Description read[DESCRIPTION-READ] d85d82a4ca178b527517f1a03e16dbd97ec2b11e6aa6680736fd8b6632e9543c That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings. |
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed |
d26d24a to
c32fb19
Compare
|
|
|
Rebased: main moved in files this PR imports or sits beside (aec8141 -> 2b91a6b) since this head went green. The new head |
|
CI note on
Coverage Gate and PR Readiness fail closed on the backend red. I'll push the same tree once in the next quarter-hour slot to re-run them; no code change. |
c32fb19 to
ae2be5d
Compare
7219353 to
e25b408
Compare
|
Rebased: |
|
Fixed the SAST (Semgrep) finding |
|
First Principles item 5 (fail-open audit in The same head also re-pins |
|
Design review watch item ("the stated user is never granted the tool"): The same push rebases onto main at |
|
Rebased onto main to clear the conflict with #17662, which retired the remote turn relay and deleted The one conflict was the import block in 1009 targeted tests pass locally (session control, retry, Continue, relay archive, composition contract, agent grants), along with flake8, black and docs-lint. Before pushing I rebased once more onto current main, which had picked up two doc conflicts. In |
|
Rebased onto main with no behaviour change. Main had moved 19 commits and changed two pinned contracts that this PR also pins: the member dashboard grant tuple in |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
|
The red The same test failed with the same six paths on |
|
Rebased onto main with no behaviour change. Main's change to the Work ledger row in The push also re-runs the two reds on |
|
Rebased onto main with no code change; the range-diff shows the patch is identical. This clears the |
|
This adds a |
…turn the way Resume does Adds a kirocrew-dashboard MCP tool and POST /api/session-control/retry. The Continue endpoint's body moves into chat_handlers.continue_slot_turn, which both the Resume button and the new verb call. The verb passes require_interrupted=True, so a target whose last turn finished or was stopped is refused with turn_not_failed, and re-runs authorize_target under the slot lock before the continuation is queued.
|
Rebased onto main with no behaviour change; the range-diff shows this PR's own delta is unchanged. This head replaces
The other three conflicts came from main's reasoning-effort change to 5,499 tests pass locally across the session-control, Continue, validation, MCP dashboard, agent-contract and composition-contract files. |
buluoray
left a comment
There was a problem hiding this comment.
Approving, which also answers the hold for a maintainer call on the permission grant. session_retry reuses Resume's own path through continue_slot_turn, so every Continue refusal still applies, and it adds its one refusal of its own: turn_not_failed.
Checked against this head:
- Removing the
require_interruptedcheck reddenstest_a_turn_that_succeeded_is_refusedandtest_a_turn_the_user_stopped_is_refused. Removing thebefore_dispatch()re-check reddenstest_a_target_linked_while_the_lock_was_awaited_is_refused. - The Continue endpoint keeps its codes and bodies, including
slot_subagents_running. The only behaviour change is the best-effort audit, which fixes the stuck-queue-entry case. - The member grant sits under the same
created_byfence assession_send/session_stopand does less thansession_send, so no approval prompt is fine. Conductors stay withheld.
Follow-up, non-blocking: Design's note about confirming _is_interrupted covers every failure tail a patrol loop sees (backend error mid-turn, gateway restart) is worth a test case later.
#16434 duplicates this PR and is closed in favour of this one; #15459 stacks on it.
|
todo (non-blocking): add the Thanks for the review. I'll leave this head as it is so the approval and readiness stay intact. After this merges I'll open a follow-up PR with test cases showing that |
Problem / Motivation
Goal: an agent can restart a session it created whose last turn failed, the same way a person presses Resume, without re-sending the prompt.
When a session's last turn fails (
Request initialize timed outat start, or a backend error mid-turn), the only thing another agent can do today issession_sendthe prompt again. That puts a second copy of the user message in the transcript, and a patrol loop has to guess which message was the one that failed. The dashboard's Resume button (POST /api/chat/slots/{slot}/continue) already does the right thing for a person, but no MCP tool reaches it.Why it matters
Patrol and conductor loops restart timed-out worker sessions routinely. Each restart by re-send doubles a prompt in the transcript and can re-run the wrong request when the tail holds more than one user row.
Not a goal
session_revivecovers that.What changed (motivation → approach → change)
continue_slot_turninchat_handlers.pydashboard_continueaudit line is now best-effort, so an audit failure after the recovery entry is queued cannot leave that entry strandedretry_targetinsession_control.pyauthorize_target, refuses an old relay chat with the sameis_relay_archivecheck Continue uses (relay_archive_read_only), then callscontinue_slot_turnwithrequire_interrupted=Truesession_retryinmcp_dashboard.py,POST /api/session-control/retryTool(...)entry in the session family of the table from #17098 (schema invalidation.py), and its route, registered inserver_runtime/mcp_routes.py, listed in_STRICT_INTERNAL_API_PATHSand inCHANNEL_AGENT_BLOCKED_TOOLSinchannel.pyI started from regenerate, as the issue suggested, and it is the wrong path.
api_chat_slot_regeneratewalks back from the tail for an assistant row and stops at the first user row, so the[user, error]tail a failed start leaves returnsno_assistant_message. Where it does apply, it moves a good reply into a variant. Resume is the dashboard's control for a failed turn, andis_turn_interruptedis the predicate that already decides when the composer offers it. So the verb calls the existing Continue logic directly, through one small shared helper, rather than going through regenerate.The helper takes two things only the verb uses.
require_interrupted=Truerefuses a target whose last turn finished or was stopped (turn_not_failed), so a retry cannot make a session answer again on top of a good reply.before_dispatchre-runsauthorize_targetsynchronously under the slot lock, right before the queue insert. The lock and the sub-agent probe are awaits, and a target can become channel-linked or be replaced in that window. Every refusal Continue already makes still applies, includingsession_start_repeatafter two identical failed starts.One difference from a Resume press is deliberate: the verb queues the recovery turn with
directive_user_origin=False, so the resumed turn does not carry the authenticated-human flag a person's press sets. An agent asked for it, not the person at the keyboard. The queue entry carries the caller'ssend_origin_slotstamp. The session-control audit line records the caller's session key, and the target'sdashboard_continueline recordsvia=session_control. Docs are updated insrc/kiro_crew/docs/session-control.md,docs/index.md,docs/system-specs/modules/session-control.md,docs/feature-map/README.mdanddocs/architecture/mcp.md, anddata/mcp_tool_titles.jsongets the tool's title.A crew member's DM session gets
session_retrywithout an approval prompt: it is added to_MEMBER_DASHBOARD_GRANTSinagent.py, besidesession_sendandsession_stop, so a member's unattended patrol can restart a worker whose turn timed out. The member'screated_byownership fence bounds it to worker sessions that member opened. Conductors still get an approval prompt, and the WITHHELD list says why: they have no ownership fence.test_agent_refactor_contracts.pypins both tuples.Backwards compatibility
Compatible: the Continue endpoint returns the same codes, statuses and bodies; its audit line keeps
metadata={"slot": ...}and only a session-control retry addsvia. The one behaviour change is on a failing audit: Continue now logs a warning and still dispatches, where it used to 500 with the entry left queued.Tests
test/test_chat_slot_continue.py::test_a_failing_audit_write_does_not_strand_the_queued_continue: drivesPOST /api/chat/slots/{slot}/continuewith a raising audit write. It fails on main (assert 500 == 200, the entry stays queued and every later press is refused withslot_queue_pending) and passes here, where the turn dispatches.test/test_session_control_retry.py: a retry still dispatches when the audit log raises; a failed start and a no-reply turn are both resumed with the resume body queued and no new user row; a finished turn and a stopped turn are refused withturn_not_failedand nothing queued; a running target, a target the fenced caller did not create, an old relay chat, and Resume's repeat refusal are all refused with their own codes; a target that becomes channel-linked while the lock is awaited is refused by the re-check; the handler maps refusals to their code; the route is in the strict internal set; the tool posts the verified caller key and renders success and refusal.test/test_pending_boundary_consumer_semantics.py: therunningreader moved fromapi_chat_slot_continuetocontinue_slot_turn.test/test_session_control_doc.py,test/test_mcp_dashboard_registration.py,test/test_mcp_dashboard_folders.py: the tool count and advertised set includesession_retry.test/test_chat_slot_continue.pypasses unchanged against the refactored endpoint.Manual verification
N/A: unit coverage exercises the verb against a real
DashboardStatewith only the turn dispatcher stubbed, and the Continue endpoint's own suite passes unchanged.Related Issues
Fixes #15431
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)