Skip to content

feat: make SEL rotation and retention limits env-tunable (#4993) - #4997

Closed
patrigao wants to merge 1 commit into
mainfrom
fix/sel-tunable-caps-4993
Closed

patrigao wants to merge 1 commit into
mainfrom
fix/sel-tunable-caps-4993

Conversation

@patrigao

@patrigao patrigao commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Operators cannot widen the Security Event Log (SEL) limits without changing source code. A process-local override is not enough because the gateway, CLI, and scheduled jobs share one audit-log directory. A sibling with a scrubbed environment could rotate or prune at lower defaults and erase history protected by another process's raised policy.

Why it matters

SEL records tool calls and permission decisions. Retention settings must not let an audited child erase that evidence. Operators still need a safe way to retain larger segments, more closed segments, or more days of history for compliance.

What changed (motivation → approach → change)

Three startup variables widen the limits: KIROCREW_SEL_MAX_BYTES, KIROCREW_SEL_KEEP, and KIROCREW_SEL_RETENTION_DAYS. Each value is raise-only. Invalid values fail soft to the compiled default without logging the rejected value. The keep count stays below the bounded segment scan.

The highest declared max-bytes, keep, and days values live in security_events.meta/retention_floor.json. The sandbox exposes that top-level leaf as readonly and nofollow. The shared sensitive-path gate hides it as defense in depth. Only a complete, regular, single-link marker can authorize deletion.

A writer publishes an immutable pending raise before trying the non-blocking rotation lock. A lock holder reads the marker and pending records before rotation or deletion. A successful stamp folds every visible maximum into the marker. An incomplete or unauthenticated floor disables deletion. Rotation refreshes max bytes before closing the live file. prune(keep_days=N) clamps N to the refreshed days floor before either age sweep.

Bound Rotation count sweep Closed-segment age sweep prune(keep_days=N) prune() Live-log prune
Keep count Refreshed marker + pending records set _segment_keep before excess is computed. Not used by age deletion. Not used by the cutoff. Not used by the cutoff. Not used by live-entry deletion.
Retention days Not used by count deletion. Receives the cutoff only after the shared days floor is refreshed. max(N, self._retention_days) after refresh. Uses refreshed self._retention_days. Receives the same clamped cutoff and days value.
Max bytes Refreshed marker + pending records set _segment_max_bytes before rotation. The count sweep refreshes keep independently. Not used by age deletion. Not used by the cutoff. Not used by the cutoff. Not used by live-entry deletion.

The SEL module and tests are Black-formatted and removed from the formatting baseline. The baseline removal rides along deliberately: this change already reformatted every hunk it touched in those files, and leaving them baseline-exempt afterward would let future formatting violations in them land unchecked - the exemption removal tightens the gate rather than adding churn. The test root clears the three variables between cases. Operator and system documentation describe the variables, shared floor, pending records, and fail-closed behavior. The documentation linter recognizes only the live readonly marker path.

Tests

  • python3 -m pytest test/test_sel.py test/test_sel_prune_streaming.py -q — 331 passed. This includes rotation, pruning, contention, tamper, symlink, FIFO, hard-link, malformed-marker, oversized-marker, non-integer-marker, and off-event-loop initialization regressions.
  • Eight review-round regressions fail against the prior code and pass with it: a real EIO on the directory fsync propagates instead of being swallowed as an unsupported-platform hint; a skipped retention or prune sweep emits the kirocrew.sel.retention_skipped degraded-health counter; and TB-scale KIROCREW_SEL_MAX_BYTES / 100-year-plus KIROCREW_SEL_RETENTION_DAYS overrides clamp at coherence ceilings instead of folding into the monotone floor marker; and floor authority now lives inside the OS-sealed security_events.d — a forged low floor at the legacy security_events.meta path neither lowers retention nor deletes protected audit segments on new code, and legacy values seed the new authority only upward.
  • The two new regressions fail against the prior production code: a scrubbed sibling rotates at the default max bytes, and prune(keep_days=1) deletes an entry inside a 100-day floor. Both pass with this change.
  • Seven focused marker-attack regressions passed after removal of the unused legacy read path.
  • Four targeted TestIsSensitivePath SEL cases passed for the live log, readonly metadata, rotated segments, and absolute paths.
  • The baseline-aware Black gate, black --check --target-version py310, isort, flake8, and documentation lint passed. The touched Python files remain outside the Black baseline.

Manual verification

N/A — unit coverage exercises the construction, rotation, count sweep, age sweep, live-log rewrite, lock contention, and path-security behavior without an external service.

Related Issues

Closes #4993

Pattern harvest

Rule candidate: review-prompt
Pattern: Shared deletion limits need one authenticated monotone floor that every delete-triggering path refreshes.

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

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 40367c2d01f7e35d4945dec52ad965627e80595b — 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: CONCERNS

The security_events.meta migration path serves only installs of this unmerged branch's earlier rounds — no release ever wrote that location.

Not justified as shipped

  • Item 5 — zero consumers: the "retired" security_events.meta reader migrates a marker no shipped code ever wrote — grep security_events.meta across the repo finds 9 hits, every one added by this diff (reader, spec, tests), no writer anywhere — and the description's own mechanism paragraph ("values live in security_events.meta/retention_floor.json") still describes that superseded review-round layout while its Tests section says authority "now lives inside the OS-sealed security_events.d". The zero option costs no user of any release anything.
    Subtraction: delete _read_legacy_retention_floor, _LEGACY_RETENTION_FLOOR_SUBDIR, the two old_*floor* migration tests, the security_events.meta assertions in test_sandbox_governance_mask.py, and sel.md's "On first upgrade" paragraph.
    Clears when: the deletion is made, or a shipped release that wrote security_events.meta/retention_floor.json is named.

What this change ships

Inventory (10 items) — 9 justified

Intent: let operators widen SEL audit-log rotation/retention limits without editing source (issue #4993) — an ADDITION.

  1. Three raise-only env vars widen segment size, keep count, retention days — justified
  2. A shared retention_floor.json marker (plus pending-raise records) makes raises bind every process — justified
  3. Retention and prune sweeps now delete nothing without an authenticated floor marker — justified
  4. New kirocrew.sel.retention_skipped degraded-health metric — justified (2 emit sites counted)
  5. Migration reader for a legacy security_events.meta floor — zero consumers: no release ever wrote it
  6. prune(keep_days=N) clamps to the floor; sole production caller (heartbeat.py:254) passes no args — justified
  7. Prune's segment sweep now requires the rotation lock; unlockable prune deletes nothing — justified
  8. install.md table rows and sel.md retention section, including the offline floor-reset procedure — justified
  9. sel.py/test_sel.py reformatted and removed from the Black baseline — rides along (declared deliberate)
  10. Test root clears the three env vars between cases — justified

[FIRST-PRINCIPLES-REVIEWED] 40367c2

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — 🟡 CONCERNS

Design-level review of 40367c2d01f7e35d4945dec52ad965627e80595b — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Residue of an abandoned mid-review design shipped: the description's "What changed" and a migration path both describe a security_events.meta marker that never existed on main.

Watch

  • The description states "The highest declared max-bytes, keep, and days values live in security_events.meta/retention_floor.json. The sandbox exposes that top-level leaf as readonly and nofollow," but at HEAD authority lives in security_events.d/retention_floor.json and the new test pins security_events.meta OUT of every readonly leaf set — anyone reading the PR record will hunt governance at the wrong path.
    Clears when: the "What changed" section is rewritten to the security_events.d design the Tests section already describes.
  • _read_legacy_retention_floor and the sel.md "On first upgrade, a valid marker in the retired security_events.meta location…" paragraph migrate a location with zero references in the base tree — it existed only in this PR's own review rounds, so no released install can hold one. Shipping it makes a never-shipped intermediate state permanent code surface, docs, and seven regression tests every future SEL change must preserve.
    Clears when: the legacy reader, its tests, and the upgrade paragraph are dropped (or a maintainer confirms a released/internal build actually wrote security_events.meta).

Suggestions

  • Since no release ever wrote either marker, first-merge is the one moment the "legacy seed" complexity is deletable for free; after this ships, removal itself needs a migration argument.

[DESIGN-REVIEWED] 40367c2

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — 🔴 changes requested (blocking)

GPT 5.6 found at least one blocking issue that must be resolved before merging 40367c2d01f7e35d4945dec52ad965627e80595b. 1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/sel.py:615 -- Untrusted legacy marker bypasses SEL coherence ceilings

legacy_keep, legacy_days, legacy_max_bytes = _read_legacy_retention_floor(segment_dir)
Pre-upgrade agent plants oversized legacy values -> initialization persists them unchanged -> rotation and pruning remain disabled until disk exhaustion.
Anchor: residual/crash-data-loss-corruption
Fix: Clamp legacy days and max-bytes hints to their coherence ceilings before persisting them.
[BLOCK-MERGE] 40367c2
[GPT-REVIEWED] 40367c2

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

F1 (fenced) — src/kiro_crew/sel.py:615, legacy retention-floor hint applied unclamped.

Harm rung: the fence anchors this at unbounded (crash-data-loss-corruption), but the code I opened shows the realized harm is a recoverable, visible disk-pressure issue, not silent unrecoverable loss.

Conditions confirmed this run:

  • Legacy security_events.meta must be a real, agent-writable dir (sel.py:545-552); the marker domain is agent-writable by documented design — sel.py:329-335: "A sandbox that can forge this marker could already unlink the protected segments," and raising is "monotonically non-destructive" (sel.py:305-306). The test in this PR asserts security_events.meta is unmasked.
  • Reachable only when the canonical marker is absent — a one-time migration window; once _ensure_segment_dir stamps the marker (sel.py:2268) line sel.py:613 (not marker_present) closes the legacy path forever.
  • The agent can plant the identical oversized value in the canonical marker directly (also applied unclamped at sel.py:1138,1140), so F1's legacy framing grants no power beyond the accepted design.

Recovery: offline reset of the marker; no auto self-correction (sel.py:319-320). Huge days is fail-soft — prune keeps everything without crashing (sel.py:3466-3476); keep-count still bounds segment disk, so the only disk-exhaustion vector is huge max_bytes, which requires the untrusted agent to then generate enough events to fill the disk — self-inflicted and loud.

Real fix (clamp legacy hints to _SEGMENT_MAX_BYTES_MAX/_RETENTION_DAYS_MAX) is cheap, but the acceptance case is strong: the vector attacks the agent's own audit availability in a domain the design deliberately cedes, is visible and recoverable, and the ceilings are documented as an operator fat-finger guard (sel.py:316-322), not a fence against the agent. A repository writer would plausibly accept this residual — hence FLAG, not clearance.

[ADJUDICATION] 40367c2d01f7e35d4945dec52ad965627e80595b total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] 40367c2d01f7e35d4945dec52ad965627e80595b
[ADJUDICATION-FENCED] 40367c2d01f7e35d4945dec52ad965627e80595b fenced=1 flagged=1
FLAG F1 src/kiro_crew/sel.py:615 -- The floor marker is agent-writable by documented design (sel.py:329-335, raising is "monotonically non-destructive"), so the legacy hint grants no power beyond the canonical marker the agent can already write unclamped; harm is a one-time-migration, self-inflicted, visible, offline-recoverable disk-pressure issue, not silent unrecoverable loss.
[GPT-ADJUDICATED-FENCED] 40367c2d01f7e35d4945dec52ad965627e80595b

🏷️ Fenced finding(s) machine-flagged as likely edge case

The security fence keeps these findings blocking regardless of adjudication; the only clearance path is a human override. The annotate-only pass judged the condition combination each one requires extreme, and pre-drafted the override rationale below. A repository writer must independently verify a rationale before posting it — it is machine-authored, and a wrong override on a security-class finding ships exactly the class the fence exists to stop.

  • F1 src/kiro_crew/sel.py:615 — The floor marker is agent-writable by documented design (sel.py:329-335, raising is "monotonically non-destructive"), so the legacy hint grants no power beyond the canonical marker the agent can already write unclamped; harm is a one-time-migration, self-inflicted, visible, offline-recoverable disk-pressure issue, not silent unrecoverable loss.

    /ai-review override gpt 40367c2d01f7e35d4945dec52ad965627e80595b: The floor marker is agent-writable by documented design (sel.py:329-335, raising is "monotonically non-destructive"), so the legacy hint grants no power beyond the canonical marker the agent can already write unclamped; harm is a one-time-migration, self-inflicted, visible, offline-recoverable disk-pressure issue, not silent unrecoverable loss.
    

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 40367c2d01f7e35d4945dec52ad965627e80595b: <one-sentence reason>

@github-actions

github-actions Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review — ✅ no blocking findings

Reviewed 40367c2d01f7e35d4945dec52ad965627e80595b — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 40367c2

Verdict parsed from the review's SHA-scoped output markers for commit 40367c2d01f7e35d4945dec52ad965627e80595b.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 40367c2d01f7e35d4945dec52ad965627e80595b: <one-sentence reason>

@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 Aug 21, 2026
@patrigao
patrigao force-pushed the fix/sel-tunable-caps-4993 branch from 7a1091f to c71355f Compare August 21, 2026 21:52
@patrigao

Copy link
Copy Markdown
Contributor Author

Disposition: GPT blocking finding on 7a1091f18

Finding (span ff91a2389e17): Agent-controlled child environments can erase protected audit history — KIROCREW_SEL_MAX_BYTES=65536 KIROCREW_SEL_KEEP=1 kirocrew <any-cli> makes the child's trusted SEL writer rotate the shared log early and unlink protected segments, with no forensic marker (retention deletion leaves a clean chain by design).

Verdict: LEGITIMATE — FIXED in c71355fc7 (demanded fix narrowed: revert was disproportional; the erasure channel only exists for lowering).

The overrides are now raise-only: each variable's floor is its compiled default (KIROCREW_SEL_MAX_BYTES ≥ 32 MiB, KIROCREW_SEL_KEEP ≥ 7 and ≤ 4094, KIROCREW_SEL_RETENTION_DAYS ≥ 365). Raising is monotonically non-destructive — rotation happens later, the sweep deletes no sooner, prune keeps more — so the compliance use case from #4993 (widen retention) is fully served while the environment can never narrow the shared log's protection. Lowering attempts clamp up with a warning. Narrowing now requires editing the source constants, an operator-authenticated act a child env cannot reach.

The prior 64 KiB floor is subsumed and removed. Regression test added for the exact PoC (test_lowering_attempts_clamp_to_the_compiled_defaults sets MAX_BYTES=65536 KEEP=1 RETENTION_DAYS=1 and asserts all three clamp to defaults with visible warnings); the raise-path tests prove env values still reach the rotation gate, the count sweep, and prune().

Deferred (documented in the PR body): the issue's small-disk lower-ceiling use case cannot be safely served via env vars at all — any lowerable env knob reintroduces this finding. If wanted, it needs an operator-authenticated channel (source constants today; a config-file key would need the import cycle resolved) and is out of scope here.

Docs updated in the same commit: docs/system-specs/modules/sel.md (raise-only rationale), docs/guides/install.md (env table rows marked raise-only).

@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 Aug 21, 2026
@patrigao
patrigao force-pushed the fix/sel-tunable-caps-4993 branch from c71355f to 75d296f Compare August 21, 2026 23:31
@patrigao

Copy link
Copy Markdown
Contributor Author

Review dispositions for head c71355fc7 (round 2), fixed in 75d296f3d:

  • fixed — "Scrubbed-env child enforces compiled deletion bounds on a shared directory (KEEP=100 → child keep=7 → rotation deletes 93 protected segments)."

    Fixed structurally with the process-shared source the review asked for: the two deletion bounds (keep, retention_days) now live in a high-water marker security_events.d/retention_floor.json. The marker is monotone by construction — its single write site re-reads the stored floor and writes max(stored, requested) per field under a dedicated cross-process lock (.retention_floor.lock), so no process (scrubbed or concurrent) can ever publish a lower bound over a raise. Construction takes max(own, persisted); an instance raised above the compiled defaults eagerly creates the fenced segment directory so the stamp lands before any sibling can prune; and BOTH deletion sites (_enforce_segment_retention_locked, prune()'s default path) re-read the marker before deleting, closing the reverse ordering (long-lived scrubbed child constructed before the raise). Reads are nofollow-fenced: a pre-planted link at the directory or marker path reads as no floor, never as attacker-chosen values. The marker sits inside the SEL sensitive-path floor, so the audited agent's file tools cannot touch it.
    Regression tests: test_scrubbed_env_child_cannot_lower_a_raised_deletion_floor (the review's PoC verbatim: operator KEEP=100/RETENTION=400 → scrubbed child inherits 100/400), test_a_child_constructed_before_the_raise_prunes_with_the_raised_floor (reverse ordering via prune-time refresh), test_the_floor_merge_is_per_field_monotone (concurrent differently-raised writers cannot clobber each other), test_a_planted_marker_link_is_not_trusted_and_is_replaced (nofollow), test_a_damaged_floor_marker_fails_soft.

Same-span ledger — span ff91a2389e17 (sel.py env-override bounds): hit count 2 (round 1 "agent-child-env erasure" → raise-only floors; round 2 "cross-process divergence" → process-shared monotone marker). Round 2 is now fixed at the structural invariant the span was converging on: deletion bounds come from a process-shared, monotone, operator-side source enforced at deletion time. A third blocking finding in this span triggers the restructure/escalate protocol rather than another patch.

Also carried in 75d296f3d (pre-push local dual review, GPT + Opus mirrors): per-field monotone merge under the floor lock, nofollow fences on marker/dir/lock reads, and _SEGMENT_KEEP_MAX reserve widened to _SEGMENT_SCAN_CAP - 4 so the marker and its lock can never make the bounded scanner under-count segments at the extreme cap (which would have silently stopped retention).

@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 Aug 21, 2026
@patrigao
patrigao force-pushed the fix/sel-tunable-caps-4993 branch from 75d296f to 5a06de6 Compare August 22, 2026 00:25
@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 Aug 22, 2026
@patrigao

Copy link
Copy Markdown
Contributor Author

Pre-push review round 4 (local dual-model gate on the restructure), dispositions — new head 5a06de690:

Local Opus: PASS, 0 blockers, 2 advisories (both taken). Local GPT: 4 blockers, split verdict resolved finding-by-finding:

# Finding Disposition
1 FIFO / oversized marker can block or bloat the construction-path read Fixed. _read_retention_floor now opens fd-side with O_NONBLOCK|O_NOFOLLOW, fstat-gates to a regular single-link file, and bounds the read at 4 KiB (_FLOOR_MARKER_MAX_BYTES). Regression tests: planted FIFO (thread-bounded, must return promptly), oversized decoy.
2 Hard-linked marker stays externally mutable and can lower the floor Fixed. Same fstat gate rejects st_nlink != 1; os.replace at persist already de-links our entry. Regression test: hard-linked alias with planted-high values reads as no floor.
3 A lower-cap sibling defeats a raised MAX_BYTES Rebutted. max_bytes is deliberately outside the floor: deletion is governed solely by keep/retention (see the comment above _RETENTION_FLOOR_FILE), so a divergent smaller cap rotates earlier into more, smaller segments — count retention still keeps the newest N segments and the age sweep still honors the days floor. The claimed "discards history twice as early" conflates segment count with byte volume; the retention contract is count+age, unchanged since round 2's accepted design. Extending the floor to max_bytes would re-open round 3's contention surface for a bound that cannot delete.
4 Deferred stamp leaves a window; construction should not complete until the floor is durably visible Rebutted — contradicts the round-3 invariant. "Fail/defer construction until publication" is precisely the blocking/failing construction that round 3's blocker (a) required us to remove, and the module contract (fail-soft: the audit logger must always construct) forbids. The window is narrow, self-healing (stamp retries at every construction, rotation, and sweep; the raised process never deletes below its own bounds), and now documented as deliberately accepted (sel.md) per the Opus advisory covering the same fact.

Span ledger ff91a2389e17: server hits remain at 3 (round-3 restructure is this push); local rounds are pre-push hardening, not span hits. A 4th server blocker in this span escalates to the maintainer per the runbook instead of another round.

Gates on 5a06de690: SEL 226/226 (three new fence regressions), isort/flake8/mypy/black/docs-lint green, rebased onto origin/main.

@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 Aug 22, 2026
@patrigao

Copy link
Copy Markdown
Contributor Author

⚠️ Escalation to maintainer — same-span rule, 4th server round in ff91a2389e17

Server GPT has now posted blocking findings on this span (env-override construction / floor stamping in src/kiro_crew/sel.py) in four consecutive server rounds (7a1091f18 → c71355fc7 → 75d296f3d → 5a06de690). Round 3 already triggered the restructure protocol (dedicated lock removed, stamps moved onto the rotation lock, fd-fenced reads). Per the loop's stall rule I am stopping the fix rounds — the remaining findings need maintainer rulings, not another patch. I have verified both mechanisms against the code; neither is a false positive in the narrow sense, but each demands a decision only you can make:

Finding A — sel.py:534 — "agent env can permanently disable the disk ceiling"

An agent that can run any kirocrew command with env vars (KIROCREW_SEL_KEEP=4093 kirocrew security events) gets its raise persisted process-shared by the high-water marker — that persistence is the round-2 fix working as demanded. Worst case ≈ 4093 × 32 MiB ≈ 128 GiB retained. The demanded fix is "revert environment-driven retention raises until sourced from an operator-authenticated channel."
Why this is yours to rule on: it rejects the delivery mechanism issue #4993 itself chose (env vars). No patch inside the env-var design can satisfy it — from inside the process an operator's environment and an agent's environment are indistinguishable. Either the env-var mechanism stands (accepting that a raise is also agent-reachable — a retain-more direction, never erasure) or the feature needs an authenticated config channel, which supersedes the issue.

Finding B — sel.py:276 — "contended stamp defers → prune deletes inside the requested window"

Real but directly contradicts round 3's blocker (a) from the same reviewer. Round 3 demanded construction never block on the floor lock (event-loop freeze); the demanded fix now is "construction cannot succeed before its raised floor is established" — i.e. block or fail construction until published. Both invariants cannot hold: any design either blocks construction or accepts a narrow, self-healing first-stamp window (now documented in sel.md as deliberately accepted; the raised process itself never deletes below its own bounds, and the stamp retries at every construction/rotation/sweep).

The decision

  1. Rule on the invariant pair (B): non-blocking construction with a documented deferral window, or blocking-until-published. Round 3 chose the former at this reviewer's own demand.
  2. Rule on the mechanism (A): env vars stand per feat(sel): make the segment size cap and keep-count operator-tunable without editing source #4993, or raises require an authenticated channel (redesign → new issue).
  3. Depending on 1+2: post /ai-review override gpt 5a06de69099535db6927c653299037fb82dfe5b1: <reason> (repo-writer only — I cannot), or direct a descope (e.g. ship only MAX_BYTES env-tunable and move the two deletion bounds to a follow-up), or park the PR.

State of the branch: single commit 5a06de690 on fresh origin/main, 226/226 SEL tests + all lint gates green, all other checks passing, every prior concern answered on the PR. Span ledger: ff91a2389e17 server hits = 4; loop stopped per protocol.

@patrigao
patrigao force-pushed the fix/sel-tunable-caps-4993 branch from 5a06de6 to 281b0e4 Compare August 22, 2026 02:53
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Aug 22, 2026
@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Sep 16, 2026
@patrigao
patrigao force-pushed the fix/sel-tunable-caps-4993 branch from 5e8a01b to 87b2850 Compare September 16, 2026 08:30
@patrigao

Copy link
Copy Markdown
Contributor Author
  • MAX_BYTES raises are not process-shared — disposition: fixed in 87b2850.
    self-added: yes
    mechanism: segment_max_bytes joins keep/days in the authenticated floor marker and pending records; rotation refreshes the floor under the lock before deciding to close a segment

Confirmed: the marker persisted only keep+days, so a scrubbed-env sibling rotated at the 32 MiB default and the count sweep deleted early-closed segments.
Fix extends the EXISTING marker/pending mechanism (no second mechanism): raise-only, monotone, folded on stamp; _refresh_deletion_floor and the rotation path both lift _segment_max_bytes from the shared state. A marker missing any of the three keys now fails closed (no deletion) — safe, since no released install ever wrote a marker.
Branch table posted in the fixer report: every deletion-influencing tunable x entry point names its clamp source; max-bytes governs rotation only, days clamps every prune path, keep clamps the count sweep.
Red-first: scrubbed-sibling early-rotation test fails on 5e8a01b, passes on 87b2850. SEL 306 passed; 7 marker-attack tests passed. Repair delegated to a GPT-family model (gpt-5.6-sol; served model unverified).

@patrigao

Copy link
Copy Markdown
Contributor Author
  • Explicit prune bypasses the authenticated retention floor — disposition: fixed in 87b2850.
    self-added: yes
    mechanism: explicit keep_days clamps to max(keep_days, self._retention_days) after the authenticated floor refresh

Confirmed: prune(keep_days=N) reached the cutoff unclamped, so prune(keep_days=1) could erase within-floor audit history despite the refreshed floor.
Fix is the exact clamp the finding requested; the default (keep_days=None) path already used the refreshed _retention_days and is unchanged.
Red-first: prune(keep_days=1) with floor=100 deleted a protected event on 5e8a01b, deletes nothing inside the floor on 87b2850. SEL 306 passed. Repair delegated to a GPT-family model (gpt-5.6-sol; served model unverified).

@patrigao

Copy link
Copy Markdown
Contributor Author
  • Item 7 — legacy security_events.d/retention_floor.json read path has zero consumers — disposition: fixed (subtracted) in 87b2850.
    self-added: yes
    mechanism: none — pure deletion of the legacy read path

Subtraction executed exactly as specified: deleted _LEGACY_RETENTION_FLOOR_FILE, the legacy read branch and legacy_present gate in _read_retention_floor_state, the docs_lint.py exemption for security_events.d/retention_floor.json, the sel.md legacy paragraph, and the two legacy-only tests.
Removal does not reopen the erasure defect: the readonly security_events.meta marker and fail-closed deletion rule are untouched; the 7 focused marker-attack regressions pass after the deletion. Clears-when condition met: the legacy-read path is deleted.

@patrigao

Copy link
Copy Markdown
Contributor Author
  • Item 6 — description says the contention window is "deliberately accepted" while the diff ships pending records that close it — disposition: fixed in 87b2850.
    self-added: yes
    mechanism: none — documentation and PR body correction

The stale claim was removed from sel.md and the PR body was regenerated from the whole diff before the push: both now state that a writer atomically publishes an immutable pending raise before the non-blocking lock attempt, deleters read canonical + pending maxima, and the next successful stamp folds them — lock contention cannot expose a lower-policy deletion window.

@patrigao

Copy link
Copy Markdown
Contributor Author
  • Item 10 — whole-file black reformat of sel.py/test_sel.py via baseline removal rides along — disposition: rebutted.
    self-added: yes
    mechanism: none — formatting scope ruling

The reformat was not gratuitous: CI's blocking "Check formatting (black, baselined)" gate failed on this branch because the PR's own edits to these two files no longer matched the baselined state, and the repo's gate design expects touched files to become black-clean and leave the baseline rather than accrete exemptions.
Removing the files FROM the baseline strengthens the gate (they are now enforced); reverting would reintroduce the exemption and the CI red. The reformat is confined to the two files this PR already substantially edits — no third file was touched for formatting alone.

@patrigao

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: durable publish ordering for the retention-floor marker (staged-file fsync + floor-dir fsync)

  • retention raises are acknowledged before becoming crash-durable (sel.py:425)

fixed in 4d5a1a8: the staged marker fd is flushed and fsynced before os.replace, and the floor directory is fsynced after the rename, so an acknowledged raise is durable before anything else observes it.
Windows directory-fsync rejection is tolerated (POSIX is the durability target); any POSIX failure raises, so a raise is never acknowledged while un-durable. Pending raise records are cleared only after the durable rename, closing the paired-loss window the adjudicator described.
round-6 retrospective (3rd-round rule) ruled complete-the-invariant, not shrink: the persisted authenticated marker is KEPT — every smaller replacement (floor derived from segments, config-at-start pinning) re-opens the ratchet-defeat class this finding exercises, and rebuilding crash-durability plus tamper-resistance re-derives the same mechanism.
regression test records os.fsync/os.replace call order and asserts file-fsync-before-replace and dir-fsync-after; it fails on the pre-fix code.

@patrigao

Copy link
Copy Markdown
Contributor Author
  • First Principles PASS acknowledged

PASS verdict on 87b2850 acknowledged; the Item 7 legacy-path subtraction and Item 6 doc correction from the prior round are confirmed by this verdict. No open FP items remain on this head.

@patrigao

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: none this round — documentation correction only

  • The floor is monotone forever — sel.md's claimed narrowing path (source edit) doesn't work

fixed in 6d5b5a0: the "operator-authenticated source edit" claim is deleted; sel.md now states plainly that no config, environment, or source-default edit lowers a stamped value, and a new "Lowering a stamped floor or resetting the marker" section documents the real procedure — stop the gateway and agent processes, edit or delete security_events.meta/retention_floor.json as the host user, restart so can_initialize re-stamps from current config.
The fat-fingered-raise case is named explicitly as the section's worked example.

@patrigao

Copy link
Copy Markdown
Contributor Author
  • Marker corruption disables every sweep while rotation keeps minting segments, signalled only by log warnings

fixed in 6d5b5a0 via the item's own second clears-when arm: sel.md now documents that a malformed or damaged marker halts ALL retention deletion (fail closed) while rotation continues, names the repeated "no authenticated retention floor" log warning as the signal, and gives the operator reset procedure as the remedy.
A dashboard/SEL health surface was weighed and rejected as disproportional new mechanism at round 7 of this PR; the documented reset is the reviewer's own suggested subsuming remedy.

@patrigao

Copy link
Copy Markdown
Contributor Author
  • Suggestion: document direct operator edits of the marker as the canonical adjust/reset path

fixed (adopted) in 6d5b5a0: the new sel.md section makes the gateway-stopped operator edit/delete of retention_floor.json the canonical path for both lowering and corruption recovery, with no new code.

@patrigao

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: none this round — ruling requested on the round-5 pending-record ordering

  • F1 — a concurrent raise can miss the deletion-floor refresh (sel.py:2443) — disposition: needs-a-decision.

The window is real but inherent to any lock-based order: a raise landing after a sweep's under-lock refresh is logically concurrent, the pending record is durable and folded by every subsequent refresh, and GPT's own proposed serialization does not un-delete segments an in-progress sweep already removed — the residual is identical either way.
The adjudicator's FLAG concurs the residual is narrow, forward-correcting, and one a repository writer would plausibly accept; security-class findings are procedurally withheld from adjudication, so only a maintainer can converge it.
Maintainer question: accept raise-semantics as prospective (effective for every subsequent sweep, not retroactive to an in-flight one)? If yes, paste: /ai-review override gpt 6d5b5a0: raise semantics are prospective; pending record is durable and governs all subsequent sweeps, residual single-sweep window is inherent to any non-blocking design and self-correcting.
If instead you want the window shrunk, the smallest change is a floor re-read immediately before the unlink loop — it narrows but cannot eliminate the residual; say so and the next round implements it.

@patrigao

Copy link
Copy Markdown
Contributor Author
  • Windows delegation bypasses the new readonly floor span=fa7ab943e399

rebutted: not a defect — platform parity, not a gap this PR opens.
Kiro Crew has no native Windows sandbox backend (see the delegation note in
sandbox.py wrap_argv / _delegate_to_kiro_internal_sandbox): first-party kiro-cli
spawns delegate to kiro-cli's internal sandbox and other agent spawns fail closed.
That boundary applies identically to EVERY _CREW_READONLY_LEAVES trust root today
(denied_commands.json, security_policy.json, computer_use.json, file_delivery_consent.json).
security_events.meta inherits exactly the existing trust-root posture — parity, no widening.
The floor guards retention-lowering erasure; an agent that could write crew-home files
on such a platform could unlink SEL segments directly, so the marker is not the weakest
link there. The control's guarantee is scoped to platforms with an OS write boundary
(Linux mounts, macOS seatbelt), where it holds. Windows-wide leaf enforcement is a
platform work item spanning all trust roots, not this PR's diff.

@patrigao

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: no growth — this completes round 8's own fix (error handling correctness), adds no new primitive

  • Directory-fsync failure swallow acknowledges an undurable raise span=ff91a2389e17

fixed in 8a78155: the round-8 best-effort catch is now errno-discriminated. Only the "platform/filesystem rejects fsync on a directory fd" class is tolerated (EINVAL, ENOTSUP, EOPNOTSUPP, EBADF, EPERM, EACCES — Windows/macOS rejection shapes plus sandbox denials); every other errno (EIO, ENOSPC, EDQUOT, …) propagates so the caller never acknowledges a raise the storage did not durably record. AttributeError (no os.fsync) remains a tolerated capability gap. Red-first: a simulated EIO on a supported-platform directory fsync fails on the prior code (swallowed) and propagates with the fix; the two round-8 unsupported-platform regressions still pass, so fail-closed behavior on Windows/macOS is unchanged.

  • Skipped retention/prune sweeps are only a log line, not a health signal span=1ef349b48d5c

fixed in 8a78155: both skip sites (count sweep and age sweep) now emit the kirocrew.sel.retention_skipped counter with a surface attribute (retention | prune) alongside the existing warning, via the established metrics.events facade (lazy import per its documented cycle-avoidance contract). The metric is documented in events.py as a DEGRADED signal — rotation keeps minting segments while sweeps are disabled, so a nonzero rate is dashboard-visible unbounded-growth risk. Regression intercepts the emitter and asserts the counter fires on a damaged-marker skip.

  • Raise-only env bounds accept absurd values into the monotone floor marker span=6c854f1c4a3c

fixed in 8a78155: KIROCREW_SEL_MAX_BYTES and KIROCREW_SEL_RETENTION_DAYS now clamp at sanity ceilings (1 TiB per segment; 36,500 days) mirroring the existing _SEGMENT_KEEP_MAX idiom, so a fat-fingered raise (a byte count meant as MiB) cannot pin the shared floor absurdly high until an offline reset. Ceilings are deliberately generous so they never fight a legitimate raise; clamping happens at env ingestion via the existing _env_int(maximum=) path, which already logs the clamp. Two red-first regressions cover both variables.

@patrigao

Copy link
Copy Markdown
Contributor Author

span=ff91a2389e17

Finding (F1, sel.py:2504): concurrent raises can land after both deletion-floor refreshes — needs-a-decision

This is the same inherent residual class as the standing raise-vs-sweep decision (previously sel.py:2443; the line moved because round 8 added the pre-unlink refresh). The adjudicator again ruled it UPHOLD-FENCED on record-incompleteness, not on a proven reachable harm; its earlier analysis of this class concluded the residual is inherent — serialization cannot un-delete what an in-flight sweep already removed.
Decision remains with @patrigao (one ruling covers the class):

  • Accept raise semantics as prospective (governs sweeps that begin after the raise): /ai-review override gpt 8b2744e1e15bf5ae9692b424c1c6d33b31e89246: raise semantics are prospective; an in-flight sweep's snapshot is inherently unserializable without un-deleting, per adjudicator analysis
  • Or order the shrink-window round (serialize publication before acknowledgment — narrows, cannot eliminate).
    Not re-fixed per the round-6 convergence ruling: no further mechanism growth in the floor primitive without an explicit ruling.

@patrigao

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: marker parse validation tightened — no new structure

  • infinite JSON numbers crash SEL initialization — fixed

Fixed in a54506b: floor-marker fields must now be exact non-boolean JSON integers — the int() coercion is gone, and OverflowError joins the parse catch set.
A 1e309 or fractional marker now takes the existing fail-closed path (compiled defaults kept, deletion disabled, marker preserved for inspection) instead of raising past the catch and re-crashing every SEL init.
Red-first: 6 parametrized cases (non-finite + fractional × all 3 fields) fail on the judged head with the init crash; pass with the fix. Full battery on the new head: 328 SEL tests, lockdown gate, sync-io gate, black/isort/flake8 all green.

@patrigao

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: retention-floor init deferral — one-shot flag + lock, executed on the SEL writer thread

  • first-touch retention initialization blocks the event loop — fixed

Fixed in a54506b: a running-loop first touch no longer performs the floor scan, mkdirs, and durable marker fsyncs inline — initialization is deferred to the existing SEL writer thread, whose first queued batch serializes behind the one-time setup under the init lock.
Synchronous callers and off-loop construction keep their eager behavior; a critical loop-side write refuses (OSError) rather than waiting on disk, per the repo's no-blocking-on-event-loop rule.
Red-first: the new async regression fails on the judged head with retention mkdir calls on the loop thread; passes with the fix, with both queued events written in order and the repo's sync-io-in-async gate green.

@patrigao

Copy link
Copy Markdown
Contributor Author

span=4509d9f16a93

Finding (F2, test/test_sel.py:5273): the test leaks a per-test SEL daemon writer — fixed

Legitimate and deterministic. test_first_touch_retention_init_runs_off_the_event_loop constructs an async SecurityEventLog(base_dir=sel_dir), drives it with two log() calls, flushes, and returned without joining the writer — so the sel-writer daemon thread survived teardown and could hold the chain lock at the instant a later test's loop-side critical audit takes its single shot (the cross-test flock contention the sibling tests at test_sel.py:705-721 already guard against).
Fix: added a shared module-level stop_sel_writer(log) helper (queue the None sentinel, join(), assert not alive) — the retrospective's preferred shared-helper form rather than another ad-hoc block — and called it at the end of the test. Red-first proven in the parent: without the call, log._writer.is_alive() is True after the body; with it, False. Full suite green (328 passed across test_sel.py + test_sel_prune_streaming.py), black/isort/flake8 clean.
The test keeps base_dir=sel_dir deliberately — it asserts on first-touch mkdir/fsync under that dir, which the session-scoped dir cannot observe in isolation — so the join is the correct closure, not omitting base_dir.

@patrigao

Copy link
Copy Markdown
Contributor Author

span=ff91a2389e17

Finding (F1, src/kiro_crew/sel.py:559): a pre-upgrade sandbox can forge the deletion floor — needs-a-decision

A read-only convergence retrospective verified this and ruled it UPHELD, scoped to a real supported configuration: on the macOS private-memory Seatbelt profile, a stale pre-upgrade sandbox's generated profile seals security_events.jsonl and everything under security_events.d, but has no rule for the newly introduced security_events.meta leaf (the pre-upgrade _CREW_READONLY_LEAVES never names it). That stale process can therefore write security_events.meta/retention_floor.json with the compiled defaults; a scrubbed post-upgrade sibling reads it as authenticated=pending_complete, the requested local defaults are <= the forged floor so _persist_retention_floor never re-stamps, and count/age retention then delete protected audit history against the forged floor. In ordinary modes where security_events.d is writable this collapses to the round-9 weakest-link parity (the attacker could unlink segments directly), but that does not cover the private-memory case.

This is the second new class after the mechanism was declared CONVERGING, so the retrospective downgraded the mechanism to NON-CONVERGED / REOPENED and requires your design ruling before any further local hardening round — I did not patch it, per the standing convergence commitment (no further growth in the floor primitive without an explicit ruling).

The retrospective's recommended fix is COMPLETE-THE-INVARIANT: move the floor authority (_RETENTION_FLOOR_FILE + _RETENTION_FLOOR_PENDING_PREFIX, currently under _RETENTION_FLOOR_SUBDIR = "security_events.meta") into _SEGMENT_SUBDIR = "security_events.d", the same protection domain as the history it authorizes deleting — so any sandbox that can forge the floor could already unlink segments, in every profile generation. A sandbox_generation marker field is explicitly rejected (the stale process can forge that field too).

Your decision, @patrigao:

  • Order the complete-the-invariant round (move floor authority under security_events.d, add the cross-generation regression the retrospective specifies). Say the word and I run it.
  • Or accept the residual and merge as-is: /ai-review override gpt a54506b63308cec585de2abea1c9c63028671038: version-skew forge requires a stale pre-upgrade private-memory sandbox coexisting with a scrubbed post-upgrade sibling; accepting the residual for this release

The retrospective also asks that, before the mechanism is called converging again, the invariant be reviewed at design level across current + stale sandbox profiles on Linux, macOS private-memory Seatbelt, and platforms with no equivalent segment seal.

@patrigao

Copy link
Copy Markdown
Contributor Author

span=6ebfad1fd011

Item 9 (whole-design): the Black-baseline removal + reformat of sel.py/test_sel.py rides along and ships no surface — adopted, justified

Correct that it ships no runtime surface, and deliberate. This change already reformatted every hunk it touched in those two files; leaving them in .github/black-baseline.txt afterward would let future formatting drift in them land unchecked. Removing the exemption tightens the gate rather than adding churn — the alternative (keep the files baseline-exempt) is strictly weaker. The PR description declares the ride-along explicitly, and the Black gate (black --check --target-version py310), isort, and flake8 all pass on the touched files with them outside the baseline. No change made; the ride-along stands as designed.

@patrigao

Copy link
Copy Markdown
Contributor Author

span=ff91a2389e17

Finding (src/kiro_crew/sel.py:336): version-skew floor forge — needs-a-decision (unchanged)

Same finding, same span, re-stamped on the round-11 head. The adjudicator again ruled UPHOLD-FENCED, and GPT's verdict has now converged to exactly this one item — F2/F3 accepted, raise-vs-sweep no longer raised. The full analysis and the convergence retrospective's ruling (mechanism NON-CONVERGED / REOPENED, complete-the-invariant recommended: move floor authority under security_events.d) are in the round-11 disposition: #4997 (comment)

Not re-fixed per the standing convergence commitment — no further growth in the floor primitive without an explicit design ruling from @patrigao.

Your decision:

  • Order the complete-the-invariant round (floor moves into the segments' protection domain + cross-generation regression) — say the word and I run it.
  • Or accept the scoped macOS-only residual: /ai-review override gpt ade7c5b5e96a508c94bc85d718708f5c09d8b280: version-skew forge requires a stale pre-upgrade private-memory sandbox already running on the host; accepted as residual, invariant completion tracked as follow-up

The segment size cap (32 MiB), keep-count (7), and retention window
(365 days) were hardcoded module constants, fixing the audit-log disk
ceiling at ~256 MiB for every install: a small-disk container could not
lower it, and a compliance install could not raise the keep-count to
match the stated retention window.

Read three overrides once at SecurityEventLog construction —
KIROCREW_SEL_MAX_BYTES, KIROCREW_SEL_KEEP, KIROCREW_SEL_RETENTION_DAYS —
via a fail-soft _env_int() helper. Malformed, zero, or negative values
clamp to the default with a warning that names the variable only (never
the rejected value, which could be a mis-pasted secret). Plain
os.environ reads on purpose: kiro_crew.config would be an import cycle.
The module constants stay the single source of the defaults, and the
rotation/prune sites now read the instance attributes.

Closes #4993
@patrigao

Copy link
Copy Markdown
Contributor Author

span=ff91a2389e17

Finding (src/kiro_crew/sel.py:336): version-skew floor forge — fixed

Design ruling received from @patrigao: complete-the-invariant, per the round-11 convergence retrospective. Landed on head 40367c2d0:

  • Floor authority moved into the segments' protection domain: the authoritative retention_floor.json now lives inside the OS-sealed security_events.d, excluded from all segment enumeration (never rotated, pruned, or counted — with a name-collision assert against the segment regex).
  • Legacy path de-authorized fail-closed: a marker at the old security_events.meta path never authenticates (pending_complete or otherwise). Legacy values seed the new authority upward only — a forged low floor can neither lower retention nor delete protected audit history on new code.
  • Cross-generation red-first regression: test_old_path_forge_cannot_lower_segment_directory_floor fails on the prior code with the attack's own signature ("the forged old-path floor deleted protected audit segments") and passes with the fix, plus three sibling invariant regressions (protection-domain, never-pruned, upward-only seeding). 2088 tests + lockdown + sync-io gates + repo-pinned black/isort/flake8 green on the rebased tree.

This closes the last open GPT finding; the floor mechanism's REOPENED status is resolved by invariant completion rather than override.

@bolichen97

Copy link
Copy Markdown
Contributor

Maintainer note: PR #11780 (merged 2026-09-19, bc0d2b0cf, "simplify member memory to one SQLite store") removed the protected-binding / private-execution member memory model. Two PRs written against the old model merged after it with a textually clean merge and broke main at import time (#11947, #11960); both are now reverted. This PR carries the same hazard.

Already conflicting; when rebasing please also update test_sandbox_governance_mask.py:302, which calls sandbox._private_memory_seatbelt_rules() (removed; memory_stores moved from HIDDEN to READONLY in the new model).

Copy link
Copy Markdown
Contributor

Open-PR triage, 2026-10-05: REBASE + CONTINUE-DEVELOPMENT

Checked head 40367c2d0 against origin/main af1eb612d. The merge-base is 1cd6811fa, and main is now 2,578 commits past it.

  • Not superseded. origin/main has no KIROCREW_SEL_MAX_BYTES/KEEP/RETENTION_DAYS, no retention-floor marker, and still has prune(self, keep_days: int = _RETENTION_DAYS) (sel.py:3028). Issue feat(sel): make the segment size cap and keep-count operator-tunable without editing source #4993 is still open.
  • Conflicts. git merge-tree reports content conflicts in src/kiro_crew/sel.py, src/kiro_crew/metrics/events.py, and .github/black-baseline.txt.
  • Hidden breakage after a clean rebase. test/test_sandbox_governance_mask.py (new test_sel_floor_shares_the_segment_protection_domain) calls sandbox._private_memory_seatbelt_rules(). refactor(memory): simplify member memory to one SQLite store #11780 removed that function from main, so this test fails even if the rebase applies cleanly. The maintainer note from 2026-09-19 already flagged this.
  • Still open. The GPT security-class finding at sel.py:615 is unresolved: legacy security_events.meta hints seed the new marker without the _SEGMENT_MAX_BYTES_MAX/_RETENTION_DAYS_MAX clamp. It needs either the cheap clamp or a human override.
  • Overlap (complementary, not duplicate). fix(sel): flush the audit tail before every gateway hard exit #6731 also edits sel.py and sel.md. Its goal is flushing the audit tail before a hard exit, and it does not touch rotation or retention, so whichever PR lands second will need a small rebase.

No duplicate or superseding PR was found, so this PR should stay open.

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

Requesting changes on head 40367c2d01f7e35d4945dec52ad965627e80595b. It addresses #4993: the three raise-only variables, the fail-soft parse that never echoes the rejected value, and the clamped keep count all follow the shape the issue asked for. I can't approve it until the following are fixed.

  1. Rebase needed. The branch is about 3,270 commits behind main and conflicts in sel.py, metrics/events.py, sel.md and .github/black-baseline.txt. main has since changed sel.py with #13308 (chain lock anchored on the log directory) and #16598 (retry a failed best-effort append and count dropped events). Please replay the floor refresh and both delete phases against the current prune() and rotation lock path, as the earlier overlap note asked.

  2. Hidden break after a clean rebase. test_sandbox_governance_mask.py:302 calls sandbox._private_memory_seatbelt_rules(), which no longer exists on main (#11780). That test fails even if the rebase applies cleanly.

  3. Open security-class finding. At sel.py:615-618, _read_legacy_retention_floor seeds keep, days and max_bytes with max() and never clamps them to _SEGMENT_MAX_BYTES_MAX / _RETENTION_DAYS_MAX. A planted legacy hint therefore lands in the new marker above the coherence ceilings. The cheap fix is to clamp the legacy hints the same way the env path clamps. That clears the fenced GPT finding without needing an override.

  4. Windows test failure in this PR's own test. On Backend Tests (Windows) (6), TestEnvOverrides::test_directory_fsync_real_io_error_propagates fails with "DID NOT RAISE OSError". Directory fsync is not attempted on Windows, so the injected EIO never fires. Skip it on Windows, or gate it on the same platform check the production code uses.

  5. Local failure to check after the rebase. Locally (Linux, Python 3.12), TestSegmentEnumerationIsBounded::test_enumeration_stops_at_the_scan_cap fails every time at this head ("walked 10 entries with a cap of 8"). The new floor-directory walk in the pending-record reader also goes through os.scandir, so the test's counting wrapper sees both walks. It passed on the Linux CI shards, so it may depend on directory order. Please make the test count only the segment walk, or make the bound explicit for both walks, so it is deterministic.

The rest of test_sel.py, test_sel_prune_streaming.py, test_sandbox_governance_mask.py and the SEL TestIsSensitivePath cases pass locally at this head (935 passed). This PR also changes the sensitive-path gate and the sandbox readonly exposure, so a maintainer will need to sign off on those parts after the rebase as well. I'll review again when the head moves.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thanks for working on this and for the careful raise-only design. We are closing this PR because main has since moved SEL rotation into src/kiro_crew/sel_rotation.py and the branch is about 7,300 commits behind, so a rebase would be close to a rewrite; cruisercohen's review on 2026-10-09 is also still open. The need is real and stays tracked in #4993. A fresh, smaller PR against sel_rotation.py is very welcome.

The branch is left untouched, so you can reopen this PR at any time, or open a fresh one on current main, if you want to pick it back up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge needs-author-decision PR blocked on author input needs-human Triage: requires a human or product decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(sel): make the segment size cap and keep-count operator-tunable without editing source

6 participants