Skip to content

refactor(sel): split SecurityEventLog's mechanisms into owner modules - #20860

Merged
bolichen97 merged 1 commit into
mainfrom
refactor/linecap-g20-sel
Oct 17, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
refactor/linecap-g20-sel

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Move SecurityEventLog's mechanisms (the HMAC trust root, the read side, the cross-process chain lock, the chained append and the rotation/retention code) out of src/kiro_crew/sel.py into five focused owner modules, with no change in behaviour.

sel.py is 3,920 lines and the campaign rule (no hand-written file over 2,000 lines, #20192) cannot be met by moving whole top-level definitions: 2,666 of those lines are the one SecurityEventLog class.

Why it matters

A change to key handling, segment reading, the chain lock or rotation today edits one 3,920-line file that also holds the record type, the writer thread and every log_* helper, so unrelated audit-log work conflicts and review diffs are hard to read. After this PR each of those responsibilities has one owner module, named in the owning spec, where new work for it goes.

Not a goal

  • No behaviour change: no fix, no hardening, no rename of any public or private name.
  • No change to SecurityEventLog's surface: every member stays an attribute of the one class, with the same kind, signature and coroutine-ness.
  • No change to the security posture registry, kiro_crew._facade_mirror or CI logic.
  • Not a split of test/test_sel.py (another campaign scope).

What changed (motivation → approach → change)

The class holds state that every part of it shares (the chain tip, the log paths, the thread lock), so the state stays on the instance. Each moved member's body moves verbatim into an owner module as a function whose first parameter is self, and the class binds it by name (_chain_lock = _sel_chain_lock._chain_lock), so every member, field and patch target stays on the one class.

Owner Owns
sel_trust_root.py the HMAC key that signs the chain (location, creation, validation, legacy migration) and the per-record MAC
sel_reader.py verify_integrity, recent, segment admission, the backward line reader and the read-side segment pins
sel_chain_lock.py the cross-process chain lock, the per-process hold registry and the pinned lock directory
sel_append.py the descriptor-checked append, re-anchoring after another process moves the log, and chain-tip recovery
sel_rotation.py size rotation, segment naming and enumeration, count retention and the age prune

sel.py keeps the record (SecurityEvent and every place that builds one), the singleton and writer thread, the write pipeline _flush_batch with its redaction, and the trust-root accessors, so the registered "SEL audit log" redaction sink stays in sel.py. It keeps binding every name it bound and serves the module-level names that moved, so every import path and kiro_crew.sel.<name> patch keeps working through kiro_crew._facade_mirror. The owning spec (sel.md) gains a module layout section, which also names main's sel_request_provenance.py as a sibling the class binds nothing from; source-reading tests and docs that named sel.py as the home of moved code now name the owner.

Move audit

Raw (move_audit.py, packet BASE 213339f671 to this head): src/kiro_crew/sel.py: 3920 -> 1456 lines; moved 44.44% (python-ast). Every unit it lists as changed is a bound method, whose AST differs only by the one-level dedent (docstring indentation) and the self: SecurityEventLog annotation, except log_api_access, which stays in sel.py and carries main's later changes byte-identically: #20620's forwarded parameter and #21212's fallback to the request-bound verdict (current_request_forwarded, imported from main's sel_request_provenance.py).

Normalized per-unit audit (replumb_audit.py: each BASE unit dedented as the recipe does, HEAD's self annotation removed, ast.dump compared): 126 units, 123 AST-identical, 3 differ in their docstring text only. The HMAC key load/create, _compute_hash, _record_signature_matches, verify_integrity, the chain-lock and rotation code (_chain_lock, _rotation_window, _rotate_under_lock, retention, prune) and the append path are all AST-identical: lock acquire/release order, _last_hash write points and retention under the lock are the BASE code.

Justified edits (not verbatim):

  • Docstrings of _on_event_loop, _live_log_moved_on, _identity_changed, and comments in _load_or_create_hmac_key, verify_integrity and _open_segment: present-tense wording (comment-history gate judges moved lines as added).
  • Two # lockdown-ok: markers shortened (_load_or_create_hmac_key, _open_rotation_lock) so black keeps each on its call's line; the rest of the first reason is a comment line above.
  • Owners are black-formatted (AST-neutral); three same-line adjacent string literals black left behind are joined (AST-neutral).
  • Every class an owner defines keeps __module__ = "kiro_crew.sel": the four exception classes, so tracebacks and logged exc_info name the import path callers use, and the three other classes (SelVerification, _SegmentDirPin, _ChainHold) so reprs and pickles do too.
  • Class body: annotations for _hmac_key, _hmac_key_file, _last_hash (fields first set from an owner member), so mypy knows them.

Diff shape (L36), git diff --numstat against git diff --minimal --numstat: every changed file adds the same lines except sel.py (239/2,713 default against 238/2,712 minimal). The one re-shown line is the BLANK line between the changed from typing import ... line and the first-party import block (both sides of it must change: TYPE_CHECKING plus # noqa: F401); it carries no gate token. Accepted as an L41 exception.

Citations re-pointed (L29)

Path only; no assertion or code changes.

  • test/test_jsonl_util.py:751 sel.py -> sel_reader.py (the handle bound before with)
  • docs/request-for-change/rfc-everything-is-an-app.md:164 src/kiro_crew/sel.py:58-63 -> src/kiro_crew/sel_trust_root.py, _TRUST_SUBDIR
  • docs/request-for-change/rfc-resumable-subagent-sessions.md:247 sel.py:856-888 / sel.py:891 -> sel.py (the cited _infer_source and _AUDIT_SOURCES stay there)
  • src/kiro_crew/security/paths.py:418, :422 sel.py -> sel_trust_root.py; :454 -> sel_rotation.py; :459 -> sel_reader.py
  • src/kiro_crew/members.py:1481, src/kiro_crew/autonudge_selfarm.py:108 (sel.py creates it 0o700) -> (sel_trust_root.py creates it 0o700)
  • src/kiro_crew/session_pid_sig.py:129 Mirrors sel.py -> Mirrors sel_trust_root.py (_HMAC_KEY_MIN_BYTES)
  • test/test_security.py:6355 sel.py -> sel_rotation.py
  • test/test_issue_radar_crew_runtime.py:3447, :3493 sel.py -> sel_chain_lock.py

Path and row re-points in source-reading tests (L30)

  • test/test_jsonl_util.py:713 _FENCED_READERS {"sel.py"} -> {"sel_reader.py", "sel_rotation.py"} (mutation: iter(handle) / iter(src_f) in each owner turns test_the_scanner_actually_detects_the_pattern red)
  • test/link_screen_sites.py: regenerated by test/gen_link_screen_sites.py; the six sel rows are re-keyed to their owners (mutation: removing the screen in sel_chain_lock._chain_lock turns test_declared_sites_still_exist red)
  • test/test_transcript_derivation_seam.py PLUMBING + ("kiro_crew/sel.py", "recent"): the class-body binding recent = _sel_reader.recent is an attribute the plain-read fence counts; it is the SEL audit log's recent, not a transcript read

References not edited (reason)

  • docs/system-specs/modules/security.md:1101 "(sel.py, dashboard/session_health.py)": still true (sel.py stays the class's import path); editing it would re-add a long one-line paragraph to the content-scanned diff. Intended text, as in sel.md: "(sel.py and its owner modules, dashboard/session_health.py)".

Backwards compatibility

Compatible: every module path, public and private name, SecurityEventLog member, signature and patch target that worked before still works; kiro_crew.sel binds or serves every name it bound, each the owner's object.

Removes nothing: no public module-level function leaves sel.py (every moved module-level def is private), and the two public classes that moved (SelChainContention, SelVerification) stay importable from kiro_crew.sel (test/campaign_facade_inventories/kiro_crew.sel.json, checked by test_campaign_facades_base_public_names).

Logger names (L25): owners call logging.getLogger("kiro_crew.sel"), the same Logger object as the facade's.

Tests

  • New test/test_sel_bindings.py: the frozen member inventory (kind, coroutine, signature digest, owner, identity with the owner function), no unbound self function left in an owner, no zero-arg super()/__class__/name-mangling in a bound body, no owner importing kiro_crew.sel at run time, owner layer order, each owner's field list, owner logger, moved classes' __module__, the served names are exactly the moved module-level names, patch reach over the test corpus, and the on-loop "no time import" guard joined over the facade and every owner. Each scan has a can-fail self-test.
  • Source-reading tests re-pointed (path only; assertions unchanged; one mutation each): test/test_jsonl_util.py _FENCED_READERS (sel.py -> sel_reader.py, sel_rotation.py); test/link_screen_sites.py regenerated with test/gen_link_screen_sites.py (6 sel rows re-keyed to their owners).
  • Rows: the sel facade inventory test/campaign_facade_inventories/kiro_crew.sel.json (the public names main's sel.py binds, including current_request_forwarded, and each re-bound name's home, read by test_campaign_facades_base_public_names.py); test/test_transcript_derivation_seam.py PLUMBING gains ("kiro_crew/sel.py", "recent") (the class binds sel_reader.recent; it is the SEL audit log's recent, not a transcript read, like the existing SEL rows); .github/file-line-cap-baseline.txt sel.py row deleted; .github/docs-lint-baseline.txt three line-ref rows deleted with their citations rewritten to symbols.
  • Floor run locally: 208 test files (every file that imports or patches kiro_crew.sel or names a moved construct, plus the mirror, link-screen, jsonl, posture and ratchet guards), pytest -n 3: 19,785 passed, 39 skipped, 3 failed on the 120 s timeout under host load (the three tree scans in test_dashboard_files_composition_contract.py; that file passes alone, 89 passed). Line coverage on that run: sel.py 95.6%, sel_append.py 95.4%, sel_chain_lock.py 90.7%, sel_trust_root.py 89.7%, sel_rotation.py 87.8%, sel_reader.py 85.5%. mypy src/kiro_crew clean; semgrep (CI configs) 0 findings and no parse errors; the built wheel imports every owner module.
  • After the rebase onto 8d33a33bfe: the touched surface (21 files: the sel suites, the guards above, test_transcript_derivation_seam.py, test_agent_spec_hardened_reads.py, test_security.py, test_issue_radar_crew_runtime.py, test_security_gate_liveness.py, test_session_pid_sig.py), pytest -n 3: 2,663 passed, 1 skipped. After the rebase onto 6d4f2874e8, which brings feat(sel): record forwarded provenance on every request-bound audit row #20620's log_api_access(forwarded=...) into the facade-kept method byte-identically (the frozen inventory digest for log_api_access follows its new signature): 11 sel/guard files, 705 passed, including test_sel_forwarded_provenance.py. Refreshed onto c6d610673b with the facade inventory as test/campaign_facade_inventories/kiro_crew.sel.json: 14 sel/guard/security files, 2,326 passed, 1 skipped; the static gates above re-run green. Refreshed onto eb2dad9bed, which brings fix(sel): record forwarded provenance on handler-level audit rows #21212 into sel.py: 192 files (the sel suites and guards, plus every test file main changed since the previous base that reads kiro_crew.sel or scans the source tree), pytest -n 3: 18,483 passed, 56 skipped, 5 xfailed; mypy src/kiro_crew clean; semgrep (CI configs, diff against the base) 0 new findings; the static gates re-run green.
  • scripts/local-gate.py --dry-run selects 734 backend files, over the campaign's ~600-file cap, so the floor above ran instead; CI runs the full matrix.

Manual verification

N/A — a pure move; behaviour is covered by the existing SEL suites, which pass unmodified apart from the listed path re-points.

Related Issues

Part of #20192

Follow-up: #21320 (the deferred comment citation listed under References not edited)

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 15, 2026 14:58
@bolichen97
bolichen97 requested a review from buluoray October 15, 2026 14:58
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 8a8d4b8
  • What rule changed: none. The only sensitive path, src/kiro_crew/security/paths.py, changes four comment lines at :418, :422, :454 and :459, each re-pointing a "sel.py" citation to the owner module that now holds the cited SEL code (sel_trust_root.py, sel_rotation.py, sel_reader.py).
  • Before -> after (what was allowed/blocked, now): unchanged; no entry of the sensitive-path floor, no matcher and no code line differs, and the file keeps its line count.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a comment names the wrong module; no command, secret or user is affected because no executable line changed.
  • Evidence checked (which sandbox result proves it): git diff of security/paths.py is four comment-only lines; the AST of security/paths.py is unchanged; test_security.py and test_security_gate_liveness.py pass on this head.
  • Tools still work (which tools/commands were run, result): pytest -n 3 over test_security.py, test_security_gate_liveness.py, test_security_posture.py, the SEL suites and the facade guards on this head: 2,540 passed, 1 skipped.
  • Backward compatible (old config / old data / old callers still work, how checked): yes; no config, data or caller touches a comment, and the package line budget in test_security_gate_liveness.py is unchanged and green.
  • Existing tests (which suites passed on this head): test_security.py, test_security_gate_liveness.py, test_security_posture.py, test_sel*.py, test_facade_mirror_guards.py, test_mirrored_owner_storage.py, test_link_screen_hold_pin.py, test_jsonl_util.py.
  • How to undo: revert the four comment lines (or the PR); nothing else depends on them.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 15, 2026
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/paths.py

  • @bolichen97 posted a complete reasoning template for 770ae3e.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 770ae3e0d22a3ce487cdd9fbb7e4838d3ad34a91 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Before merging, check that the test that limits _sel_hmac_key_bytes to one production caller still passes, since it skips only files named sel.py. Today the accessor stays in sel.py, so it holds.

[DESIGN-REVIEWED] 770ae3e

Description read

[DESCRIPTION-READ] 814ecbb290bd8213d9d219544f9122b4039398efbf5033eedd381e67c3038971

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 770ae3e0d22a3ce487cdd9fbb7e4838d3ad34a91 — 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

Rerun the per-unit AST audit at this head to confirm 123 of 126 moved units are identical and the 3 others differ only in docstrings.

What this change ships

Inventory (8 items) — 8 justified

Intent: break up the 3,920-line sel.py so audit-log work lands in focused modules and meets the 2,000-line cap. This is a refactor, not a FIX or an ADDITION, and it adds no capability.

  1. HMAC key handling and the per-record MAC move to sel_trust_root.py. — justified
  2. Integrity checks, recent and segment reads move to sel_reader.py. — justified
  3. The cross-process chain lock moves to sel_chain_lock.py. — justified
  4. The chained append and re-anchoring move to sel_append.py. — justified
  5. Rotation, retention and prune move to sel_rotation.py. — justified
  6. sel.py keeps every import path and patch target, using the existing _facade_mirror.install. The same pattern appears in 30 modules, and history.py's _SERVED_ONLY has the same shape. — justified
  7. sel.py leaves file-line-cap-baseline.txt, as the AGENTS.md line cap requires. — justified
  8. A new test_sel_bindings.py pins the member inventory. It follows the campaign convention: 30+ sibling *_bindings.py tests and 43 facade inventories. Path citations in docs and tests are re-pointed to the new modules. — justified

[FIRST-PRINCIPLES-REVIEWED] 770ae3e

Description read

[DESCRIPTION-READ] 1ec77ed8bbace91a46dc1b83cf0aeffdd3c0f9e0b087db5c4e465eae9c693756

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@bolichen97
bolichen97 enabled auto-merge (squash) October 15, 2026 15:05
@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 770ae3e0d22a3ce487cdd9fbb7e4838d3ad34a91 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 770ae3e

Verdict parsed from the review's SHA-scoped output markers for commit 770ae3e0d22a3ce487cdd9fbb7e4838d3ad34a91.

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

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does 770ae3e0d22a3ce487cdd9fbb7e4838d3ad34a91 newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 6 classified, 0 newly refused, 6 still allowed.
  • ubuntu-latest (platform posix): 6 classified, 0 newly refused, 6 still allowed.
  • windows-latest (platform windows): 2 classified, 0 newly refused, 2 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

TIGHTENING: None. Nothing in the tool-call deny composite (sensitive-bash, exfil, deny-rules) changed. This PR splits src/kiro_crew/sel.py into the owner modules sel_trust_root, sel_reader, sel_chain_lock, sel_append and sel_rotation, behind a facade at kiro_crew.sel. The only hunk under security/ changes comments: - # SEL trust-root directory: sel.py stores/migrates the audit chain's HMAC / + # SEL trust-root directory: sel_trust_root.py stores/migrates the audit chain's HMAC. The entries in _CREW_SECRET_LEAVES (sel_hmac.key, trust, security_events.jsonl, security_events.d) are unchanged, and no pattern, path fence, validator or argv floor is added. The candidates are therefore controls: the maintainers' own daily operations on the moved modules and on security/paths.py.

ADJUDICATED: 8 candidates, 0 confirmed newly-refused (no rows were handed back to this review as confirmed)

PLATFORM COVERAGE: I wrote candidates in posix and windows spellings. The diff adds no new assumption about a path, separator, interpreter or environment variable to any deny tier. The new modules' file opens move code that already existed and do not pass through the shell gate. So the coverage aims at the touched area itself:

  • posix: pytest runs over test/test_sel_bindings.py and TestIsSensitivePath, a grep, a git diff --stat and a mypy run over the new module paths, and a python3 -c import check through the facade.
  • windows: the same binding test through .venv\Scripts\python.exe with backslash paths, and a PowerShell Select-String over src\kiro_crew\sel_rotation.py. Both probe drive-less backslash spelling and a .exe interpreter name.

No platform spelling the diff assumes is left without a candidate.

[SCOPE-REVIEWED] 770ae3e

@github-actions

github-actions Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 770ae3e0d22a3ce487cdd9fbb7e4838d3ad34a91 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 770ae3e

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

@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 15, 2026
@bolichen97
bolichen97 force-pushed the refactor/linecap-g20-sel branch from 8a8d4b8 to 15573e9 Compare October 15, 2026 18:57
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 15573e9
  • What rule changed: none. The only sensitive path, src/kiro_crew/security/paths.py, changes four comment lines at :418, :422, :454 and :459, each re-pointing a "sel.py" citation to the owner module that now holds the cited SEL code (sel_trust_root.py, sel_rotation.py, sel_reader.py).
  • Before -> after (what was allowed/blocked, now): unchanged; no entry of the sensitive-path floor, no matcher and no code line differs, and the file keeps its line count.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a comment names the wrong module; no command, secret or user is affected because no executable line changed.
  • Evidence checked (which sandbox result proves it): git diff of security/paths.py is four comment-only lines; the AST of security/paths.py is unchanged; test_security.py and test_security_gate_liveness.py pass on this head.
  • Tools still work (which tools/commands were run, result): pytest -n 3 over test_security.py, test_security_gate_liveness.py, test_security_posture.py, the SEL suites and the facade guards on this head: 2,663 passed, 1 skipped (on the same patch, before its final rebase), and 705 passed after the rebase that brought feat(sel): record forwarded provenance on every request-bound audit row #20620.
  • Backward compatible (old config / old data / old callers still work, how checked): yes; no config, data or caller touches a comment, and the package line budget in test_security_gate_liveness.py is unchanged and green.
  • Existing tests (which suites passed on this head): test_security.py, test_security_gate_liveness.py, test_security_posture.py, test_sel*.py, test_facade_mirror_guards.py, test_mirrored_owner_storage.py, test_link_screen_hold_pin.py, test_jsonl_util.py.
  • How to undo: revert the four comment lines (or the PR); nothing else depends on them.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 15, 2026
@bolichen97
bolichen97 force-pushed the refactor/linecap-g20-sel branch from 15573e9 to 39e7299 Compare October 16, 2026 05:10
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 16, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Refreshed onto c6d610673b (main red resolved): the facade inventory moves to test/campaign_facade_inventories/kiro_crew.sel.json (the campaign's new per-facade inventory format), and this PR's rows in test/test_campaign_facades_base_public_names.py are dropped. The rest of the patch is unchanged (git range-diff "=" against the gated head). Re-gated: comment-history, brand, docs lint, line cap, black, and 14 sel/guard/security test files (2,326 passed, 1 skipped). CI re-running.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 39e7299
  • What rule changed: none. The only sensitive path, src/kiro_crew/security/paths.py, changes four comment lines at :418, :422, :454 and :459, each re-pointing a "sel.py" citation to the owner module that now holds the cited SEL code (sel_trust_root.py, sel_rotation.py, sel_reader.py).
  • Before -> after (what was allowed/blocked, now): unchanged; no entry of the sensitive-path floor, no matcher and no code line differs, and the file keeps its line count.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a comment names the wrong module; no command, secret or user is affected because no executable line changed.
  • Evidence checked (which sandbox result proves it): git diff of security/paths.py is four comment-only lines; the AST of security/paths.py is unchanged; test_security.py and test_security_gate_liveness.py pass on this head.
  • Tools still work (which tools/commands were run, result): pytest -n 3 over test_security.py, test_security_gate_liveness.py, test_security_posture.py, the SEL suites and the facade guards on this head: 2,663 passed, 1 skipped (same patch, before later rebases); after the refresh onto c6d6106: 2,326 passed, 1 skipped over 14 sel, guard and security files.
  • Backward compatible (old config / old data / old callers still work, how checked): yes; no config, data or caller touches a comment, and the package line budget in test_security_gate_liveness.py is unchanged and green.
  • Existing tests (which suites passed on this head): test_security.py, test_security_gate_liveness.py, test_security_posture.py, test_sel*.py, test_facade_mirror_guards.py, test_mirrored_owner_storage.py, test_link_screen_hold_pin.py, test_jsonl_util.py.
  • How to undo: revert the four comment lines (or the PR); nothing else depends on them.

@bolichen97
bolichen97 force-pushed the refactor/linecap-g20-sel branch from 39e7299 to ff10b58 Compare October 16, 2026 05:34
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased onto e1505fc6f2 (the PR had gone DIRTY): the only conflict was a row-union in test/test_transcript_derivation_seam.py, where #20761 added a neighbouring PLUMBING row; both rows are kept. The rest of the patch is unchanged (git range-diff shows context lines only). This head supersedes the earlier refresh at 39e72996c7. Re-gated: comment-history, brand, docs lint, line cap, black, inventory check, and 14 sel/guard/security test files (2,361 passed, 1 skipped). CI re-running.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: ff10b58
  • What rule changed: none. The only sensitive path, src/kiro_crew/security/paths.py, changes four comment lines at :418, :422, :454 and :459, each re-pointing a "sel.py" citation to the owner module that now holds the cited SEL code (sel_trust_root.py, sel_rotation.py, sel_reader.py).
  • Before -> after (what was allowed/blocked, now): unchanged; no entry of the sensitive-path floor, no matcher and no code line differs, and the file keeps its line count.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a comment names the wrong module; no command, secret or user is affected because no executable line changed.
  • Evidence checked (which sandbox result proves it): git diff of security/paths.py is four comment-only lines; the AST of security/paths.py is unchanged; test_security.py and test_security_gate_liveness.py pass on this head.
  • Tools still work (which tools/commands were run, result): pytest -n 3 over test_security.py, test_security_gate_liveness.py, test_security_posture.py, the SEL suites and the facade guards on this head: 2,663 passed, 1 skipped (same patch, before later rebases); after the rebase onto e1505fc: 2,361 passed, 1 skipped over 14 sel, guard and security files.
  • Backward compatible (old config / old data / old callers still work, how checked): yes; no config, data or caller touches a comment, and the package line budget in test_security_gate_liveness.py is unchanged and green.
  • Existing tests (which suites passed on this head): test_security.py, test_security_gate_liveness.py, test_security_posture.py, test_sel*.py, test_facade_mirror_guards.py, test_mirrored_owner_storage.py, test_link_screen_hold_pin.py, test_jsonl_util.py.
  • How to undo: revert the four comment lines (or the PR); nothing else depends on them.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Refreshed onto 9fba246d0c (the 4-hour refresh). Main had brought #21212 into sel.py, which this PR splits, so the refresh carries it over:

  • sel.py keeps fix(sel): record forwarded provenance on handler-level audit rows #21212's from kiro_crew.sel_request_provenance import current_request_forwarded, and log_api_access (which stays on the facade class) is byte-identical to main's;
  • the facade inventory lists current_request_forwarded, rebound to kiro_crew.sel_request_provenance;
  • sel.md's module layout names sel_request_provenance.py as a sibling the class binds nothing from.

Nothing else in the patch changed. This head supersedes 7453b7fcc3. Re-gated: comment-history, brand, docs lint, line cap, black, flake8, mypy src/kiro_crew, the inventory check, semgrep (diff against the base, 0 new), and 192 test files (the sel suites and guards plus every test file main changed since the previous base that reads kiro_crew.sel or scans the source tree): 18,483 passed, 56 skipped, 5 xfailed. CI re-running.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: c50f8fe
  • What rule changed: none. The only sensitive path, src/kiro_crew/security/paths.py, changes four comment lines at :418, :422, :454 and :459, each re-pointing a "sel.py" citation to the owner module that now holds the cited SEL code (sel_trust_root.py, sel_rotation.py, sel_reader.py).
  • Before -> after (what was allowed/blocked, now): unchanged; no entry of the sensitive-path floor, no matcher and no code line differs, and the file keeps its line count.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a comment names the wrong module; no command, secret or user is affected because no executable line changed.
  • Evidence checked (which sandbox result proves it): git diff of security/paths.py is four comment-only lines; the AST of security/paths.py is unchanged; test_security.py and test_security_gate_liveness.py pass on this head.
  • Tools still work (which tools/commands were run, result): pytest -n 3 over test_security.py, test_security_gate_liveness.py, test_security_posture.py, the SEL suites and the facade guards on this head: 2,663 passed, 1 skipped (same patch, before later rebases); after the refresh onto 9fba246: 18,483 passed, 56 skipped, 5 xfailed over 192 sel, guard, security and tree-scan test files.
  • Backward compatible (old config / old data / old callers still work, how checked): yes; no config, data or caller touches a comment, and the package line budget in test_security_gate_liveness.py is unchanged and green.
  • Existing tests (which suites passed on this head): test_security.py, test_security_gate_liveness.py, test_security_posture.py, test_sel*.py, test_facade_mirror_guards.py, test_mirrored_owner_storage.py, test_link_screen_hold_pin.py, test_jsonl_util.py.
  • How to undo: revert the four comment lines (or the PR); nothing else depends on them.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Oct 16, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • PASS punchline: does the ("kiro_crew/sel.py", "recent") PLUMBING row exempt only the class-body binding? — answered

The fence keys every row on (module, attribute name) (_plain_read_sites in test_transcript_derivation_seam.py), so this row, like each of the other rows, covers any .recent attribute in sel.py, not one line.
Today sel.py has exactly one: line 618, recent = _sel_reader.recent; main's unsplit sel.py has none (it defined recent with def, which the fence does not count), and sel_reader.py also defines it with def, so it needs no row.
sel.py imports no history, session, chat or transcript module, so a transcript recent read there would need a new import that a reviewer sees; narrowing the fence below module granularity is a change to the test's design, outside this split.

@bolichen97

bolichen97 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor Author
  • PASS punchline: test/test_sel.py passes unmodified on every CI platform — confirmed

git diff 9fba246d0c c50f8fe954 -- test/test_sel.py is empty, and no expected-failure or collect-ignore list (windows, macos, codebuild) names it, so every one of its kiro_crew.sel.<name> patches (_default_dir included) runs as written.
CI file-shards it by sha256(path) to shard 4 of 8: Backend Tests (3.12, 4) (job 117248525930; its progress log shows test/test_sel.py cases passing; 23,239 passed, 0 failed) and Backend Tests (Windows) (4) (job 117248525994; 21,782 passed, 0 failed) are green on this head; test_sel_bindings.py lands on shard 1, green on both.
macOS runs only on demand, and its decider (Decide whether the macOS suite runs) skipped it for this head.

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

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved by a maintainer. The triage automation held this on a size, path, category or move-check rule only; every review lane is clean.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 17, 2026
Move the SEL's HMAC trust root, read side, cross-process chain lock,
chained append and rotation/retention code out of sel.py into five
owner modules by binding: each member's body moves verbatim as a
function taking self, and the class binds it by name, so every member,
field and patch target stays on the one class. sel.py keeps the record
type and every place that builds one, the singleton and writer thread,
and the write pipeline with its redaction; it keeps binding every name
it bound, serves the module-level names that moved, and the facade
mirror carries writes to every owner. sel.py goes from 3,930 lines on
main to 1,456.

Part of #20192
@bolichen97
bolichen97 force-pushed the refactor/linecap-g20-sel branch from c50f8fe to 770ae3e Compare October 17, 2026 04:58
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision labels Oct 17, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased onto 23affa7e78 (the PR had gone DIRTY). The only conflict was in .github/docs-lint-baseline.txt, between neighbouring row deletions: this PR's two sel.py line-ref rows and main's seven session.py rows (from the session.py split). Resolved as a union of the deletions, so the file is main's minus this PR's own three rows. The rest of the patch is unchanged (git range-diff shows context lines only; the -U0 patch is identical). This head supersedes c50f8fe954. Re-checked: docs lint, line cap, comment-history, brand, the inventory check (18/18), link_screen_sites.py regeneration (no diff), and the seam, link-screen, bindings, facade-inventory and SEL suites (920 passed). CI re-running.

@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 770ae3e
  • What rule changed: none. The only sensitive path, src/kiro_crew/security/paths.py, changes four comment lines at :418, :422, :454 and :459, each re-pointing a "sel.py" citation to the owner module that now holds the cited SEL code (sel_trust_root.py, sel_rotation.py, sel_reader.py).
  • Before -> after (what was allowed/blocked, now): unchanged; no entry of the sensitive-path floor, no matcher and no code line differs, and the file keeps its line count.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a comment names the wrong module; no command, secret or user is affected because no executable line changed.
  • Evidence checked (which sandbox result proves it): git diff of security/paths.py is four comment-only lines; the AST of security/paths.py is unchanged; test_security.py and test_security_gate_liveness.py pass on this head.
  • Tools still work (which tools/commands were run, result): pytest -n 3 over test_security.py, test_security_gate_liveness.py, test_security_posture.py, the SEL suites and the facade guards on this head: 2,663 passed, 1 skipped (same patch, before later rebases); after the refresh onto 9fba246: 18,483 passed, 56 skipped, 5 xfailed over 192 sel, guard, security and tree-scan test files; after the rebase onto 23affa7: 920 passed over the SEL, seam and link-screen files.
  • Backward compatible (old config / old data / old callers still work, how checked): yes; no config, data or caller touches a comment, and the package line budget in test_security_gate_liveness.py is unchanged and green.
  • Existing tests (which suites passed on this head): test_security.py, test_security_gate_liveness.py, test_security_posture.py, test_sel*.py, test_facade_mirror_guards.py, test_mirrored_owner_storage.py, test_link_screen_hold_pin.py, test_jsonl_util.py.
  • How to undo: revert the four comment lines (or the PR); nothing else depends on them.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 17, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • PASS punchline: the _sel_hmac_key_bytes single-caller pin still holds — confirmed

test_sel.py::TestHmacKeyTrustDirMigration::test_key_bytes_accessor_has_exactly_one_production_caller passes on this head (run by node id, and in the 920-test SEL/seam run before the push). It skips files named sel.py, and the accessor is defined only there.
git grep -l _sel_hmac_key_bytes -- src/kiro_crew at this head lists exactly sel.py and session_pid_sig.py: no owner module (sel_trust_root.py and the others, which the pin does scan) names it, so the caller set the pin asserts is unchanged.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • PASS punchline: rerun the per-unit AST audit at this head — done

replumb_audit.py against this head's base 23affa7e78 (each moved unit dedented the way the recipe does, the self: SecurityEventLog annotation removed, ast.dump compared): {"IDENTICAL": 123, "DOCSTRING-ONLY": 3}; the three are _on_event_loop (sel_chain_lock), _live_log_moved_on and _identity_changed (sel_append), as the body says.
Against the packet BASE 213339f671 the same audit reports 122 + 3 + 1: the one is log_api_access, which stays in sel.py and carries main's later #20620 and #21212 edits byte-identically to main.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention labels Oct 17, 2026

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on behalf of the maintainer: code-move refactor or test split held by the cron on the file cap, the Opus size warning or a path rule alone. Every review lane on the current head is clean (only size notes); the lanes found no behavior change.

@bolichen97
bolichen97 merged commit 57a53bb into main Oct 17, 2026
159 of 164 checks passed
@bolichen97
bolichen97 deleted the refactor/linecap-g20-sel branch October 17, 2026 17:31
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants