Skip to content

feat(nodes): prefetch worker archives before first session - #182115

Merged
steipete merged 1 commit into
mainfrom
steipete/cs-140425-1023b
Oct 24, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/cs-140425-1023b

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Fixes #140425

What Problem This Solves

The first session on a persistent node after a Gateway update still has to acquire the new worker archive, even when the node has been connected and idle.

User Impact

Capable persistent paired nodes now prefetch and verify the current pinned archive in the background. A session preempts an unfinished prefetch or reuses its completed archive. Failed prefetch and older nodes retain normal session-owned installation. Extraction, worker publication, prewarm, and activation remain owned by the session; this does not eliminate all first-start preparation time. No new configuration option is needed.

Why This Change Was Made

This deliberately revisits the background-installation boundary from #140449 using a negotiated archive-only mode in the existing bundle RPC. Prefetch never extracts or executes worker code, so it cannot publish or prewarm a runtime under a superseded enrollment owner. Downloads and verification are cancellable; foreground installation aborts background work before taking the node's installation queue. Gateway preparation is bounded to one attempt per node, connection, and build, is cancelled on disconnect, enrollment takeover, transport replacement, and shutdown, and warns on failure without a retry loop.

Maintenance pins the current hash before prefetch. The archive occupies the existing hash directory without an installation receipt and follows normal bounded bundle retention; no second cache, state store, dependency, or retention policy is introduced. Each session verifies staged bytes and falls back to acquisition if staging is absent or corrupt. Optional capability negotiation preserves older-node and older-Gateway behavior and excludes disposable cloud hosts.

Evidence

  • Node 24.22.1, frozen dependency installation. 147 distinct focused tests pass across the native installer, bundle protocol, Gateway installer, retention coordinator, connection negotiation, and inventory suites.
  • pnpm test src/gateway/worker-environments/node-workspace-retain-coordinator.test.ts src/gateway/worker-environments/node-worker-bundle-installer.test.ts src/node-host/connection.test.ts src/infra/node-runner-inventory.test.ts --maxWorkers=1: 96 passed, 299.81 seconds wall time including the first compiled worker-cache preparation.
  • Final rerun after mechanical lint corrections: pnpm test src/node-host/node-worker-bundle-installer.test.ts src/worker/node-bundle-install-protocol.test.ts src/gateway/worker-environments/node-workspace-retain-coordinator.test.ts --maxWorkers=1: 90 passed, 21.51 seconds wall time. The earlier native/protocol run also passed all 51 tests in 19.51 seconds.
  • The archive-staging regression fails against the original installer as intended (7.85 seconds wall time), then passes with this change (8.53 seconds). Real HTTP and filesystem fixtures prove one acquisition total across prefetch plus first session, foreground progress while the prefetch response is held, failed/corrupt-prefetch fallback, disconnect cancellation, and normal archive cleanup. Coordinator tests cover warning-only failure, enrollment/shutdown cancellation, old-node fallback, independent maintenance, and current-build pins.
  • Core typecheck, scoped type-aware lint through the repository wrapper, formatting, and git diff --check pass. Independent Codex review found no actionable P0–P2 findings; subsequent changes only correct mechanical lint issues.
  • No current deployment-latency claim: improve: retain current worker builds between sessions #140449's historical 31.97-second cold versus 7.79-second warm activation is not a measurement of this archive-only change. Live Gateway/paired-node upgrade testing was not run; PR CI supplies broader proof.

Stage the pinned worker archive on capable persistent hosts after retention pins it. Foreground installation preempts downloads and owns extraction, publication, prewarm, and activation. Preserve session fallback and old-node behavior.
@clawsweeper

clawsweeper Bot commented Oct 24, 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 24, 2026 02:37
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 24, 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-24T02:40:12.691364Z 1379a96 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 docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: M labels Oct 24, 2026
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 1379a96c4c3f4fc7e77cd4f26e908318ace23b58
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server/ws-connection/connect-hello.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. 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. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Oct 24, 2026
@clawsweeper

clawsweeper Bot commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Prefetch verified worker archives on capable persistent nodes while keeping installation and activation owned by session requests.

Example: A persistent session host remains connected after a Gateway update.

  • Before: Its first session downloads the new worker archive before installation.
  • After: The session reuses a completed background download or preempts unfinished prefetch and installs normally.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation is coherent and focused, but required authority and existing-state upgrade evidence remains incomplete.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Feature · Worth it: Yes · Fix scope: Partial
User problem: A connected idle persistent node still downloads the new worker archive when its first session starts after a Gateway update.
Reason: The feature owner explicitly sponsors archive-only preparation, and the implementation preserves the earlier execution boundary; the broader linked performance request should remain related work rather than be treated as fully resolved.

Merge readiness

⛔ Blocked before merge - 4 items remain

Keep open: this maintainer-authored PR adds a useful optimization absent from main; source review found no concrete introduced defect.

Priority: P2
Reviewed head: 1379a96c4c3f4fc7e77cd4f26e908318ace23b58

Before merge

  • Add real behavior proof - Authority-chain proof required: supplied installer tests exercise real HTTP and disk but bypass the production Gateway grant, while coordinator tests mock prefetch; show allowed transfer and rejection after hosting revocation, enrollment takeover, or connection replacement through the real grant and HTTP owner, with sensitive values redacted. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Resolve security review attention item - No concrete authorization bypass was found, but the new connection-owned transfer lifetime requires final-effect proof.
  • Resolve merge risk - Before merge, the PR owner must establish that the new sessionless transfer grant rejects revoked hosting consent or replaced enrollment ownership before serving archive bytes.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Supply a redacted production-boundary trace of prefetch authorization and revocation, plus a latest-stable paired-host upgrade showing preserved settings, existing bundles, and first-session reuse.
Agent review details

How this fits together

Gateway retention maintenance selects eligible paired hosts and grants archive transfer; the node installer verifies and stores bytes, then a session owns extraction, publication, prewarming, and activation.

flowchart TD
  A[Paired host inventory] --> B[Gateway retention coordinator]
  B --> C[Existing bundle installer RPC]
  C --> D[Authorized HTTP archive transfer]
  D --> E[Verified archive directory]
  F[Session request] --> C
  E --> G[Session owned installation]
  G --> H[Worker activation]
Loading

Technical review

Best possible solution:

Keep archive staging within the existing installer and retention owners, preserving session-owned activation and verified upgrade compatibility.

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

Current-main source confirms that a missing worker build is acquired under the first session request; current deployment latency was not reproduced.

Is this the best way to solve the issue?

Archive-only staging is a focused extension of existing owners and preserves execution custody, but it addresses acquisition rather than the broader preparation and activation delay.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Prove connection-owned transfer revocation (recommended)
    The PR owner should exercise the production prefetch grant and HTTP owner with an allowed host, then revoke hosting or replace its enrollment and demonstrate rejection before further archive delivery.

Provenance checked

  • Reconnect maintenance and current-build retention changes intended behavior with a stated reason (4cf8d68: Retain current builds without a separate background installation lifetime.)
  • Node installation cancellation and publication keeps the original intent (33b5e22: Cancelled installation must not report successful preparation, renew retention, or publish through an unchecked cancellation boundary.)
  • Local prepared archive acquisition keeps the original intent (6f32f8d: Reuse verified immutable archives from prepared snapshots through the existing installer.)
  • Optional node capability negotiation keeps the original intent (f19f62c: Send extended worker preparation forms only to nodes that advertise support.)

Testing

Proof path: in-process harness.

Security

Needs attention: No concrete authorization bypass was found, but the new connection-owned transfer lifetime requires final-effect proof.

Evidence

What I checked:

PR surface

Source +170, Tests +251, Docs +7. Total +428 across 16 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 10 205 35 +170
Tests 5 255 4 +251
Docs 1 14 7 +7
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 16 474 46 +428

Root-cause cluster

Relationship: partial_overlap
Canonical: #140425
Summary: The canonical issue concerns overall first-session preparation; this PR advances archive acquisition while the earlier merged PR supplied retention.

Members:

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

Labels

Label changes:

  • add P2: This improves first-session preparation on persistent nodes while retaining normal foreground fallback.
  • add merge-risk: 🚨 security-boundary: Background preparation creates a transfer capability outside a session request, and its final-effect revocation behavior lacks production-boundary proof.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: This improves first-session preparation on persistent nodes while retaining normal foreground fallback.
  • merge-risk: 🚨 security-boundary: Background preparation creates a transfer capability outside a session request, and its final-effect revocation behavior lacks production-boundary proof.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final-effect proof that revoked hosting consent or reassigned enrollment invalidates the prefetch grant before archive I/O.
  • Show a latest-stable upgrade preserving existing settings and installed bundles while enabling archive prefetch.

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 23, 2026, 10:53 PM ET / October 24, 2026, 02:53 UTC.

@steipete
steipete merged commit 4d0430c into main Oct 24, 2026
233 of 238 checks passed
@steipete
steipete deleted the steipete/cs-140425-1023b branch October 24, 2026 03:09
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
…es (openclaw#182115)

After a Gateway update, the first session on each persistent node paid the full worker-bundle download (about 24 s measured in openclaw#140449). Nodes that negotiate the new capability now receive a low-priority, archive-only prefetch: the node downloads and verifies the pinned bundle archive but never extracts, repairs, publishes or activates it; a session's own install preempts any in-flight prefetch and reuses the verified archive. Prefetch failures are warnings only, old nodes keep the session-owned install, and existing retention handles the archive.

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

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. security-sensitive-changed size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slow first session start on persistent nodes after Gateway updates

1 participant