Skip to content

feat(ledger): expire closed session ledgers on the archive switch - #11193

Merged
chenmingwei23 merged 1 commit into
kirodotdev:mainfrom
chenmingwei23:feat/ledger-retention
Sep 17, 2026
Merged

chenmingwei23 merged 1 commit into
kirodotdev:mainfrom
chenmingwei23:feat/ledger-retention

Conversation

@chenmingwei23

@chenmingwei23 chenmingwei23 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

The append-only session ledger had no retention writer. Transcript archives expire on
session.archive_retention_days, but the ledger beside them grew without bound, and permanently
deleting a session removed only its transcript. A Design-lane advisory on #10091 named it: bodies now
live in the ledger, so the smaller half of a conversation's history was being expired while the larger
half stayed on disk forever.

Two further defects were found while building the fix, and both were invisible from the outside.
session_lifecycle.destroy wrote no session/closed -- only the reset route did -- and that single
missing entry defeated retention from both sides at once. The emitter keeps a per-session handle that
carries the unit's write lease, so a removal claiming that lease sole answered owned for every
session the gateway had actually written for; and a unit whose newest lifecycle entry is not a close
reads as OPEN, so the sweep skipped it whatever its age. A destroyed session's ledger was immortal.

Why it matters

Someone who deletes a conversation expects it gone. They were getting the transcript row removed while
the ledger kept the message bodies, the tool calls and the model configuration of that conversation on
disk indefinitely -- and with no second setting to find, because none existed. On a long-lived gateway
the same gap grows the data directory without limit.

The two defects made it worse than a missing feature: a delete that reported success removed nothing
of the ledger, and no later pass would ever collect it either.

What changed

Chained from the symptom to the root cause:

  • Symptom: ledgers accumulate and survive a delete. Cause: nothing calls a removal.
    store.remove_unit is the one spelling of deletion in the package -- lease claimed non-blocking and
    sole, a REQUIRED guard re-decision inside the hold, segments first, .lease unlinked last and
    only by its holder -- and both the sweep and the delete funnel call it. store.sweep_expired runs
    from history._cleanup_old_archives, so session.archive_retention_days governs ledgers too: one
    switch, the existing hourly throttle, no new config key, and a negative value disables both halves.
  • Symptom: the funnel's removal always answered owned. Cause: destroy never recorded its
    teardown, so the emitter never released the handle holding the lease. destroy now writes
    session/closed {destroyed} beside the reset route's entry, which is also what releases the handle;
    the funnel flushes and then claims the lease. A flush that times out is not a failure -- the entry
    stays owed, so the sweep collects the unit once it lands.
  • Symptom: the sweep skipped destroyed sessions. Cause: the same missing entry made them read
    as open. Fixed by the same change, which is why one entry closes both.
  • Only a destroyed close authorizes collection, and that word asserts REVOCATION COMPLETED.
    destroy removes exactly one map key, so before claiming it the teardown checks whether any OTHER key
    still maps that ACP id; when one does it records destroyed_sid_retained instead and the log stays.
    Two keys on one sid is a state the system itself produces -- importing a transferred session twice
    allocates a new slot key each time and deliberately leaves the source intact
    (dashboard/session_transfer.py) -- so the other holder is not revoked to make the record tidy, and
    the shared log is kept while it can resume. An unreadable map withholds the claim for the same reason,
    and the permanent-delete funnel applies the same veto because it deletes without consulting the reason.
    Reading the map to WITHHOLD a claim is safe in the way reading it to grant one is not: a forged or
    emptied map can only make the gateway assert less than the truth, and the sweep itself still reads
    nothing but the ledger. reset is excluded even though it cold-starts its successor on a new id,
    because its own clear_sid is guarded by if clear_conversation and session is not None: a reset that
    keeps the conversation writes session/closed {reset} while leaving the old id mapped and resumable.
    An earlier revision asked session_map.json which sessions were still mapped and KEPT those; that was
    removed, because a VALID EMPTY map is not a failed read -- it reads as "nothing is revivable" and hands
    the trusted sweep a positive answer that authorizes deleting a fenced unit. Absence of protection must
    never be authorization.
  • Expiry reads the newest LIFECYCLE entry, not the newest close. A resumed session appends to the
    ledger it already had, so ... closed ... opened ... is a live conversation; reading the newest
    close alone would have deleted its log.
  • A failed removal no longer claims its history survived. Segments go first, so the ordinary
    partial removal is history already gone with something else left standing, and the log line says
    which of the two happened.

Open units, torn tails, crew ledgers, linked unit directories, a linked kind root, and a header whose
id does not fold back to its own directory are all refused regardless of age. Nothing is ever written
into a ledger that is about to be removed; a citation into a removed unit is already answered by
Ref.resolve reporting gone.

Alternatives considered and rejected: holding the write lease from a session's open through its append
(it contradicts ownership ending between turns by design, which is what lets an idle session be
collected at all); gating removal on the ledger being READABLE (that would make a damaged unit
immortal -- the one unit nothing can use would be the one retention could never reclaim); and matching
the delete funnel's target by slot key (slots are recycled, so a successor tab's ledger would be
collateral, which is exactly why the work ledger is preserved by this same funnel).

Tests

1,275 tests pass across test_ledger_retention.py, test_remove_slot_for_history_key.py,
test_ledger_core.py, test_ledger_lease.py, test_session_ledger_emit.py, test_history.py and
test_session.py.

What the new tests lock in: an expired closed unit is removed and an open one never is, however old;
a torn tail is left to the resume repair; a revived session is not expired by its older close; crew
ledgers are never scanned; a negative setting disables both halves; a unit a writer still owns is
skipped while its neighbour is collected; the lease file is removed last; a failure is counted and
never reported as a removal; destroy writes its teardown entry; a destroyed unit is then collectable
by the sweep; the funnel removes the matched ACP unit and no sibling; an unresolvable id removes
nothing; a refused or raising teardown keeps the ledger; both halves of the partial-removal report; a
mapping that names another slot's session removes nothing; a header with no slot is left to retention;
a destroyed close is collectable while reset, discarded, shutdown, crash, eviction, unknown, absent
and non-string reasons are not; a VALID EMPTY session map cannot authorize collecting a reset-closed
expired unit; and the sweep opens no file outside the ledger tree.

Every new test is mutation-verified -- the behaviour is inverted and the test must go red. 20 of 20
reddened on the final commit, including destroy writing no close, the funnel skipping its flush, the
terminal-reason check removed and then made to reject everything, reset re-admitted as terminal, the
reason no longer type-checked, a session_map.json read re-introduced into the sweep, the header-slot
check removed, a slotless header accepted, and the header reader skipping its id fold-back.

Two tests were strengthened after a mutation SURVIVED, rather than the mutation being weakened. The
no-file-created test now refuses the removal, because a ledger created and then removed leaves exactly
the state of one never created -- the end-state assertion could not see the property at all. And the
funnel test asserts owned BEFORE running the funnel, so a fixture that does not reproduce the
emitter-held lease fails loudly instead of passing quietly. That second one is how the defect above
hid: every earlier removal test built its ledger with Ledger.create, which leaves nothing holding
the unit, so they were green while the gateway could not collect a real one.

Manual verification

The emitter-held-lease behaviour was measured directly against the real emitter in a throwaway data
home, because it is the claim the whole delete-funnel half rests on: a ledger opened through the
emitter answers owned to a removal, and removed only once its close has landed.

The retention pass was also driven through the real config-resolved entry point
(history._cleanup_old_archives with no explicit retention) in an isolated home holding a real archive
file plus open, revived, closed and crew ledgers. It collected both halves in one pass and left the
open, revived and crew units alone.

Pod verification was attempted and is BLOCKED, not skipped: systemctl --user cannot reach the session
bus from this session's process, so kirocrew pod up exits 0 while starting nothing. The runtime check
above was substituted rather than falling back to the live gateway.

Related Issues

No linked issue.

Implements the retention section of merged RFC #10090 (docs/request-for-change/rfc-append-only-ledger.md
on main). Follows #10091, merged as 69aeb2803. Sibling #11185 wires the remaining emit sites; it does
not touch session_lifecycle.py, so the teardown entry here does not collide with it.

Pattern harvest

Rule candidate: review-prompt

Pattern: a test fixture that builds the object under test directly, rather than through the producer
production uses, can leave the feature dead while the suite is green. Here every removal test created
its ledger with Ledger.create, which leaves nothing holding the unit's write lease -- so the
sole-lease refusal that made the delete funnel a no-op in the gateway was never exercised. The
general shape: when a behaviour depends on OWNERSHIP or on state a long-lived process caches, the
fixture has to reproduce that ownership, and the test should assert the refusal it expects BEFORE
asserting the outcome, so a fixture that does not reproduce it fails instead of passing quietly.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|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

Other suggestions on the work

  • OWNER DISPOSITION -- "queued revival can lose a live session ledger" is NOT fixed here, by owner
    decision.
    The GPT lane's fenced finding is real and its mechanism is verified: on_session_opened
    does its work inside a job handed to the writer thread, so between a resume starting and its
    session/opened landing, the sweep's under-lease re-read still sees the old close and can win the
    race. Closing it needs a pending-open registration on that function's SYNCHRONOUS path plus a public
    per-session query -- live_turn reports only a PINNED turn, and buffered_writes() is process-global
    -- which means changing session_ledger_emit.py's queue structure and public surface. That file and
    its test belong to sibling PR feat(ledger): resolve slot keys and wire eight session emitters #11185, which is open and editing both, and this change is deliberately
    log-side only. Residual risk and the bound on it are recorded in a comment on this PR; the follow-up
    is has_pending_or_live(session_id) in the emitter with the guard extended to
    _still_expired(...) and not has_pending_or_live(unit_id).

  • All three security-class findings from the review rounds are FIXED in this commit, not deferred.
    The forged-mapping path is closed by requiring the unit's own header to name a proven slot. The
    unreadable-map path and then the valid-empty-map path are closed by removing session_map.json from
    the decision entirely: a unit is now collectable only on positive proof from inside the fenced tree,
    its own terminal close reason. My first two passes got this wrong in the same direction twice -- first
    documenting the window as an accepted residual, then guarding only the UNREADABLE map while a valid
    empty one still read as "nothing is revivable". Absence of protection is not authorization.

  • session_map.json being agent-writable is still worth its own issue. Nothing in this PR trusts
    it any more, but the same file authorizes session resume and subagent continuation across the
    gateway, so a forged entry still grants read and write of a victim's live conversation. Sealing it
    means adding the file to security/paths.py, a trust root, which does not belong in a retention
    change.

  • A close reason this build does not know keeps the unit forever. That is the safe direction, but it
    means a future teardown path that emits a new reason will silently stop collecting its sessions until
    the reason is added to _TERMINAL_CLOSE_REASONS. The alternative -- treating unknown reasons as
    terminal -- would delete history on a guess, so the tradeoff is deliberate; a doctor check counting
    uncollectable units would be a reasonable follow-up.

@chenmingwei23
chenmingwei23 requested review from a team and iamwhatever September 16, 2026 05:07
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: checking Automated validation is still running labels Sep 16, 2026
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — 🟡 CONCERNS

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

Design-Verdict: CONCERNS

Conversation-clearing resets unmap the sid but record non-terminal reset, so those ledgers stay uncollectable forever — the stated leak survives on that path.

Watch

The compaction-escalation path calls reset(..., clear_conversation=True) (session_compaction.py:611), which runs clear_sid — the id is unmapped and unresumable, exactly the "revocation completed" state destroyed asserts — yet the ledger gets session/closed {reset}, which _TERMINAL_CLOSE_REASONS excludes. The PR's exclusion argument ("a reset that keeps the conversation... leaves the old id mapped") covers only the conditional branch; the clearing branch produces a unit neither the sweep nor the funnel can ever collect, with full message bodies retained indefinitely on a long-lived gateway. The information to claim a terminal reason (or destroyed_sid_retained via the same veto) is available at that reset site, mirroring what this PR already does in destroy — and because entries are immutable, every unit written before a follow-up lands is stranded permanently, so deferring has a one-way cost.
Clears when: the clear-conversation reset branch records a terminal close (with the same other-key veto), or a spec note names this class an accepted residual with the doctor-check follow-up tracking it.

Suggestions

  • The proposed doctor check counting uncollectable units would also surface the clear-conversation class above; if it ships, wire the count per close reason so stranded classes are diagnosable, not just visible.

[DESIGN-REVIEWED] db993b1

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

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

Premise-level review of db993b17c92ebacac4a7e5f72b4c5183f1afcf28 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 coverage call: the RFC records the delete half (FR-7, #10705) but lists "Session ledger retention" as an open question — confirm riding session.archive_retention_days with destroyed-only collection is the answer maintainers wanted.

What this change ships

Inventory (10 items) — 10 justified

Intent: make deleting a conversation actually delete its ledger and stop opted-in ledgers growing without bound — an ADDITION (the retention path rfc-append-only-ledger.md FR-7 requires before the flag may default on), carrying the two destroy-path defects it surfaced.

  1. Permanently deleting a conversation now deletes its session ledger too — justified
  2. Closed session ledgers expire on the existing session.archive_retention_days switch; no new config key — justified
  3. Destroying a session now records session/closed {destroyed} in its ledger, as reset already did — justified
  4. A destroy leaving another slot key on the same session id records destroyed_sid_retained and keeps the log — justified
  5. Only a destroyed close authorizes the sweep; every other reason keeps the ledger — justified
  6. One removal path (remove_unit: sole lease, in-hold re-decision, identity last, counted failures), 2 counted consumers — justified
  7. The delete funnel refuses unless the ledger's own header names a slot this delete proved — justified
  8. Archive cleanup now runs its ledger half even before any archive directory exists — justified
  9. A failed removal's log says whether history was already partly destroyed — justified
  10. The sweep refuses links, torn tails, crew ledgers, foreign headers and open units regardless of age — justified

[FIRST-PRINCIPLES-REVIEWED] db993b1

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

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

Reviewed db993b17c92ebacac4a7e5f72b4c5183f1afcf28 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/ledger/store.py:733 -- queued revival can lose a live session ledger (origin: validation)
KIND_SESSION, unit_id, guard=partial(_still_expired, cutoff_ms, unit_id)
resumed session -> on_session_opened queues asynchronously -> guard still sees the old close and deletes history before the open lands.
Anchor: residual/crash-data-loss-corruption
Fix: coordinate removal with pending opens so a resumed session holds or vetoes the lease before becoming live.
[BLOCK-MERGE] db993b1
[GPT-REVIEWED] db993b1

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

The adjudicable block is empty (0 findings). One fenced finding, F1.

F1 — store.py:733, the sweep's remove_unit(..., guard=partial(_still_expired, cutoff_ms, unit_id)). Harm rung: UNBOUNDED — irreversible loss of a live conversation's ledger history, no recovery path once _remove_unit_contents unlinks the segments (store.py:964,969).

Conditions I confirmed from code opened this run:

  • The revival write is asynchronous: on_session_opened submits _job via _submit (session_ledger_emit.py:2389) and the write lease is taken lazily inside the job at ledger.append/_handle, not synchronously — so between resume-decision and first append the lease is unheld and the on-disk session/opened has not landed.
  • The guard _still_expired/_expired_unit_id decides on the newest on-disk lifecycle entry (store.py:1227-1238); with the session/opened still queued it sees only the terminal session/closed {destroyed} and returns the id, authorizing the delete.
  • The sweep path does NOT flush the emitter before claiming the lease (only the delete funnel does, sessions.py:466), so nothing forces the queued open to land first.
  • The design's defense ("an id whose mapping the gateway DELETED cannot be resumed") rests on the map, which _TERMINAL_CLOSE_REASONS itself documents as agent-writable (store.py:1029-1035); a re-planted mapping + in-flight resume is producible by the untrusted writer this whole mechanism is built to defend against — not a system-internal impossibility.

I cannot complete a record showing the condition combination is contradictory or that the trusted writer alone cannot produce it; the async-write window the finding names is real and the loss is irreversible. When torn on an unbounded, unrecoverable class, the contract requires UPHOLD-FENCED.

[ADJUDICATION] db993b1 total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] db993b1

[ADJUDICATION-FENCED] db993b1 fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/ledger/store.py:733 -- the async session/opened write leaves a window where the guard sees the terminal close and the lease is unheld, so a re-planted-map revival can be irrecoverably deleted; conditions are producible by the agent-writable map, not contradictory.
[GPT-ADJUDICATED-FENCED] db993b1

@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] db993b1

@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 Sep 16, 2026
@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 Sep 16, 2026
@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 Sep 16, 2026
@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 Sep 16, 2026
@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 Sep 16, 2026
…switch

Session message bodies live in the append-only ledger now, but nothing
expired it: `session.archive_retention_days` collected the transcript
archive while the ledger it points into grew forever, and permanently
deleting a session removed only the transcript.

One removal primitive, `store.remove_unit`, is what both callers use --
two callers deleting one tree two ways is two chances to get the order
wrong, and the order is the whole correctness argument. It claims the
unit's `.lease` non-blocking and SOLE, removes the segments, then the
per-append lock, then the lease LAST and only as its holder, counts every
failure, and writes nothing into a ledger it is about to delete.

`sole` is load bearing rather than decorative: the lease is refcounted per
process, so a plain claim against a unit this process is already writing
succeeds by joining that count and proves nothing -- which would let a
sweep inside the gateway unlink the segments the emitter's cached handle
is appending to. A sole holder also blocks every later claim until it is
released, so a writer cannot join the remover's own lock from the other
side.

`store.sweep_expired` runs inside `history._cleanup_old_archives`, on the
same setting and the same hourly throttle, with no new config key and a
negative value disabling both halves. It walks `ledgers/sessions` alone,
ages a unit from the last `session/closed` entry's own time (mtime only as
a fallback, since a restore resets it), and skips an open unit, a torn
tail, and a directory no id addresses.

The permanent-delete funnel removes the deleted session's ledger by the
ACP session id its claim proved, after the teardown released the lease.
That is the opposite of the rule for the WORK ledger, which the same
funnel preserves, and the difference is mechanical: a work ledger is keyed
by the recycled slot key, so a successor legitimately inherits it, while a
session ledger is keyed by the ACP session id and holds a lease.
@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 Sep 16, 2026
@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 Sep 16, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor Author

Owner disposition: not fixing "queued revival can lose a live session ledger"

Recording an owner decision on the GPT lane's fenced finding at src/kiro_crew/ledger/store.py,
titled "queued revival can lose a live session ledger". Its red row stays; this PR does not change
code for it. Accepted by the PR owner (Raymond Chen / chenmingwei23).

The mechanism is real, and verified

session_ledger_emit.on_session_opened does all of its work inside a nested _job() handed to
_submit(...); its synchronous portion only READS live_turn(session_id) and calls
_release_session_live(...). So between a resume starting and its session/opened reaching disk, the
file's newest lifecycle entry is still the old close, and the sweep's under-lease guard re-read reaches
the same answer it did outside the lease. The removal then wins the race and the queued open creates a
fresh ledger, so the pre-resume history is gone.

Why it is not fixed here

The fix requires the emitter to register a pending open on the SYNCHRONOUS path -- before the write is
enqueued -- and to expose a per-session query the sweep's guard can consult. Neither exists:

  • There is no synchronous registration point. The open's existence check, creation and append all run on
    the writer thread inside _job.
  • The only public per-session surface is live_turn, which reports a PINNED turn. A turn is pinned by
    turn/started, so a resume that has not yet started its turn reports zero and the window stays open.
    buffered_writes() is process-global, so consulting it would veto collection whenever any unrelated
    session had a queued write.

Adding the registration and the query means changing session_ledger_emit.py's queue structure and
public surface. That file, and its test, are owned by the sibling PR #11185, which is open and actively
editing both. This PR is deliberately log-side only and does not reach into the emit sites.

Residual risk, stated plainly

Reaching this window requires all of: a destroyed close whose revocation this PR verified (no key
mapped to the sid), a mapping for that sid RE-PLANTED afterwards so a resume can name it, a resume in
flight, and the hourly sweep firing inside the gap before the open lands. The re-planting step is the
agent-writable session_map.json trust question already disposed of separately -- it is not closable
from inside this PR either.

Two properties bound the damage rather than removing it. The loss is RECORDED, not silent: the queued
open finds no ledger and creates one, and the emitter's own loss accounting covers a write that could not
land. And every way of making the id reachable again that DOES land an entry makes the unit uncollectable
instead, because the deciding entry is the newest lifecycle one -- a session/opened after a
destroyed puts the unit permanently out of the sweep's reach.

What would close it

A pending-open registration on on_session_opened's synchronous path plus a public
has_pending_or_live(session_id), with the sweep's guard extended to
_still_expired(...) and not has_pending_or_live(unit_id). That belongs in the emitter, so it is a
follow-up on #11185 or a change after it merges -- not a redesign of retention.

@chenmingwei23
chenmingwei23 merged commit e65ec3e into kirodotdev:main Sep 17, 2026
95 of 102 checks passed
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 17, 2026
@didhd didhd mentioned this pull request Sep 17, 2026
5 tasks done
amadsalmon pushed a commit to amadsalmon/KiroCrew that referenced this pull request Sep 22, 2026
…switch (kirodotdev#11193)

Session message bodies live in the append-only ledger now, but nothing
expired it: `session.archive_retention_days` collected the transcript
archive while the ledger it points into grew forever, and permanently
deleting a session removed only the transcript.

One removal primitive, `store.remove_unit`, is what both callers use --
two callers deleting one tree two ways is two chances to get the order
wrong, and the order is the whole correctness argument. It claims the
unit's `.lease` non-blocking and SOLE, removes the segments, then the
per-append lock, then the lease LAST and only as its holder, counts every
failure, and writes nothing into a ledger it is about to delete.

`sole` is load bearing rather than decorative: the lease is refcounted per
process, so a plain claim against a unit this process is already writing
succeeds by joining that count and proves nothing -- which would let a
sweep inside the gateway unlink the segments the emitter's cached handle
is appending to. A sole holder also blocks every later claim until it is
released, so a writer cannot join the remover's own lock from the other
side.

`store.sweep_expired` runs inside `history._cleanup_old_archives`, on the
same setting and the same hourly throttle, with no new config key and a
negative value disabling both halves. It walks `ledgers/sessions` alone,
ages a unit from the last `session/closed` entry's own time (mtime only as
a fallback, since a restore resets it), and skips an open unit, a torn
tail, and a directory no id addresses.

The permanent-delete funnel removes the deleted session's ledger by the
ACP session id its claim proved, after the teardown released the lease.
That is the opposite of the rule for the WORK ledger, which the same
funnel preserves, and the difference is mechanical: a work ledger is keyed
by the recycled slot key, so a successor legitimately inherits it, while a
session ledger is keyed by the ACP session id and holds a lease.
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.

1 participant