Skip to content

fix(chat): re-check app ownership in resume's reserved window - #17110

Merged
bolichen97 merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/16433-resume-reserved-followup
Oct 6, 2026
Merged

bolichen97 merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/16433-resume-reserved-followup

Conversation

@jeeshofone

@jeeshofone jeeshofone commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #16435.

Problem / Motivation

Goal: An app's resume of a closed session never publishes, or writes closed onto, a transcript another app owns, and the reserved window's delete check is pinned by a test.

Since #16435 every resume of a closed session, app callers included, clears closed inside a reserved window after the slot is built. The re-reads after that window's awaits check existence, the delete-in-flight marker and created_at, but not ownership. On a line with no created_at, a delete and same-key recreate under another app inside the window passes all of them: the app resume answers 200 and publishes the other app's transcript. The marker restore decides "same transcript" by created_at too, so a refusal there could put closed on the other app's line. Separately, no test fails when the tail's own in-flight check is removed.

Why it matters

App isolation is a boundary: one app must not open or alter a transcript another app owns. The late barrier before construction already enforces that; the window after it is the gap. The missing test means a later edit could drop the tail's in-flight check and leave a deleted conversation open as a tab with CI green.

Not a goal

What changed (motivation → approach → change)

An app resume could adopt another app's transcript because ownership was checked once, before the awaits that let a delete and recreate land. The fix re-asks the same question wherever the window already re-reads the line.

Where Change
_identity_refusal in chat_api/resume.py Re-asserts app_owns_transcript_meta on every re-read, audits the denial, and answers the app's uniform 404.
_restore_closed_marker A line the app does not own is not this resume's transcript, so the rollback leaves it alone.
_claim_history_delete docstring in handlers/sessions.py Names resume_conflict, the code resume answers.

docs/system-specs/modules/history.md states the ownership re-check.

Backwards compatibility

Compatible: the only new refusal is an app resume of a transcript that app no longer owns, which the pre-construction barrier already refuses with the same 404. Dashboard resumes and app resumes of their own transcripts behave as before.

Removes nothing: no key, route, field or public function is removed or renamed.

Tests

  • test_slot_ownership_checkpoint.py::...::test_resume_rechecks_app_ownership_after_the_reopen_write: parks clear_closed, deletes the legacy-shaped transcript and recreates it under another app, and expects 404, no slot, and the other app's line untouched. Fails on origin/main 6f70008 with status 200. Removing only the restore guard fails it on "the rollback closed another app's transcript".
  • test_resume_refuses_an_in_flight_delete.py::test_a_delete_opening_during_the_reopen_write_refuses_the_resume: opens the delete window inside clear_closed, after construction, and expects 409 resume_conflict, no slot, no leaked construction mark, and closed restored. Fails when the tail's in-flight term is replaced with False.
  • test_a_finished_delete_releases_its_window, test_a_delete_that_raises_releases_its_window, test_a_cancelled_delete_releases_its_window: the window closes after each.
  • test_a_resume_after_the_delete_finished_still_refuses_and_one_before_it_publishes is renamed test_a_skipped_delete_leaves_nothing_that_refuses_a_later_resume, which is what it covers.

Run: test_resume_refuses_an_in_flight_delete.py, test_session_control_revive.py, test_slot_ownership_checkpoint.py, test_remove_slot_for_history_key.py, test_resume_publishes_hydrated_slot.py (431 passed; with test_dashboard_chat.py, 1321 passed on the head rebased onto e281eca), test/test_history*.py and test/test_sessions_*.py (1026 passed); black, isort, flake8 and mypy on the changed files; check_comment_history.py, docs_lint.py and check_feature_map.py against origin/main.

Manual verification

N/A: the change is server-side ordering inside one request, and the tests force each interleaving deterministically.

Related Issues

Closes #17105

Pattern harvest

Rule candidate: review-prompt
Pattern: a check done once before an await is not re-asserted on the re-reads after it, so a guard the pre-await barrier enforces is missing from the window it was meant to cover.

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

@jeeshofone
jeeshofone requested a review from a team as a code owner October 5, 2026 19:13
@jeeshofone
jeeshofone requested a review from bolichen97 October 5, 2026 19:13
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Oct 5, 2026
@jeeshofone
jeeshofone force-pushed the fix/16433-resume-reserved-followup branch from 3ddd53a to 30eab77 Compare October 5, 2026 22:14
@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 Oct 5, 2026
@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

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

Design-Verdict: PASS

Nothing to check.

[DESIGN-REVIEWED] aecc55f

Description read

[DESCRIPTION-READ] ca0a45caeb0394b5bed389609a20c3a8fe8edcd20b7a714bce94f14f2c73e099

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] aecc55f

@github-actions

github-actions Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

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

Premise-level review of aecc55f786bf1a28f37d37218413823567bfb52c 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

Check that a resume after a finished delete really should answer 200. The old docstring said "A finished delete is still refused by the existence re-check", and test_a_finished_delete_releases_its_window now pins the opposite.

What this change ships

Inventory (7 items) — 5 justified

Intent: stop an app's resume from opening or closing a transcript that a different app recreated during the reopen window. This is a FIX.

  1. An app resume of a transcript deleted and recreated under another app during the reopen write now gets 404 instead of 200 — justified
  2. A refused resume no longer writes closed onto another app's recreated transcript — justified
  3. The ownership re-check covers all 3 re-reads in the window (_identity_refusal call sites at 1694, 1734, 1770), not just one — justified
  4. A new test pins the reserved tail's in-flight delete check — justified
  5. Three tests check the delete window is released after a delete that finishes, raises or is cancelled — rides along: tests only, no new surface
  6. The pinned-skip test is renamed and its docstring drops the "finished delete is refused" claim, which the test body never asserted — rides along
  7. The _claim_history_delete docstring names resume_conflict; history.md states the ownership re-check — justified

[FIRST-PRINCIPLES-REVIEWED] aecc55f

Description read

[DESCRIPTION-READ] 00832a128aedbf624c1cf4df215204a7c81807ff7040f5af94f300b9385cc407

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

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] aecc55f

@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 5, 2026
@jeeshofone
jeeshofone force-pushed the fix/16433-resume-reserved-followup branch from 30eab77 to 2d2ef83 Compare October 6, 2026 00:24
@jeeshofone

Copy link
Copy Markdown
Contributor Author
  • Item 3 -- resolved-directory key for delete marks rides along (reviewed 30eab77)

    fixed in 2d2ef83: removed. _delete_in_flight_marks keys on str(self._dir) again, as on main; _delete_mark_base, test_two_logs_naming_one_directory_differently_share_a_window and the spec wording are gone. The production users of the window all go through one state.conversation_log, so no caller needed it. The commit and the description no longer mention it.

Reds on 30eab77, all outside this diff (chat_api/resume.py, handlers/sessions.py, two test files and the history spec):

@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 Oct 6, 2026
@jeeshofone
jeeshofone force-pushed the fix/16433-resume-reserved-followup branch from 2d2ef83 to 89bc630 Compare October 6, 2026 00:34
@jeeshofone

Copy link
Copy Markdown
Contributor Author

New head 89bc630: 2d2ef83 rebased onto main 782dedd, no content change, so the Coverage Gate baseline row #17114 removed is not flagged here. The First Principles disposition above applies to it unchanged.

@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 6, 2026
A closed session's resume clears `closed` after the slot is built, in an
awaited worker call, and re-reads the metadata line after it. Those re-reads
checked existence, the delete-in-flight marker and `created_at`, but not
transcript ownership. On a line with no `created_at`, an app resume could
publish a transcript another app deleted and recreated inside that window,
and the rollback could write `closed` onto the other app's line.

`_identity_refusal` now re-asserts `app_owns_transcript_meta` on every
re-read and answers the app's uniform 404, and the marker restore treats a
line the app does not own as not this resume's transcript.

Tests pin the reserved tail's in-flight arm and the window's release after a
finished, raising or cancelled delete.
@jeeshofone
jeeshofone force-pushed the fix/16433-resume-reserved-followup branch from 89bc630 to aecc55f Compare October 6, 2026 03:15
@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 6, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Reviewed, not approving (crew-pr-reviewer). This changes an app-ownership authorization check in dashboard/chat_api/resume.py and dashboard/handlers/sessions.py. Our review rules leave auth and identity changes to a security owner, so I am not approving it from here.

@bolichen97 bolichen97 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.

Reviewed on behalf of the maintainers (sweep 2026-10-06): full diff read, callers verified against current main, readiness passed, required checks green, no blocking review threads. Security half: extends the existing app-ownership check into the post-await race window, gated on request_app, uniform 404 for apps, no effect on dashboard users or an app's own transcript. Bypass-closing class. Approving and merging.

@bolichen97
bolichen97 merged commit 557c8f8 into kirodotdev:main Oct 6, 2026
103 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 6, 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.

History resume of a closed session does not re-check app ownership after its reopen write

3 participants