Skip to content

fix: bound design tweak startup log reads - #8163

Closed
leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/design-tweak-bounded-log-tail
Closed

leonlaiyc wants to merge 1 commit into
kirodotdev:mainfrom
leonlaiyc:fix/design-tweak-bounded-log-tail

Conversation

@leonlaiyc

@leonlaiyc leonlaiyc commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

When an owned project's dev server exits during the 45-second startup window,
Design Tweak reports the failure with the last 800 characters of the server's
log. It obtained them by loading the whole file and slicing:

tail = log.read_text("utf-8", errors="replace")[-800:]

The size of that read is chosen by the child process, not by the backend.

Why it matters

A dev server can emit an arbitrarily large log inside that 45-second window — a
build loop, a stack-trace flood, a dependency resolver in a retry cycle. Because
the failure path reads the file in full before discarding all but the last 800
characters, a noisy child turns an ordinary launch failure into backend memory
exhaustion.

The bad case is reached precisely when something has already gone wrong, so the
diagnostic path is at its least robust exactly when it is needed.

What changed (motivation → approach → change)

Symptom — the startup failure path at server.py:739 loads an entire
child-controlled log to produce an 800-character diagnostic.

Root cause — the read is unbounded because the bound was applied after
reading, as a slice. The 800-character contract was expressed at the wrong end
of the operation.

Change — extract _read_dev_log_tail(), which seeks to the end of the file
and reads only the bytes the diagnostic can need, then decodes that window:

  • _DEV_LOG_TAIL_BYTES = _DEV_LOG_TAIL_CHARS * 4, because UTF-8 encodes a
    character in at most four bytes. The byte bound therefore cannot cut the
    character contract short, while the child no longer chooses the read size.
  • Decoding uses errors="replace" on the window, so a multibyte character
    straddling the seek boundary degrades to a replacement character instead of
    raising.
  • The final [-_DEV_LOG_TAIL_CHARS:] keeps the existing 800-character contract
    exact after decode.
  • OSError still yields "", preserving the previous behaviour when the log
    cannot be read at all.

The response shape and the 800-character diagnostic are unchanged; only the
amount read from disk is bounded.

Tests

test/test_design_tweak_devproc.py::test_process_exit_reads_only_a_bounded_log_tail
— writes a large payload ending in 900 multibyte characters, then patches
Path.read_text to raise AssertionError if the dev log is ever read whole.
That inversion is what makes the test meaningful: it pins the absence of the
unbounded read rather than merely observing an output that a whole-file read
would also produce. It then asserts the returned tail equals the last
_DEV_LOG_TAIL_CHARS of the payload, so the multibyte boundary is exercised
rather than assumed.

Red-before: the regression fails on Path.read_text() at server.py:739
without the production change.

Validation at this exact head (21717fcbf), the focused suite re-run to confirm
it still holds: test/test_design_tweak_devproc.py green (53 passed, 3 platform
skips); repository-scoped Black gate clean; isort and flake8 clean on both
touched files; isolated mypy on server.py clean; subprocess-encoding gate,
feature-map gate and brand gate clean; git diff --check clean.

Manual verification

N/A — unit coverage sufficient. Reproducing the unbounded read by hand means
driving a real dev server into emitting a multi-gigabyte log; the regression
asserts the whole-file read never happens, which is the property at issue and is
checked directly rather than inferred from memory behaviour.

Related Issues

No linked issue.

Pattern harvest

Review prompt: inspect other diagnostic-tail call sites for whole-file reads
followed by a slice, especially child-process logs whose producer controls file
size.

Checklist

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

Contribution License Agreement

🤖 Generated with Claude Code

@leonlaiyc
leonlaiyc requested review from a team and CrysisDeu September 3, 2026 13:04
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Sep 3, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated.

Missing sections:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed
  • ## Tests

Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle.

3 similar comments
@iamwhatever

Copy link
Copy Markdown
Contributor

👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated.

Missing sections:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed
  • ## Tests

Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle.

@dwu96

dwu96 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated.

Missing sections:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed
  • ## Tests

Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle.

@dwu96

dwu96 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated.

Missing sections:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed
  • ## Tests

Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle.

@bolichen97
bolichen97 force-pushed the fix/design-tweak-bounded-log-tail branch from 21717fc to f38123b Compare September 8, 2026 12:13
@bolichen97

Copy link
Copy Markdown
Contributor

Rebased onto main 02d7a2d06 by a maintainer as part of the 2026-09-08 open-PR audit. The branch was 583 commits behind; it is now f38123bdd, with your single commit and diff unchanged (+49/-5 in 2 files).

Conflicts: none, clean rebase. No behaviour was changed.

Gates run locally on changed files only: isort and flake8 pass. black --check reports test/test_design_tweak_devproc.py, but that file is already in .github/black-baseline.txt and none of black's suggested hunks touch your added test. pytest test/test_design_tweak_devproc.py: your new test_process_exit_reads_only_a_bounded_log_tail passes; 3 TestClassifyProject failures are reproduced identically on plain origin/main, so they are pre-existing and unrelated.

Please review the rebase. A maintainer push makes the maintainer the last pusher, so under the repo's last-push rule a second approver is needed. Reply if anything looks wrong.

@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 8, 2026
@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — ✅ PASS

Design-level review of f38123bdd65674a21fa396b96dea0e2cbe9d37a3 via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

The change matches its description exactly: a real bound-at-the-wrong-end defect on a failure path, fixed at the read with the character contract and OSError behavior preserved, pinned by a test that asserts the absence of the whole-file read. The changed branch runs in CI unit tests on every platform, so the "Manual verification: N/A" claim covers nothing CI misses. No design-level findings survive.

Design-Verdict: PASS

A child-controlled unbounded read, bounded at the read itself; contract, failure behavior, and response shape preserved — root-cause fix, proportionate, trivially reversible.

[DESIGN-REVIEWED] f38123b

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — ✅ no blocking findings

Reviewed f38123bdd65674a21fa396b96dea0e2cbe9d37a3 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] f38123b

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed f38123bdd65674a21fa396b96dea0e2cbe9d37a3 via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] f38123b

@github-actions

github-actions Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — ✅ PASS

Premise-level review of f38123bdd65674a21fa396b96dea0e2cbe9d37a3 via the fork AI-review pipeline — 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.

All checks done. Here is the review.

First-Principles-Verdict: PASS

Nothing to check.

What this change ships

Inventory (3 items)

Intent: stop a failed dev-server launch from loading the child's entire log just to show its last 800 characters — a FIX.

  1. Startup-failure diagnostics now read at most 3,200 bytes of the dev log instead of the whole file; the 800-character message is unchanged — justified
  2. A multibyte character cut at the new read boundary degrades to a replacement character instead of raising — justified
  3. A regression test pins that the whole-log read never happens on the failure path — justified

Evidence checked against the base tree: the unbounded read exists verbatim at src/kiro_crew/apps/builtins/design_tweak/backend/server.py:741; the added test fails on base by construction (Path.read_text raises AssertionError, which the base's except OSError does not catch), so the defect has checkable provenance. Sibling count: grepped read_text(...)[-N and .read()[...][-N across src/ — 1 production instance, the one fixed, so no unfixed siblings. The nearest existing mechanism, _stderr_tail at src/kiro_crew/cron_script.py:1255, is a private method on core's MCP client, unreachable from a self-contained builtin app backend — not a duplicate.

[FIRST-PRINCIPLES-REVIEWED] f38123b

@dwu96 dwu96 added the needs-pr-triage PR scanner: awaiting automated triage label Sep 15, 2026
@chenmingwei23 chenmingwei23 added drive-to-green PR claimed by drive-to-green pipeline and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 15, 2026
@chenmingwei23

Copy link
Copy Markdown
Contributor

Kiro Crew [operator: chenmingwei23#de330d0c]

Triaged as solvable and claimed for the drive-to-green pipeline.

No conflict and no blocking review verdict. The only real failure is PR Hygiene,
and its reason is exact:

The Pattern harvest section must contain a "Rule candidate:" or
"Not generalizable:" line.

That is a PR-body requirement, not a code defect. The fix is to add one such line
to the Pattern harvest section, keeping the rest of your description byte-identical.
The macOS shards were in progress at triage, not red.

No code change is expected. Content security scan passed with no findings.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Sep 30, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

Thank you @leonlaiyc for this fix. #14949, which carries this change (bounding the design-tweak startup log reads), has now been merged. Closing this as resolved by #14949. 🙏

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 30, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor

@leonlaiyc quick follow-up: your work here landed on main via #14949 (merged). Your commit was kept with your authorship, so your name is on the change in the git history, and you're listed in the README Contributors section. Thanks again for the contribution!

@mbriones98 mbriones98 removed the drive-to-green PR claimed by drive-to-green pipeline label Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) merge conflict Branch has merge conflicts with its base — author must resolve before merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants