Skip to content

fix: bound design tweak startup log reads - #14949

Merged
chenmingwei23 merged 2 commits into
mainfrom
fix/design-log-read-inrepo
Sep 30, 2026
Merged

chenmingwei23 merged 2 commits into
mainfrom
fix/design-log-read-inrepo

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Supersedes #14285 and #8163 by @leonlaiyc (original head is a fork; this in-repo branch carries the identical commit so CI + the same-repo review lanes can run and the PR can be driven to green). No code change vs #14285 — same head 907ae39590972041c6eab7989eae4d40d8c2e97e.

Problem / Motivation

Goal: A credential a failing dev server printed never reaches the dashboard, and the diagnostic read that carries the failure stays memory-bounded.

When an owned project's dev server fails to start, the design-tweak backend attaches the tail of the dev-server log to the error it returns. It did this with log.read_text("utf-8", errors="replace")[-800:], which reads the entire log into memory before slicing off the last 800 characters. A child process that emits a very large amount of output to that log forces the parent to load the whole file just to keep the last 800 characters.

Why it matters

The diagnostic read size is chosen by whatever the child writes, not by the parent, so a noisy dev server can make the failure path allocate memory proportional to the full log when only a bounded tail is used. The same failed-launch tail is returned to the dashboard, so a credential the dev script printed before dying must not survive into it — including a multi-line private key whose -----BEGIN ... PRIVATE KEY----- header sits far above the retained tail.

Not a goal

  • Changing what the tail contains for a successful launch, or the 800-character tail size.
  • Reworking the shared redaction floor itself; this call site composes the existing floor through redact_via_context, which delegates to that floor on a standalone build and additionally applies a loaded companion's credential policy when one is composed.
  • Bounding the log file's own size on the write side.

What changed (motivation → approach → change)

  • Symptom: the failed-launch diagnostic read loads the whole log before slicing, and returns the raw tail to the dashboard.
  • Root cause: read_text(...)[-800:] reads everything, then discards all but the tail, and the tail is unredacted. Bounding before redaction would also sever a credential whose opening anchor precedes the window (a PEM body with no visible header is not recognised by the header-anchored redactor).
  • Change: _read_dev_log_tail(log) in src/kiro_crew/apps/builtins/design_tweak/backend/server.py reads at most _DEV_LOG_READ_WINDOW (64 KiB) bytes from the end of the log into one buffer, redacts that whole buffer in a single redact_via_context pass, and keeps the last _DEV_LOG_TAIL_CHARS (800) characters. redact_via_context delegates to the URL-then-credential floor on a standalone build and also applies a composed companion's credential policy when one is loaded. On a mid-file (truncated) read the window's start is untrusted, so _drop_truncated_window_head(window) first discards the partial first line and then masks through the first -----END ... PRIVATE KEY----- marker in the window, so a key body whose BEGIN header sat above the window start cannot reach the tail even when a later full PEM follows. Memory stays bounded by the window, the single pass sees a PEM BEGIN header and its body together so the body is scrubbed even when the header sits above the retained tail, and there is no chunk boundary a credential could straddle to escape redaction.

Backwards compatibility

Compatible: the returned value is still at most 800 characters of the log's end. What changes is that the read is memory-bounded (a 64 KiB window rather than the whole file) and the text is redacted in one pass before it is returned, so a credential in the tail — or one whose anchor sits above the tail but within the window — is scrubbed rather than surfaced.

Tests

Added in test/test_design_tweak_devproc.py:

  • test_process_exit_reads_only_a_bounded_log_tail: a large payload yields a tail bounded to _DEV_LOG_TAIL_CHARS.
  • test_process_exit_redacts_credentials_from_the_log_tail: a dying dev server prints an AWS-shaped access key; the raw credential is absent from the returned tail.
  • test_process_exit_redacts_a_key_whose_header_precedes_the_tail: a PEM key whose BEGIN header sits far above the retained tail is still scrubbed from the body — the case a window-over-the-end read would miss.
  • test_process_exit_redacts_a_key_straddling_the_read_window_edge: with the window shrunk below the log size, a PEM whose header lands just inside the window start is still scrubbed — the single pass has no seam where the old per-chunk redaction could split header from body.
  • test_process_exit_masks_a_key_body_bisected_by_the_window_start: a key whose BEGIN header fell before the window leaves an anchorless body at the window start; the truncated-head drop masks through the unmatched END so the body never reaches the tail.
  • test_process_exit_masks_an_orphan_body_before_a_later_full_pem: an orphaned body (no END of its own) followed by a complete PEM — so the window's first BEGIN precedes its first END — is still masked, because the head drop masks through the first END regardless of any later BEGIN.

Manual verification

N/A — unit coverage sufficient. The change is a bounded-memory, single-pass redacted refactor of the diagnostic read with tests that lock in the bound and the redaction (including the header-above-tail and window-edge cases).

Related Issues

Replaces #8163 by @leonlaiyc.

Pattern harvest

Not generalizable: this is a one-off — a single diagnostic read that sliced a tail out of a full-file read and returned it unredacted, and whose fix must stay memory-bounded while still seeing a credential's opening anchor. The redaction primitive already exists; this call site now reads one bounded window and redacts it once through redact_via_context (the floor on a standalone build, plus a composed companion's policy when loaded). The existing test/test_core_path_redact_before_bound.py already pins the wider "bounded slice before redaction" class.

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

Co-authored-by: leonlaiyc <276034861+leonlaiyc@users.noreply.github.com>
@iamwhatever
iamwhatever requested a review from a team as a code owner September 29, 2026 06:20
@iamwhatever iamwhatever added the drive-to-green PR claimed by drive-to-green pipeline label Sep 29, 2026
@iamwhatever iamwhatever self-assigned this Sep 29, 2026
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5) — ✅ PASS

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

Design-Verdict: PASS

Verify the copied PEM anchors (_PEM_BEGIN_RE/_PEM_END_RE) stay byte-identical to the redaction floor's — a later floor widening silently reopens the bisected-body gap.

Suggestions

  • Export the PEM marker anchor from security/redaction.py (which already owns the shape at redaction.py:116,1461) and import it here — server.py, preview_files.py:185, and cron_script.py:1648 now carry four hand-copied variants of it, and drift between the mid-file head-mask and the floor it mirrors is exactly the seam this PR exists to close.

[DESIGN-REVIEWED] 39ef139

Description read

[DESCRIPTION-READ] 441afff03ca04f4aca51539e43da7eea7884f02974fa50a514fbb1c1ce471082

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 Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5) — 🟡 CONCERNS

Premise-level review of 39ef1395e4a6ffc5efe3a60f053dee5e100180c4 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: CONCERNS

_PEM_BEGIN_RE ships with zero consumers — a leftover from the preceding-BEGIN design the final END-mask deliberately rejects — and the base64 head-drop is undeclared.

Not justified as shipped

  • Item 4 — undeclared: the description's What-changed names only "discards the partial first line and then masks through the first -----END ... PRIVATE KEY----- marker"; the ≥2-consecutive-base64-line head drop, which silently removes legitimate base64-shaped diagnostic lines from every truncated tail, appears nowhere in it (its test is also absent from the Tests list).
  • Item 6 — zero consumers: _PEM_BEGIN_RE (server.py:294) is never referenced — grep _PEM_BEGIN_RE across the repo: 1 hit, the definition itself; its own comment describes a "END with no preceding BEGIN" check the shipped code explicitly does not perform ("Masking through the FIRST END unconditionally").
    Subtraction: delete _PEM_BEGIN_RE and its two-line comment.
    Clears when: the constant is deleted from server.py.

What this change ships

Inventory (7 items) — 5 justified

Intent: FIX — a failed dev-server launch's diagnostic tail must stay memory-bounded and never carry a printed credential to the dashboard (linked #8163/#14285; class pinned by test/test_core_path_redact_before_bound.py).

  1. Failed-launch log read is bounded to a 64 KiB end window instead of the whole file — justified
  2. The returned tail is redacted before reaching the dashboard, companion policy included — justified
  3. On logs larger than the window, the partial first line is dropped from the tail — justified
  4. On truncated reads, a leading run of ≥2 base64-only lines is silently dropped — undeclared, absent from the description's What-changed and Tests sections
  5. On truncated reads, content through the first PEM END marker is masked — justified
  6. Module constant _PEM_BEGIN_RE — zero consumers, defined and never used (1 grep hit: the definition)
  7. Nine regression tests pin the bound, redaction, and truncated-head cases — justified

No unfixed siblings: grep read_text\([^)]*\)\[- in src/ returns 0 matches after this change.

[FIRST-PRINCIPLES-REVIEWED] 39ef139

Description read

[DESCRIPTION-READ] 942cba8ce589378f253ddd8fcbf96f2fe3bd0a0f0a94df63ca398cd7b9f3e391

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 Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review — ✅ human override accepted

Human judgment by @iamwhatever overrides the GPT 5.6 finding for 39ef1395e4a6ffc5efe3a60f053dee5e100180c4; the recorded reason is authoritative for this commit.

[GPT-OVERRIDE] 39ef139

This comment is updated in place on each push.

The model was not re-run because an authorized human decision supersedes it.

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

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5 Review — ✅ no blocking findings

Reviewed 39ef1395e4a6ffc5efe3a60f053dee5e100180c4 — this comment is updated in place on each push.

Review details

Non-blocking: one prose/code contradiction — _read_dev_log_tail's docstring documents a "no preceding BEGIN" condition the code deliberately does not implement.

FINDING — src/kiro_crew/apps/builtins/design_tweak/backend/server.py:720 — the docstring states the END-mask fires only if a "-----END ... PRIVATE KEY-----" marker appears with no preceding ``BEGIN`` inside the window, but _drop_truncated_window_head runs end = _PEM_END_RE.search(window) with no BEGIN test at all, and its own docstring says the opposite (Masking through the FIRST END unconditionally is why a later ``BEGIN`` cannot re-expose the bisected body); _PEM_BEGIN_RE (server.py:294), whose comment claims to implement that condition, has no reference anywhere in src/ or test/ → Fix: rewrite server.py:719-723 to state the three guards the code actually applies (drop the partial first line, drop a leading run of ≥2 base64-only lines, mask through the first -----END ... PRIVATE KEY----- unconditionally) and delete _PEM_BEGIN_RE with its comment at server.py:291-294.

[OPUS-REVIEWED] 39ef139

Verdict parsed from the review's SHA-scoped output markers for commit 39ef1395e4a6ffc5efe3a60f053dee5e100180c4.

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

@iamwhatever
iamwhatever force-pushed the fix/design-log-read-inrepo branch from 907ae39 to 08c018d Compare September 29, 2026 07:51
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 29, 2026
Read the last 64 KiB of the failed-launch log into one buffer and redact
it in a single pass, replacing the fixed-chunk StreamRedactor loop. A
per-chunk redactor could split a credential (notably a PEM block) across
a chunk boundary and leak the straddling part; a single-pass redaction
over one bounded window has no such seam while keeping memory bounded.

Co-authored-by: leonlaiyc <276034861+leonlaiyc@users.noreply.github.com>
@iamwhatever
iamwhatever force-pushed the fix/design-log-read-inrepo branch from 08c018d to 39ef139 Compare September 29, 2026 08:19
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 29, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

/ai-review override gpt 39ef139: The orphaned-PEM leak needs a dev-server log over 64 KiB whose PEM header sits above the window start and whose in-window head opens with encrypted-PEM metadata (Proc-Type/DEK-Info/blank), so the leading-body scan stops at run=0, no END is in the window, and a later secret's redaction shrinks the tail below 800 chars. The guard already drops multi-line base64 bodies and masks through the first END. Security-class, strictly safer than main; skipping the metadata is a follow-up.

@github-actions

Copy link
Copy Markdown
Contributor

Human judgment recorded

@iamwhatever marked the gpt AI finding as false positive, not applicable, or explicitly accepted for 39ef1395e4a6ffc5efe3a60f053dee5e100180c4.

The orphaned-PEM leak needs a dev-server log over 64 KiB whose PEM header sits above the window start and whose in-window head opens with encrypted-PEM metadata (Proc-Type/DEK-Info/blank), so the leading-body scan stops at run=0, no END is in the window, and a later secret's redaction shrinks the tail below 800 chars. The guard already drops multi-line base64 bodies and masks through the first END. Security-class, strictly safer than main; skipping the metadata is a follow-up.

This decision applies only to this commit. A new push requires a new judgment.

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

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

Bulk approve: readiness passed, board green, no outstanding changes requested.

@chenmingwei23
chenmingwei23 merged commit 89b9e76 into main Sep 30, 2026
120 of 124 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/design-log-read-inrepo branch September 30, 2026 03:45
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Sep 30, 2026
@dodgeblaster dodgeblaster removed the drive-to-green PR claimed by drive-to-green pipeline label Sep 30, 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.

4 participants