Skip to content

fix: nested session tools retain caller scope on multi-agent hosts - #126221

Merged
obviyus merged 1 commit into
mainfrom
t3code/fix-code-mode-session-scope
Aug 19, 2026
Merged

obviyus merged 1 commit into
mainfrom
t3code/fix-code-mode-session-scope

Conversation

@obviyus

@obviyus obviyus commented Aug 19, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes an issue where Code Mode calls to sessions_list and sessions_search could fail on multi-agent hosts when the model omitted an explicit scope:

Multiple agents are configured, but the request has no explicit owner.

Related session lookups could also use the sandbox policy key instead of the durable originating session.

Why This Change Was Made

The tool factory resolved the caller agent from the sandbox/policy key before it built the session tools. A policy key such as global is ownerless on an explicit multi-agent roster, even though the same attempt already carries an agent-scoped runSessionKey. The factory now uses that durable run key for both owner resolution and list/search/history requester context. Gateway discovery remains unscoped where visibility policy requires it, so existing visibility and agent-to-agent checks still govern authorized foreign/global results.

Maintainer decision: @obviyus explicitly requested and approved preserving the originating caller identity while retaining authorization for explicit cross-agent/global queries. Configured visibility: "all" discovery remains unchanged.

No overlapping open PR fixes this invariant. #126177 touches the embedded search stub for result modes only; #111101 and #114194 address different session visibility/history behavior.

Production LOC: +2/-2 (net 0) | Tests: +167

User Impact

Nested session discovery and history now authorize from the originating run on multi-agent hosts instead of failing during owner resolution. Authorized all-agent discovery and explicit cross-agent/global queries continue to work.

Evidence

  • Pre-fix owner-boundary regression: AgentSelectionRequiredError: Multiple agents are configured, but session agent resolution has no explicit owner.
  • Post-fix grouped focused run: 21 test files, 440 tests passed, including list/search/history and embedded gateway siblings.
  • Two-agent visibility: "all" plus agent-to-agent coverage proves implicit foreign discovery remains authorized.
  • git diff --check
  • Targeted Oxfmt and Oxlint passed for both changed files.
  • pnpm tsgo:core
  • pnpm check:test-types
Redacted two-agent owner-boundary red/green trace

Before the production substitution, the first regression test failed through the real session lookup owner boundary:

FAIL openclaw session lookup context > binds nested session lookups to the durable caller
AgentSelectionRequiredError: Multiple agents are configured, but session agent resolution has no explicit owner.
The agent-scoped session key belongs to "research", not "main".
  at resolveSessionAgentId (src/agents/agent-scope.ts:329)
  via sessions_list

Exact-head rerun:

$ pnpm test src/agents/openclaw-tools.session-context.test.ts -- --reporter=verbose
PASS binds nested session lookups to the durable caller
PASS preserves implicit all-agent discovery for authorized callers
Test Files  1 passed (1)
Tests       2 passed (2)

Exact-head CI run 32229894840 passed all 172 jobs at
049691803e488d2f579cf61ac952ca7abc194ac5.

Provenance: the split between sandbox policy identity and runSessionKey was introduced in #76995 by @amknight and intentionally applied to session_status; the session lookup trio retained the policy key. The PR was squash-merged by clawsweeper[bot] after /clawsweeper automerge from @amknight on 2026-05-04. This patch completes that owner-boundary split for list, search, and history.

@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 19, 2026
@obviyus
obviyus force-pushed the t3code/fix-code-mode-session-scope branch 3 times, most recently from 216bde2 to 649077e Compare August 19, 2026 07:25
@obviyus
obviyus force-pushed the t3code/fix-code-mode-session-scope branch from 649077e to 0496918 Compare August 19, 2026 07:52
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 19, 2026
@clawsweeper

clawsweeper Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 3:58 AM ET / 07:58 UTC.

ClawSweeper review

What this changes

The PR makes Code Mode session list, search, and history tools derive their caller identity from the durable run session rather than an ownerless sandbox policy key.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. Current main still resolves nested session-tool ownership from the sandbox policy key, while this PR consistently uses the durable run key and retains the existing visibility checks. No blocking patch defect was found; the protected maintainer label and active exact-head checks leave it for maintainer review.

Priority: P1
Reviewed head: 049691803e488d2f579cf61ac952ca7abc194ac5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-neutral owner-boundary repair with credible regression coverage and no blocking code finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The PR carries the protected maintainer label; its reported focused test run is supplemental and the external-contributor real-behavior-proof gate does not apply.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The PR carries the protected maintainer label; its reported focused test run is supplemental and the external-contributor real-behavior-proof gate does not apply.
Evidence reviewed 6 items Current-main failure path: Current main passes only agentSessionKey into owner resolution; a global policy key is ownerless on an explicit multi-agent roster, while the PR substitutes runSessionKey first.
Owner-resolution contract: The resolver rejects unscoped keys when no configured owner or explicit agent exists; its existing tests explicitly cover global-session owner selection.
Caller and callee boundary: The coding-tool assembly already passes both the sandbox key and run key into the core factory; list, search, and history derive authorization context through the shared session-access helpers.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/agents/openclaw-tools.session-context.test.ts

Result: FAIL (partial) — step 2 expect_output openclaw session lookup context: expected terminal output was not visible within 30 seconds: "openclaw session lookup context"

node scripts/run-vitest.mjs src/agents/openclaw-tools.session-context.test.ts
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126221-HQqKA9/target$ node scripts/run-vitest.mjs src/agents/openclaw-tools.session-context.test.ts
node scripts/run-vitest.mjs src/agents/openclaw-tools.session-context.test.ts
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126221-HQqKA9/target

 ✓  agents-core  src/agents/openclaw-tools.session-context.test.ts (2 tests) 626ms
     ✓ preserves implicit all-agent discovery for authorized callers  362ms

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  07:59:32
   Duration  22.60s (transform 17.91s, setup 1.09s, import 20.51s, tests 626ms, environment 0ms)

[test] passed 1 Vitest shard in 28.29s
runner@runnervmzvulz:/tmp/clawsweeper-live-proof-126221-HQqKA9/target$ node scripts/run-vitest.mjs src/agents/openclaw-tools.session-context.test.ts
[test] starting test/vitest/vitest.agents-core.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-126221-HQqKA9/target































Assertions:

  • FAIL expect_output: openclaw session lookup context

How this fits together

Embedded OpenClaw agent runs carry both a sandbox policy session and a durable run session. The core tool factory turns those into session lookup tools, which then apply visibility and agent-to-agent policy before sending Gateway requests.

flowchart LR
A[Embedded agent attempt] --> B[Sandbox policy key]
A --> C[Durable run session key]
B --> D[Core tool factory]
C --> D
D --> E[Session caller context]
E --> F[List search history tools]
F --> G[Visibility and agent policy]
G --> H[Gateway session requests]
Loading

Before merge

  • Resolve merge risk (P1) - This changes the requester identity used at the session-visibility boundary; exact-head checks should confirm sandbox clamps and explicit cross-agent policy still deny unauthorized reads.
Agent review details

Security

None.

PR surface

Source 0, Tests +167. Total +167 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 167 0 +167
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 169 2 +167

Review metrics

Metric Value Why it matters
Production versus regression coverage production +2/-2 (net 0); tests +167/-0 The repair changes two shared caller-context selections and adds focused coverage for all three affected session tools.

Merge-risk options

Maintainer options:

  1. Verify the session-access boundary before merge (recommended)
    Finish exact-head checks with the durable-run regression and existing sandbox visibility coverage so the new requester identity cannot widen unauthorized session reads.

Technical review

Best possible solution:

Retain the single durable-run caller context for session lookups, with existing visibility and agent-to-agent checks continuing to authorize every foreign or global target.

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

Yes, in source: construct a multi-agent roster with agentSessionKey "global" and a scoped runSessionKey; current main resolves ownership from the global key and fails before the lookup tools are built. This read-only review did not execute that regression.

Is this the best way to solve the issue?

Yes. Resolving both the factory agent and lookup requester from the already-threaded durable run key fixes the owner boundary at its producer, while the existing session visibility and agent-to-agent checks remain the authorization authority.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against c2b61a40beb5.

Labels

Label changes:

  • add P1: Current main can block nested session list, search, and history on explicit multi-agent hosts when the policy key has no owner.
  • add merge-risk: 🚨 security-boundary: The PR changes the caller identity consumed by session visibility and cross-agent authorization, which needs exact-head boundary validation beyond ordinary compilation.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR carries the protected maintainer label; its reported focused test run is supplemental and the external-contributor real-behavior-proof gate does not apply.

Label justifications:

  • P1: Current main can block nested session list, search, and history on explicit multi-agent hosts when the policy key has no owner.
  • merge-risk: 🚨 security-boundary: The PR changes the caller identity consumed by session visibility and cross-agent authorization, which needs exact-head boundary validation beyond ordinary compilation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The PR carries the protected maintainer label; its reported focused test run is supplemental and the external-contributor real-behavior-proof gate does not apply.

Evidence

What I checked:

Likely related people:

  • amknight: Merged fix: session_status 'current' resolves to live run session instead of stale sandbox key (#76708) #76995 established the durable-run-versus-policy-session split for session status. (role: introduced adjacent run-session behavior; confidence: high; commits: 3f732aee83d5; files: src/agents/openclaw-tools.ts, src/agents/tools/session-status-tool.ts)
  • Peter Steinberger: Blame assigns the current-main factory lines that still use the policy key to this recent agents-area commit. (role: recent current-main contributor; confidence: medium; commits: 093b19131899; files: src/agents/openclaw-tools.ts, src/agents/agent-tools.ts)

Rank-up moves

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

  • Let exact-head CI complete, including the focused session-context and visibility coverage.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@obviyus

obviyus commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer decision: approved. Extend the established durable runSessionKey requester identity from session_status to sessions_list, sessions_search, and sessions_history. Keep sandbox policy/delivery identity separate, and retain the existing visibility and agent-to-agent authorization checks for cross-agent/global queries.

@obviyus

obviyus commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator Author

Landing proof note: the required Telegram changed-path lane was attempted repeatedly on exact head 049691803e488d2f579cf61ac952ca7abc194ac5, but explicit multi-agent Telegram channel activation stopped before any provider request. It is not counted as live proof. The maintainer explicitly accepted that gap before landing. Substitute proof is the pre-fix failing owner-boundary regression, post-fix list/search/history coverage including authorized all-agent discovery, direct Codex/runtime source inspection, exact-head openclaw/ci-gate, and the final local ClawSweeper PASS (0 findings, 0 security concerns, no maintainer decision, 0 Rank-up moves).

@obviyus
obviyus merged commit 16c87e6 into main Aug 19, 2026
243 of 245 checks passed
@obviyus
obviyus deleted the t3code/fix-code-mode-session-scope branch August 19, 2026 08:38
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 20, 2026
…26221)

Use the durable run-session identity for nested session lookups on multi-agent hosts while retaining existing visibility and agent-to-agent authorization.

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

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant