Repository navigation
perf(logging): flush file transport asynchronously off the request path - #114769
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 7:29 PM ET / 23:29 UTC. ClawSweeper reviewWhat this changesReplaces synchronous JSONL file-log appends with a bounded ordered asynchronous queue, adds shutdown draining, and updates logging tests to wait for queued writes. Merge readiness⛔ Blocked until real behavior proof from a real setup is added - 8 items remain Keep this PR open for maintainer review. The asynchronous transport addresses a credible gateway hot-path stall, but the branch also adds a public plugin-SDK callable for process shutdown and deliberately changes file-log durability under overload and bounded shutdown; those contracts need an owner decision and real after-fix behavior proof before merge. Priority: P2 Review scores
Verification
How this fits togetherGateway request tracing and other runtime paths emit structured logs through the shared logger. This change moves file-backed JSONL writes off those request paths, then coordinates flushing during gateway shutdown so queued records reach the configured log file. flowchart LR
A[Gateway and runtime events] --> B[Shared structured logger]
B --> C[Bounded file-log queue]
C --> D[Ordered async file writer]
D --> E[Rotated JSONL log files]
F[Graceful gateway shutdown] --> G[Flush timeout decision]
G --> C
G --> H[Process exit]
Decision needed
Why: The performance benefit is plausible, but the acceptable durability tradeoff and the permanence of a plugin-visible shutdown control are operational product contracts rather than mechanical implementation details. Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +309, Tests +189, Generated 0, Other +2. Total +500 across 19 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep flushing and timeout coordination in a core-owned lifecycle boundary, make the overload and shutdown-durability policy explicitly approved, then attach redacted live evidence showing ordered output and the graceful/forced shutdown behavior. Do we have a high-confidence way to reproduce the issue? Not applicable as a conventional bug reproduction: this is a performance and lifecycle refactor, and the PR does not attach a current real-world before/after run demonstrating the claimed request-path improvement. Is this the best way to solve the issue? No, not yet. The asynchronous transport is a plausible approach, but publishing its shutdown drain through the plugin SDK is not the narrowest owner boundary and the durability tradeoff needs explicit approval. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 1755087bca79. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
- +1 public export/callable budget with annotation: logger file-transport flush for graceful shutdown drains; regenerate SDK API baseline - three tests that read the log file right after logging now drain the async file transport first (flushLogger) instead of racing the flusher
|
Merged via squash.
|
…th (openclaw#114769) * perf(logging): flush file transport asynchronously off the request path * fix(ci): record flushLogger surface growth and drain before log reads - +1 public export/callable budget with annotation: logger file-transport flush for graceful shutdown drains; regenerate SDK API baseline - three tests that read the log file right after logging now drain the async file transport first (flushLogger) instead of racing the flusher * test: drain async log transport before reading talk and request-trace logs * test: drain async log transport in CLI logger file tests * test: drop unused withTempDirSync import
What Problem This Solves
Every gateway ws response slower than
DEFAULT_WS_SLOW_MS(50ms) emits a[ws] ⇄ reslog line whose file transport doesJSON.stringify+ aredactSensitiveTextregex sweep +fs.statSyncrotation accounting + a blockingappendRegularFileSync— all on the event loop. Under bursts this is a positive feedback loop: each slow response's sync append pushes concurrent responses over 50ms, which then also pay it.Why This Change Was Made
Production perf campaign on team.openclaw.ai: the sync file append is pure event-loop stall on the hottest logging path, amplifying exactly when the gateway is busiest.
User Impact
Log file writes no longer stall request handling. No change to log content, redaction, format, thresholds, or console/TTY transports — only when bytes hit disk:
An earlier iteration used a worker thread; it was deliberately simplified to this in-process flusher — the IPC/lifecycle/build wiring wasn't paying rent.
Evidence
git diff --check; Blacksmith Testboxpnpm format+pnpm tsgo:core(run 30309359392).DEFAULT_WS_SLOW_MSunchanged.