Repository navigation
fix: unhandled rejection crashes process when raw stream write fails - #119400
vincentkoc merged 3 commits into
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 6, 2026, 10:39 PM ET / August 7, 2026, 02:39 UTC. ClawSweeper reviewWhat this changesThe PR makes opt-in raw diagnostic JSONL writes ignore rejected filesystem appends and adds regression coverage for failure, success, disabled, and cyclic-payload cases. Regression provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep this PR open for normal maintainer merge review: current main still drops a rejected diagnostic-write promise, while the exact-head patch repairs that owner boundary with no actionable finding. Priority: P1 Review scores
Verification
How this fits togetherEmbedded-agent message handling optionally emits raw diagnostic JSONL records during agent runs. Those records pass through a filesystem append helper, but diagnostic failure must not affect the agent process. flowchart LR
A[Embedded agent messages] --> B[Raw diagnostics enabled]
B --> C[Serialize JSONL record]
C --> D[Filesystem append]
D --> E[Append succeeds]
D --> F[Append rejects]
F --> G[Ignore diagnostic failure]
E --> H[Agent run continues]
G --> H
Before merge
Agent review detailsSecurityNone. PR surfaceSource +2, Tests +86. Total +88 across 2 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Merge the narrow producer-boundary repair so failed opt-in diagnostics remain non-fatal while successful JSONL output and synchronous serialization containment stay unchanged. Do we have a high-confidence way to reproduce the issue? Yes. The PR supplies an exact-head process reproduction using an existing directory as the raw-stream target, and current source shows why its rejected append escapes the synchronous guard. Is this the best way to solve the issue? Yes. Attaching a rejection handler where the fire-and-forget append is produced is the narrowest maintainable fix; moving containment to callers would leave the shared producer boundary unsafe. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 21e9634f1084. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (8 earlier review cycles)
|
|
Updated fix pushed — addressing ClawSweeper review feedback: ✅ Preserved sync guard: outer
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
d1dd4b7 to
a5f6ff6
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
a5f6ff6 to
e12fabf
Compare
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
The try/catch wrapper around void appendRegularFile() could not catch async rejections because the void operator evaluates the Promise to undefined synchronously. If appendRegularFile rejected (disk full, permission denied, symlink parent rejected), the unhandled rejection handler classified it as FATAL and exited the process with code 1. Replace the broken try/catch with a proper .catch() handler that correctly ignores raw stream write failures as originally intended. Co-Authored-By: Claude <[email protected]>
ClawSweeper review feedback: the outer try/catch guards against synchronous failures before the promise is returned, while the .catch() handler catches async rejections. Both layers are necessary for defense-in-depth. Add fault-injection test coverage verifying: - Async rejection (ENOSPC) is contained without process crash - Synchronous throw from the dependency is caught - Normal write path works correctly - Disabled stream is a no-op Co-Authored-By: Claude <[email protected]>
Punchcard-Session: brisk-cedar-brook-w3
e12fabf to
d634520
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
ClawSweeper dependency-contract follow-up:
Conclusion: the dependency-source evidence gap in the exact-head review is resolved. The terminal |
|
Merged via squash.
|
* origin/main: refactor(test): compress repetitive fixtures in mega-tests, batch 2 (openclaw#120124) refactor(ui): adopt shared chat-host fixture across chat suites (openclaw#120120) fix(ci): provision native Android resources for frozen current-contract targets (openclaw#120081) fix: preserve agent delivery identity (openclaw#120108) fix(qqbot): add cause-specific setup guidance (openclaw#119780) fix(venice): replay Gemini tool signatures by turn occurrence (openclaw#119783) fix(gateway): yield before TTS status diagnostics (openclaw#119788) fix: gateway restart fails and leaves the macOS LaunchAgent unloaded when the gateway drains active work (openclaw#116875) fix(clickclack): show native agent progress while replying (openclaw#116683) fix: unhandled rejection crashes process when raw stream write fails (openclaw#119400) fix: prevent duplicate outbound delivery during concurrent recovery (openclaw#119966) # Conflicts: # src/agents/embedded-agent-runner/run.incomplete-turn.test.ts
…penclaw#119400) * fix: prevent unhandled rejection crash when raw stream write fails The try/catch wrapper around void appendRegularFile() could not catch async rejections because the void operator evaluates the Promise to undefined synchronously. If appendRegularFile rejected (disk full, permission denied, symlink parent rejected), the unhandled rejection handler classified it as FATAL and exited the process with code 1. Replace the broken try/catch with a proper .catch() handler that correctly ignores raw stream write failures as originally intended. Co-Authored-By: Claude <[email protected]> * fix: preserve sync guard alongside async rejection handler ClawSweeper review feedback: the outer try/catch guards against synchronous failures before the promise is returned, while the .catch() handler catches async rejections. Both layers are necessary for defense-in-depth. Add fault-injection test coverage verifying: - Async rejection (ENOSPC) is contained without process crash - Synchronous throw from the dependency is caught - Normal write path works correctly - Disabled stream is a no-op Co-Authored-By: Claude <[email protected]> * fix(agents): prove raw stream rejection containment Punchcard-Session: brisk-cedar-brook-w3 --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Vincent Koc <[email protected]>
What Problem This Solves
Fixes an issue where enabling the raw diagnostic stream could terminate the
gateway when its best-effort filesystem append was rejected. A directory
target, disk failure, permission error, or rejected symlink parent could escape
as an unhandled promise rejection instead of only dropping the diagnostic
record.
Why This Change Was Made
The raw-stream producer now attaches a terminal rejection handler to the exact
appendRegularFile()promise. The existing synchronous guard remains narrowlyresponsible for JSON serialization failures, including cyclic diagnostic
payloads.
The regression tests use the installed
@openclaw/fs-safeimplementationinstead of mocking the append boundary. They cover a real rejected
directory-target append, exact JSONL output, disabled behavior, synchronous
cyclic-payload containment, and shared temporary-directory cleanup.
User Impact
Operators can keep raw diagnostics enabled without a failed diagnostic write
terminating an otherwise healthy agent run. Successful records retain the same
JSONL format, and the feature remains opt-in.
Evidence
OPENCLAW_RAW_STREAM=trueandOPENCLAW_RAW_STREAM_PATHset to an existing directory, forcing the installed@openclaw/fs-safeappend to reject:origin/mainatdb90dff1396fecbf7029e9e9ea19d6c6ca3e644e:current-main-exit=1.d63452035e702c33292b8c37d8c06b058c404c2f:printed
survivedandrebased-head-exit=0.node scripts/run-vitest.mjs src/agents/embedded-agent-subscribe.raw-stream.test.ts src/agents/embedded-agent-subscribe.block-reply-rejections.test.ts src/agents/embedded-agent-subscribe.handlers.messages.test.ts./node_modules/.bin/oxfmt --check src/agents/embedded-agent-subscribe.raw-stream.ts src/agents/embedded-agent-subscribe.raw-stream.test.tsgit diff --check origin/main...HEADnode scripts/check-changed.mjs -- src/agents/embedded-agent-subscribe.raw-stream.ts src/agents/embedded-agent-subscribe.raw-stream.test.tstbx_01kzcfb71fymv38890e7xetaj6patch correct with 0.98 confidence.
AI-assisted: the contributor used Claude Code; maintainer validation and the
final test rewrite were independently reviewed with Codex.
Punchcard-Session: brisk-cedar-brook-w3