Repository navigation
refactor(sel): split SecurityEventLog's mechanisms into owner modules - #20860
Conversation
Sensitive change review
|
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Before merging, check that the test that limits [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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of 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 shipsInventory (8 items) — 8 justifiedIntent: break up the 3,920-line
[FIRST-PRINCIPLES-REVIEWED] 770ae3e Description read[DESCRIPTION-READ] 1ec77ed8bbace91a46dc1b83cf0aeffdd3c0f9e0b087db5c4e465eae9c693756 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS TIGHTENING: None. Nothing in the tool-call deny composite ( 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:
No platform spelling the diff assumes is left without a candidate. [SCOPE-REVIEWED] 770ae3e |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
8a8d4b8 to
15573e9
Compare
Sensitive change review
|
15573e9 to
39e7299
Compare
|
Refreshed onto |
Sensitive change review
|
39e7299 to
ff10b58
Compare
|
Rebased onto |
Sensitive change review
|
|
Refreshed onto
Nothing else in the patch changed. This head supersedes |
Sensitive change review
|
|
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
Approved by a maintainer. The triage automation held this on a size, path, category or move-check rule only; every review lane is clean.
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
c50f8fe to
770ae3e
Compare
|
Rebased onto |
Sensitive change review
|
|
|
KiroCrewCaptain
left a comment
There was a problem hiding this comment.
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.
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 ofsrc/kiro_crew/sel.pyinto five focused owner modules, with no change in behaviour.sel.pyis 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 oneSecurityEventLogclass.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
SecurityEventLog's surface: every member stays an attribute of the one class, with the same kind, signature and coroutine-ness.kiro_crew._facade_mirroror CI logic.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.sel_trust_root.pysel_reader.pyverify_integrity,recent, segment admission, the backward line reader and the read-side segment pinssel_chain_lock.pysel_append.pysel_rotation.pyprunesel.pykeeps the record (SecurityEventand every place that builds one), the singleton and writer thread, the write pipeline_flush_batchwith its redaction, and the trust-root accessors, so the registered "SEL audit log" redaction sink stays insel.py. It keeps binding every name it bound and serves the module-level names that moved, so every import path andkiro_crew.sel.<name>patch keeps working throughkiro_crew._facade_mirror. The owning spec (sel.md) gains a module layout section, which also names main'ssel_request_provenance.pyas a sibling the class binds nothing from; source-reading tests and docs that namedsel.pyas the home of moved code now name the owner.Move audit
Raw (
move_audit.py, packet BASE213339f671to 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 theself: SecurityEventLogannotation, exceptlog_api_access, which stays insel.pyand carries main's later changes byte-identically: #20620'sforwardedparameter and #21212's fallback to the request-bound verdict (current_request_forwarded, imported from main'ssel_request_provenance.py).Normalized per-unit audit (
replumb_audit.py: each BASE unit dedented as the recipe does, HEAD'sselfannotation removed,ast.dumpcompared): 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_hashwrite points and retention under the lock are the BASE code.Justified edits (not verbatim):
_on_event_loop,_live_log_moved_on,_identity_changed, and comments in_load_or_create_hmac_key,verify_integrityand_open_segment: present-tense wording (comment-history gate judges moved lines as added).# 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.__module__ = "kiro_crew.sel": the four exception classes, so tracebacks and loggedexc_infoname the import path callers use, and the three other classes (SelVerification,_SegmentDirPin,_ChainHold) so reprs and pickles do too._hmac_key,_hmac_key_file,_last_hash(fields first set from an owner member), so mypy knows them.Diff shape (L36),
git diff --numstatagainstgit diff --minimal --numstat: every changed file adds the same lines exceptsel.py(239/2,713 default against 238/2,712 minimal). The one re-shown line is the BLANK line between the changedfrom typing import ...line and the first-party import block (both sides of it must change:TYPE_CHECKINGplus# 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:751sel.py->sel_reader.py(the handle bound beforewith)docs/request-for-change/rfc-everything-is-an-app.md:164src/kiro_crew/sel.py:58-63->src/kiro_crew/sel_trust_root.py,_TRUST_SUBDIRdocs/request-for-change/rfc-resumable-subagent-sessions.md:247sel.py:856-888/sel.py:891->sel.py(the cited_infer_sourceand_AUDIT_SOURCESstay there)src/kiro_crew/security/paths.py:418,:422sel.py->sel_trust_root.py;:454->sel_rotation.py;:459->sel_reader.pysrc/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:129Mirrors sel.py->Mirrors sel_trust_root.py(_HMAC_KEY_MIN_BYTES)test/test_security.py:6355sel.py->sel_rotation.pytest/test_issue_radar_crew_runtime.py:3447,:3493sel.py->sel_chain_lock.pyPath 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 turnstest_the_scanner_actually_detects_the_patternred)test/link_screen_sites.py: regenerated bytest/gen_link_screen_sites.py; the six sel rows are re-keyed to their owners (mutation: removing the screen insel_chain_lock._chain_lockturnstest_declared_sites_still_existred)test/test_transcript_derivation_seam.pyPLUMBING+("kiro_crew/sel.py", "recent"): the class-body bindingrecent = _sel_reader.recentis an attribute the plain-read fence counts; it is the SEL audit log'srecent, not a transcript readReferences not edited (reason)
docs/system-specs/modules/security.md:1101"(sel.py,dashboard/session_health.py)": still true (sel.pystays the class's import path); editing it would re-add a long one-line paragraph to the content-scanned diff. Intended text, as insel.md: "(sel.pyand its owner modules,dashboard/session_health.py)".Backwards compatibility
Compatible: every module path, public and private name,
SecurityEventLogmember, signature and patch target that worked before still works;kiro_crew.selbinds 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 fromkiro_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
test/test_sel_bindings.py: the frozen member inventory (kind, coroutine, signature digest, owner, identity with the owner function), no unboundselffunction left in an owner, no zero-argsuper()/__class__/name-mangling in a bound body, no owner importingkiro_crew.selat 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 "notimeimport" guard joined over the facade and every owner. Each scan has a can-fail self-test.test/test_jsonl_util.py_FENCED_READERS(sel.py->sel_reader.py,sel_rotation.py);test/link_screen_sites.pyregenerated withtest/gen_link_screen_sites.py(6 sel rows re-keyed to their owners).test/campaign_facade_inventories/kiro_crew.sel.json(the public names main'ssel.pybinds, includingcurrent_request_forwarded, and each re-bound name's home, read bytest_campaign_facades_base_public_names.py);test/test_transcript_derivation_seam.pyPLUMBINGgains("kiro_crew/sel.py", "recent")(the class bindssel_reader.recent; it is the SEL audit log'srecent, not a transcript read, like the existing SEL rows);.github/file-line-cap-baseline.txtsel.py row deleted;.github/docs-lint-baseline.txtthreeline-refrows deleted with their citations rewritten to symbols.kiro_crew.selor 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 intest_dashboard_files_composition_contract.py; that file passes alone, 89 passed). Line coverage on that run:sel.py95.6%,sel_append.py95.4%,sel_chain_lock.py90.7%,sel_trust_root.py89.7%,sel_rotation.py87.8%,sel_reader.py85.5%.mypy src/kiro_crewclean; semgrep (CI configs) 0 findings and no parse errors; the built wheel imports every owner module.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 onto6d4f2874e8, which brings feat(sel): record forwarded provenance on every request-bound audit row #20620'slog_api_access(forwarded=...)into the facade-kept method byte-identically (the frozen inventory digest forlog_api_accessfollows its new signature): 11 sel/guard files, 705 passed, includingtest_sel_forwarded_provenance.py. Refreshed ontoc6d610673bwith the facade inventory astest/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 ontoeb2dad9bed, which brings fix(sel): record forwarded provenance on handler-level audit rows #21212 intosel.py: 192 files (the sel suites and guards, plus every test file main changed since the previous base that readskiro_crew.selor scans the source tree),pytest -n 3: 18,483 passed, 56 skipped, 5 xfailed;mypy src/kiro_crewclean; semgrep (CI configs, diff against the base) 0 new findings; the static gates re-run green.scripts/local-gate.py --dry-runselects 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)