Repository navigation
Conversation
Design Review (Opus 5.5, fork) — 🟡 CONCERNSDesign-level review of Design-Verdict: CONCERNS The PR rebuilds process-death detection by hand: PID, start id, incarnation, monotonic heartbeat, 1 h ceiling, token fencing and receipts. A per-session OS try-lock does that by itself. Watch
Suggestions
[DESIGN-REVIEWED] a4491e3 Description read[DESCRIPTION-READ] 5f4883c4a6d4346f679e40dde1e78887b7d2e544fed9c1f1a7627dffb311d5db 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, fork) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS The lease, its fence and its liveness test fix the cause. A second mechanism, digest receipts written into users' memory files, rides along, and one wall-clock lease field has no reader. Not justified as shipped
What this change shipsInventory (10 items) — 6 justifiedIntent: stop the CLI and the gateway from both billing and writing memory for the same session span — FIX.
[FIRST-PRINCIPLES-REVIEWED] a4491e3 Description read[DESCRIPTION-READ] 37554f0d212ed000ecd8868c0ba34eb78a92d6f9ac2f39d64b963906abbb4a89 That sha256 names the PR description this verdict read. Recompute it with |
GPT 6.1 Review (fork) — 🔴 changes requested (blocking)Reviewed 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands. BLOCKING -- src/kiro_crew/history_consolidation.py:1305 -- A stale holder can permanently cap the replacement’s span
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 is the only finding, and it is fenced. My ruling is FLAG: it keeps blocking, and the only way to clear it is still an F1: I confirmed the failure path. The conditions needed are rare, all at once:
The harm is LOW to MEDIUM and contained. At the cap the span would have been dropped without a memory pass anyway. The only extra damage is a missing marker, and the base already documents and accepts that exact state for a failed abandonment-marker write ( 🏷️ Fenced finding(s) machine-flagged as likely edge caseThe 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.)
|
Opus 5.5 Review (fork) — ✅ no blocking findingsReviewed Review detailsNo findings block this merge. Three advisory findings follow. FINDING — src/kiro_crew/memory.py:97 — FINDING — src/kiro_crew/history_consolidation.py:1305 — the FINDING — src/kiro_crew/memory.py:514 — [OPUS-REVIEWED] a4491e3 |
|
Both fenced findings addressed — one fixed, one I'd like to argue against. New head: F1 — lease expires during a supported pass ( The finding is right, and the ceiling's own comment gave the game away: it claimed an hour was "far past any real pass", which is a statement about duration when the thing it needs to bound is silence. A holder that is alive and working past the ceiling is exactly the pass that most needs the exclusion — a long transcript on a slow provider — and it was the one that lost it.
Two details worth calling out, both pinned by tests:
I chose renewal over the alternative the finding offers ("cover the maximum supported consolidation duration") because there is no such maximum to cover. Widening the ceiling to fit the worst transcript we can imagine only moves the boundary; it does not stop it from cutting across a live pass. F2 — fail-open on lease-write failure ( This one I think should stay, and the adjudication above reaches the same conclusion — it flags F2 as an edge case on the grounds that the fail-open is a deliberate, documented tradeoff. Returning The two also need very different conditions. Fail-open costs anything only when a metadata write fails and a cross-process peer is consolidating the same session in the same window. Fail-closed costs a wedged session on the metadata write failure alone. If you'd still like this closed, the shape I'd suggest is not a fail-closed return but a retry with backoff around |
668fa3c to
f0f4c18
Compare
f0f4c18 to
1d371ad
Compare
9f21ca8 to
c5b1892
Compare
|
🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: This PR has been idle since 2026-09-26 with a blocking review and a conflicting base. I've assessed the blockers and they appear resolvable — I'll push fixes directly to this branch as a co-author. Assessment: GPT blocks because lease freshness is measured on the wall clock, so an ordinary forward step (suspend/resume, NTP) lets a peer take a demonstrably live holder's lease and both processes consolidate the same span. The stated fix is to measure heartbeat age with a cross-process monotonic timestamp and keep wall time only as a reboot fallback, plus re-snapshotting after acquisition since the lease is currently taken after One tension I will resolve rather than escalate: First Principles asks to delete the heartbeat/renewal subsystem outright, which pulls against GPT's fix, and deleting it reopens the earlier-round finding the heartbeat was added for. That is exactly the repair-versus-remove comparison our PR procedure already defines, so I will rule on it, take the smaller complete option that keeps the goal intact, and post a disposition either way. I will also flag that If you'd prefer I don't touch this PR, add the |
c1bd966 to
01da51d
Compare
01da51d to
0ab49b4
Compare
|
Current-head verification at
No source or branch change. Remaining review decision: accept the explicitly documented retention/expiry trade, or specify a different recovery policy. macOS verification of the shutdown flake remains outstanding. |
|
Pushed The current macOS shard-4 log fails I reproduced that exact assertion deterministically on Linux by injecting a second executor's All 71 subprocess-pool tests pass (Python 3.12, two workers), as does the deterministic interleaving probe. Changed-file Black/isort/flake8, Comment History Gate and diff-check pass. The previously completed 176 lease/retry/CLI tests were not rerun because their code is unchanged. Native macOS confirmation remains outstanding; Linux reproduction is not a claim of a green macOS run. PR Hygiene is already SUCCESS in the refreshed check list (run |
|
@NicholasRBowers — thanks for the offer. The blocker has moved since your assessment: the wall-clock-freshness finding is addressed at the current head via the monotonic lease stamp, and the remaining GPT 6.1 finding — the metadata CAS reporting success when its locked write skips a row-first line — is now fixed at head (8bd8167: the CAS fails when the write is skipped, with a regression test). No further pushes should be needed from your side. One gate remains: the Issue Gate wants an issue of this repository declared, and there is none — this exclusion work follows the consolidation changes already merged. Could you waive issue-gate, or point me at the issue it should reference? |
|
New head Root cause: the lease CAS made The fix splits the contract instead of choosing a side: Verified at this head: 143 passed across |
UX Review (Opus 5.5, fork) — ⏭️ skippedRevision |
Claim a durable, renewable session lease before consolidation. Compare the holder PID, process identity and monotonic heartbeat across processes; fence every publication and marker write with the acquisition token under the transcript lock. An unpersisted or unavailable claim refuses the pass without advancing caller completion bookkeeping. A holder can lose its lease after publishing but before acknowledging the transcript. Commit V1 publication receipts in the same atomic replacement as their outputs, and consult them on takeover. Validate the published history prefix and retain its boundary when new messages arrive. Preserve document receipts through owner edits and repair derived indexes on replay. Exercise takeover, interrupted publication, midnight rollover and source changes. Bound heartbeat cancellation checks with completion signals and isolate clock patches from the shared standard-library module. Co-Authored-By: Claude Code <noreply@anthropic.com>
AI-authored by kirocrew-steward (Codex). |
|
AI-authored by kirocrew-steward (Codex). Audit disposition ata4491e3200dbf969756d4071b72913b7cbe30fdd: data-loss repair and design ruling required; not review-ready. The stale-holder finding is legitimate: failure accounting happens before ownership is fenced, and _LeaseLostMidRun falls through to on_abandoned. A retained-lease repair must fence ownership and failure increment atomically and suppress abandonment on lease loss. Memory receipts must not leak source comments into context/indexing/cap warnings; the same finding appears at both history-read and projects-write sites. Compare receipt removal with crash/takeover behavior before editing the persisted format. The actual Windows CRLF receipt tests and V1 prompt test red need reproduction/classification. The separate OS-lock alternative is put to maintainers because it conflicts with the frozen Not-a-goal. No data-loss deferral, override or clearance is claimed. |
|
Thank you @Premshay for this work. The cross-process consolidation lease, its liveness test and the write fence are your design, and they now continue in #21159, with you as the commit author. Main moved a lot under this PR (sub-message slicing in #17965, and the
All checks on #21159 are green. Tracking issue: #21158. I'm closing this one in favour of #21159; your branch is left as it is. |
Problem / Motivation
Goal: Two processes never run a history consolidation over the same session span at the same time, so a span is billed and written to memory once.
HistoryConsolidator._runningis an in-memory set. It stops two consolidation passes over one session inside a single process and says nothing about another one — andkirocrew consolidateIS another process, running against the same transcripts while the gateway's 60s idle sweep is live.Both processes snapshot the same span, both spend a provider turn on it, and both write the history entry, preferences and lessons that turn produced.
Why it matters
Nothing catches it afterwards.
mark_consolidatedis idempotent, so the durable offset ends up correct and no error is raised: the cost is a duplicate billed turn and doubled memory writes for the same span, with no signal that it happened. The_runningguard reads like exclusion at every call site, which is what makes the gap easy to keep.The collision is not exotic —
kirocrew consolidate --allagainst a live gateway is enough, and every session whose idle sweep fires inside that window is exposed.Not a goal
_runningset, which stays as the cheap scheduling short-circuit.What changed (motivation → approach → change)
_consolidatetakes a durable lease on the session's metadata line, immediately after the retry-eligibility gate and before anything can be billed. It is claimed throughConversationLog.update_metadata_if, whose guard runs under the same cross-processflockas the write, so two processes arriving together cannot both pass it.No new locking machinery. The compare-and-set, the lock and the metadata line all already existed for the consolidation retry accounting — which is state about the same span, read under the same lock on every pass. The lease is four more fields on that line.
The
flockis held only for the compare-and-set, never across the LLM turn. Holding it for the pass would block every append to the session and freeze the conversation behind a provider call. That makes the lease a durable record rather than a held lock, so it needs its own answer to a holder that dies mid-pass.Liveness, not a timeout.
_lease_holder_is_livereads the recorded PID plusplatform_compat.get_process_start_id— already this repository's idiom for "still the process that wrote this record" (session_pid._pid_start_token), in-process on every platform that answers it, and different across a PID reuse. A crashed holder therefore stops excluding peers on the very next attempt rather than after a wait.Nonefrom that lookup means "cannot tell" and is never read as a mismatch, so a Windows holder degrades to pid-exists plus the ceiling instead of being falsely stolen from._CONSOLIDATION_LEASE_CEILING_SECS(1 h) bounds silence when the persisted monotonic heartbeat is comparable with the current clock. It is not a maximum pass duration. Legacy/malformed heartbeats and future monotonic stamps with inconclusive process identity retain a live PID until release, exit, identity mismatch or a usable heartbeat; the one-hour bound does not cover those cases. Expiry permits a peer to acquire the lease, and the previous holder is cancelled when its renewal detects the replacement.The token identifies one ACQUISITION, not the holder. That is what makes a second attempt from the same process refuse, and what stops a pass that overran the ceiling from clearing the claim that replaced it on its way out. The lease fields are deliberately not in
_CONSOLIDATION_META_KEYS: those are dropped when a span is marked consolidated, and the lease is still held at that point — the memory, lesson and history writes all come after it.Every write is fenced on that token. A holder whose renewals fail past the ceiling keeps working until its next renewal notices, so the expiry that lets a peer claim the span also opens a window where both passes are running over the same messages — and both reach publication. The acquisition token therefore travels with the run:
_publication_hold_checkedre-reads it inside the transcript lock the publication is about to take (dropping this process's cached metadata line first, the same precautionupdate_metadata_iftakes for its guard) and raises_LeaseLostMidRunwhen the line names another acquisition._mark_consolidated_fencedholds that same lock across the check and the marker rewrite, so a stale holder cannot advance the marker either, and the abandon marker in_note_failed_attemptis fenced the same way so it cannot retire messages the new holder is reading. A fenced pass returns_CONSOLIDATION_REFUSED, charges no attempt and leaves the span to the new holder — including when an earlier output already committed, because the pass does not own what it would write next._CONSOLIDATION_BUSYis a second instance of the sentinel class_CONSOLIDATION_REFUSEDalready uses. Callers now test with_no_pass_raninstead of against one instance, because what they act on is the shared part: no prompt was sent, nothing was billed, no window was covered — so the idle sweep's throttle,maybe_consolidate's preference offset and the CLI's success flag all have to stay put. Testing one instance is exactly how a new refusal reason reads as a completed pass; the preference offset advancing over a window nothing extracted is the case with teeth, and it has a test.Heartbeat age is monotonic. Every claim and renewal stamps
time.monotonic(), and liveness measures silence on that clock, so a forward or backward wall-clock step (NTP, VM resume) cannot release a working holder.platform_compat.process_incarnation_idadds a reboot-unique identity (Linux start ticks plus boot UUID, macOS libproc start, Windows creation FILETIME), so a PID/start pair reused after a reboot is not mistaken for the holder. A record with no monotonic stamp (legacy) keeps a live holder until it releases or exits rather than guessing elapsed time from the wall clock.The lease is taken before the authoritative snapshot, so a busy attempt reads nothing and a winner snapshots a span no peer can still be consolidating. Acquisition is shielded from cancellation, and a token written during a cancellation is recovered so
finallyreleases it. A refusal after billing (a source change, a lost lease) returns the same no-pass sentinel, andkirocrew consolidatereports "no completed pass recorded" for it.Deliberately out of scope
The lease does not replace
_running. The in-process set stays as the cheap scheduling short-circuit that avoids taking the lock at all, the same role the entry points'retry_eligiblepre-checks play for the backoff.Pattern harvest
Rule candidate: an in-process guard is not mutual exclusion over durable state. Where a resource is reachable by a second process — a file, a metadata line, a billed external call keyed on one — a set, a flag or a lock held in one interpreter's memory reads like exclusion at every call site while providing none. The tell is a guard whose lifetime is the process and whose subject is on disk.
Two consequences worth carrying: the exclusion has to live where the contention does (here, the same locked metadata line the state already occupies, not a new lock file), and a durable claim that outlives its holder needs a liveness answer, because a record cannot release itself. Prefer an identity the platform can verify (PID plus process start time) over a duration guess; keep a ceiling only as the backstop for what that identity cannot answer.
Tests
New
test/test_history_consolidation_lease.py(55 tests): who still holds a lease (missing/unparsable record, running holder, dead holder, recycled PID, unknowable identity, ceiling), taking and dropping it (claim, refuse, release, stale-token release, dead-holder takeover), what a refused pass costs (no provider call, span untouched, no attempt charged, holder's lease survives, preference window not marked covered), that the lease does not outlive its pass (completed and raising), and that a taken-over lease publishes nothing: the pass is refused,append_historyandmark_consolidatedare never reached, the span stays for its new holder, and a peer write hidden behind this process's cached metadata line is still seen.test/consolidation_lease_helpers.pygives the mock-log fixtures a metadata record the lease compare-and-set can read back, so a fixture that grants a lease it never records stops reading as a stale holder.The fence tests were also run against the pre-fix revision and fail there — the stale holder completes its pass and publishes — so that coverage is non-vacuous too.
Both exclusion guards confirmed non-vacuous by disabling the gate and observing
test_a_held_session_never_reaches_the_providerandtest_a_prefs_window_is_not_marked_coveredfail.pytest -q -k "history or consolidat or cli or memory" --ignore=test/test_transcribe.py— 7543 passed, 31 skipped. One unrelated pre-existing failure in the run,test_webex_client.py::TestReadLoopFrameDispatch::test_malformed_binary_frame_does_not_crash_the_loop, confirmed failing onmainwithout this change. Repo gates pass on the changed set: black ratchet, sync-io-in-async, comment-history, docs lint.Manual verification
N/A — the race is between two processes on a shared metadata line, and the compare-and-set, liveness and ceiling paths are all covered above.
Related Issues
Touches
consolidate_now's refusal handling and the CLI's skip message, which #9742 also edits. The two are logically independent — this one is about exclusion, that one about prompt size — and whichever lands second will be rebased.Checklist
Contribution License Agreement
N/A — template placeholder; no CLA wording is supplied.
🤖 Generated with Claude Code