Skip to content

host: the diagnostics report prints a state-backup name uncleaned, so a control character breaks the one-line shape #3173

Closed

Description

@HugoXK

Implementation: FlyBot (ours) — PR follows within 24h. Do not pick up without a pickup-ok comment on this issue.

Written-by: FlyBot Lead
Claimed-by: FlyBot Lead
Claim-Id: bf1f29f715bf43769b186edf685536b8
Branch: dev/1-diagnostics-backup-names
Base: b303da8
At: 2026-11-18T16:42:47Z

Bot: FlyBot Dev-1

The diagnostics report draws every path through cleanPath, except the state-backup names: backupFact / backupProblem in core/src/host/diagnostics.js (lines ~394-401 on 25ab31c9) interpolate the raw readdir + lstat name straight into the markdown, and line ~145 inserts it unchanged. A backup name containing a control character therefore breaks the report's one-line-per-fact shape, and a name shaped like a saved key is printed in the clear.

Reproduction

In the diagnostics home directory, create a state backup whose name carries a line break (allowed on Linux/APFS; store itself only ever writes state.json.broken-<stamp> / state.json.v1, so this name has to be made by hand):

state.json.broken-a<LF>| Read-only | no |

Run the diagnostics report (or test/diagnostics.test.js against a real installDiagnostics with that home). On 25ab31c9 the report's state backups: fact is

state.json.broken-a
| Read-only | no | (2 KB, 2 h ago)

i.e. one injected line — the report goes from 13 lines to 14. A name carrying \r leaves a bare carriage return in the markdown, and a name shaped like sk-abcdefghijklmnop is printed verbatim instead of being hidden.

Red-first on 25ab31c9 (TZ=UTC TMPDIR=/tmp node --import ./test/harness-resolve.mjs --test test/diagnostics.test.js): the three new cases fail, # tests 78 / # pass 75 / # fail 3; with the fix they are 78 pass / 0 fail and no existing assertion changed. main moved to b303da8a (#3172) before this was filed; the branch rebases onto it and the same three cases fail there.

Expected

  • A backup name is drawn on one line, like every other name in the report: control characters (\u0000-\u001f, \u007f-\u009f, \u2028, \u2029) folded to spaces, runs of whitespace collapsed, trimmed — the single-line idiom already used in tasks.js, meetings.js, decisions.js. Wrapping cleanText alone is not enough: cleanText redacts and shortens but does not fold newlines.
  • The same one-line value goes through the report's existing redaction, so a name shaped like a saved key is hidden.
  • Report line count with one such backup differs from the no-backup report by exactly one line; state backups: state.json.v1 (12 KB, 2 h ago) and and N more stay byte-identical (pinned by test/diagnostics.test.js).

Scope

  • core/src/host/diagnostics.js only: one helper used by both backupFact and backupProblem; stateBackups() keeps its lstat-only reads, newest-first order, BACKUPS_SHOWN = 3 cap, and N more and none behaviour.
  • No new filesystem call, no open/read of a backup — lstat metadata only.
  • New cases in core/test/diagnostics.test.js, guarded { skip: process.platform === 'win32' } (Windows file names cannot carry a newline and the nightly runs the same suite on windows-latest).
  • node scripts/ds-bot-patches.mjs generate re-emits patches/ds-bot/0001-core-fixes.patch and 0007-version-and-tooling.patch; check must stay clean.
  • changelog.d/<issue>-backup-name-one-line.fixed.md, and ARCH_DOCS_BASE=<base> npm run arch-docs after the fix (docs sentence at docs/subsystems/core-host.md, the state-backup paragraph).
  • Tier T2 (core/src/host/**): a reviewer PASS at the exact tip is required before the queue.

Boundary, so this is not read as bigger than it is: the only hard reproduction is a control character in a name that a person has to create by hand; length is bounded (a single name is capped by the filesystem at 255 bytes, at most three names are shown, so the line stays around 800 characters); the sk-… case is a second consequence of the same missing clean-up, not a separate defect; backups are still never opened.

Dedup

state backups in:title → 0 issues; diagnostics backup name cleanText → only closed #2434 (2026-11-04), which added backup names to the report in the first place — this is the clean-up that was missed there. No open issue or PR covers it.

Zero-write note for the frozen gate PRs: this issue does not touch policy/gates.json gateFiles.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions