Skip to content

fix: unhandled rejection crashes process when raw stream write fails - #119400

Merged
vincentkoc merged 3 commits into
openclaw:mainfrom
YangManBOBO:fix/raw-stream-unhandled-rejection-crash
Aug 7, 2026
Merged

vincentkoc merged 3 commits into
openclaw:mainfrom
YangManBOBO:fix/raw-stream-unhandled-rejection-crash

Conversation

@YangManBOBO

@YangManBOBO YangManBOBO commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

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 narrowly
responsible for JSON serialization failures, including cyclic diagnostic
payloads.

The regression tests use the installed @openclaw/fs-safe implementation
instead 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

  • Real process-level before/after proof with OPENCLAW_RAW_STREAM=true and
    OPENCLAW_RAW_STREAM_PATH set to an existing directory, forcing the installed
    @openclaw/fs-safe append to reject:
    • origin/main at db90dff1396fecbf7029e9e9ea19d6c6ca3e644e:
      current-main-exit=1.
    • This PR at d63452035e702c33292b8c37d8c06b058c404c2f:
      printed survived and rebased-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
    • 3 files passed, 79 tests passed.
  • ./node_modules/.bin/oxfmt --check src/agents/embedded-agent-subscribe.raw-stream.ts src/agents/embedded-agent-subscribe.raw-stream.test.ts
    • Passed.
  • git diff --check origin/main...HEAD
    • Passed.
  • Blacksmith Testbox changed gate:
  • Fresh max-P1 autoreview on the exact rebased head: no actionable findings;
    patch 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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Aug 5, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 6, 2026, 10:39 PM ET / August 7, 2026, 02:39 UTC.

ClawSweeper review

What this changes

The 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 provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep 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
Reviewed head: d63452035e702c33292b8c37d8c06b058c404c2f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) This is a focused owner-boundary repair with strong real process proof; the unavailable dependency source is the only material evidence gap.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides exact-head terminal before/after evidence of a real rejected filesystem append and the repaired process surviving; redact any local paths or other private details if that evidence is reposted.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides exact-head terminal before/after evidence of a real rejected filesystem append and the repaired process surviving; redact any local paths or other private details if that evidence is reposted.
Evidence reviewed 7 items Current-main defect: The current raw-stream writer discards the append promise inside a synchronous guard, so a later rejection is not consumed.
Owner-boundary repair: The PR attaches a terminal rejection handler to that exact best-effort append while retaining synchronous JSON serialization containment.
Crash consequence: The process-level unhandled-rejection handler exits for applicable unhandled failures, making an enabled diagnostic append capable of ending an agent run.
Findings None None.
Security None None.

How this fits together

Embedded-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
Loading

Before merge

  • Resolve merge risk (P1) - The pinned @openclaw/fs-safe source and types were unavailable locally and package retrieval failed, so its precise implementation contract could not be independently read; the real-dependency process proof and facade inspection mitigate this residual evidence gap.
  • Complete next step (P2) - The focused contributor PR already owns the repair and has sufficient real behavior proof; no separate automated repair lane is needed.
Agent review details

Security

None.

PR surface

Source +2, Tests +86. Total +88 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 3 1 +2
Tests 1 86 0 +86
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 89 1 +88

Review metrics

Metric Value Why it matters
Production versus test delta production +3/-1; tests +86/-0 The small production increase is the required terminal rejection guard at the diagnostic-write owner boundary; the test growth exercises real append failure and sibling behavior.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Merge the narrow producer-boundary repair so failed opt-in diagnostics remain non-fatal while successful JSONL output and synchronous serialization containment stay unchanged.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦞 diamond lobster.
  • remove rating: 🦞 diamond lobster: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: When raw diagnostics are enabled, a filesystem write failure can currently terminate an otherwise healthy agent process.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit. Replaced prior rating: 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body provides exact-head terminal before/after evidence of a real rejected filesystem append and the repaired process surviving; redact any local paths or other private details if that evidence is reposted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head terminal before/after evidence of a real rejected filesystem append and the repaired process surviving; redact any local paths or other private details if that evidence is reposted.

Evidence

What I checked:

Likely related people:

  • Shakker: Git blame and the introducing commit identify this contributor as the most direct current-main history connection to the raw-stream writer. (role: introduced behavior; confidence: high; commits: e118e607bc68; files: src/agents/embedded-agent-subscribe.raw-stream.ts, src/agents/embedded-agent-subscribe.handlers.messages.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (8 earlier review cycles)
  • reviewed 2026-08-05T02:26:21.738Z sha cd4152e4c3d6b0f990ddab947c49a94a56ef76da :: needs real behavior proof before merge. :: [P2] Retain the synchronous best-effort guard
  • reviewed 2026-08-05T03:20:24.687Z sha cd4152e4c3d6b0f990ddab947c49a94a56ef76da :: needs real behavior proof before merge. :: [P2] Preserve the synchronous best-effort guard
  • reviewed 2026-08-05T04:11:34.538Z sha d1dd4b7aeed50f77e86a8add1819637c2269480c :: needs real behavior proof before merge. :: [P3] Remove the leaked raw-stream test directory
  • reviewed 2026-08-05T04:21:23.646Z sha d1dd4b7aeed50f77e86a8add1819637c2269480c :: needs real behavior proof before merge. :: [P3] Clean up all raw-stream test directories
  • reviewed 2026-08-06T09:46:00.461Z sha d1dd4b7aeed50f77e86a8add1819637c2269480c :: needs real behavior proof before merge. :: [P3] Clean up all raw-stream test directories
  • reviewed 2026-08-06T22:55:03.608Z sha a5f6ff6 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-06T23:39:45.413Z sha a5f6ff6 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-07T02:33:46.738Z sha d634520 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Aug 5, 2026
@YangManBOBO

Copy link
Copy Markdown
Contributor Author

Updated fix pushed — addressing ClawSweeper review feedback:

✅ Preserved sync guard: outer try/catch retained for synchronous failures before Promise is returned
✅ Preserved async guard: .catch() handler catches Promise rejections correctly
✅ New tests (raw-stream.test.ts, 8 tests across 2 files):

  • survives a rejected write without throwing — ENOSPC injection, verifies containment
  • survives a synchronous throw from the dependency — sync throw contained by outer try/catch
  • writes successfully in the normal case — happy path works
  • is a no-op when OPENCLAW_RAW_STREAM is not set — opt-in gate
    ✅ All 152 tests pass (4 test files, 0 failures)

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Aug 6, 2026
@vincentkoc vincentkoc self-assigned this Aug 6, 2026
@vincentkoc
vincentkoc force-pushed the fix/raw-stream-unhandled-rejection-crash branch from d1dd4b7 to a5f6ff6 Compare August 6, 2026 22:05
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. labels Aug 6, 2026
@vincentkoc
vincentkoc force-pushed the fix/raw-stream-unhandled-rejection-crash branch from a5f6ff6 to e12fabf Compare August 7, 2026 00:44
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

YangManBOBO and others added 3 commits August 7, 2026 08:57
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
@vincentkoc
vincentkoc force-pushed the fix/raw-stream-unhandled-rejection-crash branch from e12fabf to d634520 Compare August 7, 2026 01:03
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member

ClawSweeper dependency-contract follow-up:

Conclusion: the dependency-source evidence gap in the exact-head review is resolved. The terminal .catch() observes the dependency contract at the raw-stream producer; no code change is needed.

@vincentkoc
vincentkoc merged commit 38c3ef1 into openclaw:main Aug 7, 2026
538 of 545 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 7, 2026
* 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
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 7, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants