Skip to content

fix(update): retain late imports on Bun - #183429

Merged
steipete merged 3 commits into
mainfrom
steipete/standalone-retained-runtime-hooks
Oct 25, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/standalone-retained-runtime-hooks

Conversation

@steipete

@steipete steipete commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes retained updater imports on Bun after an installation is replaced, and removes a Node-only named import that prevented experimental AOT binaries from linking.

User Impact

An updater running on Node or the pinned Bun runtime keeps using its original generation through cleanup, including CommonJS dependencies, JSON, and already-loaded module state. Imports outside that generation keep using the active installation. Standalone installations retain their existing immutable update path.

Why This Change Was Made

The retained-import owner now uses each runtime's supported hooks: Node's module hooks and Bun's public plugin resolver/loader. CommonJS and ESM keep their respective package export conditions. Both share the retained-file inventory and preserve original module identities while resolving against retained files. CommonJS uses native loading, and the existing package-format helper moves to the shared infra owner. Node's CommonJS resolution also explicitly uses the retained parent because changing a hook context's parent URL does not update its captured resolver.

Evidence

  • The real retained-update process flow passes on Node and pinned Bun, covering replacement, ESM/CommonJS/JSON, loaded singleton identity, absolute and query imports, conditional package exports, external tooling, and teardown. The final run took 15.07 seconds including cold pinned-runtime staging (a warm run before the conditional-export addition took 3.95 seconds); CI timing is pending.
  • Follow-up CI required an explicit invariant comment for the Bun global type assertion. The invariant is now documented, and the assertion-safety ratchet passes; executable code is unchanged.
  • Initial PR CI caught a missing trusted-wrapper inventory entry for the moved helper. The inventory is corrected; both failing extraction tests pass locally (12.95 seconds).
  • Retained-runtime and native-module sibling tests pass: 47 tests total. Scoped source/test typechecks, lint, formatting, and diff checks pass.
  • The actual owner graph compiles and runs as emitted-JS and original-TypeScript hardened AOT with the experimental compiler. The pre-fix named node:module.registerHooks import could not link.
  • Additional native Node proof confirms retained JSON require/import behavior without a transpiler; actual Bun controls cover native addons and CommonJS TypeScript.

Experimental compiler-runtime limitation: its ordinary Bun runtime currently skips public onResolve callbacks for bare package imports. A standalone 24-line reproducer fails on that compiler and passes on the pinned production Bun. Therefore the full mutable-update flow is qualified on Node and pinned Bun, while experimental AOT proof here covers linking and startup. Immutable standalone artifact behavior is validated separately.

Inherited CI failure on final head: run 40176730508 failed UI shard 5/7 only in cloud-workers-settings.e2e.test.ts, reconnect profile deletion, where the row remained after one patch request. The inspected CI merge has byte-identical UI/config/Gateway-client source, dependency manifests, and test launchers to its main parent. This PR does not execute its retained-import path in that mocked browser flow. The focused replay passes (1.958 seconds test time, 33.97 seconds including the UI build); that replay does not establish a repair. The timing cause remains unresolved and the failed result is retained for native inherited-failure admission. Security and required reviews remain enforced.

Keep runtime import retention on the supported Node and Bun hook APIs so the updater survives installation replacement and experimental AOT can link. Preserve CommonJS conditional exports and loaded state while sharing the existing package-format owner.
@clawsweeper

clawsweeper Bot commented Oct 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.

@steipete
steipete marked this pull request as ready for review October 25, 2026 08:09
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: M labels Oct 25, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-25T08:12:57.244199Z 757d853 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Oct 25, 2026
@steipete
steipete enabled auto-merge (squash) October 25, 2026 08:20
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@steipete
steipete disabled auto-merge October 25, 2026 08:27
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 25, 2026
@clawsweeper

clawsweeper Bot commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR adds Bun-compatible retained imports and corrects CommonJS resolution so an updater can finish after its installation is replaced.

Example: A Bun updater imports dist/late-old-hash.mjs after activation replaces dist.

  • Before: The Node-only retention path cannot reliably serve the removed module on Bun.
  • After: Bun loads the retained bytes under the original module identity, including during cleanup.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, coherent repair with meaningful production-owner fixture coverage and no definite finding; evidence remains below shipped-entry-point verification.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body reports real Node and pinned-Bun process fixtures plus AOT linking/startup, but provides no live shipped-update trace, and earlier linked Node verification does not establish the new Bun behavior.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An updater can lose access to its original modules after installation replacement, preventing completion or cleanup on Bun.
Reason: The maintainer-authored direction restores the documented update contract without adding configuration, dependencies, or a competing retention subsystem.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: it addresses a remaining runtime gap on current main, and inspection found no definite introduced defect.

Priority: P2
Reviewed head: 812148f41a60f4bac65762c186c80e0b750d8824

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied evidence does not show a shipped Bun update from the latest stable release or a base-failing run of the newly added regression cases.
Agent review details

How this fits together

The update runtime owner snapshots the running installation before replacement; runtime-specific module hooks then serve late imports from that snapshot while preserving original URLs and loaded state.

flowchart TD
  A[Update command] --> B[Retained runtime owner]
  B --> C[Retained file inventory]
  C --> D[Node module hooks]
  C --> E[Bun plugin hooks]
  D --> F[Original updater and cleanup]
  E --> F
Loading

Technical review

Best possible solution:

Keep runtime-specific loading within the existing retention owner while sharing its inventory, module identities, and package-format classification.

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

Current main unconditionally uses Node hooks, while the existing plugin loader explicitly routes Bun away from those hooks; the reported failure is source-supported, but no target code was executed during this read-only review.

Is this the best way to solve the issue?

The patch repairs the existing owner, preserves its cleanup lifetime, and shares the unchanged package-format helper; the runtime adapters and added fixture cases serve distinct loading contracts.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 192947deb5f3.

Provenance checked

  • Parent-process retained imports and cleanup lifetime keeps the original intent (714e589: Keep lazy imports working after build replacement while preserving original URLs and singleton identity through process exit.)
  • Shared package-format classification keeps the original intent (2400454: The earlier plugin reload repair placed native package classification in a focused owner; this PR relocates that implementation unchanged for reuse.)
  • Process regression coverage keeps the original intent (719b2cf: Consolidate redundant test setup while retaining platform, lifecycle, and failure-path coverage.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 714e589 adds src/infra/update-retained-runtime-imports.ts:8 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 714e58997d94; files: src/infra/update-retained-runtime-imports.ts)
  • Ayaan Zaidi: Raw commit a81bb54 adds src/plugins/plugin-instance-module-loader.ts:63 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: a81bb54f094f; files: src/plugins/plugin-instance-module-loader.ts)

PR surface

Source +153, Tests +57, Docs +4, Other +1. Total +215 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 184 31 +153
Tests 1 98 41 +57
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 0 +1
Total 7 287 72 +215

Labels

Label changes:

  • add P2: This is a scoped update-runtime compatibility repair without evidence of an ongoing widespread outage or blocked first-use flow.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a scoped update-runtime compatibility repair without evidence of an ongoing widespread outage or blocked first-use flow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 25, 2026, 4:44 AM ET / 08:44 UTC.

@steipete
steipete merged commit a355200 into main Oct 25, 2026
154 of 159 checks passed
@steipete
steipete deleted the steipete/standalone-retained-runtime-hooks branch October 25, 2026 09:13
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 26, 2026
* fix(update): retain late imports on Bun

Keep runtime import retention on the supported Node and Bun hook APIs so the updater survives installation replacement and experimental AOT can link. Preserve CommonJS conditional exports and loaded state while sharing the existing package-format owner.

* fix(tooling): include shared module format in PR wrapper

* docs(update): explain the Bun runtime type invariant
RomneyDa added a commit that referenced this pull request Oct 28, 2026
* fix(update): retain late imports on Bun

Keep runtime import retention on the supported Node and Bun hook APIs so the updater survives installation replacement and experimental AOT can link. Preserve CommonJS conditional exports and loaded state while sharing the existing package-format owner.

* fix(tooling): include shared module format in PR wrapper

* docs(update): explain the Bun runtime type invariant

(cherry picked from commit a355200)

Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: M 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.

1 participant