Skip to content

fix(sessions): expose batch lifecycle actions to gateway-bound agents - #120850

Closed
clawsweeper wants to merge 1 commit into
mainfrom
fix/sessions-tool-lifecycle-parity
Closed

clawsweeper wants to merge 1 commit into
mainfrom
fix/sessions-tool-lifecycle-parity

Conversation

@clawsweeper

@clawsweeper clawsweeper commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Gateway-bound embedded agents could list and spawn sessions but could not use the model-facing sessions lifecycle tool, forcing shell/CLI fallback for archive and delete work. It also closes lifecycle drift where the CLI supported ordered batch dry-runs and generation fencing while the agent tool handled only one target at a time.

Why This Change Was Made

The sessions tool now follows the same trusted Gateway-bound registration gate as sessions_spawn. Archive batching reuses the Gateway-owned sessions.patchMany lifecycle path; a shared adapter retains ordered CLI results and generation-safe delete orchestration. CLI confirmation and agent owner/visibility authorization remain caller-owned boundaries.

Lifecycle inputs are action-validated, every mutation requires authoritative generation identity, current-session targets fail independently, and model-visible batches are limited to eight indexed outcomes under the existing 3,840-byte result budget. Archived targets are revalidated through sessions.patchMany; errors are bounded by UTF-8 bytes with a fixed-size fallback. sessions is hard-denied for leaf, orchestrator, and ACP child inventories. Existing deferred self-archive remains the canonical path for archiving the running session.

The policy catalog and Codex prompt snapshots now advertise the same current session surface. Standalone local embedded mode remains excluded.

Production growth provides the new bounded batch capability and shared lifecycle owner; the obsolete CLI-only mutation loop is removed.

User Impact

Main agents can preview and archive or delete ordered session batches through sessions without invoking the CLI. Results preserve input order, continue after individual failures, remain complete within the model-result budget, and fence mutations to the selected session generation. Delegated child agents cannot access destructive session lifecycle actions.

Evidence

  • Rebased onto current origin/main after sessions.patchMany landed.
  • pnpm check
  • pnpm check:test-types
  • pnpm check:docs
  • pnpm prompt:snapshots:check
  • pnpm deadcode:dependencies
  • pnpm deadcode:exports
  • Focused Vitest coverage across the sessions tool, bounded lifecycle batches, CLI adapter, leaf/orchestrator/ACP inventories, Gateway sessions.patchMany authorization/fencing, policy catalog parity, and Codex prompt snapshots: 237 tests across 7 shards.
  • Review regressions cover missing/recreated targets, stale archived state, identity-less dry runs, lifecycle-only fields on other actions, mixed valid/self/valid batches, multibyte maximum-size results, and archive integration through sessions.patchMany.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation commands Command implementations agents Agent runtime and tooling extensions: policy size: L maintainer Maintainer-authored PR labels Aug 9, 2026
@shakkernerd shakkernerd self-assigned this Aug 9, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 9, 2026
@clawsweeper

clawsweeper Bot commented Aug 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 9, 2026, 7:52 AM ET / 11:52 UTC.

ClawSweeper review

What this changes

The PR exposes bounded archive and delete batches through the model-facing sessions tool for trusted Gateway-bound agents, sharing lifecycle execution with the CLI.

Merge readiness

⚠️ Ready for maintainer review - 5 items remain

Keep open. The prior UTF-8 result-budget blocker is addressed, but batch delete now obtains a synthetic operator.admin scope merely to retain its generation fence; it should remain on the archive-only write path before merge. The required sibling Codex source is unavailable, so the prompt-snapshot contract cannot be certified in this review.

Priority: P1
Reviewed head: bd8a7f121131567f2dc5e876af7e708ecad18e2a

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The shared lifecycle design and repaired byte budget are strong, but the unresolved least-privilege defect blocks a higher rating.
Proof confidence 🌊 off-meta tidepool Not applicable: This is a maintainer-associated PR, so the external-contributor proof gate does not apply; the body reports focused tests and CI, but no independently observed live run was supplied.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer-associated PR, so the external-contributor proof gate does not apply; the body reports focused tests and CI, but no independently observed live run was supplied.
Evidence reviewed 6 items Prior result-budget finding addressed: The revised lifecycle envelope truncates errors by UTF-8 bytes and falls back to indexed detail omission; the added regression asserts eight multibyte outcomes serialize within 3,840 bytes.
Changed delete call carries fenced identity: The new batch adapter forwards expected session identity with archived-only delete requests.
Current scope contract escalates that request: The current write-scoped delete allowlist excludes expectedSessionId and expectedLifecycleRevision, so any such archived-only delete classifies as operator.admin.
Findings 1 actionable finding [P2] Keep fenced deletes on the write-scoped path
Security Needs attention Fenced delete escalates to synthetic admin scope: The batch adapter forwards expected session identity, while the Gateway scope classifier treats those fields as outside archived-only write scope; the in-process caller then supplies operator.admin for the request.

How this fits together

A Gateway-bound agent invokes the sessions tool, which resolves visible session targets and asks the Gateway to archive or delete authoritative session records. The tool returns ordered, bounded outcomes to the model while Gateway scope and session-sharing checks enforce the mutation boundary.

flowchart LR
  A[Gateway-bound agent] --> B[Sessions tool]
  B --> C[Visibility and identity checks]
  C --> D[Batch lifecycle adapter]
  D --> E[Gateway archive or delete]
  E --> F[Ordered bounded outcomes]
  F --> G[Model-visible result]
Loading

Before merge

  • Keep fenced deletes on the write-scoped path (P2) - targetParams(target) adds expectedSessionId (and may add expectedLifecycleRevision), but the current sessions.delete write envelope permits neither. The in-process caller therefore mints operator.admin for this new model-facing archive-then-delete path. Add the identity fields to the narrow archived-only write allowlist and cover the exact resolved scope; do not drop the generation fence.
  • Resolve security concern: Fenced delete escalates to synthetic admin scope - The batch adapter forwards expected session identity, while the Gateway scope classifier treats those fields as outside archived-only write scope; the in-process caller then supplies operator.admin for the request.
  • Resolve merge risk (P1) - The added fenced delete request is granted synthetic operator-admin scope instead of the archive-only write scope, weakening the intended least-privilege boundary.
  • Resolve merge risk (P1) - The Codex dynamic-tool snapshot portion remains unverified against the required sibling Codex runtime source.
  • Complete next step (P2) - A narrow mechanical scope-policy repair and regression test can resolve the merge blocker; final review must also inspect the required sibling Codex source.

Findings

  • [P2] Keep fenced deletes on the write-scoped path — src/sessions/session-lifecycle-batch.ts:230-233
  • [medium] Fenced delete escalates to synthetic admin scope — src/sessions/session-lifecycle-batch.ts:230
Agent review details

Security

Needs attention: The new destructive agent path obtains an unnecessary synthetic admin scope because its identity-fence fields are absent from the write-scope envelope.

PR surface

Source +431, Tests +634, Docs +1. Total +1066 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 6 586 155 +431
Tests 13 734 100 +634
Docs 2 18 17 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 1338 272 +1066

Review metrics

Metric Value Why it matters
Production versus test delta production +586/-155; tests and fixtures +734/-100 The production growth is justified by the new shared batch lifecycle owner and agent capability, but the new authorization boundary needs focused correction before merge.

Stored data model

Persistent data-model change detected: serialized state: src/agents/tools/sessions-tool.lifecycle-batch.test.ts, serialized state: src/agents/tools/sessions-tool.test.ts, serialized state: src/agents/tools/sessions-tool.ts, serialized state: src/commands/sessions-lifecycle.test.ts, serialized state: src/commands/sessions-lifecycle.ts, serialized state: src/sessions/session-lifecycle-batch.test.ts, and 7 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Preserve write-scoped fenced deletion (recommended)
    Allow only expected session identity fields alongside archivedOnly, then add a scope regression proving the model-facing delete call remains operator.write.
  2. Retain admin scope deliberately
    Document why this narrowly constructed agent call must run with operator.admin despite the existing archive-only write-scope contract.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Preserve generation fences while classifying archived-only deletes with expected session identity as operator.write; add exact scope regression coverage.

Technical review

Best possible solution:

Keep the shared lifecycle adapter, allow only expected session identity fields on the archived-only write-scoped delete envelope, and verify the Codex dynamic-tool snapshot contract from the required sibling source before landing.

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

Yes, from source: invoke a batch delete with a resolved target identity; the new adapter sends expectedSessionId, while the current scope classifier upgrades that archived-only request to operator.admin. This review did not execute the path because the checkout is read-only.

Is this the best way to solve the issue?

No. The shared batch lifecycle owner is the right design, but its delete call must preserve the archive-only write scope rather than obtaining admin scope for its safety identity fields.

Full review comments:

  • [P2] Keep fenced deletes on the write-scoped path — src/sessions/session-lifecycle-batch.ts:230-233
    targetParams(target) adds expectedSessionId (and may add expectedLifecycleRevision), but the current sessions.delete write envelope permits neither. The in-process caller therefore mints operator.admin for this new model-facing archive-then-delete path. Add the identity fields to the narrow archived-only write allowlist and cover the exact resolved scope; do not drop the generation fence.
    Confidence: 0.94

Overall correctness: patch is incorrect
Overall confidence: 0.9

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add merge-risk: 🚨 security-boundary: Generation-fenced archived deletes currently cause the in-process Gateway caller to mint operator-admin rather than operator-write scope.
  • remove merge-risk: 🚨 other: Current PR review merge-risk labels are merge-risk: 🚨 security-boundary.

Label justifications:

  • P1: This PR exposes destructive session lifecycle actions to agents, and its current scope classification needs correction before that path can safely land.
  • merge-risk: 🚨 security-boundary: Generation-fenced archived deletes currently cause the in-process Gateway caller to mint operator-admin rather than operator-write scope.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: This is a maintainer-associated PR, so the external-contributor proof gate does not apply; the body reports focused tests and CI, but no independently observed live run was supplied.

Evidence

Security concerns:

  • [medium] Fenced delete escalates to synthetic admin scope — src/sessions/session-lifecycle-batch.ts:230
    The batch adapter forwards expected session identity, while the Gateway scope classifier treats those fields as outside archived-only write scope; the in-process caller then supplies operator.admin for the request.
    Confidence: 0.94

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/gateway/method-scopes.test.ts src/agents/tools/sessions-tool.lifecycle-batch.test.ts.
  • [P1] pnpm prompt:snapshots:check.
  • [P1] pnpm check:changed -- src/shared/session-method-scopes.ts src/gateway/method-scopes.test.ts src/sessions/session-lifecycle-batch.ts.

What I checked:

  • Prior result-budget finding addressed: The revised lifecycle envelope truncates errors by UTF-8 bytes and falls back to indexed detail omission; the added regression asserts eight multibyte outcomes serialize within 3,840 bytes. (src/agents/tools/sessions-tool.lifecycle-batch.test.ts:152, bd8a7f121131)
  • Changed delete call carries fenced identity: The new batch adapter forwards expected session identity with archived-only delete requests. (src/sessions/session-lifecycle-batch.ts:230, bd8a7f121131)
  • Current scope contract escalates that request: The current write-scoped delete allowlist excludes expectedSessionId and expectedLifecycleRevision, so any such archived-only delete classifies as operator.admin. (src/shared/session-method-scopes.ts:24, 11e897a63035)
  • In-process caller mints the resolved scope: The sessions tool's Gateway caller resolves least-privilege scopes from request parameters and installs them on a forced synthetic client. (src/agents/tools/in-process-gateway.ts:30, 11e897a63035)
  • Lifecycle ownership history: Blame attributes the current delete write-scope envelope to the recent main-line session work; the broader sessions-tool history is primarily associated with Peter Steinberger. (src/shared/session-method-scopes.ts:24, e09b0ebfbaa3)
  • Codex contract gate unavailable: The repository policy requires direct inspection of sibling ../codex for Codex-related prompt/runtime verdicts, but that checkout is absent and this read-only environment cannot create it.

Likely related people:

  • steipete: Current session-tool, lifecycle-race, and self-archive work is attributed to this contributor, including the PR head. (role: feature owner and recent area contributor; confidence: high; commits: bd8a7f121131, 9f5ba09a0dc2, 91f04499f53f; files: src/agents/tools/sessions-tool.ts, src/sessions/session-lifecycle-batch.ts, src/gateway/server-methods/sessions-delete.ts)
  • Erick Kinnee: Recent adjacent history covers Gateway session-sharing and materialization paths that enforce target access. (role: adjacent Gateway session-sharing contributor; confidence: medium; commits: 0b1ef9017b; files: src/gateway/session-sharing.ts)

Rank-up moves

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

  • Keep expected identity fields on the archived-only operator-write path and add exact scope coverage.
  • Inspect sibling ../codex and verify the dynamic tool snapshot contract before an approval verdict.
  • Finish exact-head required checks after the repair.

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-09T03:46:50.249Z sha 2c0607c :: found issues before merge. :: [P0] Bound batch lifecycle results before returning them to the model
  • reviewed 2026-08-09T05:42:59.101Z sha 0177258 :: needs changes before merge. :: [P1] Bound lifecycle result output by UTF-8 bytes

@clawsweeper
clawsweeper force-pushed the fix/sessions-tool-lifecycle-parity branch from 2c0607c to 0177258 Compare August 9, 2026 03:57
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 9, 2026
@clawsweeper
clawsweeper force-pushed the fix/sessions-tool-lifecycle-parity branch from 0177258 to bd8a7f1 Compare August 9, 2026 11:41
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Aug 9, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. and removed merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. labels Aug 9, 2026
@VACInc

VACInc commented Sep 28, 2026

Copy link
Copy Markdown
Member

Related update: #160296 is merged on main with a restricted agent-facing archive/restore/Stop surface for eligible operator.write callers. That restricted surface excludes batch operations and deletion; it does not implement the broader Gateway-bound batch archive/delete contract, previews, and per-item behavior proposed here. This PR is not superseded by that merge and should remain open.

@steipete

Copy link
Copy Markdown
Contributor

Thanks for the PR. We're closing older pull requests that have gone stale against current main.

This branch has had no commits since August 9, and #160296 has since landed a restricted agent-facing archive/restore/stop surface for sessions. Batch delete through the agent tool would need a fresh, narrowly scoped proposal.

If this change is still needed, please open a fresh PR against current main and we'll review it there.

@steipete steipete closed this Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation extensions: policy gateway Gateway runtime 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants