Skip to content
This repository was archived by the owner on Nov 9, 2026. It is now read-only.

fix(baseline): Read only the last 4 MiB of a reviewer log - #466

Merged
mpaulosky merged 4 commits into
mainfrom
chore/bound-reviewer-log-input
Nov 6, 2026
Merged

mpaulosky merged 4 commits into
mainfrom
chore/bound-reviewer-log-input

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

Why

Copilot's review of mpaulosky/TicketManager#258 (a verbatim copy of this Template file) pointed out that lib/role-logs.mts read every reviewer log whole into a string, then built a line array and a same-length keep array from it. The sandbox writes that log, so its size is the sandbox's choice, and a huge log cost the host memory in proportion to its size while generating the run report. The view keeps only the last lines of each kind, so reading the end of the log is enough.

What changed

Both the Template's Owned role-logs.mts and dotfiles' copy of it:

  • REPORT_INPUT_LIMIT (4 MiB): liveRoleLogFs.read reads at most the last 4 MiB (plus one byte, so a cut on a line break keeps that line), from a whole line; allowlistedView applies the same cap to the text it is given.
  • A log that was cut starts with the existing [... lines left out] marker, so a cut log can't be mistaken for a quiet one.
  • readLogTail checks the log with lstat before opening it (a symlink, device, FIFO, socket or directory is refused without an open), then opens with O_NOFOLLOW | O_NONBLOCK | O_NOCTTY and checks with fstat, so an entry swapped in after the check can't make the host wait on a FIFO. A device node swapped in inside that window is still opened and refused afterwards; the comment names that accepted gap.
  • references/sandcastle.md gets one sentence on the cap.

The Template's tests cover the cut at n-1, n and n+1 for both caps, a cut on a line break, a tail with no line break, CRLF, an empty file, a cut in the middle of a multi-byte character, and the refusal of a symlink, a directory and a FIFO (the FIFO swap in a child process, so a regression fails the test instead of hanging the suite). Shifting each bound or dropping each flag fails a test; the one mutant that survives is equivalent.

Not part of this change: Copilot's other thread on #258 (credentials split by invisible fillers or hex chunks in error lines).

Review

Local pre-push review: 4 rounds, 16 findings (2 Warnings and 1 Critical, all fixed behind tests), 1 Advisory left open (the wording of the comment on the accepted gap, which needs the sandbox's write access to the logs folder confirmed).

🤖 Generated with Claude Code

mpaulosky and others added 4 commits November 6, 2026 10:49
…le line

The report view read every reviewer log whole, then built a line array and a
same-length keep array from it, so a huge sandbox-written log cost the host
memory in proportion to its size during final cleanup. It keeps only the last
lines of each kind, so reading the end is enough.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…cut log, and test the cut at a character boundary

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ed open, and test the swap in a child process

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…and pin the FIFO refusal at both layers

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 19:21

Copilot AI 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.

🔵 Needs a closer look

The accepted device-node swap race requires human security review because the source snapshot and flag tests cannot establish deployed sandbox permissions or whether opening an attacker-swapped device is safe.

No open issues 🎉

What changed in this PR

This PR bounds memory use when Sandcastle generates reviewer-log reports, updating both the reusable Baseline Template and dotfiles’ copies.

Changes:

  • Limits log input to a 4 MiB tail, preserves whole-line boundaries, and marks omitted content.
  • Adds filesystem checks and open flags to reject non-regular logs and avoid blocking on swapped-in FIFOs.
  • Adds boundary, encoding, and filesystem regression tests, and documents the cap.
File Description
Support For New Projects/​.claude/​skills/​repo-ci-baseline/​template/​owned/​.sandcastle/​lib/​role-logs.test.mts Tests input limits, line boundaries, encoding, and unsafe file types.
Support For New Projects/​.claude/​skills/​repo-ci-baseline/​template/​owned/​.sandcastle/​lib/​role-logs.mts Implements bounded tail reads and filesystem safeguards in the Template.
Support For New Projects/​.claude/​skills/​repo-ci-baseline/​references/​sandcastle.md Documents the cap and truncation marker.
.sandcastle/​lib/​role-logs.test.mts Mirrors the Template’s regression tests.
.sandcastle/​lib/​role-logs.mts Mirrors the Template’s bounded log-reading implementation.

Review effort: Balanced

@mpaulosky
mpaulosky merged commit 694356a into main Nov 6, 2026
3 checks passed
@mpaulosky
mpaulosky deleted the chore/bound-reviewer-log-input branch November 6, 2026 19:27
mpaulosky added a commit to mpaulosky/TicketManager that referenced this pull request Nov 7, 2026
## Why

Re-Apply the repo-ci-baseline Template so this repo carries the Template
changes from mpaulosky/dotfiles#461, #460, #465 and #466.

## What changed

- `4c4de51` Apply commit, `apply.sh` output alone: brings the Template
changes above (new Sandcastle modules, the Template's `check.sh`, role
prompts, workflow and skill updates).
- Hand edits after the Apply, each a separate commit:
- `.sandcastle/check.sh` (this repo's own Docker-free gate) renamed to
`.sandcastle/sandbox-gate.sh`, so Apply can add the Template's Owned
`check.sh`; `GATE_COMMAND` and `GATE_SCRIPT` follow.
- `GATE_LIMIT_MINUTES`, which the new `step-limit.mts` needs, added to
`repo-config.mts`; `CHECK_PATHS` and `.github/ci/sandcastle.sh`'s
`SANDCASTLE_PATHS` extended to the review paths, with tests in
`.sandcastle/repo-scripts.test.mts`.
- `shared-rules.md` says a role prompt's `scripts/gate.sh` means
`.sandcastle/sandbox-gate.sh` in the sandbox.
- `.sandcastle/lib/role-logs.mts` and its test come from
mpaulosky/dotfiles#466 (a reviewer log is read only as far as its last 4
MiB, which answers Copilot's memory-bound thread on this PR).
- `LICENSE` keeps its 2022 year (the Template's Owned copy says 2021, so
each re-Apply reverts it); the Seed Dockerfile pins markdownlint-cli2
0.24.0 to match `scripts/gate.sh` and the v25 lint action.

## Verification

- Against `main` this PR changes no pinned action, no `global.json` SDK
and no LICENSE year (the Template now carries the newer pins,
mpaulosky/dotfiles#465).
- The pre-push gate (`scripts/gate.sh`) passed, and the local pre-push
review is recorded clean (3 rounds, 6 findings, all fixed; then a second
run on the re-Applied `role-logs.mts`: 1 Advisory left open, about CI
treating the review skills' Markdown as docs-only, which needs a
Template change).
- `GATE_LIMIT_MINUTES = 10` is the Template default: `sandbox-gate.sh`
took 52 s on a warm worktree outside the sandbox, a cold or loaded
sandbox run was not timed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants