Skip to content

fix: send the approval target from the chat embed and the python client - #39520

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/23636-targeted-approval-callers
Nov 19, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/23636-targeted-approval-callers

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The app chat embed (ChatEmbed) and the Python client (kirocrew_client.resolve_approval) can decide a tool approval by the request the card showed, its owner-bound target, instead of by its request id alone.

An app's chat embed posts Approve, Reject and Trust to POST /api/chat/slots/{slot}/approve with {action, request_id} only, and resolve_approval in the Python client has no way to send anything else. A request id recurs, so when request B takes over request A's id, a press on A's card decides B.

Why it matters

A request id recurs, so a decide that names only the id resolves whichever request holds that id when the press lands: an embed card left up for request A decides request B once B takes over A's id. The dashboard's own controls already send the target. The embed and the published Python client are the first-party callers still sending the bare id, and the server cannot refuse the bare form from apps and the owner's session (the rest of #23636) until they stop.

Not a goal

  • Refusing the bare form on either decide route. That is the later change for approvals: the owner session and apps can still decide by bare id #23636; this one changes no server route.
  • Changing who may decide an approval, or which decisions an embed card offers.
  • Deciding a coordinator-injected card from an embed: an app token never resolves a background approval, before or after this change.

What changed (motivation → approach → change)

The embed and the client name a request by its id alone, and the id is not unique over time. The route already takes a targeted form that resolves only the exact pending request (the dashboard has sent it since #27511), so both callers now send that form.

Caller What it sends now
ChatEmbed Approve / Reject / Trust, and a group's Approve all {action, origin: "native", request_id, request_mid}, built from the card row's own meta with permissionRowTarget. A row with no native target (no mid, or a coordinator-injected row) sends nothing and rolls back with the existing "no longer pending" notice.
ChatMessageList (app SDK) Hands the host the pending row's meta as a third argument to onApprove, and each row's meta beside its id to onApproveBatch. Optional: a host that ignores it keeps working.
resolve_approval(..., request_mid=, instance=) request_mid (with slot_id) sends the native target on the slot route. instance sends ?origin=coordinator&slot=&instance= on /api/approvals/{id}/{action} for a list_approvals() record. Both at once, or request_mid without slot_id, raises VALIDATION_ERROR before any request. Without either, the call is the same bare call as before.

The spec (app-kit-platform.md, "ChatEmbed approvals") and docs/app-kit/api-reference.md describe the targeted forms. The bare-id guard test's header comment says the embed sends the target.

Backwards compatibility

Compatible: the bare resolve_approval(id, action, slot_id) call sends exactly what it sent before, and the new keyword arguments and callback arguments are optional. No server route changes, so every existing caller is answered as it was.

Removes nothing: the only behaviour that differs is an embed card whose row carries no request target, which now shows as no longer pending instead of deciding whichever request holds its id.

Tests

  • ChatEmbed.approvalRollback.test.tsx ("ChatEmbed approval target"): single and batch decides post origin: 'native' + request_mid from each row; a row with no mid posts nothing and rolls back with the refusal.
  • ChatEmbed.test.tsx: Approve and Trust post the row's target; Trust still sends trust.
  • ChatMessageList.test.tsx: the batch handler receives each row's meta aligned with its id.
  • packages/kirocrew-client-py/tests/test_gateway_contract.py: request_mid sends the native body on the slot route; instance sends the coordinator query (with a slot, and empty for a slotless record); the three unsendable combinations raise before any request.

Proof: not provable -- other: prove.py is INCONCLUSIVE (exit 21) because with client.py reverted the new client tests raise TypeError instead of failing an assertion, and the frontend half is vitest. With the production files reverted, 7 vitest cases and 6 client cases fail; all pass with the fix.

Determinism: the four changed vitest files ran 3x in order and once with --sequence.shuffle (90/90 each run); the client test file ran 3x (92 passed each; neither pytest-randomly nor pytest-random-order is installed on the test host).

Manual verification

Reproduced and smoke-tested on Ubuntu 24.04.5 LTS (x86_64). No live agent turn could be raised inside an app embed there, so the exact code paths were driven instead:

  • Server, unchanged by this PR (real api_chat_slot_approve through aiohttp TestClient, app caller): request A under id r1 settled, request B under the same r1. The bare body resolves B. A's target gets 404 approval_not_pending and B stays pending; B's target resolves B.
  • Embed (real ChatEmbed → ChatMessageList → CollapsibleToolGroup), after the fix:
EMBED Approve on row meta={"approval_id":"r1","mid":"m-A","tool_input":"echo hi"}
  POSTs=[["/api/chat/slots/slot-1/approve",{"action":"approved","origin":"native","request_id":"r1","request_mid":"m-A"}]]
EMBED Trust on row meta={"approval_id":"r1","mid":"m-A","tool_input":"echo hi"}
  POSTs=[["/api/chat/slots/slot-1/approve",{"action":"trust","origin":"native","request_id":"r1","request_mid":"m-A"}]]
EMBED Approve on row meta={"approval_id":"r1","tool_input":"echo hi"}
  POSTs=[]
  notice="This approval expired, was already decided, or was replaced by a newer request — the agent is no longer waiting on it."

Before the fix all three posted {"action":…,"request_id":"r1"} only. The same run in Chromium (Playwright, route-mocked gateway) gave the same requests.

  • Python client against the real decide handlers (aiohttp TestServer):
CLIENT instance=<record instance> slot=dashboard:selected -> resolved=True
CLIENT request_mid=A's -> ErrorCode.NOT_FOUND; B done=False
CLIENT request_mid=B's -> B done=True result=approved

Real-machine verification

Machine: EC2 m7i.2xlarge, Ubuntu 24.04.5 LTS x86_64, 8 vCPU / 32 GiB
Before (main c22557c): the three temporary repro scripts above (server through pytest -n0, embed through vitest run, client against a recording gateway) -> card A's bare body resolves B (200, B done=True); the embed posts {"action":"approved","request_id":"r1"} for a row carrying mid: "m-A"; resolve_approval(..., request_mid="m-A") raises TypeError.
After (head d9fe84917adc, same commands): the embed posts origin: "native" + request_mid: "m-A", a row with no mid posts nothing, the client sends the native body and the coordinator query, and A's target is 404 approval_not_pending with B still pending. Head 101b984 is that change rebased onto main be1ce64 with one validation message reworded; on its tree a machine of the same type ran the client suite (92 passed, 3x), the route contract (8 passed), the four changed vitest files (90 passed, 3x in order and shuffled), semgrep on the diff (0 findings), black, flake8, tsc and eslint (all 0).
Cleanup: the repro, gates and screenshot machines of the earlier heads terminated; describe-instances and describe-volumes by their ids return []. Every machine is SSM only, with no key pair and no inbound rule; the one that ran this head's checks is terminated when idle.

Screenshots / video

The embed's pending approval row:

Embed pending approval row

After Approve on a row that carries its target:

Embed row approved

After Approve on a row with no target: nothing is sent and the row shows it is no longer pending:

Embed row without a target refused

Related Issues

Part of #23636

Sibling sweep

Swept: git grep -nE "/approve['`]|/approve"|request_id: ?(id|approvalId)" -- website/src packages
Sibling: website/src/app-sdk/ChatEmbed.tsx -- changed here
Sibling: packages/kirocrew-client-py/kirocrew_client/client.py -- changed here
Sibling: website/src/apps/mochi/panel/panelBridge.ts:1599 -- tracked in #23636
Sibling: website/src/api/client/chat.ts:350 -- not affected -- the dashboard's callers pass the row target, pinned by approvalBareIdGuard.test.ts
Sibling: website/src/pages/chat/crew-window/CrewChatWindow.tsx:375 -- not affected -- already sends origin native with request_mid

Pattern harvest

Not generalizable: the bare-id decide is closed by the server refusing it (the rest of #23636), not by a rule over callers; the dashboard's own controls already have their guard test.

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • 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 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 101b984e27f7094cb88a7075dfe23c679c993d21 — 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 does not.

First-Principles-Verdict: PASS

Nothing blocks. Each change carries the row's own target to a route that already accepts it. The real fix, refusing the bare id on the server, is deferred by name to #23636.

What this change ships

Inventory (8 items) — 8 justified

Intent: let an app's chat embed and Python-client callers decide the exact approval request the card showed, not whichever request later reuses its id. FIX.

  1. Embed Approve, Reject and Trust now send the row's native target (origin, request_mid) — justified
  2. The embed's "Approve all" sends each row's own target — justified
  3. An embed row with no mid, or one the coordinator injected, sends nothing and shows "no longer pending" — justified
  4. ChatMessageList onApprove / onApproveBatch pass the row's meta as an optional third argument — justified
  5. The Python resolve_approval gains request_mid= (needs slot_id) for the native slot target — justified
  6. The Python resolve_approval gains instance=, which sends the coordinator query on /api/approvals/{id}/{action} — justified
  7. The client raises VALIDATION_ERROR before sending when given both, request_mid without a slot, or a slot-only action with instance — justified
  8. The spec section and the API reference describe the targeted forms — justified

[FIRST-PRINCIPLES-REVIEWED] 101b984

Description read

[DESCRIPTION-READ] 9308905321b105c57166e062506114a30b6c47e98dbe0da7afe058f4514eeddf

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 Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 101b984e27f7094cb88a7075dfe23c679c993d21 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: both callers now use the targeted decide form the route already accepts and the dashboard has sent since #27511. No server route changes, and the bare client call is unchanged.

Notes

  • If any live permission row reaches an app's slot history without meta.mid, the embed's Approve button stops working on it: the press shows "no longer pending" and sends nothing. The dashboard already depends on mid the same way, so this is a known risk, but it's worth checking that the app-token history path keeps mid on every row.

[DESIGN-REVIEWED] 101b984

Description read

[DESCRIPTION-READ] eaa0da065667845221d1327401c615bb06ec9dfcf8fac3716e6b99ad4ff1becd

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 Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 101b984e27f7094cb88a7075dfe23c679c993d21 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

Nothing blocks: the diff adds no control or string. It changes only the request payload and reuses the existing "no longer pending" notice, which shot-03 shows.

Notes

  • In shot-03, the rolled-back row's header reads "0 tool calls" above a visible ls -la row. The blind reader said "'0' seems to clash with the request shown right below it." This is existing group-header copy, and fixing it belongs in a follow-up.

[UX-REVIEWED] 101b984

Description read

[DESCRIPTION-READ] c8c50c57dbfef8f4b7dc50042e5b3dab34faf870bcc87c898225f6dfc1b8a112

That sha256 names everything this verdict read: the PR description, plus the 6 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 Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 101b984e27f7094cb88a7075dfe23c679c993d21 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 101b984

Verdict parsed from the review's SHA-scoped output markers for commit 101b984e27f7094cb88a7075dfe23c679c993d21.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 101b984e27f7094cb88a7075dfe23c679c993d21 false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 101b984e27f7094cb88a7075dfe23c679c993d21 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 101b984

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 101b984e27f7094cb88a7075dfe23c679c993d21 false-positive: <reason, 20 to 500 characters>

@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 Nov 19, 2026
A request id recurs, so a decide that names only the id resolves
whichever request holds it when the press lands: an embed card left up
for request A decided a later request B that took over A's id. The
dashboard's own controls already send an owner-bound target; the app
chat embed and the Python client were the first-party callers still
sending the bare id.

ChatMessageList now hands its host the pending row's meta beside the
id (and the rows' metas beside a batch's ids). ChatEmbed builds each
decide's native target from that row and posts origin "native" with
request_mid; a row with no native target sends nothing and rolls back
as no longer pending. resolve_approval gains keyword-only request_mid
(slot route, native target) and instance (coordinator target in the
query of /api/approvals/{id}/{action}); both at once, or request_mid
without slot_id, is refused before any request. The bare call is
unchanged, and no server route changes here.

Part of #23636

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in .github/workflows/ci.yml and the two Windows-red tests' files since this head's CI ran (205d08d -> be1ce64); CI re-running.

The reds on 25578f1 were main's, not this diff's (it touches no backend code):

The diff is unchanged (same patch-id); its tests, semgrep and the static checks ran green on the rebased tree.
[operator: bolichen97]

@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 Nov 19, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed head 101b984. The chat embed and the Python client now send the request target that the decide routes already accept, and no server route changed. I checked that the new fields can only narrow what a caller resolves. The slot route still runs its session control check first, then resolves only a pending request in the addressed slot or one sharing its session whose delivery id matches, and an app token still cannot resolve a background approval through the coordinator form. The embed's approve, reject and trust actions are all accepted in the targeted form, a row without a target rolls back without sending anything, the client contract tests pass on this head, and the frontend suites are green in CI. Nothing blocks.

@KiroCrewCaptain
KiroCrewCaptain merged commit de824ec into main Nov 19, 2026
101 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/23636-targeted-approval-callers branch November 19, 2026 22:50
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 19, 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.

2 participants