Skip to content

fix(resume): refuse to publish a slot while its session's delete is in flight - #16435

Merged
iamwhatever merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/16433-resume-delete-in-flight
Oct 5, 2026
Merged

iamwhatever merged 1 commit into
kirodotdev:mainfrom
jeeshofone:fix/16433-resume-delete-in-flight

Conversation

@jeeshofone

@jeeshofone jeeshofone commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Resuming a history session while that session is being permanently deleted is refused, so the deleted conversation never stays open as a tab.

History resume re-checks that the session still exists, and is still the same session, after its threaded transcript read. That re-check is a lock-free get_metadata_status read. delete_session holds the transcript lock across its whole transaction (search-index drop, attachment and reply-thread staging, the unlink), so a re-check that lands inside the transaction still sees the file with its original created_at and resume publishes the slot (200). DELETE /api/sessions/{key} captures which slot to remove before its first await and removes only that slot afterwards, so the slot the resume published survives the delete.

The same window shows up in CI. test_a_delete_during_the_read_does_not_republish_the_transcript and test_a_delete_then_recreate_during_the_read_does_not_overwrite_the_replacement failed on Backend Tests (Windows) (4) for #15596 and #15592 with "resume published a slot ... (status 200)". Their parked transcript read has a 10 s fallback, and on a slow runner the racer's delete_session was still running when it fired (both tests took about 11.5 s), so resume re-checked mid-delete.

Why it matters

A user who deletes a session while a resume of it is in progress (a History click, a session-control revive) is left with an open tab holding the deleted conversation. The slot save's delete-won guard keeps that tab from writing the transcript back, so what they type there is silently dropped instead of saved. It also makes two resume tests fail at random on Windows CI for unrelated PRs.

Not a goal

  • Detecting a delete made by another process (the CLI). The marker is process-local; the save's delete-won guard remains the backstop there.
  • Adding a durable tombstone to delete_session.
  • Changing the timing of the existing tests in test/test_resume_publishes_hydrated_slot.py. With the fix they pass in either interleaving.
  • Other republishing paths (fork, transfer export). They already probe session_was_deleted before republishing.

What changed (motivation → approach → change)

Symptom: resume answers 200 for a session whose delete is in progress. Root cause: the existence and identity re-check cannot see a delete that holds the transcript lock but has not unlinked yet, and the delete handler only removes slots it captured before it started. Taking the transcript lock in the re-check is not an option, because the re-check is synchronous on the event loop just before the publish and must add no suspension point. So the delete publishes an in-process marker for its whole span, and resume, on seeing it at its last synchronous step, refuses with a retryable resume_conflict and leaves the session exactly as it found it. A retry after the delete ends finds the session gone or opens it.

  • ConversationLog.delete_in_flight_window(key) / delete_in_flight(key) (src/kiro_crew/history.py): a process-wide, counted marker keyed by store directory and transcript lock stem, so every spelling of one session shares it and nested windows release cleanly. It is dict bookkeeping under a threading.Lock, with no I/O, so it is safe on the loop. delete_session holds it for its whole transaction.
  • src/kiro_crew/dashboard/handlers/sessions.py: _claim_history_delete is now the one way a delete handler takes a slot claim. It opens the window on an ExitStack and captures the claim in the same synchronous step, and the caller closes the stack after its slot cleanup. A resume that published before that point is in the claim and is removed; one that re-checks after it is refused. api_session_delete and the bulk api_sessions_clear both use it (each row's window stays open until the batch cleanup). Their bodies moved unchanged into _delete_claimed_session and _clear_history_rows. The single delete's app check on the live slot runs on the claim inside the window, before the first await.
  • src/kiro_crew/dashboard/chat_api/resume.py (the resume core's home since refactor(dashboard): compose the chat handlers from chat_api owners #16427): when the resume core sees the marker held for a session that existed, at the last synchronous step before construction (after the member-binding read, so a delete whose window opens during any earlier await is seen), it publishes nothing and refuses with the existing resume_conflict (409). The containment hook's path makes the same check in _identity_refusal after its own awaits and refuses the same way through its existing _discard, which restores the marker.
  • A resume of a closed session now takes the hooked path's reserved window whether or not a hook is passed: the slot is built retracted under its construction mark, the closed clear runs there (compare-and-clear against the resume's start), the write is awaited and its result verified, the identity barrier re-runs on that read, and only then is the slot published. A clear that raises refuses with the existing reopen_failed (503) and publishes nothing; a refusal after the clear puts the marker back through the existing _discard. Every refusal before construction, the in-flight one included, leaves the marker as it was found and has nothing to roll back, so the lost-race arm's marker restore, the app-ownership late barrier's marker restore and the identity-baseline adjustment for the old eager clear are removed; both arms still answer an app with the uniform 404. A second resume that arrives during the clear finds the key under construction and gets resume_in_progress. The construction set keeps its meaning (only a slot build marks a key).
  • test/test_session_control_revive.py: the lost-race test now checks that a click refused resume_in_progress leaves closed set, and a new test checks that a click refused by an in-flight delete makes no durable write at all.
  • docs/system-specs/modules/history.md documents the marker, the refusal, and that the refusal leaves the session as it was found.

Backwards compatibility

Compatible: a resume that races an in-process delete of its session now answers 409 resume_conflict, an existing retryable code. A resume of a closed session clears closed after its slot is built and before it is published, instead of before its transcript read; if that write fails it answers the existing reopen_failed (503) instead of opening a tab that would not restore. No API, field or stored format changes.

Removes the lost-race arm's and the app late barrier's marker restores in the resume core, which nothing reaches once the clear follows construction. No path, record, key or public function is removed or renamed.

Tests

  • test/test_resume_refuses_an_in_flight_delete.py (new):
    • test_a_resume_that_rechecks_while_the_delete_holds_its_lock_is_refused: parks delete_session inside its locked section and releases the resume's read there. Expects 409 resume_conflict while the delete is still parked, no slot published. Fails on origin/main.
    • test_a_resume_racing_the_delete_handler_before_its_unlink_is_refused: the same against DELETE /api/sessions/{key}, parked at its first await after the slot claim. Fails on origin/main.
    • test_a_bulk_clear_racing_a_resume_before_its_unlink_is_refused: the same against DELETE /api/sessions, parked inside its worker after the row's claim and before delete_session.
    • test_a_resume_after_the_delete_finished_still_refuses_and_one_before_it_publishes: a skipped delete of a pinned session leaves no marker behind, so a later resume still publishes (control).
    • test_a_refused_resume_leaves_a_closed_session_closed_and_a_retry_opens_it: a closed session's resume inside a window that does not delete answers resume_conflict with closed and closed_at unchanged and no hold left behind; a retry after the window opens it with closed cleared.
    • test_the_reopen_write_lands_before_the_publish: the resume of a closed session is parked inside its marker clear, which finds the slot not yet published; a second resume gets resume_in_progress, and the first publishes once the clear lands with closed gone. Fails on 60779c3 (the clear ran after the publish).
    • test_a_reopen_write_that_fails_publishes_nothing: a raising clear answers 503 reopen_failed, publishes no slot, releases the construction mark and leaves closed set. Fails on 60779c3 (answered 200).
    • test_a_delete_starting_during_the_member_binding_read_is_seen: opens the delete window while a member resume is suspended in its late binding read. Expects 409 and no slot.
  • test/test_session_control_revive.py:
    • test_a_history_click_that_loses_the_race_leaves_the_marker_untouched and test_a_history_click_refused_by_an_in_flight_delete_writes_nothing: the second fails on the previous head (it cleared and restored the marker).
  • test/test_slot_ownership_checkpoint.py (app-ownership tests that pinned the old eager clear): the destination-interleaving test now expects the source still closed during the reads; test_a_late_refusal_leaves_the_closed_marker_untouched and test_construction_starting_during_the_reads_leaves_the_marker check that both refusals answer the app's 404 with no clear attempted and closed still set.
  • test/test_remove_slot_for_history_key.py: its fake transcript store gains a no-op delete_in_flight_window, the one method the handler now calls on it.
  • Commands run on the commit:
    • Rebased onto main af1eb61. Every test_app_*, test_history*, test_*resume*, test_dashboard_session* and test_session_control* file, plus the delete, transfer and chat-handler composition suites: 5063 passed, 17 skipped.
    • Every test file that touches clear_closed or the resume route (test_slot_ownership_checkpoint.py, test_channel_slots.py, test_members_dm_thread.py, test_session_end_interaction.py and others): 3228 passed, 8 skipped. test_app_script_cron_sibling_import.py errors at collection on this machine because its platform profile resolves to a non-default context; it does not import the changed modules.
    • black, isort --check-only, flake8 on the changed files, mypy on chat_api/resume.py, history.py and handlers/sessions.py, the black gate, comment-history gate against origin/main, docs lint: clean.
  • test_session_control_durable_sid_across_processes.py::test_the_store_names_another_slots_log_in_a_process_that_mapped_nothing fails locally on origin/main as well, unchanged by this PR.

Manual verification

N/A: the race is reproduced with forced interleavings in the tests above, which also cover the HTTP delete route end to end.

Related Issues

Closes #16433

Pattern harvest

Rule candidate: review-prompt
Pattern: a lock-free existence probe used as a barrier against a writer that holds a lock across a multi-step transaction cannot see the writer until it commits; pair it with an in-flight marker the writer sets before its transaction (and before any claim it takes), or take the same lock.

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

Contribution License Agreement

N/A: no CLA text has been published for this repository yet.

@jeeshofone
jeeshofone requested a review from a team as a code owner October 3, 2026 08:23
@jeeshofone
jeeshofone requested a review from iamwhatever October 3, 2026 08:23
@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 labels Oct 3, 2026
@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5, fork) — ✅ PASS

Design-level review of c9f19c5f781b2b228eefa0ea300b708b079e7e9c 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

Check that a hook-less resume of a closed session still broadcasts its rows when it publishes, now that broadcast_rows=not reserved holds them back during construction.

[DESIGN-REVIEWED] c9f19c5

Description read

[DESCRIPTION-READ] c2c52acf68cc1578caa666c3beaacd876ac16ea2662c8de0479f421af0b491ea

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

Copy link
Copy Markdown
Contributor

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

Premise-level review of c9f19c5f781b2b228eefa0ea300b708b079e7e9c 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 before merge: a failed closed clear now returns 503 reopen_failed. That reverses the deleted base comment "Best-effort: resume anyway" for History clicks.

Not justified as shipped

  • Item 5 — rides along: the bug being fixed doesn't need this change. It comes from reusing the hooked path's existing refusal branch. The description gives the reason ("instead of opening a tab that would not restore").

What this change ships

Inventory (8 items) — 7 justified

Intent: when someone deletes a history session while a resume of it is in progress, the deleted conversation is never left open as a tab. This is a FIX.

  1. Resuming a session while its delete is in progress in this process now answers 409 resume_conflict and creates no slot — justified
  2. DELETE /api/sessions/{key} marks the delete as in progress from the moment it captures the slot to remove until its cleanup has run — justified
  3. Bulk DELETE /api/sessions does the same for each row until the batch cleanup has run — justified
  4. A History resume of a closed session clears closed only after the hidden slot is built, so the tab appears only after that write lands — justified
  5. If clearing closed fails, the resume now refuses with 503 reopen_failed instead of opening the tab anyway — rides along, reverses "Best-effort: resume anyway"
  6. A second resume that arrives while the first one is clearing closed gets resume_in_progress — justified
  7. New ConversationLog.delete_in_flight_window / delete_in_flight (2 real callers each) — justified
  8. The two delete handler bodies moved, unchanged, into helpers that run inside the new window — justified

[FIRST-PRINCIPLES-REVIEWED] c9f19c5

Description read

[DESCRIPTION-READ] ef3b46dbf9a3e87a237de07edf608ef10a2e48abc8e7885727348a0e28f6d96a

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] c9f19c5

@github-actions

github-actions Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review (fork) — ✅ no blocking findings

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

Review details

No findings.
[GPT-REVIEWED] c9f19c5

@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 3, 2026
@jeeshofone
jeeshofone force-pushed the fix/16433-resume-delete-in-flight branch from 2537794 to cbbde04 Compare October 3, 2026 10:02
@jeeshofone

Copy link
Copy Markdown
Contributor Author
  • Restore the closed marker before refusing resume

fixed in cbbde04: the in-flight arm in resume_slot_from_history now calls _restore_closed_marker() before returning 409 when the eager clear ran (cleared_closed), answering reopen_rollback_failed (503) if the restore cannot be confirmed, the same answer the other refusal paths give.
_restore_closed_marker and pre_identity moved above the barrier unchanged so the arm can reach them; the restore stays identity-guarded, so a delete that lands leaves nothing to restore.
regression: test_a_refusal_for_an_in_flight_delete_puts_the_closed_marker_back (fails on 2537794, passes on cbbde04).

@jeeshofone

Copy link
Copy Markdown
Contributor Author
  • In-flight refusal skips the closed-marker restore

fixed in cbbde04, same change as the GPT finding on this line: the hook-less in-flight arm restores a closed marker the eager clear dropped before it refuses, and answers 503 reopen_rollback_failed if that cannot be confirmed.
regression: test_a_refusal_for_an_in_flight_delete_puts_the_closed_marker_back (fails on 2537794, passes on cbbde04).

@jeeshofone

Copy link
Copy Markdown
Contributor Author
  • Bulk clear is not covered.

fixed in cbbde04: api_sessions_clear takes each row's claim through _claim_history_delete, which opens that row's delete-in-flight window on an ExitStack held until the batch's slot cleanup has run. The per-row body moved unchanged into _clear_history_rows.
regression: test_a_bulk_clear_racing_a_resume_before_its_unlink_is_refused parks the clear inside its worker after the row's claim and before delete_session, then releases the resume there. It expects 409 and no surviving slot; it fails on 2537794 and passes on cbbde04.

@jeeshofone

Copy link
Copy Markdown
Contributor Author
  • Pair the window with the claim capture

fixed in cbbde04: _claim_history_delete(windows, state, key) in dashboard/handlers/sessions.py is now the only call site that takes a slot claim for a delete. It enters the window and captures the claim in one synchronous step, and both api_session_delete and api_sessions_clear use it. A future delete handler that takes a claim this way gets the barrier with it.
_capture_history_delete_claim is still called directly only by _remove_slot_for_history_key's no-claim fallback, which runs after the unlink and removes the slot it captures in the same step, so it has no window to open.

@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 3, 2026
@jeeshofone
jeeshofone force-pushed the fix/16433-resume-delete-in-flight branch from cbbde04 to 8b7d28c Compare October 3, 2026 13:22
@jeeshofone

Copy link
Copy Markdown
Contributor Author
  • Member resumes can publish after the delete claim (chat_handlers.py:13617)

fixed in 8b7d28c: the hook-less in-flight check moved below the member-binding read and its live-slot re-check, to the last synchronous step before _materialise_slot_from_history. No await separates it from construction, so a delete whose window (and claim) opens during the late binding read is seen.
regression: test_a_delete_starting_during_the_member_binding_read_is_refused parks the second read_dm_binding_for_slot call, opens the delete window there, then releases it. Expects 409 and no slot; fails on cbbde04 (200), passes on 8b7d28c.

  • Refusal rollback can archive a successfully reopened session (chat_handlers.py:13622)

fixed in 8b7d28c, in two parts:

  1. The in-flight arm reserves the key (begin_slot_construction) while _restore_closed_marker awaits and releases it after, the posture the hooked path's _discard already takes. A resume of the same key that the delete's end lets through during the rollback is refused resume_in_progress instead of publishing a tab the rollback then archives.
  2. A resume that was already past its early checks when the rollback ran is caught at publish time: if its eager clear dropped closed and the line re-read after its last await carries closed again, the hook-less path refuses resume_conflict (409). That is the answer the hooked path already gives when its deferred clear finds the marker back. The marker is already present, so there is nothing to restore.
    regressions: test_a_resume_let_through_by_the_delete_ending_cannot_be_archived_by_the_rollback (part 1) and test_a_closed_marker_put_back_after_the_eager_clear_refuses_the_publish (part 2). Both fail on cbbde04 and pass on 8b7d28c.

Local on 8b7d28c: test/test_resume_refuses_an_in_flight_delete.py 8 passed; every test file referencing resume, delete_session or delete_in_flight (44 files) 4575 passed, 8 skipped; flake8, isort, black, mypy on the changed source clean.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

Replies to the two advisory notes on cbbde04 (both lanes were PASS):

  • Design, test doubles with a truthy delete_in_flight: the check only runs when the session existed, and the resume suites that build their state with mock logs (test/test_dashboard_chat.py, test/test_title_refresh.py) pass on 8b7d28c (993 passed), as do the 44 files referencing resume or session delete. The one hand-written fake store the delete handler reaches (test/test_remove_slot_for_history_key.py) has an explicit no-op delete_in_flight_window.
  • First Principles, bulk-clear rows refusing resume until the batch finishes: intended. The window has to stay open until the batch's slot cleanup runs, because that cleanup removes only the slots claimed up front; closing a row's window earlier reopens the race for that row. A row that ends up skipped (pinned) or failed costs one retryable 409 while the batch is still running, and a resume after the batch publishes normally (test_a_resume_after_the_delete_finished_still_refuses_and_one_before_it_publishes is the control).

@jeeshofone
jeeshofone force-pushed the fix/16433-resume-delete-in-flight branch from 8b7d28c to 1e5211d Compare October 3, 2026 14:01
@jeeshofone

Copy link
Copy Markdown
Contributor Author
  • Item 4, the resume_conflict refusal when closed comes back, is a rider

narrowed in 1e5211d to the rollback case this PR creates. The arm that refused on any reappearing closed marker is gone, so the existing close-vs-resume race is left as it was. In its place, DashboardState._closed_marker_rollbacks counts the markers an in-flight-delete refusal has put back for a key; the refusal bumps it while it still holds the key reservation, and a resume refuses at publish only if that count moved since its own start.
Why the reservation alone is not enough: it refuses a same-key resume that reaches its checks while the restore runs. A resume that passed them before the reservation was taken (both read the session as closed, the first clears, the second's clear is a no-op) is still suspended when the restore lands, and would publish onto the archived line.
regression: test_a_resume_past_its_checks_cannot_publish_onto_a_rolled_back_marker forces that interleaving with the real refusal and rollback (no hand-written marker). It fails with the publish-time count check removed and passes on 1e5211d.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

Update to the GPT disposition above for the rollback finding, part 2: on 1e5211d the publish-time guard no longer refuses on any reappearing closed marker. It refuses only when an in-flight-delete refusal rolled this key's marker back after the resume started (a per-key count on DashboardState, bumped while the key is still reserved), on both the hook-less and the hooked path. The regression is now test_a_resume_past_its_checks_cannot_publish_onto_a_rolled_back_marker, which drives the real refusal and rollback. Part 1 (the key reservation during the restore) is unchanged.

@jeeshofone
jeeshofone force-pushed the fix/16433-resume-delete-in-flight branch from 1e5211d to c528448 Compare October 3, 2026 15:28
@jeeshofone

Copy link
Copy Markdown
Contributor Author

All three findings on 1e5211d sit in the rollback counter, and c528448 removes the rollback they guard rather than patching it a third time.

  • Rollback-conflict refusal leaves an archived session reopened (chat_handlers.py:13888)
  • Transcript aliases bypass rollback detection (chat_handlers.py:13235)
  • Hooked delete refusals omit the rollback counter increment (chat_handlers.py:14017)

fixed in c528448 by restructuring. The hook-less arm no longer refuses while a delete is in flight, so it never writes a closed marker back and there is nothing for another resume to race. _closed_marker_rollbacks and the publish-time count check are gone. Instead, when the core sees the marker at its last synchronous step before construction, it publishes nothing and hands back to resume_slot_from_history, which waits in a worker thread on ConversationLog.wait_for_delete (a condition notified as each window closes, keyed by the transcript lock stems, so every spelling of one session waits on the same marks). It then refuses resume_session_deleted if the session is gone or its created_at changed, or starts over from scratch if it survived. A delete that outlasts 60 s refuses with a retryable resume_conflict.

  • Finding 1: the conflict refusal it names no longer exists, and no in-flight path restores a marker.
  • Finding 2: the per-spelling counter is gone; the wait reads the stem-keyed marks.
  • Finding 3: there is no counter for _discard to miss. The hooked path's in-flight check in _identity_refusal refuses through its existing _discard, unchanged from main's handling of the other hooked refusals.
    regressions: test_a_resume_waiting_out_a_delete_that_does_not_go_through_publishes, test_two_resumes_waiting_out_one_delete_leave_the_session_open (two closed-session resumes on one aborted delete end with one tab and closed cleared), test_a_delete_that_outlasts_the_wait_refuses_with_a_retryable_conflict, and the delete-goes-through cases (lock, handler, bulk clear, member-binding read), which now expect the resume to wait and then answer 409 with no slot published at any point.

@jeeshofone
jeeshofone force-pushed the fix/16433-resume-delete-in-flight branch from 30114ad to 60779c3 Compare October 5, 2026 09:38
@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 merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Oct 5, 2026
…n flight

Resume re-checks existence and created_at identity with a lock-free metadata
read, but delete_session holds the transcript lock until it unlinks, so a
re-check inside the delete's transaction sees the file and publishes. The
session-delete handlers remove only the slot they captured before their first
await, so that slot survives as a tab of a deleted conversation.

Add a process-local in-flight marker on ConversationLog, keyed by store
directory and transcript lock stem. delete_session holds it for its
transaction, and _claim_history_delete opens it in the same step as the slot
claim for both DELETE /api/sessions/{key} and the bulk clear. Both resume
barriers refuse with a retryable resume_conflict while it is held.

A resume of a closed session, with or without a containment hook, now builds
its slot retracted under the construction mark and clears the closed marker
there: the write is awaited and verified before the publish, a failed clear
refuses with reopen_failed, and a refusal after it puts the marker back. Every
refusal before construction therefore leaves the marker as it was found and
has nothing to roll back.

Closes kirodotdev#16433
@jeeshofone
jeeshofone force-pushed the fix/16433-resume-delete-in-flight branch from 60779c3 to c9f19c5 Compare October 5, 2026 10:41
@jeeshofone

Copy link
Copy Markdown
Contributor Author

GPT F1 on 60779c3 (persist-before-you-publish: the hook-less clear_closed ran after the publish and a failure was logged while the resume answered 200): fixed in c9f19c5.

A resume of a closed session now takes the same reserved window the containment-hook path already used, with or without a hook. The slot is built retracted under its construction mark, the compare-and-clear runs there and is awaited, its verification read goes through the identity barrier (which includes the delete-in-flight check), and the slot is published only after that. A clear that raises refuses with reopen_failed (503) and publishes nothing; a refusal after the clear restores the marker through _discard. The post-publish clear is gone.

A second resume during the clear now finds the key under construction and gets resume_in_progress instead of the live slot.

Tests: test_the_reopen_write_lands_before_the_publish and test_a_reopen_write_that_fails_publishes_nothing (test/test_resume_refuses_an_in_flight_delete.py) both fail on 60779c3 and pass on c9f19c5.

The same head also fixes the four test_slot_ownership_checkpoint.py failures on Backend Tests (3.12, 2) and (Windows) (2) at 60779c3. Those tests pinned the old eager clear (the source was expected reopened during the reads, and two refusals were expected to restore a marker they had cleared). The clear now follows construction, so they assert that the source stays closed during the reads and that both refusals answer the app's 404 without attempting a clear.

@jeeshofone

Copy link
Copy Markdown
Contributor Author

Replies to the advisory notes on 60779c3 (both lanes PASS):

  • First Principles, the post-publish clear_closed failing or being cut off: fixed in c9f19c5 together with GPT F1 (see the disposition above). The clear now runs before the publish in the reserved window; a failure refuses with reopen_failed and publishes nothing, so no open tab can come back as closed after a restart.
  • Design, how the dashboard handles resume_conflict: this PR adds no new code. resume_conflict and resume_in_progress were already answered by this route, and resumeFromHistory (website/src/store/chat/lifecycle.ts) has no per-code branch, so a refused resume is handled like any other failed resume. The refusal text says "try again". A person who deleted the session does not retry, and a retry after the delete ends finds the session gone or opens it. Code-specific UI for resume refusals would cover every existing code, not just this one, so it is left for a separate change.

@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
@jeeshofone

Copy link
Copy Markdown
Contributor Author

Replies to the advisory notes on c9f19c5 (both lanes PASS):

  • Design, rows of a closed session's hook-less resume no longer emitted as live chat_message events during construction: intended. The tab that clicked gets every hydrated row in the resume response itself (resumeFromHistory in website/src/store/chat/lifecycle.ts builds its view from messages in that response), and other clients only learn of the slot from the slots push at publish. Events for a slot that is still retracted could describe a build that is then refused and discarded. The hooked revive path has always built with broadcast_rows=False for the same reason. An open (not closed) session's hook-less resume still builds unreserved and broadcasts as before.
  • First Principles, a failed closed clear now answering 503 reopen_failed instead of "best-effort: resume anyway": kept. This is the GPT finding on 60779c3, upheld under the repository's blocking persist-before-you-publish rule, which forbids logging a failed durable write while reporting success. Opening the tab anyway would give the person a session whose line still says closed, so it vanishes at the next start while they keep typing into it. The 503 is the refusal the hooked path already answered for the same failure, and it is retryable.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Oct 5, 2026

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

The race fix is sound. The in-process marker is counted, released in finally, and opened at the same instant the delete handler claims its slot. Resume checks it at every last synchronous step before publishing, so the window the issue describes is closed. A failed or cancelled delete releases the marker, so resume isn't refused forever. Two Low notes: the _claim_history_delete docstring names resume_session_deleted but the code returns resume_conflict, and moving the hook-less closed clear grows the PR beyond its goal (it's covered by tests). I read the tests but didn't run them against base myself. Approving.

Things I couldn't verify:

  • I did not check out either PR or run any tests; there was no local clone. For 16435, the new tests either call delete_in_flight_window, which doesn't exist on base, or expect a refusal where base returns 200, so they should fail without the fix. That conclusion comes from reading the tests, not a run. CI is green: 90 pass, 10 skipped, PR Readiness passed.
  • #16433 is tier:T1 with no triaged label, which T1 doesn't need.
  • Nothing was posted or modified on either PR. The @kirocrew-computer MCP server was not configured in this session; this review didn't need it.

@iamwhatever
iamwhatever enabled auto-merge (squash) October 5, 2026 16:15
@iamwhatever
iamwhatever merged commit 79f7da0 into kirodotdev:main Oct 5, 2026
101 checks passed
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 5, 2026
bolichen97 added a commit that referenced this pull request Oct 6, 2026
Backend Tests (Windows) (2) fails on unrelated PRs with 409
resume_conflict ("this session changed while resuming"). The cause is
not an unreadable identity re-read. A resume clears `closed` only when
closed_at is strictly earlier than the resume's start, and a tie keeps
the marker on purpose (#15444). Both stamps come from time.time(),
which moves every ~15.6 ms on Windows CPython 3.12, so a test that
closes a session and resumes it at once ties there, the clear is
skipped, and the post-clear verification refuses. Since #16435 every
closed resume verifies that clear.

Add close_before_resume() to chat_test_helpers: it states the
precondition "closed BEFORE the resume begins" by moving closed_at
60 s back, as test_session_control_revive._archive already does. Call
it from test_slot_ownership_checkpoint's _persist_and_close and from
the two close-then-resume tests in test_dashboard_chat.
test_resume_close_resume_no_duplicate_history also asserts that both
of its resumes return 200; on a tie its second resume was refused
unasserted and the test passed without running the cycle it covers.

Fixes #17117
iamwhatever pushed a commit that referenced this pull request Oct 6, 2026
…#17145)

Backend Tests (Windows) (2) fails on unrelated PRs with 409
resume_conflict ("this session changed while resuming"). The cause is
not an unreadable identity re-read. A resume clears `closed` only when
closed_at is strictly earlier than the resume's start, and a tie keeps
the marker on purpose (#15444). Both stamps come from time.time(),
which moves every ~15.6 ms on Windows CPython 3.12, so a test that
closes a session and resumes it at once ties there, the clear is
skipped, and the post-clear verification refuses. Since #16435 every
closed resume verifies that clear.

Add close_before_resume() to chat_test_helpers: it states the
precondition "closed BEFORE the resume begins" by moving closed_at
60 s back, as test_session_control_revive._archive already does. Call
it from test_slot_ownership_checkpoint's _persist_and_close and from
the two close-then-resume tests in test_dashboard_chat.
test_resume_close_resume_no_duplicate_history also asserts that both
of its resumes return 200; on a tie its second resume was refused
unasserted and the test passed without running the cycle it covers.

Fixes #17117
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 publishes a slot for a session whose delete is still in flight

2 participants