Skip to content

fix(acp): answer open permission requests as cancelled on cancel - #14406

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/acp-multiturn-cancel-pending-permission
Sep 28, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/acp-multiturn-cancel-pending-permission

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Pressing Stop while a tool approval is open ends the turn right away on goose and pi, instead of waiting 10 seconds and killing the harness.

On goose and pi, a Stop that arrives while a permission request is still unanswered is never acknowledged. The turn waits out the whole soft-stop budget (agent.soft_stop_budget_secs, 10 s by default). Then Crew hard-kills the harness process and respawns it. The dashboard does not hit this, because its Stop rejects the open approval first. Slack's Stop does not, so it takes this path.

Why it matters

Stop is a basic control. On these two backends it cost a 10-second hang and a process kill every time an approval was open. The conversation survives, because the respawn resumes the session, but the Stop still feels broken.

Not a goal

  • Changing how any surface resolves its own approval cards on Stop.
  • The deepseek permission-card title, or how goose stores a cancelled turn in its own history.

What changed (motivation → approach → change)

Symptom: goose and pi never acknowledge a session/cancel while a session/request_permission is open, so Stop falls through to a hard kill.

Root cause: the ACP spec says that after it sends session/cancel, the client MUST answer every pending permission request with the cancelled outcome. AcpClient.cancel_session sent the cancel and nothing else. opencode and deepseek acknowledge anyway. goose and pi wait for the answer, which never came.

Change: AcpClient.cancel_session in src/kiro_crew/acp/client.py now answers every request still in _permission_options with cancelled after the cancel is written. That map holds the unanswered requests: reject_tool and approve_tool's usual path pop their entry, and each new turn clears it. The map is emptied as the answers go out, so nothing is answered twice. Each cancelled approval is a denial Crew made, so it gets its own SEL record (outcome=rejected_on_cancel) before the answers go out. All the records are written in one off-loop hop with a time limit, so a stuck audit backend costs a Stop at most one audit timeout. The cancellation section of docs/system-specs/modules/acp-client.md now says this. A cancelled pi gate dialog is recorded as denied, the same as a rejection, so pi's gate tripwire still holds. The kiro runtime path (AcpSessionHandle) is untouched.

Backwards compatibility

Compatible: the only new wire traffic is a cancelled answer to a request that was otherwise left open, and only after the turn is already being cancelled.

Tests

  • test/test_acp_goose_backend.py::test_a_cancel_answers_the_open_permission_request_as_cancelled: replays goose's live permission frame, cancels, and checks three things: the session/cancel is followed by exactly one cancelled answer for that request id, one rejected_on_cancel SEL record is written for it off the event loop thread, and a second cancel sends nothing more.
  • test/test_acp_pi_backend.py::test_a_cancel_answers_the_open_gate_dialog_as_cancelled: the same check against pi's live gate-dialog frame.

Both fail on origin/main and pass with the fix. The related suites also pass (979 tests): test_acp_client, test_acp_turn_state_parity, test_deny_bounded_write, test_acp_provider_cov80, and the goose and pi backend files.

Manual verification

A live drive against real harnesses (goose 1.52.0, pi 0.87.1 with pi-acp, opencode 1.18.32, dsh 0.1.5-rc.3) and a local fake model. The drive opens a tool approval, leaves it unanswered, and calls SessionManager.stop_turn, which is what Slack's Stop does:

Backend Before After
goose hard, 10.3 s soft, 0.0 s
pi hard, 10.1 s soft, 0.0 s
opencode soft soft
deepseek soft soft

In every run, the next message continued the same session.

Related Issues

N/A. Found while checking the multi-turn lifecycle of the opencode / pi / goose / deepseek ACP backends.

Pattern harvest

Not generalizable: cancel_session is the one place this client sends session/cancel.

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

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify the "no caller passes an explicit option_id" claim holds — a stale _permission_options entry would get a second, contradictory cancelled answer on Stop.

Suggestions

  • The ACP "answer every open request on cancel" MUST now lives in only one of the two cancel writers; AcpSessionHandle.cancel (session_handle.py:1857) stays non-compliant, relying on kiro-cli acking anyway. A follow-up making the runtime path answer its _permission_options the same way removes the divergence before some multiplexed harness pays for it.

[DESIGN-REVIEWED] 1eb6935

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — ✅ PASS

Premise-level review of 1eb693587ccd1943e3292fa413cf4484438796ac — 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

Verify the declared exclusion: AcpSessionHandle.cancel (session_handle.py:1857) still answers nothing after session/cancel — safe only while kiro-cli keeps acking a cancel with an approval parked.

That is the one counted sibling of the root cause (2 session/cancel senders; 1 fixed). The description declares it untouched, kiro-cli acks cancel regardless (session_handle.py:3881), and the handle's pre-turn drain answers stranded requests fail-closed — so no harm is nameable there today, but the ACP obligation binds that path too.

Inventory (5 items) — 5 justified

Intent: FIX — Stop with an open tool approval should end the turn at once on goose and pi, not wait 10 s and kill the harness.

  1. Stop with an open approval now ends the turn immediately on goose/pi (cancel answers each open request cancelled) — justified
  2. Each cancel-answered approval leaves a SEL record (approval_cancel/rejected_on_cancel) — justified
  3. A cancelled pi gate dialog counts as denied for the gate tripwire — justified
  4. acp-client.md cancellation section updated in the same commit — justified
  5. Stop now spends up to one bounded SEL-audit hop inside the cancel path — justified

[FIRST-PRINCIPLES-REVIEWED] 1eb6935

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ no blocking findings

GPT 5.6 completed its review of 1eb693587ccd1943e3292fa413cf4484438796ac and found no blocking issues.

This comment is updated in place on each push.

Review details

FINDING -- src/kiro_crew/acp/client.py:12812 -- _note_pi_gate_denied(request_id) survives deletion because the pi fixture lacks a gate nonce -> Fix: set the nonce and assert the cancelled call is marked denied.
[GPT-REVIEWED] 1eb6935

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

@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 1eb693587ccd1943e3292fa413cf4484438796ac — this comment is updated in place on each push.

Review details

One advisory finding; nothing blocks the merge.

FINDING — src/kiro_crew/acp/client.py:12806 — self._permission_options.clear() runs while the dashboard Stop path has only just resolved the approval future (_reject_pending_approvals → fut.set_result("rejected"), then await stop_turn → provider.cancel → cancel_session), and on a Slack-mirrored approval the woken chat_runner is parked in its finally on await state.slack_client.delete_message(...) (chat_runner.py:15252) before it reaches await client.reject_tool(...) (chat_runner.py:15423) — so the cancel answers and erases the entry first, and reject_tool's recorded = self._permission_options.pop(request_id, None) then reads None on a harness that did advertise a deny option ("kind": "reject_once" in test/fixtures/acp_frames/pi/permission-request-live.jsonl), emitting the false operator warning "reject_tool: no deny option advertised for req=%s; answering 'cancelled'…" and writing a second JSON-RPC response frame for a request id cancel_session already answered → Fix: have cancel_session record the ids it answered in a per-turn answered set that reject_tool/approve_tool check and return early on, so exactly one response frame is written per request id and the deny-option warning is not emitted for a request the cancel consumed.

[OPUS-REVIEWED] 1eb6935

Verdict parsed from the review's SHA-scoped output markers for commit 1eb693587ccd1943e3292fa413cf4484438796ac.

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

@iamwhatever
iamwhatever requested a review from a team as a code owner September 27, 2026 10:36
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Sep 27, 2026
@github-actions

github-actions Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Fable 5) — ⏭️ skipped

Revision 1eb693587ccd1943e3292fa413cf4484438796ac touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@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 Sep 27, 2026
@iamwhatever
iamwhatever force-pushed the fix/acp-multiturn-cancel-pending-permission branch from ebde388 to 106073f Compare September 27, 2026 11:17
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 27, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Maintainer sweep (2026-09-27, on behalf of @bolichen97): every gate was green on 106073f, but the branch went dirty against main during this afternoon's merge wave (sibling ACP fixes landed first). Please rebase; I will approve on the new head.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 27, 2026
ACP requires the client to answer every pending session/request_permission with the cancelled outcome after it sends session/cancel. goose and pi hold a cancelled turn open until that answer arrives, so a Stop from a surface that had not rejected the open approval first waited out the whole ack budget and hard-killed the harness process. Each cancelled approval gets one SEL record before the answers go out.
@iamwhatever
iamwhatever force-pushed the fix/acp-multiturn-cancel-pending-permission branch from 106073f to 1eb6935 Compare September 27, 2026 17:18
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Sep 27, 2026
@chenmingwei23
chenmingwei23 merged commit ae6f199 into main Sep 28, 2026
142 of 143 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/acp-multiturn-cancel-pending-permission branch September 28, 2026 00:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 28, 2026
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.

3 participants