Repository navigation
fix(nodes): give node sessions the same prompt and bootstrap context as local sessions - #164647
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed October 4, 2026, 3:24 AM ET / 07:24 UTC (Revision 6). ClawSweeper reviewWhat this changesNode-hosted sessions reuse Gateway-selected instructions, bootstrap files, and conversation context while adding node execution facts and preserving runtime context through transcript replay. Merge readiness⛔ Blocked before merge - 1 item remains The fix remains necessary on current main. The previous replay findings are resolved, and source inspection supports the final compatibility assessment; no additional blocking defect was found. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway prepares an agent's instructions, tools, and conversation history before dispatching execution to a node. The node runs the turn and returns transcript and workspace results for Gateway-owned settlement. flowchart TD
A[Session and agent configuration] --> B[Gateway prompt preparation]
C[Bootstrap files and conversation history] --> B
B --> D[Prepared worker launch]
D --> E[Node execution facts and tools]
E --> F[Provider request]
F --> G[Transcript and workspace results]
G --> H[Gateway context settlement]
Before merge
Agent review detailsSecurityNone. PR surfacePR surface statistics unavailable: the file list is incomplete. Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one Gateway-owned prompt preparation path for both placements, with executor-specific facts added on the node and byte-preserving transcript replay. Do we have a high-confidence way to reproduce the issue? Yes: current-main source shows the reduced node prompt path, and the recorded baseline provider capture demonstrates missing bootstrap markers and Memory Recall guidance; this review did not execute it. Is this the best way to solve the issue? Yes: reusing the existing Gateway preparation owners removes the competing node renderer while preserving public SDK contracts and executor-specific facts. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 61ef2a47fdc5. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
…as local sessions Node turns used a generic coding prompt and incomplete workspace bootstrap. Prepare their context through the existing Gateway prompt and bootstrap owners, preserve typed runtime context in the transcript, and complete execution-host facts on the node. Keep prepared prompts authoritative when tools change. Retire internal session defaults made redundant by prepared inputs while preserving the documented session-extension SDK and native loader. Context selection and settlement remain Gateway-owned, after workspace reconciliation. Provider schema normalization is excluded. The SDK regression fails on the original prompt owner. Validated 899 tests across 52 whole files and siblings after fixture repairs; production and scoped test types, lint, export guards, documentation links, and P0-P2 Codex review pass. Production delta versus the prerequisite refactor: +147 lines. Committed with --no-verify because this sparse checkout has no dependencies; pnpm exec oxfmt --check passed on the validation lease. Full build and AWS live capture/performance proof must complete before publication.
77d5e11 to
5c6bd12
Compare
Preserve supported historical runtime-context metadata and content, and reserve both current-turn message slots before windowing anchored replay. Regressions fail on the prior head and pass after this repair. Keep the shared turn-begin operation outside the lease/attempt import cycle and prune its obsolete assertion-baseline entry. Update prompt fixtures for prepared skills, timestamped model projections, and active executable tool handles. Whole replay, context-owner, and affected fixture suites pass, along with core and scoped test types, import-cycle and assertion guards, and P0-P2 Codex review. The complete PR remains +149 production lines against the landed prerequisite. Committed with --no-verify because this sparse checkout has no dependencies; pnpm exec oxfmt --check passed for the changed files on the AWS validation lease.
|
Maintainer compatibility assessment for There is no database DDL, session-version bump, or existing-row rewrite. The repaired tests preserve source-only and marker-only runtime carriers, string/text-block contents, committed/reopened context, and subsequent-turn replay. All four new replay regressions fail on the prior head and pass after repair; the final capture again proves local/node prompt parity. The PR body records the complete compatibility, CI-repair, and final-head live evidence. |
|
Merged via squash.
|
…as local sessions (openclaw#164647) * fix(nodes): give node sessions the same prompt and bootstrap context as local sessions Node turns used a generic coding prompt and incomplete workspace bootstrap. Prepare their context through the existing Gateway prompt and bootstrap owners, preserve typed runtime context in the transcript, and complete execution-host facts on the node. Keep prepared prompts authoritative when tools change. Retire internal session defaults made redundant by prepared inputs while preserving the documented session-extension SDK and native loader. Context selection and settlement remain Gateway-owned, after workspace reconciliation. Provider schema normalization is excluded. The SDK regression fails on the original prompt owner. Validated 899 tests across 52 whole files and siblings after fixture repairs; production and scoped test types, lint, export guards, documentation links, and P0-P2 Codex review pass. Production delta versus the prerequisite refactor: +147 lines. Committed with --no-verify because this sparse checkout has no dependencies; pnpm exec oxfmt --check passed on the validation lease. Full build and AWS live capture/performance proof must complete before publication. * fix(nodes): preserve replay carriers and complete prompt budgets Preserve supported historical runtime-context metadata and content, and reserve both current-turn message slots before windowing anchored replay. Regressions fail on the prior head and pass after this repair. Keep the shared turn-begin operation outside the lease/attempt import cycle and prune its obsolete assertion-baseline entry. Update prompt fixtures for prepared skills, timestamped model projections, and active executable tool handles. Whole replay, context-owner, and affected fixture suites pass, along with core and scoped test types, import-cycle and assertion guards, and P0-P2 Codex review. The complete PR remains +149 production lines against the landed prerequisite. Committed with --no-verify because this sparse checkout has no dependencies; pnpm exec oxfmt --check passed for the changed files on the AWS validation lease.
Prerequisite #164768 is merged as
6a3f4a2bd2612a216cbdd26cc222adab17b32c65. Final candidate:3ba415841b1a12e8390fd5c9d7ecc9b839ff7b55. Scope and LOC figures compare this head directly with the landed prerequisite.What Problem This Solves
Fixes missing agent instructions, persona, memory guidance, and conversation context when an OpenClaw session runs on a node instead of the Gateway.
User Impact
Node sessions receive the same selected prompt and bootstrap context as Gateway-local sessions, with workspace paths, host, OS, shell, and process facts describing the node. Prepared instructions remain authoritative when tools change, and runtime-context entries survive transcript commit and replay.
Same-lease live captures at final head
3ba415841b1aconfirm identical direct-tool definitions, canonical bootstrap and memory guidance, and sender/time envelopes, with remaining differences describing location, session, and project facts. Provider tool-schema normalization is outside this change; the known Tool Search schema difference remains a separate follow-up.Why This Change Was Made
The worker assembled a generic coding prompt around a smaller bootstrap instead of using the Gateway's prompt preparation. Node turns now call the existing bootstrap, system-prompt, prompt-hook, and context-engine owners. The node completes execution-host facts and materialized skill paths without rebuilding the selected instructions.
Context selection and settlement remain Gateway-owned. Post-turn context work runs after workspace reconciliation, while the placement claim still holds authority. Model preparation supplies the credential-dependent transcript policy used by prompt preparation. Internal session factories consume prepared resources and tool definitions, removing the redundant default prompt, resource discovery, and fallback tool construction. The documented session-extension SDK and native/Jiti loader remain supported.
Compatibility assessment for the final head: no user configuration key, schema, or configured default changes.
src/agents/config.tsonly makes the now-private directory helper parameterless after its removed internal factory caller; the installation-directory resolution owner is unchanged. Internal session construction now requires already-prepared inputs. The documentedsrc/plugin-sdk/agent-sessions.tsbarrel, extension SDK, and native loader remain supported. No database DDL, session-version bump, or existing-row rewrite is introduced. Historical source-only/marker-only carriers and string/text-block content are covered by exact replay preservation, transcript reopen, subsequent-turn, and legacy owner-mismatch regressions. Existing worker build/provisioning ownership is unchanged.This is a correctness fix with an approved +152 production-line ceiling. The current diff is +1,728 / -1,579 = +149, counted independently after the prerequisite; none of its deletions are borrowed. There are 117 total paths, 61 production/counting paths, 34 substantive production paths, and 27 mechanical/deletion/bookkeeping paths. This includes the new sibling containing the moved context-engine begin operation. The detailed growth and deletion ledgers are below.
Evidence
node scripts/run-vitest.mjs <whole files> --maxWorkers=1; this remains prior-head evidence.5c6bd12abefore repair. After repair, 68 tests across three whole files passed in 176.38 seconds. The replay repair also passed its types, lint, formatting, and scoped review.3ba415841b1a: all 24 turns completed with exact pong responses. The final candidate's local/node tool arrays matched byte-for-byte, both included all five selected bootstrap markers and Memory Recall, and each session retained identical system/tool/cache-key bytes across six turns.openclaw/ci-gatepass. Native landing completed: reviewed head3ba415841b1amerged as06d4475d6079aaa875a9b477ac0935d1459b1023; main ancestry was verified. The initial CI failures and verified repairs are recorded below; no green final-head CI result is claimed.Regression boundaries, fixture repairs, and measured test cost
The primary prepared-prompt regression is
src/agents/sessions/sdk.test.ts, “preserves an exact base system prompt when active tools change.” On the prerequisite it fails with the old “expert coding assistant” prompt instead of the supplied “personal assistant running inside OpenClaw” prompt.src/gateway/worker-environments/worker-turn-execution.test.tschecks canonical agent instructions, persona and user context, selected execution-project instructions, node workspace paths, and current sender context at the actual launch boundary. It also verifies that unselected execution-workspace persona files remain excluded.src/worker/worker.runtime.test.tsincludes the prompt suite that checks exact prepared prompt bytes and two-turn runtime-context persistence/replay.worker-turn-context-engine.test.tsverifies both direct and outer-owned settlement, including reconciled workspace contents and live claim authority during post-turn work.Two custom-provider Ultra fixtures initially failed before their intended capacity-error boundary because the new model preparation performs auth resolution earlier. The fixtures now supply synthetic provider credentials; the approval owner remains exercised. The repaired whole worker execution file passes all 26 cases.
The retained legacy-store/Doctor owner-mismatch regression initially omitted the original ownership-inspection precondition before its filesystem snapshot. That made SQLite's first inspection create WAL/SHM files only in the later snapshot. Restoring the inspection before the baseline snapshot preserves the original migration invariant; the final whole auth-migration file passes all 17 cases. No snapshot exclusions or weakened migration assertions were added.
The changed settings mock now explains its isolation, and its obsolete mock-baseline entry was pruned. An unused test import and a shadowed fixture variable were corrected. The unused internal
LoadExtensionsResultre-export was removed; the virtual SDK still exports the public type directly from its owner.Recorded wall time: the initial multi-suite batch took 604.50 seconds and exposed the two custom-provider fixture failures; the repair/remainder batch took 606.76 seconds; the final whole auth-migration file took 46.11 seconds including runner preparation. These are separate invocations with overlap, not an additive CI estimate. The worker execution file reported 126.20 seconds of Vitest duration on its successful whole-file run. The transport and context-engine suites use existing fixtures because the contracts cross launch, transcript persistence, workspace publication, and authority settlement; pure renderer tests cannot prove those boundaries.
Pre-repair AWS whole-file timings via
pnpm test <file> --maxWorkers=1: resource-loader 36.60 s (5 tests), skill resources 13.09 s (20 tests), SDK 25.35 s (33 tests), worker execution 128.94 s (26 tests), worker context engine 62.16 s (2 tests), and worker runtime 66.50 s (84 tests). All 170 cases passed. These reran the changed rebase inputs and recorded separate primary-boundary costs; they do not cover the later repairs. Final-head CI passes: 51 successful Node jobs total 9,727 job-seconds, including setup; this is aggregate selected-lane cost, not incremental per-test cost.The initial CI run exposed five failing jobs:
agent-session-extensions.tsentry after duplicate tool construction was removed. The exact stale entry is now pruned; the ratchet passes.context-engine-logical-turn.tsandcontext-engine-turn-attempt.ts. The unchanged ordered begin operation now lives incontext-engine-turn-begin.ts; callers import it there. This moves existing behavior without adding another policy owner. Madge reports zero cycles, with 75 context-owner cases passing across three whole files in 42.46 seconds.structuredClone(context). Correctly activated custom tools now carryexecutefunctions, causing a verifiedDataCloneErrorbefore the fixture recorded a request. The three capture sites now clone messages and retain tool handles shallowly. All 16 cases pass in 16.23 seconds; no production workaround was added.Review also found two replay defects. Historical runtime carriers identified by source-only or marker-only metadata, with either string or text-block content, must retain their provider-visible bytes. Replay admission must also reserve the complete current-turn message budget, including the runtime-context carrier. Both are repaired at the worker message/window owners. Four regressions failed on
5c6bd12a; the repaired transcript-message, worker-turn-payload, and worker-turn-execution whole files pass 68 tests in 176.38 seconds. The final whole payload file additionally passes all 25 cases in 52.84 s viapnpm test <file> --maxWorkers=1; its transport-boundary image/replay cases account for the cost. Typed lint passes on all nine remaining repair files. These repair batches overlap earlier proof and must not be summed into a new distinct-test total.Final-head live provider capture and performance proof
All results below use the final repaired head
3ba415841b1a12e8390fd5c9d7ecc9b839ff7b55.Captured exact OpenAI request bodies on one AWS lease at baseline
6a3f4a2bd261and candidate3ba415841b1a, with the same agent configuration and six local plus six node turns per head. The baseline/final runtime builds took 53.2/53.6 seconds. Lab-only capture was restored out of source after each build; candidate source SHA-256 stayedc71ba4c5146d4975d60b15a97a6b3823a610c9f9c60e4fd9c2c1ba22729e3bb8. All 24 turns completed with exact expected pong outputs.The controlled tool configuration uses
tools.codeMode.enabled=false,tools.toolSearch=false, and a read/write/edit/memory allowlist. The admitted surface also includesapply_patchandskills_read, for seven function tools. This exercises the shared prompt owner without importing the excluded Tool Search schema-normalization change.Both
3ba415841b1atool arrays have normalized JSON SHA-25626bbd96af432548b71c0354c8e7673f8f83f34039b6186562949f9909b42b109. Both prompts contain identical syntheticParity fixture: <filename> canonical agent context.markers for AGENTS.md, SOUL.md, IDENTITY.md, USER.md, and MEMORY.md. TOOLS.md and HEARTBEAT.md are excluded by the existing canonical bootstrap policy; they are not node omissions.The baseline generic coding prompt bypassed
worker-turn-prompt's now-shared owners: it lost canonical style/execution/control guidance, bootstrap persona/user/memory, memory-recall instructions, runtime/time/channel context, and the sender envelope. The remaining3ba415841b1asystem diff contains only these classes:bashversus nodesh; the runtime-line field order changes accordingly.After those location/session/project fields, the system diff is empty. All six
3ba415841b1auser messages match after normalizing their actual UTC turn timestamps; the synthetic sender envelope and user text are identical. Full-system/tool/cache-key stability is checked across all six turns; independent session keys intentionally yield separate cache keys. Transcript persistence/replay is additionally covered by the two-turn worker boundary regression.Warm medians exclude turn zero (five observations per placement). Prompt tokens include input plus cache reads and writes; cached tokens are cache reads.
Node warm TTFT increases 108 ms in this sample; tail increases 40 ms. No tail-speed improvement is claimed. The restored node context reuses a 5,710-token cached prefix on every warm turn. Baseline node token totals are confounded by its extra native web-search tool, so this fresh capture proves missing context rather than reproducing the historical half-token ratio.
This live lane covers direct WebChat, UTC, Linux execution facts, selected canonical bootstrap, catalog presence, and prompt cache reuse. It does not claim group-channel, non-UTC, cross-OS, actual skill-read or memory-retrieval proof. Those behavior families remain outside this live lane.
Per-file positive production growth justification
All deltas use the campaign classifier against the prerequisite head. Added sibling modules include code moved from existing owners; the paired reductions explain that accounting.
packages/agent-core/src/harness/messages.tspackages/gateway-protocol/src/schema/worker-admission.tspackages/gateway-protocol/src/schema/worker-inference.tspackages/gateway-protocol/src/schema/worker-protocol-primitives.tspackages/gateway-protocol/src/worker-transcript-budget.tssrc/agents/embedded-agent-runner/run-entry.tssrc/agents/embedded-agent-runner/run/attempt-bootstrap-prepare.tssrc/agents/embedded-agent-runner/run/attempt-prompt-build.tssrc/agents/embedded-agent-runner/run/attempt-system-prompt-prepare.tssrc/agents/embedded-agent-runner/run/context-engine-admission.tssrc/agents/embedded-agent-runner/run/run-settlement.tssrc/agents/embedded-agent-runner/run/runtime-context-prompt.tssrc/agents/harness/context-engine-lifecycle.tssrc/agents/harness/context-engine-turn-begin.tscontext-engine-logical-turn.ts. No new policy is introduced.src/agents/runtime-execution-facts.tsruntime-facts-prompt.ts.src/agents/runtime-prompt.tssrc/agents/sessions/system-prompt-metadata.tssrc/agents/system-prompt-report.tssrc/agents/system-prompt-runtime.tssystem-prompt.ts.src/gateway/worker-environments/inference-model.tsinference-runtime.ts. No tool-schema normalization is added.src/gateway/worker-environments/transcript-commit.kernel.tssrc/gateway/worker-environments/worker-gateway-tool-contract.tssrc/gateway/worker-environments/worker-gateway-tool-runtime.tssrc/gateway/worker-environments/worker-turn-payload.tssrc/gateway/worker-environments/worker-turn-prompt.tssrc/skills/runtime/resources.tssrc/worker/embedded-agent-transcript.runtime.tssrc/worker/embedded-agent.runtime.tssrc/worker/launch-descriptor.tssrc/worker/replay-message-window.tssrc/worker/transcript-message.tsThe main reductions are the prepared-only session factory (-141), generic session renderer (-138), duplicate tool construction (-99), session prompt/default state (-77), resource-loader defaults and duplicate settings reload (-66), local history assembly (-57), Runtime renderer move (-41), local finalization (-33), prompt-transform plumbing (-24), context-engine begin extraction from the logical-turn module (-24), node bootstrap assembly (-18), attempt session setup (-14), and compaction setup (-11). These removals are all within the affected prompt/session/worker owners.
Mechanical migration, deletion, and retained-contract ledger
These 27 paths are outside the 34 substantive production paths. They remain included in the production LOC total.
config/assertion-safety-baseline.txtconfig/test-mock-exports-baseline.txtsrc/agents/cli-runner/prepare.tssrc/agents/config.tssrc/agents/embedded-agent-runner/run-entry.tssrc/agents/embedded-agent-runner/run-orchestrator.tssrc/agents/embedded-agent-runner/run/attempt-bootstrap-prepare.tssrc/agents/embedded-agent-runner/run/attempt-history-prepare.tssrc/agents/embedded-agent-runner/run/attempt-system-prompt.tssrc/agents/embedded-agent-runner/run/run-settlement.tssrc/agents/embedded-agent-runner/run/runtime-context-prompt.tssrc/agents/harness/context-engine-logical-turn.tssrc/agents/harness/context-engine-turn-begin.tssrc/agents/harness/selection.tssrc/agents/package-metadata.tssrc/agents/runtime-execution-facts.tssrc/agents/sessions/agent-session.tssrc/agents/sessions/extensions/index.tsLoadExtensionsResultre-export; the public virtual SDK retains the type through its owner.src/agents/sessions/extensions/runner.tssrc/agents/sessions/extensions/types.tssrc/agents/sessions/system-prompt-metadata.tssrc/agents/sessions/system-prompt.tssrc/agents/system-prompt-report.tssrc/agents/system-prompt.tssrc/gateway/worker-environments/worker-turn-rpc.tssrc/gateway/worker-environments/worker-turn-user-message.tssrc/worker/embedded-agent-transcript.runtime.tsThe other 56 paths are documentation, tests, test support, or test routing. Fixture changes supply prepared resources/tools, distinguish raw transcripts from model-bound projections, avoid cloning executable tool handles, exercise the new context boundaries, and preserve lifecycle and migration coverage. Tests tied only to the retired internal default session creation or generic renderer are removed; the legacy owner-mismatch Doctor contract remains covered.
Retained contracts:
src/plugin-sdk/agent-sessions.ts,src/agents/sessions/extension-sdk.ts, the native/Jiti extension loader and its tests, and the virtual-SDK Knip entry. There is no public SDK deprecation or removal in this change.