Repository navigation
fix(logging): keep file logging from blocking Gateway requests - #197586
Conversation
Move complete file preparation, rotation and append units into one lazy worker while preserving FIFO, graceful drain, best-effort failures and explicit forced-exit rescue. Default existing tslog source-map probing off without overriding an explicit diagnostic policy; retain raw callsites. Observed steady-state synchronous calls fall from 69 to zero per 23 settled batches, and from 381 to zero with rotation. Preserve independent A/A CPU, allocation and cold-worker cost evidence. Repair the affected cross-agent UI fixture by selecting All agents through its public picker; exact parent reproduces the missing-scope failure and all four cases pass after correction.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Integrate main at 3b13df5 and preserve both exact standalone entries in the Knip conflict. Logger runtime, regression, UI fixture, docs, benchmark and build registration bytes remain identical to the reviewed candidate; worker lifecycle context is unchanged. Independent Codex review and targeted formatting/diff validation passed.
|
Codex review: needs maintainer review before merge. What this changesThis PR moves ordinary file-log filesystem work into a lazy worker and disables implicit source-map probes while preserving diagnostic opt-in. Example: The reported macOS Node 26 workload writes 23 settled logging batches with rotation.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR addresses a current Gateway stall path and retains meaningful unique work; no definite correctness or security regression was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherGateway log records enter the existing bounded FIFO transport, which dispatches filesystem operations to one worker and produces rotated JSONL files or best-effort warnings. flowchart LR
A[Gateway logging] --> B[JSONL serialization]
B --> C[Bounded FIFO transport]
C --> D[Lazy logging worker]
D --> E[Guarded filesystem operations]
E --> F[Log files and archives]
C --> G[Forced exit rescue]
G --> E
Technical reviewBest possible solution: Retain the existing FIFO transport and guarded filesystem contract while using the shared worker infrastructure for ordinary logging I/O. Do we have a high-confidence way to reproduce the issue? Current-main logging and pinned fs-safe source establish synchronous filesystem work on the Gateway thread; the author reports baseline failures and after-fix counters, but this read-only review ran no target code. Is this the best way to solve the issue? The change fixes the owning filesystem boundary without duplicating admission policy or adding caches; its worker entry modules serve distinct build and deployment boundaries. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 4eb318d5eea7. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +173, Tests +193, Docs +9, Other +141. Total +516 across 19 files. Added test files: 2. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed November 12, 2026, 4:16 AM ET / 09:16 UTC (Revision 4). |
Count callable Sync exports while excluding unavailable lchmodSync on Linux. Preserve native realpath instrumentation, descriptor restoration and counter-free timing/allocation windows. Actual-main-thread regression passes on Linux Node26 and macOS; no production or workload change.
|
Addressed both items from the review of 0e20bf7:
The four UI E2E cases are compatibility proof only because their fixture silences file logging. Actual logging is covered by the main-thread process regression, the extracted portable artifact regression, and the retained local Gateway measurement. The exact main parent's 27-line test-ratchet regression is documented separately; this PR funds its full 193-line test delta. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
The final CI repair removes one unnecessary native PR-wrapper inventory entry in 0186f3a. Both reported wrapper import-closure failures reproduce before the removal and pass after it; fresh independent Codex review is clean. Portable deploy bootstraps are not imports of the native PR wrapper, so the corrected wrapper inventory retains the ordinary logger worker without pulling in the sealed deployment graph. The two prior review items remain resolved on this head:
The body includes the corrected proof and the separately attributed main test-line regression. @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
The current-main conflict is resolved in ebad47c. Native admission stopped before sending a merge request when main added another worker at the same build-entry list position. The prior numbered items remain resolved:
Final head @clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Merged via squash.
|
…law#197586) * fix(logging): isolate runtime file work from Gateway requests Move complete file preparation, rotation and append units into one lazy worker while preserving FIFO, graceful drain, best-effort failures and explicit forced-exit rescue. Default existing tslog source-map probing off without overriding an explicit diagnostic policy; retain raw callsites. Observed steady-state synchronous calls fall from 69 to zero per 23 settled batches, and from 381 to zero with rotation. Preserve independent A/A CPU, allocation and cold-worker cost evidence. Repair the affected cross-agent UI fixture by selecting All agents through its public picker; exact parent reproduces the missing-scope failure and all four cases pass after correction. * test(logging): preserve filesystem counters on Linux Count callable Sync exports while excluding unavailable lchmodSync on Linux. Preserve native realpath instrumentation, descriptor restoration and counter-free timing/allocation windows. Actual-main-thread regression passes on Linux Node26 and macOS; no production or workload change. * fix(logging): include file worker in portable archives * fix(logging): keep portable bootstrap out of PR wrapper * chore(logging): remove obsolete test allocation
Worker threads already perform file logging directly. Route them to the loaded filesystem owner before importing the main-thread writer pool. An in-place update can replace the old hashed chunk before a worker isolate first flushes during SIGTERM, putting final log writes at risk. Keep one lazy main-thread writer as in #197586, and inject the owning transport flush to remove the reverse import. Relocated package: existing filter caught the post-SIGTERM logger-worker chunk on 9e93dae and returned no matches on the fix (1,085 probe entries; positive control passed). The fixed CLI exited zero and persisted the final shutdown log record. Runtime build, tarball validation, bootstrap import budgets, both cycle checks, focused logger tests and the isolated real-Node logger fixture passed. Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes: a stalled filesystem lookup during Gateway logging can block its main thread, delaying requests and liveness checks.
User Impact
File logging now performs preparation, admission, rotation and append in one lazy worker. FIFO ordering, graceful drain and best-effort errors remain; forced process-exit rescue retains its explicit synchronous contract.
Default logging also stops tslog's automatic synchronous source-map probes. Raw callsite metadata remains, and the dependency's existing
TSLOG_SOURCE_MAPSoverride still enables diagnostic mapping. This adds no OpenClaw configuration option.Why This Change Was Made
The existing asynchronous append helper still used synchronous lstat/fstat admission. Moving the entire filesystem operation to the existing worker infrastructure preserves its security checks and rotation ordering without adding metadata caches or replacing the dependency's admission policy. Existing worker threads write directly, avoiding recursive logger workers. A deployed worker process still has a main thread and uses the same lazy logger worker; its sealed deployment, runtime mapping and archive inventory now include that entry.
The tradeoff is one lazy worker: cold synthetic measurements added a median 49.3 MiB of process RSS. First settled log latency under a busy host was 996 ms median (176–1837 ms); this measures isolated logger construction and its first write, not whole Gateway boot. Warm total CPU increased about 5 ms per observed 23-batch minute. Production core grows by 173 lines because no complete filesystem owner previously existed.
Evidence
On macOS Node 26.12.1, the same warmed, steady-state 23-settled-batch workload reproduces 69 main-thread synchronous Node fs API calls for normal logging and 381 with rotation; both become zero. These are API counters, not kernel syscall counts. Cold module-loader calls are excluded from this count claim. Separate A/A controls, five interleaved timing and allocation windows, and five independent worker cold starts are retained. Exactly one worker serves repeated targets; allocation measurements cover the main isolate only. Host load and A/A wall differences preclude a wall-speed claim.
The actual default-environment Node main-thread regression fails on the parent and passes with the fix. It checks rotation, persisted tail, raw callsites, explicit diagnostic opt-in, first-target failure/recovery, lifecycle drain and existing-worker recursion. Existing logger consumers, browser-import tests, type/lint/format/runtime guards, unused-file checks and the full private-QA runtime build pass. Codex independent review found no actionable P0–P2 issues.
The affected real-Gateway Control UI file passes all four compatibility cases (its fixture silences file logging; it is not the logging I/O proof). Its two cross-agent cases also failed on the exact parent: the test expected both agents while leaving the page scoped to the default agent. The fixture now selects All agents through the public picker and preserves every owner/reset assertion. The missing precondition originated in #128803 (source-history attribution); the parent failures remain recorded.
The actual-main-thread regression also passes on Linux Node 26.12.1. Its counter and the maintained benchmark exclude unavailable non-callable exports such as Linux
lchmodSync, while preserving all callable-method and native-realpath instrumentation. The macOS timing/allocation evidence is unchanged: only count windows install wrappers.The extracted portable archive regression failed before the packaging correction: flush settled after an append warning, but the expected log file was missing. The repaired archive persists the record through the same worker owner and sealed filesystem bootstrap. The added test/support proof is exactly 193 net lines: 147 initial proof lines, three for Linux callable-export filtering, and 43 for the portable regression plus its required bundle fixture.
Portable validation passes 104 tooling assertions, 22 bundle-owner tests and two browser-import tests. One native-mode fixture initially refused the external scratch volume’s unsafe ancestor permissions; its isolated replay passes using the normal private test temp directory, with no safety-policy change. Core/tooling types, lint and format pass. An earlier local test-line ratchet reproduced the exact main parent’s 27-line overage (introduced by #197543, commit 3b13df5). That historical failure remains recorded. After the required current-main conflict integration, the supported ratchet passes with 193 net added lines under main’s fixed 400-line per-PR allowance and zero allocation credit. This PR’s obsolete allocation was removed; no allowance was added to absorb the earlier main regression.
CI also caught an overbroad native PR-wrapper inventory entry: portable deployment bootstraps are not native wrapper imports. Removing that one entry keeps the sealed deployment/archive registrations intact and restores both wrapper import-closure checks (red before removal, green after). No product source or test behavior changed.
Native merge admission found a later conflict when another worker was added at the same private build-entry list position. The integration preserves both
secretFileReadandfileLog; logger runtime, portable bootstrap/archive and UI fixture bytes remain unchanged. Both workers’ build graphs, shared-chunk exclusion and package inventory pass (four focused cases), and fresh Codex review is clean. The prior native attempt aborted before dispatch; the integrated head requires fresh CI and final-head review.The final bookkeeping-only commit removes the obsolete allocation after main introduced its fixed per-PR test budget. The narrow budget check passes with 193 added lines and zero credit; independent Codex review is clean. Runtime and test source remain unchanged.