Skip to content

fix(gateway): prevent sessions from using unconfigured agents - #127661

Merged
steipete merged 1 commit into
mainfrom
steipete/infallible-gould-ca77da
Aug 21, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/infallible-gould-ca77da

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Closes #127659

What Problem This Solves

Fixes an issue where creating a dashboard session with a stale or otherwise unconfigured explicit agent selection could succeed, but later dispatch, reclaim, and delete operations rejected that same session as owned by an unknown agent. Managed-worktree sessions could therefore become impossible to continue or clean up through the normal lifecycle.

Why This Change Was Made

Session creation now uses the same configured-agent ownership policy as the rest of the lifecycle and validates the canonical owner before filesystem, session-store, or managed-worktree side effects. Agent-qualified creation keys count as explicit ownership, while the separate historical-read contract for sessions whose agent was later removed remains intact.

The creation-only permissive resolver option and duplicate selection branches were removed. Production code is net negative: +22/-74 lines (net -52).

User Impact

Operators can no longer create sessions under an unconfigured agent owner. Invalid requests fail immediately with Unknown agent id, while configured explicit owners and valid implicit owner selection remain fully manageable through create, dispatch, reclaim, and delete.

Evidence

Pre-fix regression proof: the new worktree lifecycle test received ok: true and allocated an agent:main:dashboard:* worktree where INVALID_REQUEST was expected.

Post-fix validation:

  • node scripts/run-vitest.mjs src/gateway/session-request-agent.test.ts — 20 passed
  • node scripts/run-vitest.mjs src/gateway/server.sessions.delete-worktree-lifecycle.test.ts — 16 passed
  • node scripts/run-vitest.mjs src/gateway/server.sessions.create.test.ts — 224 passed
  • node scripts/check-changed.mjs -- src/gateway/session-request-agent.ts src/gateway/server-methods/sessions-create.ts src/gateway/session-create-service.ts src/gateway/server.sessions.delete-worktree-lifecycle.test.ts src/gateway/server.sessions.create.test.ts — passed
  • git diff --check — passed
  • Codex-backed autoreview — no accepted/actionable findings

This change was AI-assisted and reviewed. The implementation and owner boundary were inspected directly, and the regression test was demonstrated failing before the production fix.

Validate the canonical configured owner before session and worktree side effects so dispatch, reclaim, and delete can manage every created session.
@clawsweeper

clawsweeper Bot commented Aug 21, 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 gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 21, 2026
@steipete
steipete marked this pull request as ready for review August 21, 2026 22:14
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 6:34 PM ET / 22:34 UTC.

ClawSweeper review

What this changes

The PR makes Gateway session creation reject explicit or key-derived agents that are absent from the configured agent roster before session or worktree side effects.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking patch defect found. This remains the candidate fix for the linked Gateway lifecycle bug and needs protected maintainer review of its deliberate compatibility change.

Priority: P1
Reviewed head: 1382d4ecb2ed40b399a269cf663c5cff4f02ded8
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, net-negative owner-boundary repair with direct lifecycle regression coverage and no identified correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This maintainer-authored Gateway repair includes focused owner-boundary regression evidence; the external-contributor 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: This maintainer-authored Gateway repair includes focused owner-boundary regression evidence; the external-contributor proof gate does not apply.
Evidence reviewed 5 items Current-main defect: Current main retains the creation-only permissive resolver option, allowing an explicit unconfigured agent to pass owner resolution.
Canonical owner validation: The PR removes the permissive option and resolves the selected owner before the create service can prepare lifecycle resources.
Lifecycle boundary coverage: The added Gateway-boundary test verifies invalid explicit and key-derived owners create neither a session row nor a worktree, while configured and implicit owners remain deletable.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/server.sessions.delete-worktree-lifecycle.test.ts

Result: FAIL (partial) — step 2 expect_output sessions.create only allocates worktrees for lifecycle-manageable agent owners: expected terminal output was not visible within 30 seconds: "sessions.create only allocates worktrees for lifecycle-manageable agent owners"

node scripts/run-vitest.mjs src/gateway/server.sessions.delete-worktree-lifecycle.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127661-N9PGDz/target$ node scripts/run-vitest.mjs src/gateway/server.sessions.delete-worktree-lifecycle.test.ts
node scripts/run-vitest.mjs src/gateway/server.sessions.delete-worktree-lifecycle.test.ts
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127661-N9PGDz/target

[vitest] still running with no output for 30000ms (test/vitest/vitest.gateway.config.ts).











































Assertions:

  • FAIL expect_output: sessions.create only allocates worktrees for lifecycle-manageable agent owners

How this fits together

Gateway session creation turns RPC requests into persisted session state and optional managed worktrees. Later dispatch, reclaim, and deletion use the same agent owner, so creation must select an owner those operations can manage.

flowchart LR
  Request[Session creation request] --> Resolve[Resolve configured owner]
  Resolve --> Valid{Owner configured?}
  Valid -->|No| Reject[Invalid request]
  Valid -->|Yes| Create[Persist session and worktree]
  Create --> Lifecycle[Dispatch, reclaim, delete]
Loading

Decision needed

Question Recommendation
Should Gateway deliberately reject creation for an unconfigured explicit or key-derived owner, even for callers that previously received a session and worktree they could not later manage? Approve immediate rejection: Accept the fail-fast invalid-request response so every newly created session has an owner valid for its later lifecycle.

Why: The implementation is internally consistent, but it intentionally changes the response for existing callers and the PR carries the protected maintainer label.

Before merge

  • Resolve merge risk (P1) - Existing callers that deliberately created sessions for unconfigured explicit owners will now fail immediately instead of creating lifecycle-unmanageable state; this is the intended compatibility change and needs maintainer confirmation.
Agent review details

Security

None.

PR surface

Source -52, Tests +100. Total +48 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 22 74 -52
Tests 2 102 2 +100
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 124 76 +48

Review metrics

Metric Value Why it matters
Production versus test delta production +22/-74 (net -52); tests +102/-2 (net +100) The repair removes the creation-only bypass and adds owner-boundary coverage for rejected and manageable worktree lifecycles.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/server-methods/sessions-create.ts, serialized state: src/gateway/session-create-service.ts, serialized state: src/gateway/session-request-agent.ts, unknown-data-model-change: src/gateway/server-methods/sessions-create.ts, unknown-data-model-change: src/gateway/session-create-service.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Accept fail-fast owner validation (recommended)
    Approve the intentional compatibility change: invalid explicit owners fail before state or worktree creation rather than failing during later lifecycle operations.

Technical review

Best possible solution:

Land the single configured-owner admission rule after confirming immediate rejection is the intended upgrade behavior, while retaining historical read access for removed-agent sessions.

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

Yes—current main’s resolver explicitly permits the unconfigured owner only for creation, and the added Gateway-boundary test exercises the resulting worktree lifecycle path.

Is this the best way to solve the issue?

Yes—the patch removes the creation-only exception at the shared owner-resolution boundary rather than compensating after state or worktree allocation.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The current behavior can strand a session and managed worktree from normal Gateway lifecycle operations.
  • merge-risk: 🚨 compatibility: Merging changes explicit unconfigured-owner creation from success to an immediate invalid-request response.
  • 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: This maintainer-authored Gateway repair includes focused owner-boundary regression evidence; the external-contributor proof gate does not apply.

Evidence

What I checked:

Likely related people:

  • steipete: Current-main blame attributes the permissive owner-resolution condition to this contributor’s merged refactor; they also authored this focused repair. (role: introduced the current owner-resolution surface and authored the candidate repair; confidence: high; commits: 01e888795978, 1382d4ecb2ed; files: src/gateway/session-request-agent.ts, src/gateway/session-create-service.ts, src/gateway/server-methods/sessions-create.ts)

Rank-up moves

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

  • Obtain explicit maintainer confirmation of the intentional fail-fast compatibility behavior before merge.

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 (1 earlier review cycle)
  • reviewed 2026-08-21T22:21:02.417Z sha 1382d4e :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer decision: accept the intentional fail-fast compatibility change.

Creating a session for an unconfigured explicit or key-derived owner is invalid because the resulting session and managed worktree cannot be dispatched, reclaimed, or deleted through the normal lifecycle. The live team-server reproduction demonstrated that exact stranded state. Rejecting the request before durable session or worktree side effects is the intended behavior; historical reads for removed-agent sessions remain unchanged.

Landing proof for exact head 1382d4ecb2ed40b399a269cf663c5cff4f02ded8:

  • exact-head CI: green
  • fresh Codex autoreview: no accepted/actionable findings
  • focused owner-boundary and managed-worktree lifecycle regressions: green in the authored proof
  • ClawSweeper: no correctness or security findings; optional rank-up move resolved by this explicit maintainer decision

The ClawSweeper terminal-output observer timed out while its Vitest command was still running; that observer timeout is not treated as a product-test failure because the exact-head CI and authored focused test runs completed successfully.

@steipete
steipete merged commit 8c0cdc6 into main Aug 21, 2026
305 checks passed
@steipete
steipete deleted the steipete/infallible-gould-ca77da branch August 21, 2026 22:51
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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.

Gateway sessions.create can strand sessions under unconfigured agents

1 participant