Skip to content

fix(agents): preserve admitted CLI session context - #130475

Merged
steipete merged 3 commits into
mainfrom
codex/refactor-cli-candidate-context-20260826
Aug 27, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/refactor-cli-candidate-context-20260826

Conversation

@steipete

@steipete steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where an auto-reply run admitted with a specific session permission and placement could lose that context when the fallback cycle selected a CLI candidate. The CLI candidate previously received no admitted sessionEntry, so its real grant projection and permission cache could diverge from the admitted run.

The first repair exposed a second ordering hazard: placement admission can wait behind another turn, but the CLI resume binding was still captured before that wait. A replacement could therefore combine a newly admitted node placement with a stale native CLI session ID.

Why This Change Was Made

Fallback candidates now share one typed admitted-session context. Inside the placement-admitted callback, the CLI candidate reads one current SessionEntry snapshot and derives the permission grant, placement, context window, resume binding, and dropped-replacement state from that same snapshot. The existing expected-session-ID cleanup guard remains intact.

This keeps the admission owner authoritative without changing fallback ordering, provider selection, executable command behavior, or the Codex protocol.

User Impact

CLI fallback runs preserve the session's admitted read-only/full permission, placement, and native conversation binding instead of silently rebuilding a mixed candidate from state captured on opposite sides of the admission wait.

Evidence

  • The original missing-context regression failed before the repair and passes afterward.
  • A focused stale-binding transition failed with the old native session plus new node before the follow-up repair; it now passes and verifies the node invocation resumes only the newly admitted binding.
  • Owner and cleanup-guard coverage passes 41/41; node-invocation coverage passes 29/29; the node-resume preparation case passes.
  • Real authenticated loopback HTTP grant/list/call and read-only/full permission-cache tests pass.
  • The authenticated paired-node wire E2E passes its selected real Gateway case (1 passed, 4 skipped; 27.7s body), covering pair, inventory, invoke/result, and presence across the node transport. This is transport proof, not a claim of a full live model turn.
  • Exact changed-path lint, production and test type checks, formatting, and the full changed gate pass.
  • Fresh autoreview over the complete branch plus the P1 repair reports no actionable findings with 0.94 confidence; independent review also reports final GO.
  • Production delta: +88/-150, net -62 lines. Tests: +157/-6, net +151 lines.
  • The node-resume regression uses the canonical prepared CLI test helper instead of copying its evolving context shape. The exact same patch passes focused tests and core test types on a synthetic current-main merge tree.
  • A direct Codex source audit confirmed the change does not alter its protocol or prepared tool-binding contract; it only preserves the host-owned admitted session snapshot at the existing grant boundary.
  • A task-owned exact-lock dependency overlay linked workspace packages to this worktree's own outputs for the local paired-node proof. No dependency or overlay change is committed; exact-head CI remains required before landing.

@clawsweeper

clawsweeper Bot commented Aug 26, 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 size: M maintainer Maintainer-authored PR labels Aug 26, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 8:52 PM ET / August 27, 2026, 00:52 UTC.

ClawSweeper review

What this changes

The PR makes CLI fallback runs capture one session entry only after placement admission and use it for permission grants, node placement, context window, and native CLI resumption.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking defect was found in the repaired branch: it moves the CLI session snapshot to the post-admission owner boundary and preserves it through grant and node execution. This recent maintainer-owned PR remains necessary because current main still has the pre-admission capture; exact-head CI is still in progress.

Priority: P1
Reviewed head: 3b14b1ac98d48f40513ea1592549be60665a5d17

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The owner-boundary repair and regression are strong; exact-head CI remains the material pre-merge confirmation.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable to this maintainer-authored PR; its supplied authenticated loopback and paired-node evidence remains relevant to the exact-head merge gate.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to this maintainer-authored PR; its supplied authenticated loopback and paired-node evidence remains relevant to the exact-head merge gate.
Evidence reviewed 5 items Current-main defect: Current main reads the CLI binding before entering placement admission, so a queued turn can combine that old binding with later session state.
Post-admission repair: The branch snapshots both the session entry and CLI binding inside the placement-admitted callback, then passes that same entry to CLI run parameters.
Grant and node boundary: The internal CLI grant derives permission and placement from sessionEntry, and paired-node targeting uses that same entry's host and node fields.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw --help

Result: PASS (completed)

$ node scripts/run-node.mjs --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 98.84 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2343:31 ]
      │
 2343 │           ASM_CONSTS[start] = eval(func);
      │                               ──┬─
      │                                 ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2366:32) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
      ╭─[ node_modules/web-tree-sitter/web-tree-sitter.js:2366:33 ]
      │
 2366 │           moduleExports[name] = eval(func);
      │                                 ──┬─
      │                                   ╰─── Use of direct ˋevalˋ here.
      │
      │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
──────╯

node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

[tsdown-build] invocation 2/2 finished in 14.3s
[plugin-control-plane-loads] verified 36 built modules with native require and checked doctor closures
runtime-postbuild: 11 phases completed in 4416ms (slowest: built plugin control-plane loads 3644ms)

OpenClaw 2026.8.1 (3b14b1a) — All your chats, one OpenClaw.

Usage: openclaw [options] [command]

Options:
  --container ‹name›   Run the CLI inside a running Podman/Docker container named ‹name› (default: env OPENCLAW_CONTAINER)
  --dev                Dev profile: isolate state under ~/.openclaw-dev, default gateway port 19001, and shift derived ports (browser/canvas)
  -h, --help           Display help for command
  --log-level ‹level›  Global log level override for file + console (silent|fatal|error|warn|info|debug|trace)
  --no-color           Disable ANSI colors
  --profile ‹name›     Use a named profile (isol
… output truncated …

Assertions:

  • PASS expect_output: Usage: openclaw [options] [command]

How this fits together

Auto-reply selects a provider fallback for an admitted agent turn. For CLI-backed candidates, the admitted session entry feeds both the loopback tool grant and any paired-node CLI invocation.

flowchart LR
  A[Auto-reply turn] --> B[Fallback candidate]
  B --> C[Placement admission]
  C --> D[Current session snapshot]
  D --> E[CLI grant and resume binding]
  E --> F[Local or paired-node CLI run]
Loading

Before merge

  • Resolve merge risk (P1) - This touches authority-bearing session placement and permission data; merge only after exact-head CI and the authenticated grant/node evidence described in the PR are confirmed for the current head.
  • Complete next step (P2) - No repair lane is needed: the prior ordering finding is addressed; the remaining action is exact-head CI and maintainer merge handling.
Agent review details

Security

None.

PR surface

Source -62, Tests +151. Total +89 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 4 88 150 -62
Tests 1 157 6 +151
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 245 156 +89

Review metrics

Metric Value Why it matters
Production versus test delta production +88/-150 (net -62); tests +157/-6 (net +151) The repair consolidates production parameter ownership while adding focused ordering and grant/node regression coverage.

Merge-risk options

Maintainer options:

  1. Complete exact-head boundary validation (recommended)
    Wait for the current head's required CI and verify the claimed authenticated grant and paired-node path before merging this session-permission repair.

Technical review

Best possible solution:

Retain the post-admission single-snapshot flow so the CLI grant, resume binding, and paired-node target always describe the same admitted session state.

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

Yes—source-reproducible. The focused regression changes the active session entry while placement admission waits and demonstrates the old/new binding divergence that current main permits.

Is this the best way to solve the issue?

Yes. Capturing the entry only after the placement owner admits the turn is the narrow canonical boundary; moving the read earlier in fallback selection would retain the race.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable to this maintainer-authored PR; its supplied authenticated loopback and paired-node evidence remains relevant to the exact-head merge gate.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Current main can run a CLI fallback with session permission or native binding state captured on opposite sides of placement admission.
  • merge-risk: 🚨 session-state: The changed snapshot determines which persisted CLI conversation binding and placement a fallback resumes.
  • merge-risk: 🚨 security-boundary: The same snapshot supplies the permission and execution-host facts used by the CLI loopback grant.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable to this maintainer-authored PR; its supplied authenticated loopback and paired-node evidence remains relevant to the exact-head merge gate.

Evidence

What I checked:

Likely related people:

  • steipete: Direct blame connects the current-main pre-admission capture to this recent area work, and the branch repairs that exact boundary. (role: recent agent/session-admission contributor; confidence: high; commits: 86e208310ff2, 3b14b1ac98d4; files: src/auto-reply/reply/agent-runner-cli-candidate.ts, src/agents/session-placement-admission.ts)

Rank-up moves

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

  • Confirm required CI on commit 3b14b1a is green before merging.

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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-08-26T23:06:00.029Z sha 8cf69ee :: needs changes before merge. :: [P1] Snapshot the CLI binding with the post-admission session entry
  • reviewed 2026-08-26T23:57:13.870Z sha a424f53 :: needs maintainer review before merge. :: none

@steipete

steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Resolved the exact-head P1 on the new child commit.

The CLI candidate now reads one active SessionEntry only after placement admission and derives the native CLI binding, permission grant, placement, context window, and dropped-replacement state from that same snapshot. The existing expected-session-ID cleanup guard is preserved.

The added regression replaces an old native binding and node placement while admission is waiting. It failed before the repair by capturing the old native session with the new node, and now verifies that the CLI run and node resume arguments use only the newly admitted binding.

Fresh proof on the complete repaired diff: focused stale-binding regression green; owner/cleanup guards 41/41; node invocation 29/29; node-resume preparation green; scoped lint and production/test types green; full changed gate green; autoreview clean at 0.94; independent final review GO. Combined production delta is +88/-150 (net -62), and tests are +157/-6 (net +151).

Exact-head hosted CI is now running. The local paired-node authenticated transport proof remains green; no dependency-overlay files are included in the PR.

@steipete steipete closed this Aug 27, 2026
@steipete steipete reopened this Aug 27, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Resolved the current-main merge-ref type failure on child commit 3b14b1ac98d.

The new node-resume regression had manually copied PreparedCliRunContext, including a bootstrap warning field that current main removed when that warning moved into the system prompt. The old branch type therefore passed locally while the current merge tree correctly failed check-test-types with TS2353.

The test now builds its context through the canonical buildPreparedCliRunContext helper and overrides only the admitted run parameters, working directory, backend, and reusable session required by this assertion. This removes copied setup and keeps the fixture aligned with both the branch and current-main context owner; there is no cast, compatibility field, production change, or rebase.

Proof: focused admitted-session regression green; original owner suite 16/16 and full changed gate green; fresh autoreview clean at 0.95; the identical test patch applied to a synthetic current-main + PR merge passes the focused regression and core test types. Final PR metrics are production +88/-150 (net -62), tests +157/-6 (net +151), total +245/-156 (net +89).

Two prior manual release-gate oxlint jobs were also terminated by GitHub-hosted runner shutdowns without diagnostics; their actual ratchets passed. The new child head is receiving ordinary pull-request CI, which is the authoritative landing gate.

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 27, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Final exact-head merge gates are satisfied on 3b14b1ac98d48f40513ea1592549be60665a5d17.

  • Required ordinary pull-request CI run 33027865099 completed successfully on the exact head.
  • The latest exact-head ClawSweeper review reports Findings None and Security None. Its sole rank-up move was exact-head green CI, now satisfied.
  • The authenticated loopback grant and paired-node transport evidence described in the PR remain green; the current-main merge-proof also passes the admitted-session regression and core test types.
  • CHANGELOG.md is release-owned in this repository. The PR body carries the release-note context for the admitted session permission, placement, and native-resume fix.

Native preparation will refresh the current-main merge snapshot and revalidate the reviewed head before merge. No rebase or source change is being used to bypass drift.

@steipete
steipete merged commit f383064 into main Aug 27, 2026
210 checks passed
@steipete
steipete deleted the codex/refactor-cli-candidate-context-20260826 branch August 27, 2026 01:15
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
* fix(agents): preserve admitted CLI session context

* fix(agents): snapshot CLI session after admission

* test(agents): reuse prepared CLI fixture
alfredjbclaw added a commit to alfredjbclaw/openclaw that referenced this pull request Aug 28, 2026
… suite

Upstream openclaw#130475 grew agent-runner-execution-cli-sessions.test.ts past the
1000-line oxlint cap once this PR's cases merged in, and it moved the
replacement-drop cleanup assertion inside the placement admission callback,
where it still expected the binding record to vanish outright. Move this
PR's auth-boundary case into agent-runner-execution-cli-session-auth.test.ts
and update the relocated assertion to the unknown-provenance tombstone this
PR keeps.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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