Skip to content

fix(service): timestamp and rotate managed service logs - #7064

Merged
lidge-jun merged 2 commits into
devfrom
fix/service-log-timestamps
Oct 13, 2026
Merged

lidge-jun merged 2 commits into
devfrom
fix/service-log-timestamps

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Closes [Bug]: service.log has no timestamps and no rotation #7045. ocx start under OCX_SERVICE now prefixes console stdout/stderr lines with UTC ISO-8601 timestamps, including multiline diagnostics. Foreground output and other CLI commands retain their existing format.
  • Check service.log at startup and once per minute; above 20 MiB, copy its newest 20 MiB into .1, retain the previous archive in .2, and truncate the active inode. Existing manager append handles keep working. Checks do not run on every write, filesystem failures never stop the service, and archive paths are registered for config cleanup.
  • Add focused regression coverage and English service documentation plus the owned structure contract. No cap increases, logging of request bodies, or new diagnostic data.

Verification

  • bun test tests/service/service-log.test.ts — 6 passed / 0 failed. The CLI timestamp regression was run before implementation and failed on the missing prefix; it passes after the fix. Tests cover all console sinks, multiline formatting, non-service output, startup/periodic rotation, two bounded generations, failure handling, and writes through a pre-opened append descriptor.
  • OCX_TEST_NO_QUEUE=1 bun run test:changed --parallel=1 — 6 passed / 0 failed across 1 selected file. The initial bun run test:changed was stopped while queued behind another lane's shared test lock; the documented intentional-overlap option was used for this short single-worker run.
  • bun test tests/test-layout.test.ts tests/test-layout-tooling.test.ts tests/lab/core-lab-boundary.test.ts tests/ci-workflows/file-size-ratchet.test.ts tests/service/service-start-environment.test.ts tests/service/service-health-sentinel-launch.test.ts — 63 passed / 1 failed initially. The only failure was the new 2,000-line file-size threshold in the CLI entrypoint and layout map; both were brought below that threshold without increasing a cap. bun test tests/ci-workflows/file-size-ratchet.test.ts then passed all 9 tests. The layout, Lab import/activation boundary, and adjacent service checks passed.
  • bun run typecheck — passed.
  • bun run structure:check — passed after moving the new contract to a dedicated doc within the existing line budgets and regenerating structure/INDEX.md.
  • bun run privacy:scan — passed.
  • cd docs-site && bun install --frozen-lockfile && bun run build — passed; 569 pages built and 79,406 internal links checked.
  • Full bun run test omitted because multiple concurrent implementation worktrees contend for the shared runner. Broad Ubuntu suite coverage remains with PR CI; live launchd/systemd and Windows manager testing was not performed locally.
  • Retention caveats: the active file can exceed 20 MiB between checks; copy-truncate can lose writes during copying and an archive can begin mid-line. Each archived generation is capped at 20 MiB, including for legacy oversized logs. Existing Windows wrapper messages retain their format.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults. The sink adds only timestamps and retains existing producer redaction; rotation failures do not emit file contents or credentials.

Summary by CodeRabbit

  • New Features
    • Managed services now write proxy output to a service log. When managed-service logging is enabled, console log lines include UTC timestamps.
    • The service checks log size at startup and periodically, archiving output when the log exceeds 20 MiB. Rotation failures do not stop the service; copying and truncating the log may result in lost lines.
  • Documentation
    • Added guidance on managed-service logs, timestamps, rotation, and failure behavior.

@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 13, 2026 15:36
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 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
📝 Code Review ✅ Completed 2026-10-13T15:40:46.919816Z 37362bf PR opened
ℹ️ 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.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 6ee82ee0-c8a7-4b03-9eff-2c5333f4190e
📥 Commits

Reviewing files that changed from the base of the PR and between 37362bf and 96e1ec7.

📒 Files selected for processing (3)
  • docs-site/src/content/docs/reference/cli/lifecycle.md
  • scripts/test-layout/layout.json
  • tests/fixtures/test-layout-expected.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

📝 Walkthrough

Adds timestamped console output and bounded service.log rotation for managed service starts. The CLI activates logging when OCX_SERVICE is set. Rotation runs at startup and periodically, retains two archives, and truncates the active file in place.

Changes: Managed Service Logging

Layer / File(s) Summary
Implement service logging and validate its lifecycle
src/service/logging.ts, src/cli/index.ts, tests/service/service-log.test.ts, scripts/test-layout/layout.json, tests/fixtures/test-layout-expected.json
Adds bounded copy-truncate rotation and timestamp prefixes for five console methods. The CLI starts logging for managed start commands. Tests cover activation, output formatting, rotation limits, failure cases, and periodic rotation.
Document the service logging contract
docs-site/src/content/docs/reference/cli/lifecycle.md, structure/ops/service-logging.md, structure/ops/service-and-sidecars.md, structure/runtime.md, structure/INDEX.md, structure/manifest.json
Documents activation, timestamping, rotation, failure handling, and limitations. Adds the operations document to the structure index and manifest, and links it from related service documentation.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Medium

Sequence Diagram(s)

sequenceDiagram
  participant CLI
  participant startServiceLogging
  participant console
  participant rotateServiceLog
  participant serviceLog
  CLI->>startServiceLogging: start command with OCX_SERVICE
  startServiceLogging->>console: wrap console methods with timestamps
  startServiceLogging->>rotateServiceLog: rotate at startup
  rotateServiceLog->>serviceLog: shift archives, copy retained tail, truncate active file
  loop Each configured interval
    startServiceLogging->>rotateServiceLog: rotate service log
    rotateServiceLog->>serviceLog: shift archives, copy retained tail, truncate active file
  end
Loading
Merge Risk: ⚪ Minimal · up to 96e1e

Managed service logging adds timestamps and bounded rotation. The supplied evidence reveals no material issue requiring resolution before merge.

Pre-merge checks · Passed 4 · Failed 1

Failed Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (3 skipped: 3… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks (4 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main changes: adding timestamps and rotation for managed service logs. It matches the documented implementation and PR objectives.
Linked Issues check Passed Issue #7045 requires timestamps for managed service output and size-based rotation for service.log. src/cli/index.ts activates startServiceLogging only for start when OCX_SERVICE is set. `sr…
Out of Scope Changes check Passed The reviewed changes remain within issue #7045. tests/service/service-log.test.ts provides regression coverage for the requested logging and rotation behavior. `docs-site/src/content/docs/reference/…
Full details: Docstring Coverage

Explanation

Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 3 files. (3 skipped: 3 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the bug Something isn't working label Oct 13, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 37362bffb4

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/cli/index.ts
Comment on lines +211 to 213
if (process.argv[2] === "start" && process.env.OCX_SERVICE) startServiceLogging(join(getConfigDir(), "service.log"));
const updateRestartChild = admitUpdateRestartChild(process.argv.slice(2));
initializeNodeLauncherContext();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Detect start after consuming the launcher proof argument

When the managed Linux service uses the stable ocx launcher, bin/ocx.mjs:1168 prepends --ocx-internal-launch-proof=... before start, so process.argv[2] is the proof rather than the command at this point. Because initializeNodeLauncherContext() removes that argument only afterward, startServiceLogging is never activated for this normal systemd launch path: its output remains untimestamped and service.log grows without rotation. Consume or skip the internal proof before testing which command is running, and add coverage that enters through the package launcher.

Useful? React with 👍 / 👎.

# Conflicts:
#	scripts/test-layout/layout.json
#	tests/fixtures/test-layout-expected.json
@lidge-jun
lidge-jun merged commit 0108cf8 into dev Oct 13, 2026
37 checks passed
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer integration record (MAINTAINERS.md dev exception): squash-merged into dev by @lidge-jun without a second maintainer approval during the 2026-10-14 triage. Exact-head verification: every required check on head 96e1ec78f5ab6079740560eaffd0da446ca99845 (the dev merge that resolves the test-layout map union with #7060) completed successfully. That includes typecheck, test shards 1–4, gates, structure gate, hygiene, enforce-target, docs build and linux-systemd. macOS and Windows jobs were skipped per the PR CI policy. The merge was pinned with --match-head-commit, and there are no outstanding change requests. Known limitation: copy-truncate rotation can drop lines written during the copy, and the active log can exceed the cap for up to one check interval (60 s).

@lidge-jun
lidge-jun deleted the fix/service-log-timestamps branch October 13, 2026 16:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant