Repository navigation
fix(crew-log): let the eager seal finish before a delete removes the log - #35705
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the 2 s wait comes after the flush, runs off the event loop, and a timeout leaves the log to the retention sweep as before. Notes
[DESIGN-REVIEWED] d85cb63 Description read[DESCRIPTION-READ] f22f00e8ba43a700a3d2d25efae4db21a93e85b341e30c862d11b08de695d4c2 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. The change is one bounded call to an existing barrier, Notes
What this change shipsInventory (3 items) — 2 justifiedIntent: when someone permanently deletes a chat, its crew log should be removed every time and not left on disk until retention runs. This is a FIX.
[FIRST-PRINCIPLES-REVIEWED] d85cb63 Description read[DESCRIPTION-READ] f08f0aadb34605dbe0dc405b6d01510bcde8d187f1d8c8f036feb83058fd28bd That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
|
[operator: bolichen97] Forced-condition evidence for the Command, run 5 times in a worktree at the parent PYTHONPATH=<plugin dir> FORCE_LOG=<log file> python -m pytest -n0 -p no:cacheprovider -p _force_seal_race -q \
'test/test_remove_slot_for_history_key_crew_log.py::TestSessionLedgerOnPermanentDelete::test_a_ledger_the_emitter_itself_opened_is_still_removed'Log of one parent run (all 5 the same; each failed with Log of one run at this head (all 5 passed and none logged a refused claim; in four the delete entered
|
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. False positive or not applicable? A repository writer can comment: |
Code change approver recommendation: ApproveWhy: the decider estimates a 10% chance that this change introduces a defect, within the 12% limit for approving on its own, and every check passes. Approve. This is a small, bounded fix for a race in permanent chat delete. Closing a session writes I checked that the fix works:
An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit |
buluoray
left a comment
There was a problem hiding this comment.
Approve on 9980f97. A permanent chat delete now waits, for at most 2 seconds and off the event loop, for the eager folder to finish the seal that the chat's close woke, and only then claims the crew log's lease to remove it. Before this, a claim that landed while that seal held a shared lease was refused, and the deleted chat's crew log stayed on disk until the retention sweep. The order is sound: the close's wake is queued inside the append job, so the flush returns only after it is counted, and the seal runs inside the fold batch before the batch is counted as settled. Removing the new wait turned the existing regression test red in 5 of 20 runs; with it the test passed 20 of 20. Every wait is bounded, nothing new holds a lock across a wait, and a timeout falls back to the earlier behaviour (the log is left to retention), so no path deletes more than before or blocks forever. Follow-ups, not blocking: the drain waits for the whole folder, not only this unit, so on a busy gateway it can use its full 2 seconds while other sessions keep queuing wakes; and the forced-interleaving plugin that proves the fix deterministically is not committed, so CI only catches a regression by chance. Decisive lines: src/kiro_crew/dashboard/handlers/sessions_parts/slot_teardown.py:390, src/kiro_crew/crew_log/eager.py:1176, src/kiro_crew/crew_log/eager.py:779, src/kiro_crew/crew_log/eager.py:546, src/kiro_crew/crew_log/emit_state.py:213, src/kiro_crew/crew_log/store_removal.py:166
Permanently deleting a chat flushed the emitter so the session/closed entry landed, then claimed the unit's lease sole to remove its crew log. That close also wakes the eager folder, which seals the unit's savepoints under a shared hold of the same lease. A sole claim landing mid-seal answered owned, so the deleted conversation's log stayed on disk until the retention sweep, and the test that pins the production shape failed whenever the seal won the race. The funnel now waits for the eager folder to settle, with its own 2 s bound like the flush, before it claims the lease. Closes #34376
9980f97 to
d85cb63
Compare
|
Rebased: main moved in Both test reds on 9980f97 were main's, and #35625 fixed them: |
Problem / Motivation
Goal: Permanently deleting a chat removes its crew log every time, instead of sometimes leaving it on disk until the retention sweep.
test/test_remove_slot_for_history_key_crew_log.py::TestSessionLedgerOnPermanentDelete::test_a_ledger_the_emitter_itself_opened_is_still_removedfails in CI on pull requests that cannot reach it (Linux, macOS and Windows backend shards, #34376): after_remove_slot_for_history_keythe session's crew log is still on disk (assert not self._exists("acp-emitted")). It kept failing after #34569, which fixed a different hold on the same lease.Why it matters
That test is the production shape of a permanent delete: the gateway that deletes the chat is also the one writing its log. When the race is lost in a real gateway, the deleted conversation's crew log, which holds its message bodies, stays on disk (excluded from its slot) until the retention sweep collects it. And every unrelated pull request that draws the red pays a rerun.
Not a goal
remove_unitclaims a unit's lease, or how the eager folder seals a closed unit, for any caller.What changed (motivation → approach → change)
A delete now removes the chat's crew log even when the log was closed a moment before.
A permanent delete writes
session/closed, flushes the emitter so that entry lands and the emitter lets go of its handle, then claims the unit's leasesoleto remove the files. Since #33967 the same close also wakes the eager folder, which seals the unit's savepoints (seal_session_folds) under a shared hold of that lease. The flush does not wait for that fold, so a claim that landed mid-seal answeredownedand the log stayed._remove_session_crew_logs(dashboard/handlers/sessions_parts/slot_teardown.py) now callseager.drainafter the flush, with its own 2 s bound, so the claim comes after the folder has settled, which covers the seal the close woke.crew-log-core.mdand theeager.draindocstring name this third caller.Backwards compatibility
Compatible: the delete makes the same removal, and its response can come back at most 2 s later while the folder settles; nothing it accepts, returns or keeps changes.
Removes nothing: the change only orders an existing removal after a background fold; the units removed and the units kept are the same.
Tests
No test file changes: the existing
test_a_ledger_the_emitter_itself_opened_is_still_removedis the regression test.Determinism proof (testing-conventions, Proving a determinism fix), parent =
ee7a026dd0:ee7a026dd0-n0, 5 runsassert not self._exists("acp-emitted"); the sole claim was refused while the seal held the lease)-n0-n 4 --dist loadgroup --max-worker-restart=2withtest/test_crew_log_retention.pyandtest/test_remove_slot_for_history_key.py, 10 runstest/test_crew_log_retention.py, shuffled, seed 1874 (94 ids)The forced condition is a throwaway
-pplugin, not committed. Once the close is emitted, the delete'ssolelease claim waits until the close-time seal (checkpoint.save(final=True)) holds its shared lease. The seal keeps that lease until the delete has either made its claim or enteredeager.drain, then 0.3 s more, so this head goes green only ifdrainreally waits for the seal. The plugin logs each step, so a run where the condition never fired cannot count as evidence.Proof: not provable -- other: prove.py re-runs only changed test files and this fix changes none; the unchanged flaky test is proven by the forced condition above
Manual verification
N/A — unit coverage sufficient: the change is one bounded wait, off the event loop, before the delete's removal, and the forced condition above drives exactly that interleaving.
Screenshots / video
N/A — backend only; nothing a user sees changes.
Related Issues
Closes #34376
Sibling sweep
Swept: git grep -nE "remove_unit(|stage_unit(" -- src/
Sibling: src/kiro_crew/dashboard/handlers/sessions_parts/slot_teardown.py:509 -- changed here
Sibling: src/kiro_crew/crew_log/store_retention.py:151 -- not affected -- the sweep removes only units whose close is older than the retention window, and an owned unit is retried by the next pass
Sibling: src/kiro_crew/eventlog/service.py:1312 -- not affected -- member units are not session units, so the close-time session seal never holds their lease
Sibling: src/kiro_crew/session_storage_parts/crew_staging.py:82 -- not affected -- the trash stages only sessions untouched for MIN_RECLAIM_AGE_DAYS, long after any close fold
Pattern harvest
Not generalizable: the delete funnel is the only path that writes a session unit's close and removes the unit in the same breath; every other removal acts on units closed long before.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)