Skip to content

feat(session-control): session_retry re-runs a failed turn like Resume - #16434

Closed
iamwhatever wants to merge 1 commit into
mainfrom
rebase/15436-session-retry
Closed

iamwhatever wants to merge 1 commit into
mainfrom
rebase/15436-session-retry

Conversation

@iamwhatever

Copy link
Copy Markdown
Contributor

Replaces #15436 (fork PR) with credit to @Pearcekieser.

This is an in-repo replacement of fork PR #15436, rebased onto current main. The original is a fork PR, which cannot consume /ai-review overrides for security-class lanes; this same-repo PR carries @Pearcekieser's identical commit (authored by them, so Rebase-and-merge lands their authorship). Conflict resolution only updated the three doc tool-count/list files that main moved underneath the branch (the kirocrew-dashboard surface now advertises 30 tools, so the doc count went 29 → 30); the feature mechanism is unchanged.

Original description follows.


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 out at start, or a backend error mid-turn), the only thing another agent can do today is session_send the 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

  • Editing the prompt before re-running it (edit-resend).
  • Switching or regenerating variants of a turn that succeeded.
  • Reopening archived sessions; session_revive covers that.
  • A readiness gate the Resume button does not have.

What changed (motivation → approach → change)

Piece What it does
continue_slot_turn in chat_handlers.py The Continue endpoint's body, moved out. The Resume button and the new verb both call it. Its dashboard_continue audit line is now best-effort, so an audit failure after the recovery entry is queued cannot leave that entry stranded
retry_target in session_control.py Authorizes with authorize_target, refuses crew-bound targets with the same remote_bound_refusal predicate Continue uses, then calls continue_slot_turn with require_interrupted=True
session_retry in mcp_dashboard.py, POST /api/session-control/retry The MCP tool (schema in validation.py) and its route, in _STRICT_INTERNAL_API_PATHS and in CHANNEL_AGENT_BLOCKED_TOOLS in channel.py

I started from regenerate, as the issue suggested, and it is the wrong path. api_chat_slot_regenerate walks back from the tail for an assistant row and stops at the first user row, so the [user, error] tail a failed start leaves returns no_assistant_message. Where it does apply, it moves a good reply into a variant. Resume is the dashboard's control for a failed turn, and is_turn_interrupted is 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=True refuses 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_dispatch re-runs authorize_target synchronously 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, including session_start_repeat after 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's send_origin_slot stamp. The session-control audit line records the caller's session key, and the target's dashboard_continue line records via=session_control. Docs are updated in src/kiro_crew/docs/session-control.md, docs/index.md, docs/system-specs/modules/session-control.md, docs/feature-map/README.md and docs/architecture/mcp.md, and data/mcp_tool_titles.json gets the tool's title.

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 adds via. 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_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 with turn_not_failed and nothing queued; a running target, a target the fenced caller did not create, a crew-bound target, 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: the running reader moved from api_chat_slot_continue to continue_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 include session_retry.
  • test/test_chat_slot_continue.py passes unchanged against the refactored endpoint.

Manual verification

N/A: unit coverage exercises the verb against a real DashboardState with only the turn dispatcher stubbed, and the Continue endpoint's own suite passes unchanged.

Related Issues

Fixes #15431

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@iamwhatever
iamwhatever requested a review from a team as a code owner October 3, 2026 08:22
@iamwhatever
iamwhatever requested a review from CrysisDeu October 3, 2026 08:22
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 82bd82bdbe64dbc94fc64cd87e61ecffc783611a — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that the [user, error] tail left by a start that hit Request initialize timed out makes _is_interrupted true, so session_retry doesn't refuse it with turn_not_failed.

[DESIGN-REVIEWED] 82bd82b

Description read

[DESCRIPTION-READ] 3b6a437d1bb5ecc1e7257451c1cb58c9880a02edabc9a051f4d7782c35c63325

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 .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 82bd82bdbe64dbc94fc64cd87e61ecffc783611a — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Check one thing before merge: the Resume endpoint now dispatches when its SEL audit write fails, where it used to return a 500. Confirm the audit owners accept a turn that runs with no dashboard_continue audit line.

What this change ships

Inventory (7 items) — 7 justified

Intent: let an agent re-run a failed turn in a session it created, the way a person presses Resume, without sending the prompt again (Fixes #15431). This is an ADDITION.

  1. Agents get a session_retry tool that re-runs a peer session's failed last turn — justified
  2. New route POST /api/session-control/retry in the strict internal set (its one consumer is the MCP tool) — justified
  3. A retry is refused when the last turn finished or was stopped (turn_not_failed) — justified
  4. A retry re-checks authorization under the slot lock, so a target that gets replaced is refused (target_replaced) — justified
  5. Channel agents cannot call session_retry — justified
  6. The Resume button no longer returns a 500 when its audit write fails, and the queued entry still dispatches — justified
  7. The dashboard_continue audit line records via=session_control for agent-issued retries — justified

[FIRST-PRINCIPLES-REVIEWED] 82bd82b

Description read

[DESCRIPTION-READ] b280156cbb7f8bed6f1641487aeca6ac4e7f4a64af0b721905f471528ac089ec

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 82bd82bdbe64dbc94fc64cd87e61ecffc783611a — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 82bd82b

Verdict parsed from the review's SHA-scoped output markers for commit 82bd82bdbe64dbc94fc64cd87e61ecffc783611a.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 82bd82bdbe64dbc94fc64cd87e61ecffc783611a: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 82bd82bdbe64dbc94fc64cd87e61ecffc783611a and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 82bd82b

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 82bd82bdbe64dbc94fc64cd87e61ecffc783611a: <one-sentence reason>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 3, 2026
…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.
@iamwhatever
iamwhatever force-pushed the rebase/15436-session-retry branch from 8eadac1 to 82bd82b Compare October 3, 2026 09:40
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 3, 2026

Copy link
Copy Markdown
Contributor

Automated rebase attempt onto main (cc7e79894e): aborted, nothing pushed. The branch is still at 82bd82bdbe.

The single commit conflicts in 5 files. I didn't resolve them automatically because main has restructured the code this PR edits:

The author should rebase this by hand.

@buluoray

buluoray commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew Auto-Pipeline [operator: buluoray#ce473fca]: closing as superseded by #15436, the original session_retry PR it copies. #15436 is rebased, green, approved and carries the later _MEMBER_DASHBOARD_GRANTS change; this branch is conflicting with main. Thanks for carrying it forward.

@buluoray buluoray closed this Oct 9, 2026
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 9, 2026
@bolichen97
bolichen97 deleted the rebase/15436-session-retry branch November 6, 2026 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

session_retry: let an agent re-run a session's failed turn the way Resume does

4 participants