Skip to content

fix: isolate delegated worker transcript ownership - #168946

Merged
steipete merged 2 commits into
mainfrom
fix/independent-worker-transcript
Oct 11, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/independent-worker-transcript

Conversation

@steipete

@steipete steipete commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #159801

Problem

An in-process sessions_send into a placed worker session carries the caller's async context into the child's placement admission. Worker execution does not enter the local attempt runner that normally replaces the transcript scope. After the remote reply commits, Gateway result handling can therefore reject the child's transcript with SessionTranscriptWriterClaimReboundError, reporting failure for completed work. Thanks @alexph-dev for the report.

Change

Clear inherited transcript and CLI-history writer scope alongside the existing tool-caller scope when admitting an independent turn. Exact continuations of the same operational run retain their existing scope and live write guard. The child's placement and transcript owners continue to enforce its own authority.

The remote-handoff regression uses real placement admission, a separate parent transcript, and the existing simulated worker transport. It verifies the completed reply and conflict report, released claim, and unchanged parent transcript. The continuation cases verify that an exact continuation can write while admitted and cannot write after closure. Documentation describes the target-session behavior.

Production LOC: +1 in one file; four changed files total. This uses the existing context-exit helper and adds no lifecycle state, durable state, public contract, or limit change.

Proof

  • Pinned pre-fix main 45630ed81200bfb64f973d73ea10c29425fc0358: the delegated-worker regression fails with SessionTranscriptWriterClaimReboundError while finalizing the completed worker result (48.90 s command wall).
  • pnpm test src/gateway/worker-environments/worker-turn-launcher-remote-handoff.test.ts --maxWorkers=1: 2 passed, 76.73 s wall. Caller-scope file: 8 passed, 61.73 s wall.
  • Type-aware lint: zero warnings/errors. Export-name collisions, full pnpm check:changed --base 45630ed81200bfb64f973d73ea10c29425fc0358 (2300.16 s), and all three Knip export scans pass.
  • Independent review: scoped-clean P0/P1. The final test assertion uses the real recorder’s string content representation; the baseline rejection occurs earlier at the transcript owner boundary.

Proof uses synthetic sessions on an isolated Linux AWS host with deterministic remote-transport fixtures; it makes no live provider or macOS performance claim.

Integrated current main including the landed worker-byte repair; the four reviewed files are byte-identical to the proved change. Post-integration proof also passes: remote-handoff 2 tests/101.71 s, caller-scope 8 tests/59.55 s; type-aware lint, export-name collisions, and all three Knip scans pass. Exact-head CI is green.

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: S labels Oct 11, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR clears inherited transcript and CLI-history writer context when placement admits an independent turn.

Example: A parent calls sessions_send with message "Reply with exactly: ok" into a paired-device worker session.

  • Before: The worker commits "ok", but Gateway settlement returns SessionTranscriptWriterClaimReboundError and marks the session failed.
  • After: The target reply and workspace conflict report settle under target-session authority while the parent's transcript remains unchanged.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch has no identified correctness defect, but required authority-chain behavior proof is absent.
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: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Delegation to a paired-device session reports failure after the worker has completed and committed its reply.
Reason: The report establishes user impact, the repair is narrowly scoped, and the host identifies this as maintainer-authored work.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open: it addresses a documented delegation failure that remains on current main, and source review found no introduced correctness defect.

Priority: P1
Reviewed head: 65245c6c0274533cc2d2879ec75427f499e5000f

Before merge

  • Add real behavior proof - Authority-chain proof required: the reported Linux runs exercise placement admission, parent isolation, and conflict reporting with simulated transport; provide redacted logs or live output showing allowed target persistence and rejection before the actual report mutation after target writer replacement or workspace-result claim revocation. Redact IPs, API keys, phone numbers, and non-public endpoints. The prior review's authority-proof request remains applicable. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve security concern: Verify stale target authority at the transcript mutation - Independent admission exits the inherited writer scope. The allowed regression uses real storage with simulated transport, and the closure case uses a mocked commit; neither demonstrates that a replaced target writer or revoked workspace-result claim prevents the actual delegated report append.
  • Resolve merge risk - Before merge, establish that clearing inherited writer authority still rejects delegated report persistence when the target writer is replaced or the workspace-result claim is revoked.

Findings

  • [medium] Verify stale target authority at the transcript mutation — src/agents/session-placement-admission.ts:226

Tests

  • Missing end-to-end proof: Supply redacted production-path evidence of allowed delegated report persistence and rejection before the actual mutation after target writer replacement or workspace-result claim revocation.
Agent review details

How this fits together

Placement admission receives a prepared agent turn, selects local or worker execution, and returns its settled result; transcript and placement owners guard durable writes.

flowchart TD
A[Parent session tool] --> B[Placement admission]
B --> C[Independent context scope]
C --> D[Worker turn owner]
D --> E[Target transcript and result guards]
E --> F[Settled reply]
Loading

Technical review

Best possible solution:

Use the existing admission owner to isolate independent turns while preserving exact-continuation fences and target-owned commit guards.

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

The release report supplies a repeatable paired-device sequence and control, and current source retains the inherited writer scope; the PR reports a matching baseline harness failure, but this review ran no target code.

Is this the best way to solve the issue?

The repair addresses context leakage at the shared admission owner, reuses the existing exit helper, and preserves the exact-instance continuation branch rather than weakening target write checks.

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Keep open pending authority evidence (recommended)
    Hold merging until allowed target persistence and rejection after target writer replacement or result-claim revocation are demonstrated at the actual transcript mutation.

Provenance checked

  • Independent placement caller scope keeps the original intent (037e005: Independent worker and CLI runs must leave the launching tool's authority context, while exact operational-instance continuations retain their fences.)
  • Remote-handoff regression keeps the original intent (438d035: Paired-node worker launch coverage preserves bootstrap credentials, transcript results, and keep-local workspace conflict reporting.)

Testing

Proof path: in-process harness.

Security

Needs attention: Source retains target-owned guards, but supplied evidence does not establish their final-effect rejection after the inherited authority scope is cleared.

Evidence

Security concerns:

  • [medium] Verify stale target authority at the transcript mutation — src/agents/session-placement-admission.ts:226
    Independent admission exits the inherited writer scope. The allowed regression uses real storage with simulated transport, and the closure case uses a mocked commit; neither demonstrates that a replaced target writer or revoked workspace-result claim prevents the actual delegated report append.
    Confidence: 0.94

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit ad3c930 adds src/agents/session-placement-admission.ts:7 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ad3c93078e7f; files: src/agents/session-placement-admission.ts)
  • Josh Lehman: Raw commit 037e005 adds src/agents/session-placement-admission.ts:101 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 037e0059e9ed; files: src/agents/session-placement-admission.ts)

PR surface

Source +1, Tests +79, Docs +3. Total +83 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 2 1 +1
Tests 2 125 46 +79
Docs 1 3 0 +3
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 130 47 +83

Review metrics

Metric Value Why it matters
Production versus test growth Production net +1 line; tests net +79 lines The tests extend existing fixtures to cover parent isolation and exact-continuation closure without adding production lifecycle machinery.

Labels

Label changes:

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.

Label justifications:

  • P1: A documented delegation workflow reports successfully completed worker work as failed, disrupting session state and encouraging retries.
  • merge-risk: 🚨 security-boundary: The patch clears authority-bearing context across sessions; final-effect rejection after target writer replacement or result-claim revocation remains unproved.
  • 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 target writer replacement and workspace-result claim revocation prevent delegated report persistence, alongside the allowed case.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-11T06:50:50.554Z sha 65245c6 :: needs real behavior proof before merge. :: none

Reviewed October 11, 2026, 3:11 AM ET / 07:11 UTC (Revision 2).

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 11, 2026
@steipete
steipete merged commit 50cf629 into main Oct 11, 2026
135 of 139 checks passed
@steipete
steipete deleted the fix/independent-worker-transcript branch October 11, 2026 07:38
steipete added a commit that referenced this pull request Oct 11, 2026
## What Problem This Solves

Launcher tests repeatedly stop and restart the same database reader workers between cases, adding seconds to each case despite using independent state roots.

## User Impact

Faster node/worker test feedback, with the same behavioral coverage and per-case database isolation. No production behavior changes.

## Why This Change Was Made

Sixteen launcher, execution, detached-context, transcript-admission, and run-owner suites now opt into the fixture's existing reader-reuse mode. Each case still drains its work and closes its database resources before removing its state; the existing database cleanup owner stops the retained pool after the suite. Detached-context keeps its unjoined-owner guard in both cleanup phases.

The terminal-results suite's extra state root, lazy/module-reset tests, and import-boundary tests retain their existing isolation. No assertions, test cases, timeouts, retries, worker settings, production seams, or dependencies change.

Production LOC delta: **0**. Sixteen test files, +93/−33 lines.

## Evidence

The same 290-test command runs before and after on one AWS machine, with `--maxWorkers=1` and Vitest JSON reporting. Both revisions use the corrected Node test environment from main; the earlier jsdom-contaminated baseline is excluded from the speed comparison.

| Command wall | Before | After | Saved |
|---|---:|---:|---:|
| 290 tests, one worker | 1,755.032 s | 1,089.346 s | 665.686 s / 37.93% |
| Summed Vitest file execution | 1,717.203 s | 1,054.089 s | 663.115 s / 38.62% |

Both runs passed all 290 tests on AWS `cbx_77c6df7bbddc`, Node 24.19.0. [Paired run](https://crabbox.openclaw.ai/portal/runs/run_71809623ad760587e2a081422f8a6e5c). Independent review has no actionable P0/P1 findings. The tested candidate matches the committed files after repository import formatting. [Final source/static validation](https://crabbox.openclaw.ai/portal/runs/run_f86a2ec39ad898ca0e5ffe33907a437e) passed check:changed, type-aware lint, Knip exports, and export-name collisions. [Pre-integration CI](https://github.com/openclaw/openclaw/actions/runs/38120713206) passed: 489 s elapsed CI wall and 1,082 summed Node-job seconds. [Current-head CI](https://github.com/openclaw/openclaw/actions/runs/38125109973) also passed after preserving main’s remote-handoff regression from #168946. The timing comparison is pinned to the pre-integration base. Post-integration, both handoff tests passed in 163.877 s; type-aware lint and export-name collisions passed. Full-tree max-lines and Knip checks reproduce two unrelated base failures in `src/web-search/runtime.test.ts` and `src/infra/agent-run-terminal-writes.ts` on exact base `90f04bfb10df` with unchanged source blobs; no baseline was changed. [Base qualification](https://crabbox.openclaw.ai/portal/runs/run_9922dda00b9c648692a436c8091ac52f).

<details>
<summary>Exact timed command</summary>

```sh
pnpm test \
  src/gateway/worker-environments/worker-turn-launcher.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-computer.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-claim-admission.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-initial-setup.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-failure-recovery.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-reconcile-error.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-reconciliation-authority.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-media.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-build-recovery.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-reclaimed-placement.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-remote-handoff.test.ts \
  src/gateway/worker-environments/worker-turn-launcher.claim-recovery.test.ts \
  src/gateway/worker-environments/worker-turn-execution.test.ts \
  src/gateway/worker-environments/worker-turn-detached-context.test.ts \
  src/gateway/worker-environments/cloud-transcript-write-admission.test.ts \
  src/gateway/worker-environments/worker-turn-run-owner.test.ts \
  --maxWorkers=1 --reporter=verbose --reporter=json --outputFile=/tmp/launcher.json
```

</details>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
Closes openclaw#159801

## Problem

An in-process `sessions_send` into a placed worker session carries the caller's async context into the child's placement admission. Worker execution does not enter the local attempt runner that normally replaces the transcript scope. After the remote reply commits, Gateway result handling can therefore reject the child's transcript with `SessionTranscriptWriterClaimReboundError`, reporting failure for completed work. Thanks @alexph-dev for the report.

## Change

Clear inherited transcript and CLI-history writer scope alongside the existing tool-caller scope when admitting an independent turn. Exact continuations of the same operational run retain their existing scope and live write guard. The child's placement and transcript owners continue to enforce its own authority.

The remote-handoff regression uses real placement admission, a separate parent transcript, and the existing simulated worker transport. It verifies the completed reply and conflict report, released claim, and unchanged parent transcript. The continuation cases verify that an exact continuation can write while admitted and cannot write after closure. Documentation describes the target-session behavior.

Production LOC: **+1** in one file; four changed files total. This uses the existing context-exit helper and adds no lifecycle state, durable state, public contract, or limit change.

## Proof

- Pinned pre-fix main `f53ba67676d5dc1b182fb695b7b4b86e53409d69`: the delegated-worker regression fails with `SessionTranscriptWriterClaimReboundError` while finalizing the completed worker result (48.90 s command wall).
- `pnpm test src/gateway/worker-environments/worker-turn-launcher-remote-handoff.test.ts --maxWorkers=1`: 2 passed, 76.73 s wall. Caller-scope file: 8 passed, 61.73 s wall.
- Type-aware lint: zero warnings/errors. Export-name collisions, full `pnpm check:changed --base f53ba67` (2300.16 s), and all three Knip export scans pass.
- Independent review: scoped-clean P0/P1. The final test assertion uses the real recorder’s string content representation; the baseline rejection occurs earlier at the transcript owner boundary.

Proof uses synthetic sessions on an isolated Linux AWS host with deterministic remote-transport fixtures; it makes no live provider or macOS performance claim.

Integrated current main including the landed worker-byte repair; the four reviewed files are byte-identical to the proved change. Post-integration proof also passes: remote-handoff 2 tests/101.71 s, caller-scope 8 tests/59.55 s; type-aware lint, export-name collisions, and all three Knip scans pass. Exact-head CI is green.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
## What Problem This Solves

Launcher tests repeatedly stop and restart the same database reader workers between cases, adding seconds to each case despite using independent state roots.

## User Impact

Faster node/worker test feedback, with the same behavioral coverage and per-case database isolation. No production behavior changes.

## Why This Change Was Made

Sixteen launcher, execution, detached-context, transcript-admission, and run-owner suites now opt into the fixture's existing reader-reuse mode. Each case still drains its work and closes its database resources before removing its state; the existing database cleanup owner stops the retained pool after the suite. Detached-context keeps its unjoined-owner guard in both cleanup phases.

The terminal-results suite's extra state root, lazy/module-reset tests, and import-boundary tests retain their existing isolation. No assertions, test cases, timeouts, retries, worker settings, production seams, or dependencies change.

Production LOC delta: **0**. Sixteen test files, +93/−33 lines.

## Evidence

The same 290-test command runs before and after on one AWS machine, with `--maxWorkers=1` and Vitest JSON reporting. Both revisions use the corrected Node test environment from main; the earlier jsdom-contaminated baseline is excluded from the speed comparison.

| Command wall | Before | After | Saved |
|---|---:|---:|---:|
| 290 tests, one worker | 1,755.032 s | 1,089.346 s | 665.686 s / 37.93% |
| Summed Vitest file execution | 1,717.203 s | 1,054.089 s | 663.115 s / 38.62% |

Both runs passed all 290 tests on AWS `cbx_77c6df7bbddc`, Node 24.19.0. [Paired run](https://crabbox.openclaw.ai/portal/runs/run_71809623ad760587e2a081422f8a6e5c). Independent review has no actionable P0/P1 findings. The tested candidate matches the committed files after repository import formatting. [Final source/static validation](https://crabbox.openclaw.ai/portal/runs/run_f86a2ec39ad898ca0e5ffe33907a437e) passed check:changed, type-aware lint, Knip exports, and export-name collisions. [Pre-integration CI](https://github.com/openclaw/openclaw/actions/runs/38120713206) passed: 489 s elapsed CI wall and 1,082 summed Node-job seconds. [Current-head CI](https://github.com/openclaw/openclaw/actions/runs/38125109973) also passed after preserving main’s remote-handoff regression from openclaw#168946. The timing comparison is pinned to the pre-integration base. Post-integration, both handoff tests passed in 163.877 s; type-aware lint and export-name collisions passed. Full-tree max-lines and Knip checks reproduce two unrelated base failures in `src/web-search/runtime.test.ts` and `src/infra/agent-run-terminal-writes.ts` on exact base `587f0b81b1ce` with unchanged source blobs; no baseline was changed. [Base qualification](https://crabbox.openclaw.ai/portal/runs/run_9922dda00b9c648692a436c8091ac52f).

<details>
<summary>Exact timed command</summary>

```sh
pnpm test \
  src/gateway/worker-environments/worker-turn-launcher.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-computer.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-claim-admission.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-initial-setup.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-failure-recovery.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-reconcile-error.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-reconciliation-authority.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-media.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-build-recovery.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-reclaimed-placement.test.ts \
  src/gateway/worker-environments/worker-turn-launcher-remote-handoff.test.ts \
  src/gateway/worker-environments/worker-turn-launcher.claim-recovery.test.ts \
  src/gateway/worker-environments/worker-turn-execution.test.ts \
  src/gateway/worker-environments/worker-turn-detached-context.test.ts \
  src/gateway/worker-environments/cloud-transcript-write-admission.test.ts \
  src/gateway/worker-environments/worker-turn-run-owner.test.ts \
  --maxWorkers=1 --reporter=verbose --reporter=json --outputFile=/tmp/launcher.json
```

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

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

1 participant