Skip to content

Rotate the service's log; a refused first service install leaves no unit behind - #85

Merged
edspencer merged 1 commit into
mainfrom
g-fixes
Nov 5, 2026
Merged

edspencer merged 1 commit into
mainfrom
g-fixes

Conversation

@edspencer

Copy link
Copy Markdown
Owner

Summary

Two fixes from the CLI contract's G1 survey (patch).

The service's log is rotated (cli-contract SPEC §7). <data>/logs/service.log was never rotated. server/contract/rotate.ts is cli-contract's reference/service/rotate.ts (401fba2) @ 0.2, copied with the standard header and no local changes, and its test is test/contract-rotate.test.ts. serve starts it at boot on <data>/logs/service.log, then every 15 minutes on an unref'd timer: past 8 MB the log is copied to service.log.1 and truncated in place (launchd and systemd hold an append descriptor on it), older copies shift down, three are kept. A foreground run has no such file, so it does nothing. npm run dev skips it.

  • The never-delete guard allows contract/rotate.ts one rm, one rename, one copy and one truncate, and a new test pins each to the file and its numbered copies, and pins serve to passing it only logs/service.log.
  • Docs: the never-delete guarantee, the data directory and the service page said the log isn't rotated. They now describe the rotation. CONTRIBUTING's rule names it as the one other truncation.

A first service install the manager refuses leaves no unit behind (cli-contract d5ddc0e, in Local Review's own service code). install wrote the unit, then reloaded, enabled and started it. If systemd refused any of those, or launchd refused the bootstrap, the unit stayed. service status then said "installed, not running" (3), and the next login tried it again. Now install notes whether the file existed before write. If it didn't, a refusal calls the manager's new discard(). On systemd that's a best-effort disable, removing the file through removeServiceFile, and daemon-reload. On launchd it's removing the plist. Then the error is rethrown (exit 1, as before). A refused reinstall keeps its unit.

Testing

  • npm test: 504 passed, 0 failed, 3 skipped. One of the skips is rotate's "unwritable folder" case, which skips as root (this box) and runs on CI. npm run typecheck is clean. npm run smoke:pack is ok. The docs site builds, and check-links reports 3267 internal links OK.

  • New tests, with a control:

    • systemd refusing start → no unit, and disable and daemon-reload were called, and status exits 4;
    • systemd refusing daemon-reload or enable → no unit;
    • launchd refusing bootstrap → no plist;
    • control: a refused reinstall keeps its (rewritten) unit on both, and nothing is disabled.

    Without the fix in index.ts, the three refusal tests fail and the control passes.

  • test/cli.test.ts checks that serve rotates a held-open 8 MB+1 log at boot, that the inode is unchanged and the next append lands at 0, that a log under the limit is left alone, and that a foreground run with no log makes none.

  • Real use: the packed tarball, in a throwaway npm prefix and HOME, against the published 0.16.0 as the "before". A stand-in systemctl loads units and refuses start.

    • 0.16.0 service install exited 1 and left local-review-server.service, and status then exited 3.
    • This build exited 1 and removed it (calls: start, disable --quiet, daemon-reload), and status exited 4.
    • Control: over an existing unit, the refused reinstall kept the unit.
    • Rotation: serve from the tarball ran under pm with a 9 MB service.log and an existing service.log.1. At boot, the 9 MB went to .1, the old .1 to .2, and service.log went to 0 bytes. /api/health answered 0.16.0 from that process; its environment showed the throwaway HOME.

Checklist

  • User-facing change? It has a changeset (patch).
  • UI change? No.
  • Doesn't weaken the read-only, never-delete or localhost-only guarantees. The rotation touches only the service manager's log and its numbered copies, and the guard pins that.

🤖 Generated with Claude Code

…nit behind

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@edspencer
edspencer merged commit 464432c into main Nov 5, 2026
10 checks passed
@edspencer
edspencer deleted the g-fixes branch November 5, 2026 08:17
@github-actions github-actions Bot mentioned this pull request Nov 5, 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.

1 participant