Skip to content

fix(updater): identify the config-read child by env, not by import query - #158447

Closed
carlosjarenom wants to merge 1 commit into
openclaw:mainfrom
carlosjarenom:fix/issue-158339-bun-config-read-guard
Closed

carlosjarenom wants to merge 1 commit into
openclaw:mainfrom
carlosjarenom:fix/issue-158339-bun-config-read-guard

Conversation

@carlosjarenom

@carlosjarenom carlosjarenom commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

fix(updater): identify the config-read child by env, not by import query

Refs #158339

What Problem This Solves

A managed update started from a Bun Gateway spawns an unbounded chain of
config-read subprocesses. One report measured 8,462 descendants before the
300s verification budget expired. The update stalls, and the previous Gateway
gets stopped during activation, so the box needs manual service recovery.

Root cause

scripts/lib/update-config-runtime-compat.mts generates an io.runtime alias
that is both the reader spawner and the reader's own entry point. It
told those two roles apart by reading a query parameter off its own
import.meta.url:

readerEntry.searchParams.set("openclaw-config-read", "1");
const updating = … && new URL(import.meta.url).searchParams.get("openclaw-config-read") !== "1";

Node preserves that query across a dynamic import(). Bun 1.4.2 does not.
So under Bun the child re-evaluated the guard as the driver, fell into the
reader branch again, and forked the next child — which did the same. The chain
is self-sustaining, and only the outer verification budget ever stops it.

The fix

The parent already builds the child's environment in exactly one place
(childEnv, shared by spawnSync and spawn), so it now marks the child
there, and the guard reads that marker:

const updating = process.env.OPENCLAW_UPDATE_IN_PROGRESS === "1" && process.env.OPENCLAW_CONFIG_READ_CHILD !== "1";
…
return { ...selected, NODE_DISABLE_COMPILE_CACHE: "1", OPENCLAW_CONFIG_READ_CHILD: "1" };

With the query no longer able to identify the reader, the searchParams.set
that fed it is removed rather than left as dead code.

Why env and not a better query. The marker is written and read inside the
same generated alias, so this introduces no cross-version coupling — an alias
written by an older driver still works, and OPENCLAW_UPDATE_IN_PROGRESS keeps
its existing role. No new cross-version marker is required on either side.

Regression test

test/scripts/update-config-runtime-compat.test.ts drives the real alias
through buildUpdateConfigRuntimeAlias, then reproduces the runtime difference
by stripping the query at resolve time with module.registerHooks — the same
divergence Bun exhibits. That is the whole point of the test: it fails for the
reason the product fails, not because a mock was misconfigured.

The chain is bounded by a file-backed depth cap rather than a timer, so a
regressed alias fails fast instead of forking an unbounded chain on a shared
host.

The test is discriminante — verified in both directions:

state children reads result
production file reverted, Bun emulation 6 (cap hit) 0 candidate-config-read-failed
with fix, Bun emulation 1 1 pass
control: real Node, with and without fix 1 1 pass

The control case passes in both states, which is what rules out the harness
producing a false positive.

Measured test wall time

446 ms of test time across 3 tests, ~3 s total wall. Baseline before
this change was 1 test / 295 ms. No real timers, sleeps, or polling are used.

Evidence - validation gates

  • 21 check:changed lanes green, including tsgo:scripts
  • Targeted test run, both directions, as tabulated above

Not run, stated plainly: tsgo:test:root was not executed. It is the one
lane I could not complete, and I am not going to imply otherwise. The change is
confined to a generated string in scripts/ plus a test file, and the light
lanes covering scripts/ did pass.

What I did not verify

I have not run a real Bun Gateway update end to end, so I am not claiming
live-channel or real-device proof for this one. The test reproduces the
mechanism (query dropped across a dynamic import) directly rather than assuming
it, but a maintainer with a Bun host is in a much better position to confirm
the 8,462-descendant case is actually gone. I would rather flag that than
overstate it.

🤖 Generated with openclaw

The generated io.runtime alias is both the reader spawner and its own entry,
and told them apart by reading `openclaw-config-read` off its own
import.meta.url. Node keeps that query across a dynamic import; Bun 1.4.2
drops it, so the child re-evaluated the update guard as the driver, re-entered
the reader branch and forked the next child. One managed update from a Bun
Gateway produced 8,462 descendants before the 300s verification budget
expired, the update stalled, and the previous Gateway was stopped during
activation with manual service recovery needed.

The parent now marks the child in the env it already hands to the spawn, and
the guard reads that marker. The marker is set and read within the same
generated alias, so it introduces no cross-version coupling: an alias written
by an older driver still works, and OPENCLAW_UPDATE_IN_PROGRESS keeps its
existing role. The query can no longer be what identifies the reader, so the
searchParams write that fed it is gone.

The regression drives the real alias through buildUpdateConfigRuntimeAlias and
drops the query at resolve time with module.registerHooks, reproducing the
runtime difference Bun exhibits. A file-backed depth cap fails a regressed
alias instead of forking an unbounded chain on a shared host. Without the fix
it reports children=6 reads=0 candidate-config-read-failed; with it, exactly
one reader subprocess.

Refs openclaw#158339
@clawsweeper

clawsweeper Bot commented Sep 25, 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.

@openclaw-barnacle openclaw-barnacle Bot added scripts Repository scripts size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Sep 25, 2026
@clawsweeper clawsweeper Bot added P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 25, 2026
@clawsweeper

clawsweeper Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

The requested Bun config-reader guard is already on current main through the merged, same-repository fix at #158451. That fix also handles Bun's synchronous result transport, and it shipped in v2026.9.7. This branch has no remaining distinct production behavior to land.

I found the merged PR that appears to have closed this: #158451: fix(update): guard config-read children without import.meta.url queries and transport results without fd 3.

Root-cause cluster
Relationship: superseded
Canonical: #158451
Summary: A merged PR in the same repository owns the reported Bun config-reader failure.

Members:

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

So I’m closing this as already implemented rather than keeping a duplicate issue open.

Review details

Best possible solution:

Retain the shipped guard and Bun result-transport repair, and close this competing branch.

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

No failing current-main path remains: the merged guard and regression test cover the reported query-dropping mechanism. The related issue records the original Bun failure; this read-only review did not execute an update.

Is this the best way to solve the issue?

Yes. The merged fix keeps the child marker at the generated alias boundary, blocks nested launches, and repairs Bun's synchronous result transport.

Security review:

Security review cleared: The introduced patch changes an internal child marker and test harness without adding dependencies, secrets access, or a new authority path.

AGENTS.md: found and applied where relevant.

What I checked:

Likely related people:

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

Codex review notes: model internal, reasoning medium; reviewed against db4b605b18bb; fix evidence: merged PR #158451, release v2026.9.7, commit 5836021e126c.

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 26, 2026

@wjc2821296948 wjc2821296948 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

代码审查

// Bun 1.4.2 drops the query of a dynamically imported module, so the reader is identified by an env
// marker its parent sets. A query-derived marker re-evaluates this guard as the driver and forks
// another reader, which is the unbounded chain behind #158339.
const updating = process.env.OPENCLAW_UPDATE_IN_PROGRESS === "1" && process.env.OPENCLAW_CONFIG_READ_CHILD !== "1";

This comment was marked as spam.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 26, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 28, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 30, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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 status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 30, 2026
@carlosjarenom

Copy link
Copy Markdown
Contributor Author

Cerrando como superseded.

El fix de este PR quedó cubierto por el PR #158451 (fix(update): guard config-read children without import.meta.url queries and transport results without fd 3), MERGED el 2026-09-26 y publicado en v2026.9.7. Además, ese PR también cubre el transporte de resultados síncronos de Bun, que esta rama no abordaba.

El issue #158339 está CLOSED/COMPLETED, así que no queda trabajo vivo asociado a esta rama.

Cerrado sin más cambios: el diff no aporta comportamiento de producción distinto al que ya está en main.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts 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