Skip to content

Crash: A FileHandle object was closed during garbage collection (Node.js v25) #96585

Closed as not planned

Description

@my-gad

Bug Description

OpenClaw crashes with ERR_INVALID_STATE when an agent processes a message via the Feishu channel. The error occurs because a FileHandle (from fs.promises.open) is garbage collected without being explicitly closed.

Environment

  • OpenClaw: 2026.6.10 (aa69b12)
  • Node.js: v25.9.0 (win32 x64)
  • OS: Windows 11
  • Channel: Feishu (WebSocket mode)

Steps to Reproduce

  1. Configure a workspace that contains a file (e.g., .mp4 video)
  2. Send a message to an agent via Feishu channel that triggers workspace file access
  3. OpenClaw crashes with:
    Reason: A FileHandle object was closed during garbage collection. This used to be allowed with a deprecation warning but is now considered an error. Please close FileHandle objects explicitly.
    File descriptor: 4 (\\?\C:\Users\Administrator\.openclaw\workspace\starcraft-battle-v2.mp4)
    

Error Details

  • Error code: ERR_INVALID_STATE
  • The crash happens during agent message processing, after message.dispatch.started and during embedded_run
  • Process restarts automatically via Scheduled Task, but the crash repeats on every message to the affected agent
  • The affected file is a ~7MB .mp4 file in the workspace directory

Root Cause

Likely in openclaw's workspace/file tool code where fs.promises.open() or similar APIs create FileHandle objects but the corresponding .close() is not called before the handle goes out of scope. Node.js v25 enforces this as a fatal error (previously a deprecation warning in Node.js 18-24).

Workaround

  • Move large files out of the workspace directory
  • Downgrade to Node.js 20 LTS

Additional Info

Stability bundle with full event snapshot available at ~/.openclaw/logs/stability/

Activity

  1. clawsweeper commented on Jun 24, 2026

    @clawsweeper
    Contributor

    ClawSweeper review: did not complete due to Codex infrastructure failure. Reviewed June 28, 2026, 2:37 AM ET / 06:37 UTC.

    Summary
    Codex review failed: timeout (exit 0).

    Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Include the exact command, prompt, or workflow that triggered it.
    • Add expected vs actual behavior.

    Next step
    Review did not complete, so no work-lane recommendation was made.

    Review details

    Best possible solution:

    Retry the Codex review after fixing the execution failure.

    Do we have a high-confidence way to reproduce the issue?

    Unclear. The review failed before ClawSweeper could establish a reproduction path.

    Is this the best way to solve the issue?

    Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

    AGENTS.md: unclear because the file could not be read completely.

    Remaining risk / open question:

    • No close action taken because the review did not complete.

    Codex review notes: model internal, reasoning high; reviewed against 119dc4bd821e.

    Label changes

    Label changes:

    • add issue-rating: 🦪 silver shellfish: Current issue advisory state selects this label.
    • remove P1: Current review triage priority is none.
    • remove clawsweeper:no-new-fix-pr: Current issue advisory state no longer selects this label.
    • remove clawsweeper:needs-maintainer-review: Current issue advisory state no longer selects this label.
    • remove impact:crash-loop: Current review selected no impact labels.
    • remove issue-rating: 🦐 gold shrimp: Current issue advisory state no longer selects this label.
    Evidence reviewed

    What I checked:

    • failure reason: timeout.
    • codex failure detail: Codex review failed for this issue: Codex process timed out after 1199999ms.
    • codex stderr: 2026-06-28T06:19:50.216292Z ERROR codex_core::tools::router: error=write_stdin failed: stdin is closed for this session; rerun exec_command with tty=true to keep stdin open.
    • codex stdout: n code that imports the shared reader.\n- The test verifies the old raw-JSON path failed before the fix and the bounded-reader path cancels streams after the fix.\n- The loopback proof verifies small-response parsing and oversized-response early close through the provider HTTP boundary.\n\n## Competition / linked PR analysis\n\nThis PR is intentionally separate from fix(clickclack): bound REST success JSON response reads #96970: fix(clickclack): bound REST success JSON response reads #96970 covers ClickClack REST success JSON reads, while this PR covers Google Gemini TTS success JSON reads. Related open PR scan found no competing Google Gemini TTS bounded-reader PR.\n","files":[{"path":"extensions/google/speech-provider.test.ts","additions":55,"deletions":0,"changeType":"MODIFIED"},{"path":"extensions/google/speech-provider.ts","additions":6,"deletions":1,"changeType":"MODIFIED"},{"path":"src/plugin-sdk/test-helpers/provider-http-mocks.ts","additions":44,"deletions":0,"changeType":"MODIFIED".
    • process error code: ETIMEDOUT.

    Likely related people:

    • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
    How this review workflow works
    • 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.
  2. added
    P1High-priority user-facing bug, regression, or broken workflow.
    impact:crash-loopCrash, hang, restart loop, or process-level availability failure.
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    and removed
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    on Jun 24, 2026
  3. kzclaw commented on Jun 25, 2026

    @kzclaw

    Additional data point for this issue — same ERR_INVALID_STATE error, different trigger file and platform.

    Environment

    • OpenClaw: 2026.6.10 (aa69b12) same as reporter
    • Node.js: v26.3.0 (macOS 26.6.0, Darwin x64)
    • Platform: macOS, not Windows

    Error details

    • Trigger file: session.jsonl.lock under openclaw-active-memory-* temp directory (not a workspace .mp4)
    • File path: /private/tmp/openclaw/openclaw-active-memory-*/session.jsonl.lock
    • Both occurrences during normal agent run, not Feishu channel

    Occurrences (last 48h)

    • 2026-06-23 19:13 UTC
    • 2026-06-24 20:33 UTC

    Additional context

    • Gateway did NOT restart either time (process continued running)
    • session.jsonl.lock points to active-memory plugin session management
    • Root cause may be a shared fs/promises.open() pattern in multiple places, not just workspace .mp4

    Stability bundles in ~/.openclaw/logs/stability/:

    • openclaw-stability-2026-06-23T19-13-06-015Z-587-uncaught_exception.json
    • openclaw-stability-2026-06-24T20-33-55-647Z-60319-uncaught_exception.json
  4. xialonglee commented on Jun 26, 2026

    @xialonglee
    Contributor

    I did a thorough FileHandle lifecycle audit across both openclaw/fs-safe and openclaw/openclaw to look for potential ERR_INVALID_STATE leaks under Node.js v25+.

    What I checked:

    1. @openclaw/fs-safe (v0.3.0) — Reviewed sidecar-lock.js (releaseHeldLock, releaseAllLocksSync), root-impl.js (OpenResult dispose symbols, openVerifiedLocalFile, openWritableFileInRoot, copyFileFallback, writeFileFallback), and read-opened-file.js. All regular FileHandle paths have explicit finally { handle.close() } guards. The OpenResult uses Symbol.asyncDispose (no sync Symbol.dispose), but that's defensive since no current caller uses using syntax.

    2. openclaw/openclaw — Audited every direct fs.open() / fs.promises.open() / openLocalFileSafely() call site (~37+ across src/ and extensions/), plus every createReadStream / createWriteStream / handle.createReadStream call site (~20+). All of them have correct try { ... } finally { handle.close() } or equivalent stream cleanup (rl.close() + stream.destroy()).

    Result: No smoking gun. Every FileHandle creation point I could find has proper explicit close in finally guards. The two distinct crash signatures from the reports (Feishu workspace .mp4 path vs. active-memory session.jsonl.lock path) suggest the FileHandle owner is somewhere in the fs-safe lock or media-read stacks, but I couldn't isolate a specific leaking path in the current source.

    Possible next steps:

    • Add defensive instrumentation (e.g. a process-level uncaughtException downgrade from crash to warn for ERR_INVALID_STATE until the exact leak is pinned down, since this is a Node.js v25 enforcement change from v20-24's deprecation warning)
    • Wait for a redacted stability bundle or stack trace that pinpoints the exact FileHandle owner — the two reports mention ~/.openclaw/logs/stability/ bundles that would have the full async stack
    • A maintainer with a Windows/Node 25 Feishu setup could attempt to reproduce with --trace-gc or Node.js inspector heap snapshots

    I'll leave this for maintainer follow-up — the audit confirms the fix isn't a trivial missing .close() in a single file.

  5. added
    issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.
    and removed
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    on Jun 26, 2026
  6. openclaw-barnacle commented on Jul 12, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  7. openclaw-barnacle commented on Jul 20, 2026

    @openclaw-barnacle

    Closing due to inactivity.
    If this is still an issue, please retry on the latest OpenClaw release and share updated details.
    If you are absolutely sure it still happens on the latest release, open a new issue with fresh steps to reproduce.

  8. locked as resolved and limited conversation to collaborators on Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority user-facing bug, regression, or broken workflow.clawsweeper:needs-infoClawSweeper needs more reporter information before it can verify this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.issue-rating: 🦐 gold shrimpDecent issue quality, but reproduction details are still incomplete.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions