Skip to content

fix(chat): authorize History resume against the conversation it loads - #2842

Closed
leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/resume-history-ownership
Closed

leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/resume-history-ownership

Conversation

@leonlaiyc

@leonlaiyc leonlaiyc commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

POST /api/chat/slots/{slot}/resume has two branches, and only one of them authorizes.

When a live slot already exists, the App Kit §5.2 check runs against that slot before anything is returned. When it does not — which is the ordinary History case, a conversation with no open tab — the handler went straight to:

slot = state.get_or_create_slot(name, app=request.get("app", ""), ...)
meta = state.conversation_log.get_metadata(history_key)
all_messages = state.conversation_log.read_messages_chained(history_key)

history_key is body["key"] — caller-supplied, and not required to match the slot name in the URL. So it names an arbitrary conversation, and nothing on that path compares the caller against that conversation's owner. The only slot in scope is the one the request just created carrying the caller's own identity, so authorizing against it would let the claim stand as its own evidence.

On 24a6f8ee5, an app token can read any persisted conversation this way:

requested history result before
dashboard:chat-7-… — an ordinary dashboard user's conversation 200, full transcript
dashboard:spec-builder-99 — meta["app"] == "spec-builder" 200, full transcript
slack:1785370133.085469 — a Slack thread 200, full transcript

In every case the URL slot was app-a-scratch, unrelated to the key — so this is not about channel-shaped names. It is also not read-only: the transcript is hydrated into a new app-owned slot, which then owns that conversation's messages, its title, agent, model and folder, and clears its closed flag on the way in.

Why it matters

This is an authorization bypass, not a cosmetic gap. An app token that owns a
scratch slot can name any conversation key in the request body and receive the
full transcript back: a dashboard user's private chat, another app's conversation,
or a Slack thread. The slot in the URL never has to be related to the key that is
read, so no naming convention limits the blast radius.

/resume is the only reader of a persisted conversation that ignored
meta["app"]; every other restore path already treats it as authoritative.

What changed

Authorize against the persisted conversation, before a slot exists:

meta = state.conversation_log.get_metadata(history_key)
request_app = request.get("app", "")
if request_app and meta.get("app") != request_app:
    ...  # SEL app_isolation denial, then the shared 404

meta["app"] is the durable owner. It is written by the slot save (chat_persistence.py:1669), it is one of history.SLOT_OWNED_META_KEYS, and both restore paths already rebuild slot._app from it (chat_persistence.py:485/:559 and :869/:917). Resume was the only reader of a persisted conversation that ignored it.

Absence is an answer, not a gap. Because app is a slot-owned key, an unscoped conversation's save deliberately omits it — that states "no app owns this", not "unknown". Deny-by-default for app callers therefore follows the writer's own contract rather than guessing about legacy rows.

One metadata read. It moved above get_or_create_slot and the same dict already fed the title/agent/model/folder restoration below, so authorization and hydration decide from one snapshot rather than two reads.

A refusal is not an existence oracle. A transcript that does not exist also has no app, so a foreign conversation and a missing one take the same branch and are answered identically — no probing the history namespace for keys that exist. The two pre-existing §5.2 denials on this route gained the same code so all three bodies stay byte-identical; per AGENTS.md a new non-2xx body must carry a machine-readable code, and giving it only to the new one would itself have been the oracle. error-code-baseline.json regenerated for those three (dashboard/chat_handlers.py 76 → 74).

Dashboard callers have no app scope and are untouched.

Relationship to #2783 — adjacent, not overlapping

They are independent: even with no session binding at all, an app that can hydrate another conversation's messages has already crossed the isolation boundary. Neither fix makes the other unnecessary.

Tests — test/test_resume_history_ownership.py

Behaviour-level, through the real handler with the auth middleware's app stamp. 9 failed / 5 passed against 24a6f8ee5; 14 passed after.

Refused — an ordinary dashboard conversation, another app's conversation, a channel conversation, and a conversation with no ownership metadata (deny-by-default).

Not an oracle — a foreign conversation answers with the same status and the same JSON body as a nonexistent one; and the create-branch refusal is identical to the existing-slot branch's.

No side effects on refusal — no slot is created; no existing slot is mutated (title, agent, model, pin, linked_session_key, channel_origin, message count, dirty flag, the slot table and the restricted-key set are all snapshot-compared); and the foreign transcript is not rewritten, which the closed-flag clear would otherwise do.

Preserved, all passing before the change — an app resumes its own conversation; a dashboard caller resumes a channel conversation, an app-owned one, and an ordinary one; and the existing-slot branch still serves its owner.

Verification

Windows 11 26200 / py3.10.6.

  • test_resume_history_ownership.py — 9 failed / 5 passed before, 14 passed after.
  • Run against the exact base and against this branch, comparing failing node
    sets rather than counts: test_error_code_contract.py, test_dashboard_chat.py,
    test_open_slots_persistence.py, test_session_restore.py,
    test_rehydrate_async.py, test_channel_slots.py,
    test_one_conversation_one_session.py, test_trusted_apps_api.py,
    test_slot_detail_full_history.py plus the new file — base: 9 failed, 860
    passed, 2 skipped; branch: 869 passed, 2 skipped, 0 failed.
    Every one of the
    9 base failures is in the new file, so the delta across 869 tests is exactly
    the security coverage this PR adds and nothing else moved.
  • flake8, isort and git diff --check clean; mypy reports nothing in chat_handlers.py.
  • No spec change: docs/app-kit/ documents no resume contract, and the route's own §5.2 comments are the existing statement of the rule this extends.

@leonlaiyc
leonlaiyc requested a review from a team August 11, 2026 14:21
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Aug 11, 2026
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Aug 13, 2026
@leonlaiyc
leonlaiyc force-pushed the fix/resume-history-ownership branch from 250deaf to 326a0d4 Compare August 15, 2026 02:29
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Aug 15, 2026
@leonlaiyc
leonlaiyc force-pushed the fix/resume-history-ownership branch from 326a0d4 to b017222 Compare August 15, 2026 03:05
@iamwhatever

Copy link
Copy Markdown
Contributor

👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated.

Missing sections:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed

Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention labels Aug 15, 2026
@github-actions

github-actions Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of 36386e1e5b495172e6f6beb630ba8153c658539c via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

The meta = post_read_meta rebinding at chat_handlers.py:8816 confirms the late barrier really does re-validate a post-await snapshot, app is genuinely in SLOT_OWNED_META_KEYS (so absence-means-unowned holds), and the new guard's semantics match what the existing-slot branch already enforced ("app cannot access unscoped slots"), so the create branch now merely converges on established §5.2 behavior. The dashboard spec documents no resume authorization contract, so the no-spec-change claim holds. All diff hunks are accounted for by the description; the twin early/late structure mirrors the handler's existing member-guard pattern and is justified by the durable mutations (_unhide_folder, clear_closed) that must not run on a to-be-refused foreign transcript.

Design-Verdict: PASS

A real authorization bypass, closed at the root — the durable owner in meta["app"] — using the route's own established §5.2 pattern, with oracle-freedom and side-effect-freedom pinned by tests.

[DESIGN-REVIEWED] 36386e1

@github-actions

github-actions Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — 🔴 changes requested (blocking)

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

1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

BLOCKING -- src/kiro_crew/dashboard/chat_handlers.py:8880 -- successful ownership decisions are not SEL-audited

if request_app and meta.get("app") != request_app:
Owned app transcript -> late authorization passes -> hydration returns it without an allowed SEL event.
Anchor: backend-security-controls
Fix: Emit one outcome="allowed" event after the authoritative late check passes.
[BLOCK-MERGE] 36386e1
[GPT-REVIEWED] 36386e1

Adjudication (Opus 4.8) — is blocking on each finding proportionate?

I have the evidence I need. The adjudicable block is empty (0 findings). Only the fenced finding F1 requires a ruling.

F1 — The success path (owner resume: request_app truthy and meta.get("app") == request_app, so the late barrier at chat_handlers.py patch line 8878 falls through to get_or_create_slot) emits no outcome="allowed" SEL event. But this matches the route's pre-existing convention: the existing-slot branch on disk (base chat_handlers.py:8380-8402) logs only outcome="denied", never an allow — no path in this route has ever audited a successful resume. Every refusal, by contrast, IS audited (base :8384, :8394, and both new twins in the patch), so no §5.2 ownership denial goes unrecorded and the governance ceiling itself is enforced-and-logged. The gap is a missing positive audit record, not a credential exposure or ceiling bypass — LOW harm, and a reviewer would plausibly accept adding allow-side auditing as a follow-up rather than blocking this PR on a convention it did not regress.

[ADJUDICATION] 36386e1 total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 36386e1

[ADJUDICATION-FENCED] 36386e1 fenced=1 flagged=1
FLAG F1 src/kiro_crew/dashboard/chat_handlers.py:8880 -- The success path emits no "allowed" event, but that matches the route's existing convention (base :8380-8402 logs only denials) and every §5.2 denial IS audited, so the ceiling is enforced-and-logged and only a defense-in-depth positive trail is missing — LOW harm a human would plausibly accept as follow-up.
[GPT-ADJUDICATED-FENCED] 36386e1

🏷️ Fenced finding(s) machine-flagged as likely edge case

The security fence keeps these findings blocking regardless of adjudication; the only clearance path is a human override recorded by a repository writer, who must independently verify a rationale before recording it — it is machine-authored, and a wrong override on a security-class finding ships exactly the class the fence exists to stop. (This lane's comment deliberately carries no override command.)

  • F1 src/kiro_crew/dashboard/chat_handlers.py:8880 — The success path emits no "allowed" event, but that matches the route's existing convention (base :8380-8402 logs only denials) and every §5.2 denial IS audited, so the ceiling is enforced-and-logged and only a defense-in-depth positive trail is missing — LOW harm a human would plausibly accept as follow-up.

@github-actions

github-actions Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of 36386e1e5b495172e6f6beb630ba8153c658539c 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/CONCERNS are advisory.

First-Principles-Verdict: PASS

Verify one residual: an app's own conversation saved before app became a slot-owned key now 404s under deny-by-default — confirm no such legacy rows exist.

Not justified as shipped

  1. The late ownership re-check before slot creation — undeclared: the description shows one check; the second (post-await twin, its own SEL entry) appears only in the diff. Its basis is real — meta is rebound from a post-await re-read (chat_handlers.py:8816) and the route's member guard already uses the same early/late twin — so it stands, but it shipped unmentioned.

What this change ships

Inventory (7 items) — 6 justified

Intent: close an authorization bypass letting an app token hydrate any persisted conversation by naming its key in the resume body — a FIX. The gap is readable on base: the create branch (chat_handlers.py:8521–8834) never compares the caller against meta["app"], and history_key = body.get("key", name) (8490) is the codebase's only caller-supplied-key hydration path (grep: 1 occurrence).

  1. An app token can no longer read or adopt a foreign persisted conversation through History resume — justified
  2. An app resuming a conversation with no ownership metadata is now refused (deny-by-default) — justified
  3. A foreign conversation and a missing one now answer byte-identically — justified
  4. The two pre-existing resume denials gained code: slot_not_found — justified
  5. A second, late ownership re-check runs just before the slot is created — undeclared (real TOCTOU basis; see above)
  6. Denied resumes are logged to SEL as app_isolation — justified
  7. error-code-baseline.json counts regenerated (48 → 46) — justified

Items 1–3 reuse existing authority rather than minting new surface: meta["app"] is already in SLOT_OWNED_META_KEYS (history.py:195), both restore paths already rebuild slot._app from it (chat_persistence.py:890/1016, 1481/1549), and the refusal is the existing single-sourced _slot_not_found() (chat_handlers.py:3446). No new config key, flag, or public symbol.

[FIRST-PRINCIPLES-REVIEWED] 36386e1

@github-actions

github-actions Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 36386e1

@github-actions github-actions Bot added 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: checking Automated validation is still running labels Aug 15, 2026
@iamwhatever iamwhatever added the needs-pr-triage PR scanner: awaiting automated triage label Aug 20, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: bolichen97]: This PR has been inactive for 7+ days. I reviewed the blockers but they require your input:

  • Security-model decision (GPT 5.6 BLOCKING vs Opus 4.8 PASS). GPT 5.6 rejects the whole approach of authorizing /resume against meta["app"], arguing an app can create a victim-named slot, send once so the save rewrites meta["app"] while preserving the victim's messages, then delete it — after which meta["app"] == request_app and resume returns the transcript. Its prescribed fix is to reject all app callers on this branch until ownership uses data an app's chat-save cannot rewrite. That directly guts the PR's stated goal (letting an app resume its own conversation) and contradicts the PR body's core claim that meta["app"] is the durable, authoritative owner. Opus 4.8, Design, and UX all passed with no blocking findings. Choosing between "reject all app callers" and "keep the metadata-ownership allowlist" (and, if kept, deciding what tamper-proof signal establishes ownership) is a security-policy decision only you can make.
  • Merge conflict. The branch is CONFLICTING against main and needs a rebase/conflict resolution from you (the pipeline will not change the design direction while resolving it).

When you've addressed these, the pipeline will re-assess on its next cycle.

@bolichen97
bolichen97 enabled auto-merge (squash) August 24, 2026 07:01
@bolichen97

Copy link
Copy Markdown
Contributor

Audit note — part of this has already landed; the rest has not

This PR is not a duplicate and is not finished by anything on main. The audit checked it part by part against main, and some of what it does is already there. Flagging it so a reviewer does not have to rediscover the overlap, and so the PR is not mistaken for fully-covered work.

Which parts main already has

1 of 5. Only the 'One metadata read' dedup: origin/main chat_handlers.py:6292 # Reuse the SNAPSHOT the guard above validated. replaced the second get_metadata(history_key), landed by a231501 / #6210.

What is still genuinely yours

4 of 5, including the entire security fix. (a) No conversation-owner check on the resume create branch — meta.get("app") appears nowhere in origin/main chat_handlers.py, so an app token can still put an arbitrary dashboard:* / slack:* / other-app key in the body and have that transcript hydrated into a slot it owns. (b) The two live-slot 5.2 denials in _live_slot_resume_response (main:5825, :5835) still return {"error": "not found"} with no code. (c) error-code-baseline.json is at 64 / 1209 / 1531, not the PR's 74 / 1397 / 764. (d) test/test_resume_history_ownership.py has no equivalent on main.

Suggested action: REBASE — the remainder is real work; rebase onto the landed part rather than closing.


From a repository-wide duplicate/overlap audit of every pull request open against main (2026-09-02, 330 PRs, one reviewer per PR). Each PR was read as its full merge-base diff plus its description and every comment and review, then compared against each candidate PR's own diff and against origin/main at 1a765b88ceb7. This PR is not being closed — the note is informational. If the reading is wrong, please correct the reasoning rather than just the conclusion.

@bolichen97

Copy link
Copy Markdown
Contributor

Open PR relationship audit

This is a consolidated, point-in-time code-level audit note. It compares complete merge-base diffs and current/merged code; it does not treat a shared topic as duplication or partial coverage as completion.

Relationship findings

  • PR #7308 is OVERLAPPING relative to this PR. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #7308: CONTINUE_DEVELOPMENT. Both change the same handler's body handling for different reasons; sequence them rather than closing either. Files: src/kiro_crew/dashboard/chat_handlers.py.
  • This PR is PARTIALLY_COVERED with PR #6210. Coverage is explicitly incomplete; this finding is not a completion or closure claim. Recommended action for PR #2842: REBASE. One of five parts landed incidentally; rebase onto it rather than closing, since the entire authorization fix is still missing. Files: src/kiro_crew/dashboard/chat_handlers.py.

No PR, Issue, label, branch, or review state was changed by the relationship-note portion of this audit.

@bolichen97

Copy link
Copy Markdown
Contributor

@leonlaiyc, one overlap to flag from an audit of the open PR set. #6813 (@rnoack1, "fix(chat): persist undrained pending context across a close") edits the same window of api_chat_slot_resume in src/kiro_crew/dashboard/chat_handlers.py that this PR does.

Where they collide: your ownership gate (if request_app and meta.get("app") != request_app) is inserted directly after meta = state.conversation_log.get_metadata(history_key). #6813 rewrites that exact line into an off-loop get_metadata_with_overflow read, and adds an unconditional _live_slot_resume_response call plus _resume_binding immediately before state.get_or_create_slot(...), which is the same few lines your check occupies.

What differs: this PR decides which persisted conversation a caller may adopt, while #6813 decides whether queued pending context survives a close. There is no behavioural contradiction, so both can land.

Which side is further along: #6813 spans 46 files and ships census tests that pin the new spelling. test_the_resume_handler_folds_the_spill_on_every_metadata_read asserts zero occurrences of state.conversation_log.get_metadata,, and a companion test asserts every metadata read in that handler is offloaded. Your anchor line stops existing once #6813 lands.

Suggestion: land this PR first. It is 3 files, it closes an authorization bypass, and re-anchoring one gate afterwards is cheaper than re-deriving #6813's tests. If #6813 goes first instead, please re-place the gate inside the folded, offloaded read rather than rebasing the hunk mechanically, and keep it after the member-binding await.

Posted from the 2026-09-08 open-PR relationship audit (read-only, one auditor per PR); reply here if any of this is wrong.

@bolichen97
bolichen97 force-pushed the fix/resume-history-ownership branch from b017222 to 36386e1 Compare September 8, 2026 22:29
@bolichen97

Copy link
Copy Markdown
Contributor

Rebased onto main 6c24f116e by a maintainer as part of the 2026-09-08 open-PR audit (the branch was 3000+ commits behind and conflicting).

Conflicts and how they were resolved:

  • src/kiro_crew/dashboard/chat_handlers.py — the two 5.2 denials now return _slot_not_found(), main's single-sourced 404 with the identical body you hand-wrote. Your one metadata read is already on main via feat: add crew members page with per-member DM threads #6210, so that part was dropped.
  • Same file, the ownership check: main added awaits and durable writes (_unhide_folder, clear_closed) between the metadata read and slot creation, so a single check could not be both side-effect-free and pre-publish. It is now an early/late twin mirroring main's own member-pin guard: the early one refuses before any mutation, the late one re-validates the post-await snapshot right before get_or_create_slot.
  • error-code-baseline.json — regenerated from current main (chat_handlers 48 to 46).

Gates run locally: black, isort, flake8 on changed files; your 15 tests plus the error-code contract, test_resume_publishes_hydrated_slot, test_dashboard_chat, test_ephemeral_sessions, member-thread gate and 3 more, all passing.

Please review the twin split. A maintainer push makes the maintainer the last pusher, so a second approver is needed under the repo's last-push rule. Reply if anything looks wrong.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 8, 2026
`POST /api/chat/slots/{slot}/resume` authorizes on only one of its two
branches. When a live slot exists it applies the App Kit 5.2 check to that
slot; when none does — the ordinary History case — it created the slot
from `request["app"]` and then read `body["key"]` straight off disk.

That key is caller-supplied and need not match the slot name in the URL,
so it names an arbitrary conversation, and the only slot in scope is the
one the request just created carrying the caller's own identity: checking
it lets the claim stand as its own evidence. An app token could therefore
hydrate any persisted conversation — an ordinary dashboard user's, another
app's, or a channel thread — into a slot it owns, taking that
conversation's messages, title, agent, model and folder with it and
clearing its closed flag on the way in.

Authorize against the transcript instead, before any slot exists.
`meta["app"]` is the durable owner: the slot save writes it, it is one of
`SLOT_OWNED_META_KEYS`, and both restore paths already rebuild
`slot._app` from it. Absence is an answer rather than a gap — an unscoped
conversation's save omits the key by that same contract — so an app caller
is denied by default. The metadata read moves above slot creation and is
the one snapshot both authorization and hydration use.

A transcript that does not exist has no owner either, so it takes the same
branch and is answered identically; the two existing refusals on this
route gain the same machine-readable code so all three bodies stay byte
for byte the same and the refusal cannot be used to probe which history
keys exist.
@iamwhatever
iamwhatever force-pushed the fix/resume-history-ownership branch from 36386e1 to 8fd15da Compare September 21, 2026 19:18
@iamwhatever

Copy link
Copy Markdown
Contributor

Rebased onto main by a maintainer (20261b763 -> 8fd15dabe). The security premise was re-verified as live on current main before rebasing, so this is not a stale branch.

Conflicts resolved (2 files)

  1. src/kiro_crew/dashboard/chat_handlers.py — main has since extracted slot construction into _materialise_slot_from_history(...), so the late barrier no longer sits in front of a direct get_or_create_slot(...) call. The guard is now placed immediately before _materialise_slot_from_history(...), which is the point that publishes the slot today, and app= is passed as the request_app the early twin already binds. The barrier's own comment was updated to name that function rather than get_or_create_slot, so it does not describe code that no longer exists.
  2. error-code-baseline.json — took main's file and regenerated it with the repo's own tool (python test/test_error_code_contract.py --update) instead of hand-merging the counters. Result: missing_code 1118 -> 1116, dashboard/chat_handlers.py 48 -> 46. Note the regeneration also corrected _compliant 2132 -> 2210, which is pre-existing drift in main's committed baseline, not a change from this PR.

Red-before re-verified. test/test_resume_history_ownership.py spliced onto a detached origin/main worktree: 9 failed, 5 passed. On this rebased head: 14 passed. The unguarded path is real and still reachable on main.

Tests run

  • test/test_resume_history_ownership.py — 14 passed
  • test/test_error_code_contract.py — 7 passed (includes test_baseline_is_not_stale)
  • test/test_dashboard_chat_handlers_coverage.py — 123 passed

No behaviour was changed during the rebase; the diff is still 3 files, +380/-6, and git diff --stat origin/main...HEAD shows no upstream files touched.

Left for the author / reviewers: the open question from the earlier GPT round on whether the early twin plus late barrier is the right shape versus a single check after the awaits. I did not decide it — both guards are preserved exactly as written.

@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Sep 21, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Consolidation: PR #10365 adds the same fresh-resume ownership gate as this PR

@leonlaiyc, cc @CrysisDeu. PR #10365 (issue #9725) independently adds this PR's check at the same two points in api_chat_slot_resume. This PR is at 8fd15dab and #10365 is at e234ecc1.

Overlap

All 14 tests in test/test_resume_history_ownership.py pass on #10365's head, so #10365 covers everything this PR does.

What #10365 has that this PR lacks

  • Refusal of channel-backed transcripts (:9377 there), even when meta["app"] matches. When fix: refuse app-scoped send/export of channel-backed slots (#9725) #10365's test runs against this head, an app-stamped slack:C2:171.2 transcript returns 200.
  • A best-effort audit through _app_isolation_denied (:4097). Here, a failing sel() turns the refusal into a 500 instead of a 404.
  • _deny_app_foreign_transcript_send (:3340), a send-side gate for the stamp-forgery path raised in the 2026-08-20 comment above.

What this PR has that #10365 lacks
Side-effect tests:

  • bystander app slots are unchanged after a refusal;
  • the transcript bytes are unchanged after a refusal;
  • the create-branch refusal is byte-identical to the existing-slot refusal.

Suggested order
Land the resume gate here first. This PR touches 3 files, and its only conflict with main is error-code-baseline.json (python test/test_error_code_contract.py --update). #10365 is 1183 commits behind and conflicts in 8 files, including a semantic conflict in chat_handlers.py with merged PR #11192. It also passes launched_at= to run_background, WorkflowService.start and start_workflow_definition, none of which accept that argument.

From a full open-PR audit against origin/main c66f95b (2026-09-25); findings were checked by independent reviewers reading the code. Reply here if this is wrong.

@leonlaiyc

Copy link
Copy Markdown
Contributor Author

@bolichen97 #16198 (merged today, 075f366) lands this PR's main gate, so most of #2842 is now on main.

Already on main: resume_slot_from_history calls _app_claim_refused(state, request_app, "chat_resume", (history_key, _history_key_for(name), slot_transcript_key(name))) before any side effect (chat_api/resume.py:1015). That covers this PR's early refusal of an app resuming a transcript it does not own, and it answers with the same uniform slot_not_found 404.

Not on main: the post-await re-check. After line 1015 the handler awaits the transcript read, _unhide_folder, clear_closed, the agent and effort reads, and _live_slot_for_resume. It then re-reads metadata into post_read_meta and calls _materialise_slot_from_history without asking about app ownership again. So if the transcript is deleted and recreated under another owner inside that window, the app's new slot adopts it. #16198 re-judges ownership at the read for detail, delete and summarize, but not here. This PR's late barrier and its side-effect tests (bystander slots unchanged, transcript bytes unchanged on refusal) are the only part left.

I don't want to rebase a branch that is now mostly a duplicate of your change, so two options:

  1. Close fix(chat): authorize History resume against the conversation it loads #2842 as superseded by fix(apps): scope approvals and session history to the calling app #16198. This is right if the resume window is accepted as it stands.
  2. Narrow it to the late barrier only: one _app_claim_refused call against the post-read keys immediately before _materialise_slot_from_history, plus a delete-and-recreate-in-the-window test. That makes it a small single-file production change on current main.

Which do you prefer? Until you answer, the branch is unchanged.

Copy link
Copy Markdown
Contributor

Triage: SUPERSEDED by #16198 + #16212 — closing

Checked against origin/main af1eb612da66 (2026-10-05). #16198 and #16212 are both merged PRs, confirmed through the REST API.

What the PR's changes map to on main

  • Early ownership refusal on the resume create branch. On main, resume_slot_from_history calls _app_claim_refused(..., "chat_resume", (history_key, _history_key_for(name), slot_transcript_key(name))) at src/kiro_crew/dashboard/chat_api/resume.py:1010, then _app_resume_refusal(...) at :1043. Both run before any side effect. Landed in fix(apps): scope approvals and session history to the calling app #16198 and fix(apps): enforce app slot ownership on every per-slot route #16212.
  • The late post-await barrier. In @leonlaiyc's 2026-10-04 comment, this was the only part still missing. fix(apps): enforce app slot ownership on every per-slot route #16212 (merged 2026-10-04 21:05 UTC, d5b0edb40b) added it at resume.py:1476-1491. After meta = post_read_meta, the code runs if request_app and (destination_refusal is not None or not app_owns_transcript_meta(meta, request_app)). That writes the SEL denial "app does not own this transcript (late barrier)", restores the cleared closed marker, and returns the uniform slot_not_found 404. The check runs before _materialise_slot_from_history (:1556).
  • Uniform 404 bodies. Main uses the shared _RESUME_APP_NOT_FOUND / slot_not_found body.
  • Tests. test/test_slot_ownership_checkpoint.py covers resume, including test_resume_rechecks_a_destination_created_and_closed_during_setup and test_an_app_cannot_resume_a_users_closed_session.

Empirical check: I copied this PR's test/test_resume_history_ownership.py unchanged onto a clean origin/main worktree and ran it: 14 passed, 0 failed. On the PR's merge base, 9 of those tests fail. So main now gives every behaviour this PR pins: refusals, no existence oracle, no side effects, and preserved owner/dashboard paths.

The PR is also 2036 commits behind main. Its chat_handlers.py hunks target code that has since moved to chat_api/resume.py, so nothing on this branch still needs landing. This is option 1 in the author's comment, and it no longer depends on accepting the resume window, because #16212 closed that window.

Closing as superseded. If you find a resume behaviour that origin/main does not cover, reply here and it can be reopened.

@bolichen97 bolichen97 closed this Oct 5, 2026
auto-merge was automatically disabled October 5, 2026 10:40

Pull request was closed

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 5, 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) merge conflict Branch has merge conflicts with its base — author must resolve before merge needs-author-decision PR blocked on author input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants