Skip to content

fix(headroom): cap and rotate the daemon log - #616

Merged
Mearman merged 1 commit into
mainfrom
fix/615-rotate-headroom-log
Oct 27, 2026
Merged

Mearman merged 1 commit into
mainfrom
fix/615-rotate-headroom-log

Conversation

@Mearman

@Mearman Mearman commented Oct 27, 2026

Copy link
Copy Markdown
Member

Fixes #615.

The supervisor now rotates the headroom daemon log. At the top of every tick it checks the file's size and, once it passes HEADROOM_LOG_MAX_BYTES, copies it to headroom.log.1 and empties it in place, first shifting the earlier copies one place older and deleting the one past HEADROOM_LOG_KEPT_GENERATIONS. The live file and its kept copies therefore stay bounded however long the daemon runs.

The file is emptied rather than renamed away because the daemon holds a descriptor on it opened for appending, and a renamed file would keep receiving its output. Lines written between the copy and the emptying are lost, which is the cost of rotating a file whose writer cannot reopen it.

Rotation runs before a start attempt takes its log offset, so the early-exit report in lastError still reads only that attempt's own output. The rotation itself is a small shared helper over the farm filesystem port (src/logRotation.ts).

Tests: logRotation.test.ts covers the helper against a fake filesystem and against a real file that a descriptor opened for appending keeps writing to across a rotation. supervisorLog.test.ts covers the supervisor asking for rotation each tick, a rotation leaving the daemon running, and an early-exit report staying correct after a rotation between attempts. The supervisor tests fail with the rotation call removed.

The daemon log was appended to for the life of the supervisor and never
trimmed, so a long-running daemon grew it without bound.

The supervisor now checks the log at the top of every tick and, once it
passes a size cap, copies it to a numbered generation and empties it in
place, keeping a fixed number of earlier copies. It is emptied rather than
renamed because the daemon holds an appending descriptor on the file.
Rotation runs before a start attempt takes its log offset, so an early-exit
report still reads only that attempt's own output.

Fixes #615
@Mearman

Mearman commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-27T10:20:11.541912Z 6d3abb6 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 6d3abb63d6

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@Mearman
Mearman marked this pull request as ready for review October 27, 2026 10:15
@Mearman
Mearman merged commit a2f74a6 into main Oct 27, 2026
32 checks passed
@Mearman
Mearman deleted the fix/615-rotate-headroom-log branch October 27, 2026 10:16
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.

Headroom daemon log grows without bound

1 participant