Skip to content

fix: plugin capture fails on Bun/macOS for valid dependencies over 128 KiB - #159403

Merged
steipete merged 4 commits into
openclaw:mainfrom
sunlit-deng:sunlit/fix/issue-159313
Sep 30, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
sunlit-deng:sunlit/fix/issue-159313

Conversation

@sunlit-deng

@sunlit-deng sunlit-deng commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes plugin source capture failures with valid dependencies larger than 128 KiB on Bun for macOS.

Fixes #159313

Why This Change Was Made

On Darwin, Bun can return EBADF while copying a valid open source descriptor through /dev/fd. The fix sends only Darwin+Bun EBADF through the existing bounded copyFileDescriptorSync helper, preserving the admitted file identity and leaving other platforms and errors unchanged.

User Impact

The reported plugin-load failure no longer stops at capture when Bun/macOS hits this descriptor-copy error.

Evidence

  • Real production module boundary: capturePluginGenerationArtifact on the same generated package and Darwin arm64 /dev/fd path. Before fix, Bun 1.4.2 on base 247258e returned EBADF for 172832 bytes; after fix, tested HEAD SHA d44153d33b504358820297279e3a51b253dfad7b copied exact bytes.
  • Negative control: the 131072-byte Bun input copied exact bytes before and after. Node 24.18 copied both sizes on base and HEAD.
  • Test cost: pnpm test src/plugins/plugin-generation-artifact.streaming.test.ts --maxWorkers=1 passed (8 tests, 19.9s local wall, pinned pnpm 12.4.2). The generation-capture regression injects Bun/macOS EBADF and checks exact copied bytes and source currentness; Node/macOS EBADF, Bun/Linux EBADF, and Bun/macOS EIO remain errors.
  • Local validation: changed-file formatting/lint, core and affected test types, and pnpm deadcode:full passed. The broader test:changed selector expanded to the unit-fast project and hit the 10-minute local runner limit; no assertion failure was reported before termination.
  • Hosted CI run 36300053139: the plugin contract shard passed in 110s. One changed-core shard failed an unrelated SQLite cleanup-race assertion after 477s (2404 passed); that file passed locally on this head (18/18, 22.55s). GitHub denied rerunning the failed job because repository admin rights are required.
$ bun proof-live.mjs (base)
Bun 1.4.2 / darwin arm64: 172832 bytes -> EBADF; 131072-byte control -> captured exactly
$ bun proof-live.mjs (HEAD d44153d33b50)
Bun 1.4.2 / darwin arm64: 172832 bytes -> captured exactly; 131072-byte control -> captured exactly
$ node --import ./scripts/tsx.mjs proof-live.mjs (base and HEAD)
Node 24.18.0 / darwin arm64: both sizes captured exactly on both revisions
Testing: proof-live.mjs
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { pathToFileURL } from "node:url";

const { capturePluginGenerationArtifact } = await import(
  pathToFileURL(path.join(process.cwd(), "src/plugins/plugin-generation-artifact.ts")).href
);

function makeSource(size) {
  const header = "export type LargeDependency = { value: string };\nexport const value = \"ok\";\n//";
  if (Buffer.byteLength(header) + 1 > size) {
    throw new Error("fixture size is smaller than its TypeScript header");
  }
  return header + "x".repeat(size - Buffer.byteLength(header) - 1) + "\n";
}

function errorCode(error) {
  for (let current = error; current && typeof current === "object"; current = current.cause) {
    if (typeof current.code === "string") return current.code;
  }
  return null;
}

function capture(size) {
  const tempRoot = fs.mkdtempSync(path.join(os.tmpdir(), "openclaw-plugin-capture-proof-"));
  const source = path.join(tempRoot, "plugin");
  const dependency = path.join(source, "node_modules", "fixture");
  fs.mkdirSync(dependency, { recursive: true });
  fs.writeFileSync(
    path.join(source, "package.json"),
    JSON.stringify({ name: "capture-proof", dependencies: { fixture: "1.0.0" } }),
  );
  const entry = path.join(source, "index.ts");
  fs.writeFileSync(entry, "export { value } from \"fixture\";\n");
  fs.writeFileSync(
    path.join(dependency, "package.json"),
    JSON.stringify({ name: "fixture", main: "body.ts" }),
  );
  const body = path.join(dependency, "body.ts");
  const expected = Buffer.from(makeSource(size));
  fs.writeFileSync(body, expected);

  let artifact;
  try {
    artifact = capturePluginGenerationArtifact(source, entry);
    const alias = artifact.sourceAliases[dependency] ?? artifact.sourceAliases[fs.realpathSync(dependency)];
    if (!alias) throw new Error("captured dependency alias missing");
    const captured = fs.readFileSync(path.join(alias, "body.ts"));
    if (!captured.equals(expected)) throw new Error("captured dependency bytes differ");
    artifact.assertSourceCurrent();
    return { size, status: "captured", copiedBytes: captured.byteLength, exactBytes: true, sourceCurrent: true };
  } catch (error) {
    return { size, status: "error", code: errorCode(error), name: error?.name ?? "Error" };
  } finally {
    artifact?.dispose();
    fs.rmSync(tempRoot, { recursive: true, force: true });
  }
}

const result = {
  runtime: process.versions.bun ? "Bun " + process.versions.bun : "Node " + process.versions.node,
  platform: process.platform,
  arch: process.arch,
  large: capture(172832),
  boundaryControl: capture(131072),
};
console.log(JSON.stringify(result));
if (result.large.status !== "captured" || result.boundaryControl.status !== "captured") {
  process.exitCode = 1;
}

AI-assisted: built with Codex

@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@clawsweeper

clawsweeper Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 29, 2026, 10:31 PM ET / September 30, 2026, 02:31 UTC (Revision 6).

ClawSweeper review

What this changes

The branch lets plugin generation capture fall back to a bounded descriptor copy when Bun on macOS returns EBADF, and tests that other runtime and error combinations still fail.

Merge readiness

✅ Ready for maintainer review

Keep this PR open. Current main still propagates the reported Bun/macOS descriptor-copy error, while the branch has focused regression coverage and credible before-and-after production-boundary proof. The latest merge commit does not change the reviewed implementation.

Priority: P1
Reviewed head: 8c89ad3b99335ae674bc42d9668feb17d532f298

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The focused patch has direct before-and-after capture proof and regression controls, with no actionable defect found.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body records a Bun 1.4.2/macOS arm64 before-and-after run through plugin generation capture: the large dependency changes from EBADF to an exact-byte capture, while the boundary and Node controls still pass. Later commits change tests or merge main without changing this production fix. No stored-data contract changes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body records a Bun 1.4.2/macOS arm64 before-and-after run through plugin generation capture: the large dependency changes from EBADF to an exact-byte capture, while the boundary and Node controls still pass. Later commits change tests or merge main without changing this production fix. No stored-data contract changes.
Evidence reviewed 7 items Introduced production change: The pinned merge-base-to-head diff adds only the Darwin+Bun EBADF case to the existing fallback decision; other errors retain their prior path.
Current main still needs the fix: The fetched main source still excludes EBADF from descriptor-copy fallback.
Production capture path: Generation file capture calls the changed source-copy owner; plugin instance loading calls generation capture. The copy owner imports the fs-safe descriptor-transfer helper and bounds its fallback by the opened descriptor's size.
Findings None None.
Security None None.

How this fits together

OpenClaw copies admitted plugin source files and dependencies into a private generation before loading them. The source-copy path reads an open file descriptor and supplies captured bytes for verification and plugin execution.

flowchart LR
  A[Plugin source and dependencies] --> B[Admit source file]
  B --> C[Copy through descriptor path]
  C --> D{Copy outcome}
  D -->|Bun macOS EBADF| E[Bounded descriptor copy]
  D -->|Success or other error| F[Captured bytes or error]
  E --> F
  F --> G[Verify and load plugin]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +11, Tests +86. Total +97 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 12 1 +11
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 98 1 +97

Review metrics

Metric Value Why it matters
Runtime controls 1 fallback case, 3 error controls The capture tests cover the intended recovery and preserve failure behavior for neighboring cases.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #159313
Summary: The PR explicitly targets the open report's Bun/macOS plugin-capture failure.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Retain the narrow fallback in the plugin source-copy owner and its capture-boundary controls, then land through the normal exact-head gates.

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

Yes. The linked report and PR body give a concrete Bun/macOS capture reproduction, and current main retains the rejecting path; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. The patch uses the existing bounded copy from the admitted descriptor and limits the new fallback to the demonstrated runtime and error.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8ddafc60fc43.

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The reported Bun/macOS failure blocks a configured plugin from loading.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body records a Bun 1.4.2/macOS arm64 before-and-after run through plugin generation capture: the large dependency changes from EBADF to an exact-byte capture, while the boundary and Node controls still pass. Later commits change tests or merge main without changing this production fix. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body records a Bun 1.4.2/macOS arm64 before-and-after run through plugin generation capture: the large dependency changes from EBADF to an exact-byte capture, while the boundary and Node controls still pass. Later commits change tests or merge main without changing this production fix. No stored-data contract changes.

Evidence

What I checked:

  • Introduced production change: The pinned merge-base-to-head diff adds only the Darwin+Bun EBADF case to the existing fallback decision; other errors retain their prior path. (src/plugins/plugin-source-file.ts:21, 8c89ad3b9933)
  • Current main still needs the fix: The fetched main source still excludes EBADF from descriptor-copy fallback. (src/plugins/plugin-source-file.ts:74, 8ddafc60fc43)
  • Production capture path: Generation file capture calls the changed source-copy owner; plugin instance loading calls generation capture. The copy owner imports the fs-safe descriptor-transfer helper and bounds its fallback by the opened descriptor's size. (src/plugins/plugin-generation-file-capture.ts:148, 8c89ad3b9933)
  • Capture regression coverage: The added tests check exact captured bytes and source currentness after injected Bun/macOS EBADF, plus three neighboring error and runtime controls. (src/plugins/plugin-generation-artifact.streaming.test.ts:178, 8c89ad3b9933)
  • Contributor real-path proof: The captured PR body reports Bun 1.4.2 on macOS arm64 failing at 172832 bytes before the fix and capturing exact bytes afterward through capturePluginGenerationArtifact, with a 131072-byte control and Node controls. That run names the earlier tested head d44153d; the current head has no later production-code change. (d44153d33b50)
  • Feature-area history: Recent merged history on the source-copy path includes plugin capture and rollback-tree work by Peter Steinberger. This supports reviewer routing, not attribution of the reported failure. (src/plugins/plugin-source-file.ts, 605cc417c0c7)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RichSomeday222: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (5 earlier review cycles)
  • reviewed 2026-09-27T04:14:02.984Z sha d44153d :: needs changes before merge. :: [P2] Exercise the EBADF fallback through plugin capture
  • reviewed 2026-09-27T05:03:11.671Z sha e322f23 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-27T06:31:54.891Z sha 339cb79 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-27T06:54:45.496Z sha 339cb79 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-28T00:10:14.623Z sha 339cb79 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Sep 27, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@steipete

Copy link
Copy Markdown
Contributor

Bounded reproduction at 8c89ad3b99335ae674bc42d9668feb17d532f298 for CI run 36659826265.

The four CI failures were:

  • UI: the 390 px dark-viewport question test timed out clicking Collapse question (30 s).
  • Plugin install: the real npm-pack successor test timed out (120 s).
  • Gateway reload: the rejected-successor monitor-write test reported database is locked.
  • Gateway reload: deferred restart SecretRef revalidation with held promotion: false timed out (120 s).

Each failing case passed twice locally on macOS, Node 26.10.0, at the exact head. Runs were sequential with --maxWorkers=1 and test-name filters; UI used the documented vitest.ui-e2e.config.ts runner with --configLoader runner. Existing assertions and timeouts were unchanged.

File / selected cases Command walls, runs 1 / 2 1-minute host load, start → end
server-reload-handlers.test.ts — both cases 447.74 s / 176.86 s 56.6 → 74.4 / 74.4 → 42.1
install.npm-spec.e2e.test.ts — npm-pack successor 1533.14 s / 72.49 s 42.1 → 21.8 / 21.8 → 28.8
chat-async-questions.e2e.test.ts — 390 px dark viewport 21.07 s / 14.74 s 28.8 → 26.4 / 26.4 → 24.1

Walls include cold runtime-build/compiler-cache preparation, especially the first Gateway and npm runs. These local passes do not establish a fix for the CI failures. The added production fallback is gated on Darwin + Bun + EBADF; Linux/Node production execution does not enter that added branch. Per maintainer direction, rerunning only this run's failed jobs once.

@steipete
steipete merged commit b7303b1 into openclaw:main Sep 30, 2026
418 of 422 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 30, 2026
…8 KiB (openclaw#159403)

* fix: fall back for Bun Darwin descriptor EBADF

* test: cover Bun macOS plugin capture fallback

* test: cover descriptor fallback through capture
steipete added a commit to openclaw/bun that referenced this pull request Sep 30, 2026
On macOS, `fs.copyFile` and `fs.cp` fail with `EBADF` for regular-file `/dev/fd` sources above 128 KiB. Bun switches to `clonefile` and then Darwin’s pathname-based `copyfile` above that threshold. The latter compares pathname `stat.st_dev` with opened-descriptor `fstat.st_dev`; devfs descriptor paths have a synthetic device ID, so the identity check rejects a valid descriptor.

After an unsuccessful clone, use the bounded copy loop for devfs path sources. Node path copies use positional reads from byte zero without advancing the original descriptor. The shared sequential reader remains available to `Bun.write`, including its non-seekable-input fallback. Ordinary clone fast paths and forced-clone failures are preserved. The source remains pinned through `/dev/fd`; the fix does not reopen its original filesystem pathname.

Related: openclaw/openclaw#159313 and its application workaround openclaw/openclaw#159403.

Qualified head: `11fbdbb8dd344463605ec6019b8b975cfa335794`, macOS release build, WebKit `f20ce7744553c910bcf16a33faf976af208de091`.

- All 50 descriptor-path regression/control cases passed, covering threshold sizes, aliases, sync/callback/promise APIs, overwrite/truncation, exclusivity, forced cloning, contents, and offsets.
- The added `Bun.write` fault-injection regression passed. It forces recoverable `fcopyfile` failure and verifies exact bytes from non-seekable stdin; this caught an overly broad positional-read change in the first draft, which is corrected by the separate readers.
- `test/js/node/fs/fs.test.ts`: 660 passed, 16 skipped, 0 failed.
- `test/js/node/fs/cp.test.ts`: 54 passed, 6 skipped, 0 failed.
- Both full filesystem suites used `--max-concurrency 2`; assertions, timeouts, and internal stress loops were unchanged. An earlier run encountered a recursive-readdir timeout and subsequent FD-count failures.
- Broader `test/js/bun/io/bun-write.test.js` on the corrected pre-integration head `4cec09fc2d`: 79 passed, 4 skipped, 1 timeout. The unchanged “writes as the body arrives, and a collected Response does not stop it” case also times out in the identical full suite on a separately built pre-change fork binary at `3fc6250eff3a284fa5b1aa7246e16e367795d3e4`. Both binaries can pass the case alone; this baseline-sensitive failure is not presented as a clean broader-suite result.
- Codex review found no actionable P0–P2 findings. Formatting, `git diff --check`, and all applicable hosted checks passed.

Stock Bun 1.4.2 reproduces the 131072/131073-byte boundary and the 172832-byte report. Node 26.10.0 passes all 15 standalone threshold/API/offset controls. Native probes confirm devfs for direct and symlink descriptor paths, `EINVAL` from `clonefile`, and the pathname/descriptor identity mismatch behind `copyfile`’s `EBADF`.

The qualified head includes the landed patch-errno, injected-connection, and runtime-plugin-cache fixes. The only merge conflict was in the changelog, where both entries were retained. The integrated release build, both full filesystem suites, and the pipe-fallback regression passed again.
yozakura-ava pushed a commit to yozakura-ava/openclaw that referenced this pull request Oct 6, 2026
…8 KiB (openclaw#159403)

* fix: fall back for Bun Darwin descriptor EBADF

* test: cover Bun macOS plugin capture fallback

* test: cover descriptor fallback through capture

(cherry picked from commit b7303b1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

[Bug]: Bun/macOS plugin capture fails with EBADF for valid /dev/fd copies over 128 KiB

2 participants