Repository navigation
fix(daemon/launchd): cap unbounded gateway stdout/stderr log growth (refs #79422) - #79892
adhirajhangal wants to merge 2 commits into
Conversation
|
Thanks for the context here. I did a careful shell check against current Close this older PR: current main has a bounded, rotating Gateway file logger, while the remaining raw launchd stderr policy is separately tracked and cannot safely be revived from this stale branch. So I’m closing this older PR as already covered on Review detailsBest possible solution: Keep retention in the structured logger and address raw macOS stderr visibility, if desired, through a fresh current-main change for #90711. Do we have a high-confidence way to reproduce the issue? No current-main failure path was established: source and tests show structured Gateway logs rotate at the write owner, while launchd raw stderr now follows a different policy. Is this the best way to solve the issue? No; current main’s logger is the canonical active-write owner, so the branch’s restart-time daemon rotation is no longer the best solution. Security review: Security review cleared: The proposed rotation code adds no dependency, credential, permission, or supply-chain surface. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 2d3612da6bd2; fix evidence: commit a0f4d5462a4e, main fix timestamp 2026-08-16T19:57:34Z. |
|
Thanks @clawsweeper. Addressed the P2 in fixup
Added two regression tests in
Acceptance criteria results on this fixup: |
The launchd plist points StandardOutPath and StandardErrorPath at ~/.openclaw/logs/gateway.log and gateway.err.log, and launchd just appends forever. When a tight error loop fires (the reporter on openclaw#79422 saw acpx/runway/tts-local-cli dep-staging spinning), gateway.err.log can reach 18-19 GB between restarts and fill the disk. Add a pure helper that rotates either sink to {path}.1 once it crosses a configurable cap, dropping any pre-existing archive. Hook it into the four daemon transitions that touch the log dir or restart the LaunchAgent: install, plist rewrite, and openclaw gateway restart on both the direct-kickstart and the in-process self-handoff path (retention runs before scheduleDetachedLaunchdRestartHandoff so the detached helper does not need a copy of the rotation logic). Default cap is 64 MB per stream with one archive (so up to 128 MB on disk per stream). Configurable via OPENCLAW_GATEWAY_LOG_MAX_BYTES and OPENCLAW_GATEWAY_LOG_ARCHIVES; setting MAX_BYTES=0 disables retention entirely. Healthy non-oversized paths just stat once and return. Refs openclaw#79422 (log-retention half only; the CPU/dep-staging loop in that issue stays open for separate live-profiling).
ad6e8df to
9be6dae
Compare
|
Thanks @clawsweeper. Addressed the P2 in Changes:
Verified locally: Tests still green on the rewritten branch: If a maintainer later wants to release-note this as fully closing #79422 once the CPU side has its own fix, that can happen at squash-merge time by adding a closing keyword in the merge commit body. |
…uence Codex P3 on openclaw#79892 noted the direct-restart regression test only checked that retention and kickstart were each called, not that retention preceded kickstart. Push "kickstart" into the same callOrderState event log the retention/handoff mocks already use, then assert the strict sequence ["retention", "kickstart"] for the direct-restart test, matching the ["retention", "handoff"] sequence the self-handoff test already pins.
|
Thanks @clawsweeper. Addressed the P3 in The direct-restart test now pins the strict order in a single sequence the same way the self-handoff test does. I extended the existing // self-handoff path
expect(callOrderState.events).toStrictEqual(["retention", "handoff"]);
// direct path
expect(callOrderState.events).toStrictEqual(["retention", "kickstart"]);If retention ever drifts back below the kickstart call (or below the self-handoff scheduling), one of those two assertions fails immediately rather than just confirming both events happened. Separately, the |
|
This pull request has been automatically marked as stale due to inactivity. |
|
@adhirajhangal thanks for the PR. ClawSweeper is still waiting on real behavior proof before this can move forward. Useful proof can be a screenshot, short video, terminal output, copied live output, linked artifact, or redacted logs that show the changed behavior after the fix. Please redact private tokens, phone numbers, private endpoints, customer data, and anything else sensitive. Once proof is added to the PR body or a comment, ClawSweeper or a maintainer can re-check it. |
|
ClawSweeper applied the proposed close for this PR.
|
What this fixes
gateway.err.log(andgateway.log) under~/.openclaw/logs/can grow without bound on macOS because the LaunchAgent plist setsStandardOutPath/StandardErrorPathto fixed paths and launchd appends forever. The reporter on #79422 saw the stderr sink reach 18-19 GB across two separate incidents from a tightacpx/runway/tts-local-clidep-staging error loop, withopenclaw gateway restartas the only workaround.This PR addresses the log-retention half of that report only. The dep-staging CPU loop itself needs live profiling against current main and is intentionally out of scope. Per clawsweeper's triage the log retention defect is independent and actionable now, so the language in this PR (commit message, CHANGELOG, references below) is deliberately non-closing for #79422 — that issue stays open for the maintainer-led CPU investigation.
What changes
A new
src/daemon/log-retention.tshelper:rotateOversizedDaemonLog({ path, limits }), pure, fs-injectable, async. If the file is larger thanlimits.maxBytes, it renamespathtopath.1, deleting any pre-existingpath.1first. Witharchives > 1it cascadespath.{n-1}topath.{n}so the oldest archive is dropped.applyGatewayLogRetention(env), resolves the gateway log paths and runs rotation on bothstdoutPathandstderrPathin parallel.resolveGatewayLogRetentionLimits(env), readsOPENCLAW_GATEWAY_LOG_MAX_BYTESandOPENCLAW_GATEWAY_LOG_ARCHIVES. Defaults: 64 MB per stream, 1 archive.OPENCLAW_GATEWAY_LOG_MAX_BYTES=0disables retention. Archives are clamped to 9.src/daemon/launchd.tscallsapplyGatewayLogRetention(env)at every transition that can lead to a fresh launchd write into the sinks:writeLaunchAgentPlist(install / stage path), right afterensureSecureDirectory(logDir).rewriteLaunchAgentPlistForRestart, same seam, so the restart-recovery rewrite path rotates too.restartLaunchAgent, before theisCurrentProcessLaunchdServiceLabelself-handoff branch, so both the directlaunchctl kickstart -kpath and the in-process detached-handoff path rotate. The detached helper itself stays unchanged because the in-process call already rotated before scheduling.Healthy non-oversized paths just
statonce per stream and return. Routing semantics are unchanged: rotation only fires when the file is over the cap.Why this layer
Per AGENTS.md owner boundary: launchd is the daemon owner that wires
StandardErrorPath. Linux/systemd journals through journald (already bounded), and the Windows scheduled-task path doesn't hit this sink, so the fix lives insrc/daemon/launchd.tsrather than a generic core seam.Real behavior proof
Behavior or issue addressed: the launchd-owned gateway stderr sink at
~/.openclaw/logs/gateway.err.loggrows unbounded because nothing rotates it. With this patch,applyGatewayLogRetentionrotates oversize sinks to.1at install, plist rewrite, andgateway restart(both kickstart and self-handoff paths), and launchd recreates a fresh sink on the next start.Real environment tested: my own macOS workstation, profile
default, the liveai.openclaw.gatewayLaunchAgent already installed viaopenclaw gateway install.~/.openclaw/logs/gateway.err.loghad grown to 25 MB during normal use, so I temporarily lowered the cap to 1 MB to exercise the patched helper end-to-end against the live LaunchAgent rather than synthesize a fake oversize log.Exact steps or command run after this patch:
ls -lh ~/.openclaw/logs/gateway.err.log* ~/.openclaw/logs/gateway.log*to record the starting state.applyGatewayLogRetentionfrom this branch via tsx withOPENCLAW_GATEWAY_LOG_MAX_BYTES=1048576andOPENCLAW_GATEWAY_LOG_ARCHIVES=1.ls -lh ~/.openclaw/logs/gateway.err.log* ~/.openclaw/logs/gateway.log*again to confirm the rotation happened.launchctl kickstart -k gui/$UID/ai.openclaw.gatewayto drive the live LaunchAgent through a restart, the same path the reporter uses as their workaround.ls -lh ~/.openclaw/logs/gateway.err.log* ~/.openclaw/logs/gateway.log*once more to confirm launchd recreated the sink and the archive was preserved.Evidence after fix: copied terminal output from the run on my machine.
Before the patched helper ran:
Helper return value:
State right after the helper, before kickstart:
State after
launchctl kickstart -k gui/$UID/ai.openclaw.gateway:Observed result after fix:
.1because it was over the 1 MB cap.launchctl kickstart -k, launchd recreatedgateway.err.logfresh (205 bytes of fresh runtime output) and the archive at.1was preserved with the original 25 MB intact.This matches the design: rotation only fires when the file is over the cap, archive is kept exactly once, and the next restart starts writing into a fresh sink instead of appending to the tens-of-gigabytes file.
What was not tested: I did not live-reproduce the original 18-19 GB CPU/dep-staging loop on current main; that half of the linked report stays open for separate maintainer-led investigation as clawsweeper recommended. I also did not exercise the Windows or Linux daemon paths because launchd is the only daemon owner that wires
StandardErrorPathto a fixed file (Linux journals through journald, Windows uses Scheduled Tasks).Validation
log-retention.test.tscovers: defaults, env parsing, junk-value fallback, cap clamping, missing file, below-cap no-op, oversize rotation, archive cascade witharchives>1,archives=0drop-without-backup,maxBytes=0disabled escape hatch, ENOENT-tolerant pre-existing-archive cleanup, and non-ENOENT stat error propagation.launchd.test.tsadds two new regression tests pinning the call order inrestartLaunchAgent: retention runs beforescheduleDetachedLaunchdRestartHandoffon the self-handoff path, and retention runs beforelaunchctl kickstarton the direct path. The existinglaunchd.test.tssuite (which mocksnode:fs/promiseswithout populating the log paths) keeps passing because retention sees ENOENT and no-ops on those test runs.pnpm format:checkandpnpm exec oxlintare clean on the four touched files.pnpm check:changelog-attributionspasses with the new entry.Scope
What changes:
applyGatewayLogRetentionhelper, hooked into install, plist rewrite, and both restart paths.OPENCLAW_GATEWAY_LOG_MAX_BYTES,OPENCLAW_GATEWAY_LOG_ARCHIVES); no new JSON config knob.Unreleased > Fixes, with non-closingRefs #79422wording.What does not change:
StandardOutPath/StandardErrorPathstill point at the same files).restart-logs.tspath resolution.AI / vibe-coding disclosure
Per
CONTRIBUTING.md's AI-assisted disclosure policy: