Skip to content

fix(dashboard): audit app-token chat stops as via app:<app> - #21127

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
akushonkamen:fix/20874-app-token-stop-source
Oct 28, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
akushonkamen:fix/20874-app-token-stop-source

Conversation

@akushonkamen

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: An app token's chat stop is audited as via app:<app>, not as the owner's dashboard press.

While a turn runs, #19898 gave the embedded chat a Stop button backed by the app's token. Every stop that button makes — the soft press, the ?force=true escape, and the escalated second press — lands in the SEL audit lines as via "dashboard", indistinguishable from the owner pressing Stop in the dashboard.

Why it matters

Any app that embeds the chat can stop a running turn, and the audit is the only record of who did it. An app-token stop that reads as the owner's own press blinds the audit exactly when work was cancelled — whether diagnosing "who stopped my crew" or investigating an app acting up.

Not a goal

  • Changing the SEL events' own source field: it names the client surface and keeps its hard-coded "dashboard" (raised on the issue; will follow a maintainer's call).
  • Changing either deny check or their order.

What changed (motivation → approach → change)

Root cause: api_chat_slot_stop called stop_slot_turn without source=, and stop_slot_turn's signature (src/kiro_crew/dashboard/chat_api/turn_stop.py:427) defaults source: str = "dashboard" — a default written into all four SEL lines' metadata.via (:617, :628, :684, :749).

The route now lifts the app name it already extracted for the first deny check into request_app (:780) and passes source=f"app:{request_app}" if request_app else "dashboard" (:806): the same identity the deny checks just authorized against is the one recorded. Owner stops (no app on the request) audit exactly as before. Authorization order is untouched — both deny checks still run before any side effect, and the new test pins that.

Backwards compatibility

Compatible: no field, response shape, or accepted input changes; the only delta is the value of metadata.via on SEL lines produced by app-token stops, which is the audit correction itself. Dashboard callers keep the effective source="dashboard" they had before.

Removes nothing: the route's behavior for owner callers is unchanged, and both deny checks are byte-identical.

Tests

  • test/test_app_token_stop_source.py (new, 6 cases, pattern from test_chat_slot_muted.py's middleware identity injection and test_compaction_stop_declined.py's _make_state/SEL patching): app-token soft stop, force escape, and escalated second press each audit via app:<app>; the owner's dashboard stop still audits via dashboard; the stop_slot_turn(source=...) contract; both deny checks still precede any side effect.
    • Unfixed source: PYTHONPATH=$PWD/src .venv/bin/python -m pytest test/test_app_token_stop_source.py -q --timeout=120 → 4 failed, 2 passed (the app-token soft/force/escalated asserts fail with 'dashboard' == 'app:mail-bot').
    • With the fix: same command → 6 passed in 1.72s.
  • Related subsets, after rebase onto origin/main (0a008292): 7 stop/JSON-body guard files → 240 passed in 7.60s; 9 composition/session-control files → 725 passed in 25.36s.
  • Repo gate scripts/local-gate.py, backend (related) lane (python -m pytest -q -n auto --dist loadgroup --no-cov --timeout=120 -- test/test_app_token_stop_source.py test/test_chat_handlers_composition_contract.py test/test_json_object_body_guard.py test/test_slot_running_readers.py) → 351 passed in 15.86s. The gate's frontend lane fails in this offline environment (node_modules absent, npm ci not possible); the gate classifies this diff's frontend bucket as False (frontend=False meta=False backend=True), so the failure is environmental and CI covers it.
  • ruff/flake8 unavailable in the offline venv; both changed files pass py_compile and the 100-column line cap.

Manual verification

N/A — unit coverage sufficient: the value under change is metadata.via on the SEL lines stop_slot_turn writes, and the new tests assert it directly for both callers; no UI surface changes.

Related Issues

Fixes #20874

Claimed in #20874 (comment).

Pattern harvest

Rule candidate: review-prompt
Pattern: an audit-identity parameter with a caller-agnostic default (source="dashboard") mis-attributes cross-surface calls; a call site holding the caller's identity must pass it explicitly instead of letting the default stand in.

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

@akushonkamen
akushonkamen requested review from a team and KiroCrewCaptain as code owners October 16, 2026 07:01
@github-actions github-actions Bot added the fork Pull request from a fork (external contributor) label Oct 16, 2026
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Oct 16, 2026
@akushonkamen

Copy link
Copy Markdown
Contributor Author

Hi — friendly note on the checks: the PR Readiness failure isn't a test failure. Its message reads "5 workflow(s) awaiting maintainer approval; none has run yet", i.e. the fork workflows just need a maintainer's approval to run; the other checks (Fork PR Description, Label fork pull requests, Publish readiness signal) are green.

In the meantime, locally on fix/20874-app-token-stop-source (same head commit, e681fda9):

  • PYTHONPATH=$PWD/src .venv/bin/python -m pytest test/test_app_token_stop_source.py -q --timeout=120 → 6 passed
  • gate backend lane (pytest -q -n auto --dist loadgroup --no-cov --timeout=120 -- test/test_app_token_stop_source.py test/test_chat_handlers_composition_contract.py test/test_json_object_body_guard.py test/test_slot_running_readers.py) → 351 passed

Happy to approve workflow runs whenever convenient — thanks for taking a look!

@akushonkamen
akushonkamen force-pushed the fix/20874-app-token-stop-source branch from e681fda to d43250a Compare October 20, 2026 04:24
@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: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 20, 2026
@akushonkamen

Copy link
Copy Markdown
Contributor Author

Reworded three comments so added lines no longer carry issue references ((#20874) in src/kiro_crew/dashboard/chat_api/turn_stop.py and test/test_app_token_stop_source.py, plus Since #19898 in the test module docstring). They now state the same WHY in present tense per docs/system-specs/common/code-style.md; no behavior change. COMMENT_HISTORY_BASE_REF=origin/main python3 scripts/check_comment_history.py passes and pytest test/test_app_token_stop_source.py is 6 passed. Note: the fork's CI workflows are awaiting maintainer approval, so the gate has not run on GitHub yet.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5, fork) — ⏭️ skipped

Revision 6871f2fbefbb60608578496344368708f539f89e touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5, fork) — ✅ PASS

Premise-level review of 6871f2fbefbb60608578496344368708f539f89e via the fork AI-review pipeline — 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

The fix is at mechanism level, so nothing blocks. stop_slot_turn has five callers and this route was the only one relying on the source="dashboard" default.

Notes

  • Item 1 — symptom-level: the cause is the default described as "defaults source: str = "dashboard"", and this PR leaves it in place. Grepping stop_slot_turn( in src/ finds 5 callers. Four pass source= explicitly (turn_control.py:130, work_ledger_board.py:573, members_thread_turns.py:169, session_messaging.py:608); this route was the fifth. Subtraction: remove the = "dashboard" default from stop_slot_turn's signature (turn_stop.py:427) so source must be passed. With no default left, a new caller can't silently get the wrong audit identity.

What this change ships

Inventory (2 items) — 1 justified

Intent: when an app token stops a chat turn, the audit should name that app, not the owner's dashboard press. This is a FIX.

  1. App-token soft, force and escalated stops now show via app:<app> in their SEL audit lines — symptom-level: the caller-agnostic default that caused it stays
  2. New tests pin that both deny checks still run before any side effect — justified

[FIRST-PRINCIPLES-REVIEWED] 6871f2f

Description read

[DESCRIPTION-READ] 87d805ced4cef75f2ed13e1a304b8970a1a25a2be83d25ff1eb19ba4a2ed4219

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 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of 6871f2fbefbb60608578496344368708f539f89e via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: inside stop_slot_turn, source is only ever written to metadata.via, so passing the app identity that was already authorized fixes the mis-attribution at its root without changing any behaviour.

Notes

  • The interrupt route (api_chat_slot_interrupt) and the other app-reachable handlers in this file may also leave the "dashboard" default standing. Check them in a follow-up so the same audit gap doesn't come back on a sibling route.

[DESIGN-REVIEWED] 6871f2f

Description read

[DESCRIPTION-READ] e5d3505800aecc041c353eb0ae39ae7903e4389f17fc48282d21f0bd13b6ae76

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 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

Reviewed 6871f2fbefbb60608578496344368708f539f89e via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6871f2f

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

Reviewed 6871f2fbefbb60608578496344368708f539f89e via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6871f2f

Fixes kirodotdev#20874

Co-authored-by: akushonkamen <akushonkamen@users.noreply.github.com>
@iamwhatever
iamwhatever force-pushed the fix/20874-app-token-stop-source branch from 5453366 to 6871f2f Compare October 27, 2026 19:54
@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 Oct 27, 2026
@iamwhatever iamwhatever self-assigned this Oct 27, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD (policy-sensitive) at 6871f2f.

The code looks correct: api_chat_slot_stop now passes the app identity it already authorized against as source, so app-token stops are audited as via app:<app> while owner stops stay via dashboard, and both deny checks still run before any side effect (turn_stop.py#L833-L861). The new tests cover the soft, force and escalated paths and pin the deny order. AI lanes are clean and checks are green.

I am not recommending approval only because this changes what identity a security audit line records on an app-token-authenticated route, which this reviewer reserves for a human maintainer. The SEL source field question stays with the maintainer call on #20874.

— crew-pr-reviewer (r131)

@iamwhatever iamwhatever left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

APPROVE (security-sensitive scope, maintainer-accepted)

This PR touches a security-sensitive area, so it was held for a human decision. A maintainer reviewed the deep-check notes for this exact head (6871f2fbefbb) and accepted it. This approval supersedes any earlier HOLD from crew-pr-reviewer.

Why it is safe: records app-token chat stops in the audit log as app:; the permission check order is unchanged. CI is green on this head, the base is main, and there is no conflict.

— crew-pr-reviewer (r132)

@iamwhatever
iamwhatever enabled auto-merge (squash) October 28, 2026 16:11
@iamwhatever
iamwhatever merged commit 48af648 into kirodotdev:main Oct 28, 2026
105 of 106 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

App-token chat stop is audited as source=dashboard

2 participants