Skip to content

perf(dashboard): store display-redaction verdicts on write - #19753

Merged
buluoray merged 2 commits into
mainfrom
perf/display-verdicts-on-write
Oct 15, 2026
Merged

buluoray merged 2 commits into
mainfrom
perf/display-verdicts-on-write

Conversation

@buluoray

@buluoray buluoray commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Reopening a long chat session after a gateway restart renders fast, because text already checked for secrets is not checked again.

#19624 remembers clean display-redaction verdicts in memory, so a second open in the same process is cheap. A gateway restart empties that memory: the first open of every session after it runs the whole display battery (redact_exfiltration_urls, then redact_credentials) over every displayed string again. On 799 real sessions that is ~87 s of CPU for the first open after each restart.

Why it matters

Restarts are routine (updates, crashes, the desktop app relaunching), and the first thing a user does afterwards is open the session they were in. Long sessions are the ones that pay most: before this change the longest session in the corpus (~12k rows) took 4-5 s to open after every restart.

Not a goal

  • Changing what is redacted or how. The battery, its order and its patterns are untouched.
  • Speeding up the very first open of a session that was written before this change. It is scanned once, as today, and fast afterwards.
  • Changing the transcript format. Nothing is written into the transcript.

What changed (motivation → approach → change)

Symptom: after a restart, every session open re-runs the display battery. Cause: verdicts only live in process memory. Change: once a transcript save commits, a background worker projects the new rows the way slot_detail does and stores each displayed string's verdict (clean, or the redacted text) in a per-session sidecar under <data>/display-verdicts/. A render reads the sidecar instead of scanning.

  • dashboard/display_verdicts.py (new): the sidecar store, tags, read rule and bounds.
  • dashboard/display_battery.py (new): the display battery as one function, plus RULE_SOURCES, the files its output depends on. Its docstring states that any battery input read at run time must go into the tag or the version.
  • dashboard/chat_utils.py: _redact_for_display consults the sidecar after the in-memory cache misses and records new verdicts.
  • Save path (transcript_merge.py, chat_persistence.py, chat_handlers.py): hand rows to the worker after the write commits. A save that fails records nothing.
  • Boot (server_runtime/maintenance.py, server.py): enable the store off the event loop after bind.
  • docs/system-specs/modules/security.md: a "Stored display verdicts" entry.

Security design

The risk is showing a secret unredacted. Every rule below fails toward scanning.

  • HMAC-signed tags. A verdict is found only under HMAC(K, "tag" ‖ 0 ‖ rules_version ‖ len(text) ‖ text ‖ 0 ‖ exempt hosts)[:16]. K is a purpose-labelled subkey of token_signing.key, which the agent sandbox masks and the file tools fence, so a same-user agent that can write the sidecar cannot mint a "clean" tag for text it chose. A redacted record also carries HMAC(K, "out" ‖ 0 ‖ tag ‖ output)[:16], checked on load. No usable key: nothing is stored or read.
  • Rules version. sha256(RULE_SOURCES bytes ‖ loaded native-gate binary ‖ Python version ‖ unicodedata version ‖ darwin user-dir id). RULE_SOURCES is the battery, security/redaction.py, security/redaction_switch.py, security/exfil.py, credential_patterns.py, slack_manifest.py and slack-manifest.yaml. Any change to them changes every tag, so old verdicts are never found; a release that leaves them alone keeps its verdicts. A process whose on-disk rule files differ from the ones it imported stores and reads nothing.
  • User rules. Workspace allowed hosts and platform exempt hosts are inside every tag, so allowing or revoking a host invalidates the affected verdicts.
  • Clean and redacted tags differ. A clean verdict is stored under the second half of the 32-byte MAC, a redacted one under the first, so copying a tag from .dvr into .dvc yields nothing.
  • Length. The text's byte length is MACed before the text, so T under hosts {H, Z} and T + NUL + H under {Z} get different tags.
  • Windows. Storage stays off where there is no uid to prove the directory is owned (platform_compat.effective_uid() is None).
  • Owner view. While the credential pass is bypassed, nothing is read or written.
  • O_NOFOLLOW / O_NONBLOCK. Every sidecar open is O_NOFOLLOW | O_NONBLOCK under a directory fd, so a planted FIFO cannot block a render; the directory (created 0700) is opened O_NOFOLLOW | O_DIRECTORY too, and a non-regular sidecar is ignored. A read error, malformed or torn record, bad MAC, or another version in the file header reads as "not scanned".
  • Bounds. The save-to-worker queue holds at most 256 batches and 32 Mi characters of rows; a batch past either is left to the read path. One sidecar is truncated past 16 MiB; one redacted entry is skipped past 1 MiB; at boot, sidecars of deleted transcripts are removed and the whole directory is cleared past 512 MiB.
  • Residual risk. Same-user code that can read token_signing.key can already mint dashboard login tokens; this does not widen that.

When a render reads the sidecar

Parsing costs ~10-20 ns per sidecar byte and a scan ~40 µs per string. A render reads the session's sidecar once, after 4 misses on a cold open (misses exceed hits), or when the sidecar is at most 1 KiB per miss so far. A live session (older rows hit memory, a few new rows miss) scans up to 64 strings before it reads a long file. Verdicts already in the sidecar are not appended again.

Measured

Offline replay of real transcripts (test/perf/redact_on_write_replay.py), one fresh process per run, all trees on the same interpreter, variants interleaved, 5 runs each, median. "Before" for the first open is origin/main. Render time only (transcript read excluded).

Scenario Before After
Open all 799 sessions after a restart, no stored verdicts (= main today, 1 run) 84.2 s --
Open all 799 sessions after a restart, stored verdicts -- 12.44 s (12.29-12.55)
Battery calls for that open 785,748 3,843
First open of the 40 longest sessions, nothing stored 43.17 s 43.82 s (+1.5%)
Save thread, extra per message p50 / p99 -- 0.060 / 0.127 ms
Background projection per message p50 / p99 -- 0.18 / 2.28 ms
Sidecar size, 799 sessions (1,390 MB of transcripts) -- 19.7 MB (1.4%)
Sidecar growth per full reopen -- 640 bytes

The restart open was also compared against the earlier in-tree variant that read every sidecar up front (no 64-miss rule): 11.88 s against 12.25 s, +3.1%, 5 interleaved runs each.

Byte-for-byte oracle against origin/main: 20,375 renders over the 799 sessions (cold, restart, and first-open runs), 0 diffs.

Not measured: a full gateway benchmark on this head. The gateway harness used during development is not part of this PR, so no gateway number is quoted.

Backwards compatibility

Compatible: transcripts are unchanged and gain no field; code that predates this never reads display-verdicts/, and this code treats a missing or foreign sidecar as "not scanned".

Removes nothing: no key, field, function or record is removed; the sidecar is a new, optional cache.

Tests

  • test/test_display_verdicts.py (new): a restart renders from stored verdicts; a text ending in NUL + host after that host is revoked does not reuse the stored verdict of the shorter text (fails without the length in the tag); a changed rules version, a revoked allowed host and a changed platform exempt host each invalidate stored verdicts (each was checked to fail with its invalidation removed: plaintext shown); forged, torn and symlinked sidecars are never served; owner view neither reads nor writes; a save that never committed leaves rows unjudged; cold-open and small-sidecar read rules; a live render does not read the sidecar; reopening does not grow it (fails on the code without the dedupe); a tag copied from .dvr into .dvc is not served as clean, a FIFO sidecar does not block the read, a batch past the queue budget is dropped, and storage stays off without a uid (each of the first three fails with its fix removed).
  • test/test_display_verdicts.py is skipped on Windows, where storage is off by design.
  • test/test_display_battery_rules_version.py (new): traces the battery in a fresh interpreter and fails on any executed package file outside RULE_SOURCES; a non-rule edit keeps the digest, any rule-file edit moves it. Checked against mutants: dropping exfil.py from the list, hashing names instead of bytes, and leaving the rule digest out of the version all fail it.
  • test/test_display_redaction_source_guard.py, test/test_chat_utils.py, test/test_dashboard_server_composition_contract.py: updated for the battery's new home and the new boot step.
  • Related suites (318 test files touching the changed modules): 19,673 passed, 27 skipped, 2 failed. The 2 are test/test_stop_hook_continuation.py::TestRealHookProcess, which fail identically on unmodified origin/main in this environment.
  • flake8, isort, mypy (src/kiro_crew/), docs lint, brand-name, comment-history and feature-map gates pass locally.

Manual verification

N/A — the replay harness above drives the real render path over real transcripts; no UI changes.

Related Issues

Follows #19624.

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

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners October 13, 2026 07:11
@buluoray
buluoray requested a review from mbriones98 October 13, 2026 07:11
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security_posture.py

  • @buluoray posted a complete reasoning template for 9289dac.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 9289daca88bd63942b3a8d7d539c09166ede0b8f 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 13, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Check that no battery path reads an operator file at run time: the trace test sees executed .py files, not data files a listed module opens.

[DESIGN-REVIEWED] 9289dac

Description read

[DESCRIPTION-READ] 789e85989c16654dafb1ef52e750884609c170a8b4d085d1ea416b842112d41d

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 13, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 9289daca88bd63942b3a8d7d539c09166ede0b8f — 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

Check one thing before merge: the battery reads no runtime input (config, env var, operator pattern) that the tag and rules version leave out. The trace test only sees code.

What this change ships

Inventory (9 items) — 9 justified

Intent: reopening a long session after a gateway restart renders fast instead of re-scanning every string for secrets. This is an ADDITION (a persistent cache) aimed at a measured cost: 785,748 battery calls taking about 84 s, down to 3,843.

  1. Opening a session after a restart reads stored verdicts instead of re-running redaction — justified
  2. New on-disk store <data>/display-verdicts/ with per-session sidecars — justified
  3. After each committed save, a background worker judges the new rows — justified
  4. After the listener binds, a background task turns storage on — justified
  5. Boot removes orphaned sidecars and clears the directory past 512 MiB — justified
  6. The redaction battery moves into display_battery.py, and a rules version hashes RULE_SOURCES — justified
  7. Read heuristics (4 cold misses, 64 live misses, 1 KiB per miss) decide when a render reads the sidecar — justified
  8. NON_EGRESS_REDACTION_MODULES gains dashboard/display_battery.py — justified
  9. Two offline replay scripts under test/perf/ — undeclared: the visible description never names summarize_replay.py; dev-only, no runtime surface

[FIRST-PRINCIPLES-REVIEWED] 9289dac

Description read

[DESCRIPTION-READ] 819bc1fa32855071c84d362db7214020cb4dc290a74412944f55faf3562b2f78

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.

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🟡 CONCERNS

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

Verdict basis: the reviewer's own judgement; no confirmed regression.

Security scope review -- adjudicated candidates

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

No candidate flipped from allowed to refused.

Scope-Verdict: CONCERNS

TIGHTENING: Fail-closed admission guards on the new persistent display-verdict store (dashboard/display_verdicts.py). They are not a change to any shell deny tier. The one threat they refuse is a forged or planted sidecar entry being served as a "clean" verdict, so a credential would render unredacted. The diff names it in the docstring: "a same-uid agent that can write the sidecar still cannot mint a tag for text it chose". The guards that enforce it are if not hmac.compare_digest(mac, _out_mac(p, tag, out)): continue, _READ_FLAGS = os.O_RDONLY | _NOFOLLOW | _NONBLOCK, if not stat.S_ISDIR(st.st_mode) or st.st_uid != uid: ... return False, and raise RuntimeError("redaction sources changed since they were loaded").

ADJUDICATED: 14 candidates, 0 confirmed newly-refused. The diff does not touch SHELL_DENY_TIERS, hooks.py, security/denied_rules.py or exfil's bash audit. Its edits to security/ only add display_battery.py, which moves the existing two-call battery. I expect no shell row to flip, but the harness has not reported any verdicts to me yet. The rows probe the maintainers' own operations in the touched area: the new and edited test suites, the perf replay and summarize scripts, reading the sidecar directory, and scoped diffs and greps over security/display_battery.py and dashboard/display_verdicts.py. One row, kirocrew status, is already in the corpus; the harness will drop it as a duplicate.

PLATFORM COVERAGE:

  • posix: Covers the diff's POSIX assumptions: O_NOFOLLOW/O_NONBLOCK, dir_fd opens, a uid-owned 0o700 directory under ~/.kirocrew/display-verdicts, and the PYTHONPATH=src prefix the perf script's docstring prescribes. Rows: pytest of the new suites, perf replay render/write, summarize_replay.py, ls/du of the sidecar directory, a scoped git diff, and a grep of RULE_SOURCES.
  • windows: Covers the diff's explicit Windows branch, where storage is off because effective_uid() is None. Rows: .venv\Scripts\python.exe pytest with backslash paths, the PowerShell $env:PYTHONPATH spelling of the replay with drive-letter paths, and a $env:USERPROFILE listing of the data home.
  • any: One read-only rg search over call sites, plus the duplicate status check.
  • Not probed: Windows has no shell surface for the sidecar store, so it has no sidecar-path row.

UNADJUDICATED:

  • Guard: The display-verdict store's admission checks: the owned-directory check in enable(), the rules_version() loaded-vs-disk digest check, the MAC and tag-half checks in _load()/lookup(), the O_NOFOLLOW/O_NONBLOCK/S_ISREG checks in _read_file()/_append(), and the credential_pass_bypassed() off-switch in active()/mac_base(). None of them is a shell command, so the classifier cannot reach them.
  • Call path: Gateway boot → _kick_display_verdicts → asyncio.to_thread(display_verdicts.enable(data_home())). Read side: api_chat_slot_detail → display_verdicts.session(slot_history_key(slot)) → _prepare_messages → chat_utils._redact_for_display → display_verdicts.active() → _Scope.lookup → _load. Write side: compose_payload → note_written_lines, then _save_slot_to_history → submit_committed → worker project().
  • What I can argue but not confirm: Every refusal here falls back to a full display_battery scan, so no displayed string is newly redacted and no operation is newly refused. The cost is lost acceleration, and nothing records it. These legitimate inputs silently lose persistence and pay the full cold-open scan on every restart:
    • Owned-directory check: A data home whose display-verdicts directory is owned by another uid. Examples: a gateway run under sudo once and then as the user, a bind-mounted volume in a container with remapped uids, or a network home with squashed ownership.
    • Rules-version check: A developer running the gateway from an editable checkout and editing any of the seven RULE_SOURCES files (including slack-manifest.yaml) while it runs. rules_version() raises, and enable() returns False for the whole process lifetime.
    • Symlink check: A data home where display-verdicts itself was relocated with a symlink. The lstat/O_NOFOLLOW on the final component refuses it.
    • Windows: Every Windows host is off by design. That is stated in the security spec and pinned by test_storage_stays_off_without_a_uid.
  • Narrowing: None of these is a security regression. Each costs performance only, and the read stays correct. But nothing logs a fallback above debug, except the owned-directory case. A warning-level log on the rules_version RuntimeError branch would let a developer see why stored verdicts never turned on. I can't confirm any of this without a harness that exercises enable() against these filesystem states.

[SCOPE-REVIEWED] aef8d96

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 9289daca88bd63942b3a8d7d539c09166ede0b8f — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 9289dac

Verdict parsed from the review's SHA-scoped output markers for commit 9289daca88bd63942b3a8d7d539c09166ede0b8f.

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

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 9289daca88bd63942b3a8d7d539c09166ede0b8f and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 9289dac

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 9289daca88bd63942b3a8d7d539c09166ede0b8f: <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 Oct 13, 2026
@buluoray
buluoray force-pushed the perf/display-verdicts-on-write branch from f37a011 to b1860db Compare October 13, 2026 08:02
@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: b1860db
  • What rule changed: none. security/display_battery.py is new; it moves the existing display battery (redact_exfiltration_urls, then redact_credentials, same order, same functions) into one function and lists the files its output depends on (RULE_SOURCES). No pattern, threshold or order changed.
  • Before -> after (what was allowed/blocked, now): every string that was redacted on display is still redacted, byte for byte; what changes is that a verdict may come from a MAC-checked sidecar instead of a fresh scan. Oracle: 20,375 renders of 799 real sessions (cold, restart and first-open runs) against origin/main, 0 diffs.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): leaks secret: a stored "clean" verdict served for text the current rules would redact. Guarded by the tag (HMAC under a token_signing.key subkey over rules version, text length, text and exempt hosts), the rules version over RULE_SOURCES, and fail-closed reads.
  • Evidence checked (which sandbox result proves it): test/test_display_verdicts.py fails with plaintext shown when the version, the exempt hosts or the length is removed from the tag (mutants run locally, then restored); test/test_display_battery_rules_version.py fails when exfil.py is dropped from RULE_SOURCES or the digest ignores file bytes. No shell deny rule is touched (Security Scope Review: 0 newly refused on posix and windows).
  • No regression:
    • Tools still work (which tools/commands were run, result): the replay harness rendered 799 real sessions through _prepare_messages on origin/main and this head; identical output.
    • Backward compatible (old config / old data / old callers still work, how checked): transcripts are not rewritten; a session with no sidecar is scanned as today (first-open runs, 0 diffs); _redact_for_display keeps its signature.
    • Existing tests (which suites passed on this head): 313 related test files, 19,603 passed, 27 skipped, 2 failed (test_stop_hook_continuation.py::TestRealHookProcess, failing identically on unmodified origin/main here); flake8, isort, mypy, black and subprocess-encoding gates pass.
  • How to undo: revert the two commits. The display-verdicts/ directory is then never read; it can be deleted at any time without effect on transcripts.

@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 13, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

Addressed on b1860db41b9:

  • Opus BLOCKING (length not in the stored tag): real. The persistent MAC now absorbs len(raw) (8 bytes, big-endian) before the text, so T under {H, Z} and T + NUL + H under {Z} get different tags. New test test_a_text_ending_in_a_revoked_host_does_not_reuse_a_stored_verdict reproduces your exact chain and shows the URL unredacted with the length update removed; it passes with it.
  • Opus FINDING (os.getuid on Windows): fixed with platform_compat.effective_uid(); storage stays off quietly when it is None.
  • First Principles item 6: the gateway bench harness and summarize_gateway.py are removed; the PR quotes no gateway number now.
  • First Principles item 7: forget() and current() are removed. _NO_BASE stays: test/test_chat_utils.py on main already calls _display_redaction_cache_key(text) with one argument, and the default keeps that caller's behavior.
  • First Principles item 8: on_enable stays as the seam because chat_utils imports display_verdicts at module level; calling chat_utils._clear_display_redaction_cache() from enable() would need the reverse import, a cycle.
  • Design Review (runtime battery inputs): security/display_battery.py now states that any battery input read at run time (config, env, data file, operator pattern) must go into the tag or rules_version. The trace test pins code; that rule pins data.
  • Semgrep: os.chmod(root, 0o700) is the strictest mode for a private directory (the rule's suggested 0o644 would widen it); marked nosemgrep the same way acp/harness/pi.py does. The unseeded-random hit is fixed (fixed filler bytes). The bench hits went with the bench.
  • internal-content-scan: the PEM test fixture is built by concatenation now.
  • Cross-Platform Portability: the os.getuid and os.kill//tmp hits are gone (fix above, bench removed).
  • CodeQL py/weak-sensitive-data-hashing at chat_utils.py: false positive. The input is display text, not a password, and the digest is a keyed HMAC used as a cache key; nothing is verified against it as a credential. The same HMAC-SHA256 call already exists on main one line above. py/clear-text-storage in the replay: the --dump option that wrote rendered (already redacted) bodies is removed; the oracle compares sha256 digests only.
  • Black: new files formatted; scripts/check_black_formatting.py passes locally.

@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 Oct 13, 2026
@buluoray
buluoray force-pushed the perf/display-verdicts-on-write branch from b1860db to aef8d96 Compare October 13, 2026 08:53
@buluoray

Copy link
Copy Markdown
Contributor Author

Addressed on aef8d962b5e:

  • GPT F1 (redacted tag replayed as clean): real. The 32-byte keyed MAC is now split: a clean verdict is stored under bytes 16-32, a redacted one under bytes 0-16, so a tag copied from .dvr into .dvc names nothing and the other half cannot be derived without the key. The file magic moved to KCDV0002, so sidecars in the old layout read as empty. Test: test_a_redacted_tag_copied_into_the_clean_file_is_not_a_clean_verdict (fails with the split undone).
  • GPT F2 (planted FIFO blocks the read): real. Sidecar opens are O_NOFOLLOW | O_NONBLOCK, then the regular-file check. Test: test_a_fifo_planted_as_a_sidecar_does_not_block_the_read (hangs until the timeout without O_NONBLOCK).
  • GPT F3 (queue retains unbounded payloads): fixed. _QUEUE_MAX_CHARS (32 Mi characters of queued rows) beside _QUEUE_MAX (256 batches); a batch past either is left to the read path, and the worker returns its share on dequeue. Test: test_a_batch_past_the_queue_budget_is_left_to_the_read (fails without the check).
  • Backend Tests (Windows): storage is off on Windows by design (no uid), so test_display_verdicts.py is skipped there; test_storage_stays_off_without_a_uid covers that branch on POSIX. The rules-version trace subprocess now keeps SYSTEMROOT/WINDIR, without which Windows Python cannot import asyncio.
  • CodeQL py/weak-sensitive-data-hashing: unchanged position from my earlier comment: display text under a keyed HMAC used as a cache key, not password storage.

Re-measured on this head (replay, 5 interleaved runs, median): restart open of 799 sessions 12.19 s (variant reading every sidecar first) vs 12.60 s (+3.4%); first open of the 40 longest 43.34 s (main) vs 43.74 s (+0.9%); oracle 20,375 renders vs main, 0 diffs.

@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: aef8d96
  • What rule changed: none. security/display_battery.py is new; it moves the existing display battery (redact_exfiltration_urls, then redact_credentials, same order, same functions) into one function and lists the files its output depends on (RULE_SOURCES). No pattern, threshold or order changed.
  • Before -> after (what was allowed/blocked, now): every string that was redacted on display is still redacted, byte for byte; what changes is that a verdict may come from a MAC-checked sidecar instead of a fresh scan. Oracle: 20,375 renders of 799 real sessions (cold, restart and first-open runs) against origin/main, 0 diffs.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): leaks secret: a stored "clean" verdict served for text the current rules would redact. Guarded by the tag (HMAC under a token_signing.key subkey over rules version, text length, text and exempt hosts), the rules version over RULE_SOURCES, and fail-closed reads.
  • Evidence checked (which sandbox result proves it): test/test_display_verdicts.py fails with plaintext shown when the version, the exempt hosts or the length is removed from the tag (mutants run locally, then restored); test/test_display_battery_rules_version.py fails when exfil.py is dropped from RULE_SOURCES or the digest ignores file bytes. No shell deny rule is touched (Security Scope Review: 0 newly refused on posix and windows).
  • No regression:
    • Tools still work (which tools/commands were run, result): the replay harness rendered 799 real sessions through _prepare_messages on origin/main and this head; identical output.
    • Backward compatible (old config / old data / old callers still work, how checked): transcripts are not rewritten; a session with no sidecar is scanned as today (first-open runs, 0 diffs); _redact_for_display keeps its signature.
    • Existing tests (which suites passed on this head): 313 related test files, 19,607 passed, 27 skipped, 2 failed (test_stop_hook_continuation.py::TestRealHookProcess, failing identically on unmodified origin/main here); flake8, isort, mypy, black and subprocess-encoding gates pass.
  • How to undo: revert the two commits. The display-verdicts/ directory is then never read; it can be deleted at any time without effect on transcripts.

@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 13, 2026
@buluoray
buluoray force-pushed the perf/display-verdicts-on-write branch from aef8d96 to d367194 Compare October 13, 2026 10:17
@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 13, 2026
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 14, 2026
@buluoray
buluoray force-pushed the perf/display-verdicts-on-write branch from 7ece57c to 91c1430 Compare October 14, 2026 04:04
@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 Oct 14, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 91c1430
  • What rule changed: none. dashboard/display_battery.py is new; it moves the existing display battery (redact_exfiltration_urls, then redact_credentials, same order, same functions) into one function and lists the files its output depends on (RULE_SOURCES). No pattern, threshold or order changed. security_posture.py gains one NON_EGRESS_REDACTION_MODULES entry for that file: it returns the redacted string to dashboard/chat_utils.py (already listed there) and emits nothing itself, so the egress count is unchanged. This head is rebased onto origin/main 70d2fa6, which includes feat(security): companion URL-prefix seam for token= redaction #18287 (companion ?token= prefix seam); the stored-verdict tag now also covers that prefix set, the same way main's in-process cache key does. Since the previous head, the first save of a transcript after a restart reads the stored verdicts before judging its window (independent review, P0 refactor: rename project KiroClaw to KiroCrew #2): before, it re-scanned every row and appended every tag again on each restart.
  • Before -> after (what was allowed/blocked, now): every string that was redacted on display is still redacted; what changes is that a verdict may come from a MAC-checked sidecar instead of a fresh scan. Oracle on an earlier head: 799 real sessions (cold, restart and first-open runs) against origin/main, 0 diffs. On this head the oracle was not re-run (the replay data copy was removed); the rebase changed only the cache-key function and the restart fix changes only which rows a save scans, both covered by the tests below.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): leaks secret: a stored "clean" verdict served for text the current rules would redact. Guarded by the tag (HMAC under a token_signing.key subkey over rules version, text length, text, exempt hosts and companion token-parameter prefixes), the rules version over RULE_SOURCES, and fail-closed reads, which refuse symlinks, FIFOs and hard-linked sidecars (st_nlink != 1). The restart fix reads verdicts through the same _load path a render uses, so it serves nothing a render would not.
  • Evidence checked (which sandbox result proves it): test/test_display_verdicts.py fails with plaintext shown when the version, the exempt hosts or the length is removed from the tag; test_revoking_a_token_param_prefix_invalidates_its_stored_verdicts fails when the prefix set is dropped from the stored tag; test_restarts_do_not_rescan_or_regrow_the_sidecar_on_save fails on the previous head (600 battery calls on the first save after a restart, expected 0) and asserts the sidecar size is unchanged across 5 restarts; test/test_display_battery_rules_version.py fails when exfil.py is dropped from RULE_SOURCES or the digest ignores file bytes. A probe of 5 restart-save-open cycles on a 2,000-row session: before, each restart re-ran 4,000+ battery calls and grew the sidecar by about 66 KB; now 2 calls (the one new row) and 32 bytes. No shell deny rule is touched.
  • No regression:
    • Tools still work (which tools/commands were run, result): test/test_display_verdicts.py (27 passed) renders sessions through _prepare_messages with and without stored verdicts, including restarts.
    • Backward compatible (old config / old data / old callers still work, how checked): transcripts are not rewritten; a session with no sidecar is scanned as today; _redact_for_display keeps its signature; the sidecar format is unchanged.
    • Existing tests (which suites passed on this head): on base 2f5c7d5, 608 related test files: 52,135 passed, 59 failed, all 59 failing identically on unmodified origin/main 2f5c7d5 (test_file_explorer_app.py, test_design_tweak_backend.py, test_design_tweak_devproc.py, test_apps_registry.py, test_stop_hook_continuation.py, test_auto_improvement_members.py). After the final rebase onto 70d2fa6, the 129 save, transcript and display test files: 9,487 passed, 0 failed. black and mypy pass.
  • How to undo: revert the two commits. The display-verdicts/ directory is then never read; it can be deleted at any time without effect on transcripts.

@buluoray
buluoray force-pushed the perf/display-verdicts-on-write branch from 91c1430 to 09eede8 Compare October 14, 2026 04:42
@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 14, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 09eede8
  • What rule changed: none. dashboard/display_battery.py is new; it moves the existing display battery (redact_exfiltration_urls, then redact_credentials, same order, same functions) into one function and lists the files its output depends on (RULE_SOURCES). No pattern, threshold or order changed. security_posture.py gains one NON_EGRESS_REDACTION_MODULES entry for that file: it returns the redacted string to dashboard/chat_utils.py (already listed there) and emits nothing itself, so the egress count is unchanged. This head is rebased onto origin/main 70d2fa6, which includes feat(security): companion URL-prefix seam for token= redaction #18287 (companion ?token= prefix seam); the stored-verdict tag now also covers that prefix set, the same way main's in-process cache key does. Since the previous head, the first save of a transcript after a restart reads the stored verdicts before judging its window (independent review, P0 refactor: rename project KiroClaw to KiroCrew #2): before, it re-scanned every row and appended every tag again on each restart. Also since the previous head (GPT 6.1 Review on 91c1430): the boot check, fchmod, both sweep scans and every sweep delete go through one O_NOFOLLOW | O_DIRECTORY descriptor, so a cache directory swapped for a symlink after the check cannot make the sweep delete files elsewhere.
  • Before -> after (what was allowed/blocked, now): every string that was redacted on display is still redacted; what changes is that a verdict may come from a MAC-checked sidecar instead of a fresh scan. Oracle on an earlier head: 799 real sessions (cold, restart and first-open runs) against origin/main, 0 diffs. On this head the oracle was not re-run (the replay data copy was removed); the rebase changed only the cache-key function and the restart fix changes only which rows a save scans, both covered by the tests below.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): leaks secret: a stored "clean" verdict served for text the current rules would redact. Guarded by the tag (HMAC under a token_signing.key subkey over rules version, text length, text, exempt hosts and companion token-parameter prefixes), the rules version over RULE_SOURCES, and fail-closed reads, which refuse symlinks, FIFOs and hard-linked sidecars (st_nlink != 1). The restart fix reads verdicts through the same _load path a render uses, so it serves nothing a render would not.
  • Evidence checked (which sandbox result proves it): test/test_display_verdicts.py fails with plaintext shown when the version, the exempt hosts or the length is removed from the tag; test_revoking_a_token_param_prefix_invalidates_its_stored_verdicts fails when the prefix set is dropped from the stored tag; test_restarts_do_not_rescan_or_regrow_the_sidecar_on_save fails on the previous head (600 battery calls on the first save after a restart, expected 0) and asserts the sidecar size is unchanged across 5 restarts; test_a_directory_swapped_after_the_check_does_not_redirect_the_sweep swaps the cache directory for a symlink as the sweep starts listing and fails on the previous head (the other directory's .dvc file is deleted); test/test_display_battery_rules_version.py fails when exfil.py is dropped from RULE_SOURCES or the digest ignores file bytes. A probe of 5 restart-save-open cycles on a 2,000-row session: before, each restart re-ran 4,000+ battery calls and grew the sidecar by about 66 KB; now 2 calls (the one new row) and 32 bytes. No shell deny rule is touched.
  • No regression:
    • Tools still work (which tools/commands were run, result): test/test_display_verdicts.py (28 passed) renders sessions through _prepare_messages with and without stored verdicts, including restarts.
    • Backward compatible (old config / old data / old callers still work, how checked): transcripts are not rewritten; a session with no sidecar is scanned as today; _redact_for_display keeps its signature; the sidecar format is unchanged.
    • Existing tests (which suites passed on this head): on base 2f5c7d5, 608 related test files: 52,135 passed, 59 failed, all 59 failing identically on unmodified origin/main 2f5c7d5 (test_file_explorer_app.py, test_design_tweak_backend.py, test_design_tweak_devproc.py, test_apps_registry.py, test_stop_hook_continuation.py, test_auto_improvement_members.py). After the final rebase onto 70d2fa6, with the descriptor fix, the 150 save, transcript, display and security-posture test files: 11,735 passed, 0 failed. black and mypy pass.
  • How to undo: revert the two commits. The display-verdicts/ directory is then never read; it can be deleted at any time without effect on transcripts.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Oct 14, 2026
@buluoray
buluoray enabled auto-merge (squash) October 14, 2026 19:21
renders warm only until the gateway restarts. This stores each row's verdict
(clean, or the redacted text) in a per-session sidecar under
<data>/display-verdicts/ once the transcript save commits, and reads it back on
the next open. The transcript itself is never rewritten.

- Tag: HMAC over (rules version, text length, text, exempt hosts, companion
  token-parameter prefixes) under a subkey of
  token_signing.key; a verdict whose tag does not match is ignored. While the
  owner-view switch bypasses the credential pass, nothing is stored or read.
- Rules version: sha256 of dashboard.display_battery.RULE_SOURCES (the display
  battery and the files its output depends on), the native gate binary when
  one is loaded, and the Python and Unicode versions. A release that leaves
  the redaction rules alone keeps every stored verdict; a process whose rule
  files changed on disk since import stores and reads nothing.
- Clean verdicts are stored under the second half of the 32-byte MAC and
  redacted ones under the first, so a tag copied between the files names
  nothing.
- Fail closed: any read error, bad MAC, version mismatch, symlink
  (O_NOFOLLOW) or FIFO (O_NONBLOCK) means "not scanned"; the string goes
  through the battery. Storage stays off where there is no uid (Windows).
- Bounds: the save-to-worker queue holds at most 256 batches and 32 Mi
  characters of rows; one sidecar is cleared past 16 MiB, the directory past
  512 MiB.
- A render reads the sidecar after 4 misses on a cold open (more misses than
  hits), or when the sidecar is at most 1 KiB per miss so far; a live render
  with a few new rows scans them rather than parse a long file. Verdicts the
  sidecar already holds are not appended again, so reopening does not grow it.
- The first save of a transcript after a restart offers its whole window; it
  reads the stored set first, so judged rows are neither scanned nor appended
  again and restarts do not grow the sidecar.
… harness

test_display_verdicts covers invalidation on a rules-version, allowed-host or
exempt-host change, fail-closed reads, when a render reads the sidecar, and a
reopen that must not grow it, and a text ending in a revoked host that
must not reuse a stored verdict, a tag copied between the files, a FIFO
sidecar and a batch past the queue budget. test_display_battery_rules_version traces the
battery in a fresh interpreter and fails on any package file outside
RULE_SOURCES, and checks that a non-rule edit keeps the digest while any
rule-file edit moves it. test/perf/redact_on_write_replay.py is the replay the
PR's numbers come from.
@buluoray
buluoray force-pushed the perf/display-verdicts-on-write branch from 09eede8 to 9289dac Compare October 14, 2026 21:07
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention labels Oct 14, 2026
@buluoray

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 9289dac
  • What rule changed: none. dashboard/display_battery.py is new; it moves the existing display battery (redact_exfiltration_urls, then redact_credentials, same order, same functions) into one function and lists the files its output depends on (RULE_SOURCES). No pattern, threshold or order changed. security_posture.py gains one NON_EGRESS_REDACTION_MODULES entry for that file: it returns the redacted string to dashboard/chat_utils.py (already listed there) and emits nothing itself, so the egress count is unchanged. Since the previous head 09eede8 this head is rebased onto origin/main 3572d1c, which added wire_render.py (slot-detail row memo) to the same list; both entries are kept. In slot_detail.py the memo render and the plain render now both run inside display_verdicts.session(...), so they read the same stored verdicts as before the rebase. A row served whole from main's row memo skips the per-string redaction, so it records no new verdict on that read; it shows what main's memo shows. Two test-only changes: test/conftest.py turns stored verdicts off after every test (a startup test left them on for its whole worker), and test/test_slot_render_context_key.py passes the new optional base argument through its stand-in for _display_redaction_cache_key.
  • Before -> after (what was allowed/blocked, now): every string that was redacted on display is still redacted; what changes is that a verdict may come from a MAC-checked sidecar instead of a fresh scan. Oracle on an earlier head: 799 real sessions (cold, restart and first-open runs) against origin/main, 0 diffs. On this head the oracle was not re-run (the replay data copy was removed); the rebase changed only where the render opens the verdict session, covered by the tests below.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): leaks secret: a stored "clean" verdict served for text the current rules would redact. Guarded by the tag (HMAC under a token_signing.key subkey over rules version, text length, text, exempt hosts and companion token-parameter prefixes), the rules version over RULE_SOURCES, and fail-closed reads, which refuse symlinks, FIFOs and hard-linked sidecars (st_nlink != 1). The row memo's context key is built from the same string-cache key, so turning stored verdicts on changes the row context and does not reuse rows rendered under the salt key.
  • Evidence checked (which sandbox result proves it): test/test_display_verdicts.py fails with plaintext shown when the version, the exempt hosts or the length is removed from the tag; test_revoking_a_token_param_prefix_invalidates_its_stored_verdicts fails when the prefix set is dropped from the stored tag; test_restarts_do_not_rescan_or_regrow_the_sidecar_on_save and test_a_directory_swapped_after_the_check_does_not_redirect_the_sweep fail on the head before those fixes; test/test_display_battery_rules_version.py fails when exfil.py is dropped from RULE_SOURCES or the digest ignores file bytes. On this head, test_content_cache_key_is_a_keyed_mac_over_text_and_hosts fails after a test that turns stored verdicts on without the new conftest cleanup, and passes with it; test_row_context_follows_the_string_cache_context failed in local-gate before its stand-in took the base argument, and passes now. No shell deny rule is touched.
  • No regression:
    • Tools still work (which tools/commands were run, result): on this head, the display, chat_utils, row-memo, composition-contract and every security-posture-referencing test file: 2,734 passed, 0 failed. black, isort, flake8 and mypy pass on the touched files.
    • Backward compatible (old config / old data / old callers still work, how checked): transcripts are not rewritten; a session with no sidecar is scanned as today; _redact_for_display keeps its signature; _display_redaction_cache_key's new base argument is optional, so main's one-argument callers (wire_render._context_digest) are unchanged; the sidecar format is unchanged.
    • Existing tests (which suites passed on this head): python3 scripts/local-gate.py backend batches on this head: 44,098 + 49,272 + 14,829 passed, 114 + 11 + 12 failed. Every failing file fails the same way on unmodified origin/main (sandbox-only failures in test_file_explorer_app.py, test_design_tweak_*, test_cli.py, test_ledger_sync_git.py, test_github_profile.py, test_pi_gate_extension_mcp.py, test_terminal_commands.py and others), except test_skill_view_relaunch_harness.py, which failed once under load and passes serially twice on this head and twice on origin/main 3572d1c. Frontend batches were not run locally (no node_modules in the worktree); this PR changes no website/ file.
  • How to undo: revert the two commits. The display-verdicts/ directory is then never read; it can be deleted at any time without effect on transcripts.

@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 14, 2026

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

Checks green and readiness passed at 9289dac; no behavior change.

@buluoray
buluoray merged commit 10e53cc into main Oct 15, 2026
104 of 105 checks passed
@buluoray
buluoray deleted the perf/display-verdicts-on-write branch October 15, 2026 00:04
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 15, 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