Skip to content

fix(acp): run session/new prompts in the requested cwd - #123585

Closed
Chinmayrawat15 wants to merge 14 commits into
openclaw:mainfrom
Chinmayrawat15:fix/acp-new-session-cwd-gateway-persistence
Closed

Chinmayrawat15 wants to merge 14 commits into
openclaw:mainfrom
Chinmayrawat15:fix/acp-new-session-cwd-gateway-persistence

Conversation

@Chinmayrawat15

@Chinmayrawat15 Chinmayrawat15 commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Closes #123557

AI-assisted contribution (Claude Code). I have read and understand the change.

What Problem This Solves

Fixes an issue where ACP clients that open a session with a specific working directory would have their agent run in the default workspace instead. An IDE extension, CLI wrapper, or automation script calls session/new with cwd set to a project directory, gets back a session whose session.cwd correctly reports that directory, and then every prompt on that session executes in ~/.openclaw/workspace.

The confirming metadata is what makes this bite: the caller has positive evidence the session is scoped to their project, so files get read from and written to a directory the caller never intended.

The end-to-end capture below shows it precisely. On pre-fix code the model receives two contradictory statements in the same turn: the bridge's informational message prefix says [Working directory: $ROOT/project], while the system prompt's own ## Workspace section says Working directory: $ROOT/workspace. The agent is told one thing and executes against the other.

Why This Change Was Made

The requested directory was recorded only in the ACP bridge's in-memory session record. Nothing carried it to the Gateway: the bridge never creates a Gateway session, chat.send has no cwd field, and the Gateway therefore created the session lazily on the first prompt with no directory to work from. The agent turn resolves its cwd from requestedCwd ?? sessionEntry.spawnedCwd, and spawnedCwd was never written.

The fix records the fact at the boundary that owns it. sessions.create already accepts an absolute cwd and persists it as spawnedCwd, so the bridge now creates the Gateway session at session/new and every later turn resolves it through the existing runtime path. Public chat.send is left alone — widening it with a competing per-request cwd would add a second source of truth for state the session entry already owns.

Absence is decided by the Gateway, not the caller

Two earlier revisions of this PR got the ownership boundary wrong, and the fix for both is the same idea, so it is worth stating directly.

sessions.create applies spawnedCwd even when it adopts an existing row. So the bridge must not create over a session someone else owns — but it also cannot skip creation for explicitly routed keys, because requireExisting defaults to false and an explicit _meta.sessionKey / --session routes through unresolved, meaning the row may not exist at all. Deciding this from outside the Gateway is a check-then-create race: a row created between the bridge's probe and its write gets adopted, and the owner's directory is overwritten.

So the decision moved to where the answer is already known. sessions.create gains an opt-in cwdOnCreateOnly, applied inside the same mutation that already computes whether it created the row — right next to the existing rule that adoption must not stamp new-row facts (provenance, visibility, projectId). The bridge now calls create unconditionally with that flag:

  • new row → the requested cwd is persisted.
  • existing row → the owner's cwd is untouched, whenever it appeared.

This removes the ACP-side probe and its duplicate snapshot branch entirely; the bridge no longer reasons about session existence at all. Callers that omit the flag keep exactly the previous behavior.

The bridge reports the directory the turn will actually use

Because an adopted row keeps its own directory, the bridge must not keep assuming its request won — the visible [Working directory: …] prefix and the provenance receipt are both built from ACP-side session state, so a mismatch there recreates the same false confirmation this PR removes. session/new now reads the authoritative value back out of the create response and records that.

That leaves one case where no honest directory exists to report: an adopted key whose row has no working directory at all. The turn will run in the agent workspace, so claiming the requested directory would be the original defect again. A create that passes a cwd always returns one for a new row, so a missing spawnedCwd identifies exactly that case, and session/new fails with what to do instead rather than reporting a directory the agent will not use.

Path authorization is unchanged. sessions.create already requires the cwd to be inside a configured agent workspace unless the caller holds operator.admin. The ACP bridge connects as a CLI-mode client, which gets operator.admin by default, so the reported flow works; narrower deployments keep the Gateway's existing containment rule.

session/new now also rejects a relative cwd, matching the sibling session/resume and the ACP contract (NewSessionRequest.cwd: "The working directory for this session. Must be an absolute path.", @agentclientprotocol/sdk dist/schema/types.gen.d.ts:4649). Previously a relative path was silently accepted and quietly ignored — the capture below shows pre-fix code happily creating a session for relative/project.

Sibling surfaces: session/load and session/resume are adoption paths, not creation paths — they attach to a Gateway session that already exists and owns its spawnedCwd, and resumeSession already requires that row via getExistingSnapshot. They are intentionally unchanged.

Older Gateways never see the new field

sessions.create params are a closed schema, so unconditionally sending cwdOnCreateOnly would make session/new fail outright against a Gateway built before it — turning a bridge upgrade into a hard error. The field is therefore capability-gated using the mechanism this repo already has: the Gateway advertises sessions.create.cwdOnCreateOnly in HelloOk.features.capabilities (alongside entries like chat-send-routing-contract), the client retains the advertised set per connection, and the bridge sends the field only when it is offered. No PROTOCOL_VERSION change.

Against a Gateway that does not advertise it:

Route Behavior Why
bridge-minted key still provisioned, field omitted a fresh id cannot collide with an existing row, so applying the cwd is harmless — the reported bug stays fixed
explicit _meta.sessionKey not provisioned that Gateway would apply the cwd to a row it merely adopts, so creating could overwrite an operator's directory

The explicit-key route therefore keeps its pre-PR behavior against old Gateways — those callers keep the default-workspace bug until their Gateway updates — rather than risking someone else's state. Two consequences are deliberate and worth naming: the bridge reports the requested cwd on that degraded route even though the row may differ, and a reconnect onto a downgraded server uses the previous hello's capabilities until the new hello lands.

Protocol follow-through: the field is additive and optional, and the generated Swift bindings are regenerated in this PR (Bool? with a cwdOnCreateOnly coding key), so existing clients decode unchanged. Kotlin and dist/protocol.schema.json needed no changes. This does not reach model-visible prompt text — the agent-facing session tool schema is declared separately in src/agents/tools/sessions-spawn-visible.ts, and no protocol-only field (emitCommandHooks, spawnDepth, catalogId, succeedsParent) appears in the prompt snapshots.

Production LOC: +113 / −17 (tests +285/−14, generated Swift +5/−1), 15 files. That is well above the net-≤0 default for a bug fix and I am not going to present it as small. Roughly half is capability negotiation, which exists because shipping the field unconditionally breaks mixed-version pairings; the rest is the ownership boundary itself and the adoption-path repairs. Every increment traces to a review finding on this PR rather than scope I chose, and the one absorbing refactor available — moving absence into the Gateway mutation — was taken and removed the caller-side probe. Above the net-≤0 default, so naming it rather than burying it: the growth is a public protocol capability — opt-in create-if-absent semantics for a caller provisioning a key it may not own — plus the ACP contract assertion. Moving the decision into the Gateway is what let the ACP-side probe and duplicate snapshot branch be deleted rather than added to.

User Impact

ACP callers that scope a session to a project directory now actually get their agent running there — whether they let the bridge mint a session key or name one themselves with _meta.sessionKey / --session. IDE extensions, CLI wrappers, and automation that pass cwd to session/new stop silently operating in ~/.openclaw/workspace, which removes the risk of the agent creating or modifying files in the wrong directory while session.cwd reports the intended one. Sessions an operator already owns keep the directory they already had, with no window in which a concurrent creation could change it. session/list also reports the real directory for bridge-created sessions.

A relative cwd on session/new is now a clear error instead of being silently ignored.

Evidence

1. Real-behavior proof — ACP stdio → isolated Gateway → agent turn

Harness, all real processes: the built openclaw acp stdio bridge → a real Gateway on its own port with an isolated OPENCLAW_STATE_DIR (never the operator's gateway) → the repo's own mock provider (scripts/e2e/mock-openai-server.mjs, wired through qa-lab buildQaGatewayConfig with providerMode: "mock-openai"). ACP JSON-RPC driven over real stdin/stdout. Re-run against the current cwdOnCreateOnly build.

Both routing modes, one run, each with its own directory and a real prompt turn:

Route Session key Persisted spawnedCwd System prompt ## Workspace → Working directory: Turn
bridge-minted agent:qa:acp-bridge:e90914c3… $ROOT/project-a ✅ $ROOT/project-a ✅ end_turn
explicit _meta.sessionKey agent:qa:acp-explicit-proof $ROOT/project-b ✅ $ROOT/project-b ✅ end_turn

The default workspace appears in neither model payload (0 occurrences). session/new with cwd: "relative/project" was rejected: ACP session/new requires an absolute cwd.

Before/after on the same harness, with only the ACP lifecycle reverted to pre-fix and the dist rebuilt:

Observation Before After
Persisted session_nodes.entry_json.spawnedCwd None $ROOT/project
System prompt Working directory: $ROOT/workspace ❌ default $ROOT/project ✅ requested
Default-workspace occurrences in model payload 8 0
session/new with a relative cwd accepted, session created rejected

What the model was actually told:

BEFORE:  ...verify memory snippets.\ ## Workspace\  || Working directory: $ROOT/workspace
         ...\"input_text\",\"text\":\"[Fri 2026-08-14 ...] [ || Working directory: $ROOT/project
                 ^ the bridge's message prefix claims /project while the agent runs in /workspace

AFTER:   ...verify memory snippets.\ ## Workspace\  || Working directory: $ROOT/project

Real ACP stdio transcript (abridged):

>> session/new {"cwd":"$ROOT/project-a","mcpServers":[]}
<< {"sessionId":"e90914c3-80b0-4a30-8a09-765f1cbd49e4",...}
>> session/prompt {"sessionId":"e90914c3-…","prompt":[{"type":"text","text":"Which directory are you working in?"}]}
<< {"stopReason":"end_turn"}
>> session/new {"cwd":"$ROOT/project-b","mcpServers":[],"_meta":{"sessionKey":"agent:qa:acp-explicit-proof"}}
<< {"sessionId":"724124b2-47fa-4c54-bed7-1cb89470ecab",...}
>> session/prompt {"sessionId":"724124b2-…",...}
<< {"stopReason":"end_turn"}
>> session/new {"cwd":"relative/project","mcpServers":[]}
<< {"code":-32603,"message":"Internal error","data":{"details":"ACP session/new requires an absolute cwd."}}

Persisted rows, read out of the agent SQLite store after the run:

agent:qa:acp-bridge:e90914c3-80b0-4a30-8a09-765f1cbd49e4   spawnedCwd = $ROOT/project-a
agent:qa:acp-explicit-proof                                spawnedCwd = $ROOT/project-b

So the artifacts are not over-read: the Gateway's [ws] log records only failed or slow responses (ok === false || durationMs >= DEFAULT_WS_SLOW_MS, src/gateway/ws-log.ts:395, threshold 50 ms), so it is not a complete RPC census — the persisted rows and model payloads above are the authoritative signal. $ROOT is a temporary directory; paths are otherwise unedited, and no credentials appear (the Gateway ran unconfigured against a local mock provider).

2. Every directory-mismatch case is covered by a test that fails pre-fix

Case Behavior Pre-fix failure
bridge-minted key requested cwd persisted expected [ { method: 'sessions.list' } ] to deep equally contain { method: 'sessions.create' }
explicit key, no row requested cwd persisted (same create assertion, explicit-key variant)
explicit key, row with cwd bridge reports the owner's directory expected '/tmp/my-project' to be '/tmp/owner-project'
explicit key, row without cwd session/new refuses promise resolved instead of rejecting
relative cwd session/new refuses promise resolved instead of rejecting
old Gateway, bridge-minted key provisioned without the field n/a — new degraded-path coverage
old Gateway, explicit key not provisioned, session/new still succeeds n/a — new degraded-path coverage

The shared translator test helper now models the sessions.create response the bridge reads, instead of a bare { ok: true }; partial mocks delegate to it. That stub had been hiding this path — six previously-passing tests only passed because they asserted against a Gateway shape that does not occur.

3. The ownership race, proven deterministically

src/gateway/server.sessions.create.test.ts creates a session with one directory, then issues a second sessions.create for the same key with a different cwd and cwdOnCreateOnly: true — modelling the interleaving where the row already exists by the time the create lands. Removing the guard makes it fail for exactly the right reason:

 × sessions.create cwdOnCreateOnly leaves an adopted session's directory to its owner
 AssertionError: expected '/tmp/acp-project' to be '/tmp/owner-project'

A companion test proves the flag still sets the directory on a genuinely new row.

4. Regression test fails before the fix, for the intended reason

$ node scripts/run-vitest.mjs src/acp/translator.session-setup.test.ts   # pre-fix
 × creates the Gateway session with the requested cwd for a bridge-minted session
 × rejects a relative cwd instead of silently running elsewhere

 AssertionError: expected [ { method: 'sessions.list', …(1) } ] to deep equally contain
                 { method: 'sessions.create', …(1) }

The ACP tests assert the exact wire shape for both routing modes, including the flag, and that a rejected relative cwd creates nothing. The mock gateway returns a realistic sessions.list payload rather than a bare { ok: true }.

5. Owner-boundary and suite coverage

  • Runtime consumption: resolveSessionRuntimeCwd({ requestedCwd, sessionEntry }) returns requestedCwd ?? sessionEntry.spawnedCwd (src/gateway/server-methods/agent-session-reset.ts:269), feeding the agent run's cwd at src/gateway/agent-turn/agent-run-execution-phase.ts:483.
  • node scripts/run-vitest.mjs src/gateway/server.sessions.create.test.ts → 91 passed.
  • node scripts/run-vitest.mjs src/acp → 182 files / 1451 tests passed.

6. Gates

autoreview --engine claude --mode uncommitted: clean on every revision, "no accepted/actionable findings", clean on the final revision, TruffleHog clean. tsgo -p tsconfig.core.json exit 0; run-oxlint.mjs exit 0; oxfmt --check clean; git diff --check clean. The full protocol gate was run locally — check-protocol-registry, protocol-gen, protocol-gen-swift --check, protocol-gen-kotlin, check-protocol-since, and the git diff --exit-code over all four generated paths — and passes; checks-fast-bundled-protocol is green on the current head.

Known non-green check: check-lint is cancelled, not failed — its conclusion is cancelled and its "Run check shard" step never completed. In the previous occurrence the log showed every lane reporting finished with zero violations before the runner received a shutdown signal ([oxlint] FAILED (exit 143) = SIGTERM) while in oxlint:extensions, a lane this PR does not touch; main was independently red at the same time. Every lint lane covering these files passes locally. I cannot re-run workflows from a fork; happy to push a no-op commit if a maintainer would rather re-fire it.

Proof gap, stated plainly: pnpm check:changed routes to Crabbox, which is unavailable from this machine (selected binary failed basic --version/--help sanity checks), so per AGENTS.md the gates above were run locally instead of remotely. The end-to-end run uses the repo's mock provider rather than a live model; the observation it supports — which directory the agent is given — is independent of the provider. This change is not UI-visible, so no screenshots apply.

@clawsweeper

clawsweeper Bot commented Aug 14, 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.

@Chinmayrawat15
Chinmayrawat15 marked this pull request as ready for review August 14, 2026 09:29
@clawsweeper clawsweeper Bot added 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 18, 2026, 1:38 AM ET / 05:38 UTC (Revision 27).

ClawSweeper review

What this changes

The ACP bridge persists requested working directories through Gateway session creation, negotiates create-only directory handling, and suppresses unverified directory claims when loading existing sessions.

Regression provenance

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

Merge readiness

⛔ Blocked before merge - 9 items remain

The fix remains necessary on current main and the latest release. Keep this PR open: its fresh-session proof is useful, but adoption still changes an existing session’s filesystem permission boundary, and the branch remains conflict-marked.

Priority: P1
Reviewed head: 6253b07cdc5e932b18b2add3107ae696d15acecf
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful owner-boundary work with convincing fresh-session traces, but incomplete preservation of adopted permission state prevents merge readiness.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: Authority-chain proof required: the recorded real ACP-to-Gateway traces validly demonstrate fresh-session cwd propagation, but do not show an adopted guarded/workspace session retaining its filesystem boundary through subsequent I/O or after a rejected setup. Add redacted terminal/log evidence that an inside-root operation succeeds and a formerly forbidden sibling path remains denied after adoption and reopen. Updating the PR body should trigger re-review; otherwise ask a maintainer for @clawsweeper re-review. 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.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: Authority-chain proof required: the recorded real ACP-to-Gateway traces validly demonstrate fresh-session cwd propagation, but do not show an adopted guarded/workspace session retaining its filesystem boundary through subsequent I/O or after a rejected setup. Add redacted terminal/log evidence that an inside-root operation succeeds and a formerly forbidden sibling path remains denied after adoption and reopen. Updating the PR body should trigger re-review; otherwise ask a maintainer for @clawsweeper re-review. 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.
Evidence reviewed 11 items Pinned introduction and review continuity: Inspected the merge-base-to-head changes. The previous completed review used this same head; comparing its lifecycle and session-create files against HEAD produces no changes. The permission-root finding is therefore a late discovery.
Current main still lacks the fix: newSession stores params.cwd only in the bridge session store and does not provision a Gateway session. The prompt path sends chat.send without cwd. No merged replacement was established by the related-item review or targeted GitHub search.
Latest release behavior: The supplied latest release, v2026.9.4, also stores cwd only in ACP memory during newSession; the requested propagation is not present there.
Findings 1 actionable finding [P1] [P1] Preserve the adopted session’s permission root
Security Needs attention Adoption can widen an existing filesystem boundary: The bridge now invokes session creation during attachment, and its requested directory replaces sessionRoot even when cwdOnCreateOnly preserves the existing cwd. Guarded/workspace tool construction subsequently consumes that new root, permitting paths outside the session’s previous boundary.

How this fits together

The ACP bridge connects editors and command-line clients to OpenClaw Gateway sessions. Gateway-owned session state determines the working directory and filesystem permissions used by subsequent agent turns.

flowchart TD
  A[Editor or ACP client] --> B[ACP session setup]
  B --> C[Gateway capability check]
  C --> D[Create or adopt session]
  D --> E[Stored directory and permissions]
  E --> F[Agent turn and filesystem tools]
  E --> G[ACP directory claims]
Loading

Decision needed

Question Recommendation
Should explicit ACP session attachment remain available for cwd-less sessions and older Gateways, or should this bridge upgrade intentionally reject those documented workflows? Preserve existing-session attachment: Treat established explicit routes as adoption without changing their directory or asserting an unknown runtime cwd, while enforcing requested directories for newly created sessions.

Why: The patch intentionally replaces successful attachment with errors; the contributor discussion does not establish maintainer acceptance of that compatibility change.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: Authority-chain proof required: the recorded real ACP-to-Gateway traces validly demonstrate fresh-session cwd propagation, but do not show an adopted guarded/workspace session retaining its filesystem boundary through subsequent I/O or after a rejected setup. Add redacted terminal/log evidence that an inside-root operation succeeds and a formerly forbidden sibling path remains denied after adoption and reopen. Updating the PR body should trigger re-review; otherwise ask a maintainer for @clawsweeper re-review. 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.
  • [P1] Preserve the adopted session’s permission root (P1) - The new ACP sessions.create call passes the caller’s cwd, from which the handler derives sessionRoot. This guard preserves an existing spawnedCwd, but the following spread still replaces sessionRoot. Adopting a guarded/workspace session rooted at /projects/a with cwd /projects therefore leaves execution in /projects/a while expanding filesystem access to sibling projects; a narrower cwd instead blocks previously allowed files. The mutation also survives the bridge’s later rejection of a cwd-less row. Preserve the existing permission root in the same atomic adoption decision and extend the Gateway regression to cover subsequent filesystem access. This is a late discovery on the unchanged previously reviewed head.
  • Resolve security concern: Adoption can widen an existing filesystem boundary - The bridge now invokes session creation during attachment, and its requested directory replaces sessionRoot even when cwdOnCreateOnly preserves the existing cwd. Guarded/workspace tool construction subsequently consumes that new root, permitting paths outside the session’s previous boundary.
  • Resolve merge risk (P1) - Adopting an existing guarded/workspace session can persist a different filesystem permission root, including when newSession subsequently rejects the cwd-less row.
  • Resolve merge risk (P1) - Upgrading only the bridge makes explicit-session routes fail against older Gateways; even an updated Gateway rejects attachment through session/new to ordinary cwd-less sessions. These are deliberate changes to documented workflows without established owner approval.
  • Resolve merge risk (P1) - The conflict-marked branch has no verified test-merge result, so compatibility with current main's revised session-creation owner remains unproven.
  • Complete next step (P2) - Repair adopted-session permission preservation, obtain the attachment compatibility decision, and reconcile conflicts before validating the resulting head.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P1] [P1] Preserve the adopted session’s permission root — src/gateway/session-create-service.ts:1103-1106
  • [medium] Adoption can widen an existing filesystem boundary — src/gateway/session-create-service.ts:1106
Agent review details

Security

Needs attention: Create-only cwd handling leaves an unintended persisted change to the adopted session’s filesystem confinement; no dependency or supply-chain changes were introduced.

PR surface

Source +117, Tests +302, Other +4. Total +423 across 20 files.

View PR surface stats
Area Files Added Removed Net
Source 13 138 21 +117
Tests 6 355 53 +302
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 5 1 +4
Total 20 498 75 +423

Review metrics

Metric Value Why it matters
Production versus test growth Production +133/-21 (net +112); tests/support +360/-53 (net +307); generated Swift +5/-1 Growth implements the create/adopt boundary and capability negotiation; the permission-root omission shows why preservation must cover the complete owner state.
Protocol and compatibility surface 1 optional RPC field and 1 advertised capability added; 2 attachment refusal cases introduced The additive wire field is negotiated, but existing explicit-route workflows can still stop working after a bridge upgrade.

Stored data model

Persistent data-model change detected: database schema: packages/gateway-protocol/src/schema/frames.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #123557
Summary: This PR is the open implementation candidate for the ACP cwd-propagation issue; the task-suggestion report has a distinct producer and path-namespace defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Preserve the complete adopted policy (recommended)
    Make create-only provisioning preserve sessionRoot alongside cwd, then verify allowed and outside-root filesystem operations after adoption.
  2. Resolve attachment compatibility
    Have the owner choose preserved adoption or an explicitly documented stricter contract before validating the reconciled branch.

Technical review

Best possible solution:

Use one Gateway-owned create/adopt decision that preserves an adopted session’s complete execution policy and reports only known runtime facts; capability negotiation warrants some growth, while cwd lookup can reuse the existing snapshot read.

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

Yes, from source: current main records ACP cwd without passing it to Gateway-owned session state. On the proposed branch, adopting a workspace-mode session with a different requested directory preserves spawnedCwd but replaces sessionRoot; no runtime reproduction was executed during this read-only review.

Is this the best way to solve the issue?

Not yet. Persisting cwd at the Gateway owner is preferable to adding a competing chat.send override, but the create-only decision must preserve the coupled permission root and resolve attachment compatibility.

Full review comments:

  • [P1] [P1] Preserve the adopted session’s permission root — src/gateway/session-create-service.ts:1103-1106
    The new ACP sessions.create call passes the caller’s cwd, from which the handler derives sessionRoot. This guard preserves an existing spawnedCwd, but the following spread still replaces sessionRoot. Adopting a guarded/workspace session rooted at /projects/a with cwd /projects therefore leaves execution in /projects/a while expanding filesystem access to sibling projects; a narrower cwd instead blocks previously allowed files. The mutation also survives the bridge’s later rejection of a cwd-less row. Preserve the existing permission root in the same atomic adoption decision and extend the Gateway regression to cover subsequent filesystem access. This is a late discovery on the unchanged previously reviewed head.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: ACP project-scoped turns still use the wrong workspace on main, affecting an established agent workflow.
  • merge-risk: 🚨 compatibility: Existing explicit-session clients can fail against older Gateways or cwd-less session rows.
  • merge-risk: 🚨 session-state: The new provisioning call mutates an adopted session’s persisted permission root while retaining its old cwd.
  • merge-risk: 🚨 security-boundary: Changing sessionRoot changes the filesystem containment enforced for guarded and workspace-mode agent tools.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Authority-chain proof required: the recorded real ACP-to-Gateway traces validly demonstrate fresh-session cwd propagation, but do not show an adopted guarded/workspace session retaining its filesystem boundary through subsequent I/O or after a rejected setup. Add redacted terminal/log evidence that an inside-root operation succeeds and a formerly forbidden sibling path remains denied after adoption and reopen. Updating the PR body should trigger re-review; otherwise ask a maintainer for @clawsweeper re-review. 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.

Evidence

Security concerns:

  • [medium] Adoption can widen an existing filesystem boundary — src/gateway/session-create-service.ts:1106
    The bridge now invokes session creation during attachment, and its requested directory replaces sessionRoot even when cwdOnCreateOnly preserves the existing cwd. Guarded/workspace tool construction subsequently consumes that new root, permitting paths outside the session’s previous boundary.
    Confidence: 0.98

What I checked:

  • Pinned introduction and review continuity: Inspected the merge-base-to-head changes. The previous completed review used this same head; comparing its lifecycle and session-create files against HEAD produces no changes. The permission-root finding is therefore a late discovery. (src/gateway/session-create-service.ts:1103, 6253b07cdc5e)
  • Current main still lacks the fix: newSession stores params.cwd only in the bridge session store and does not provision a Gateway session. The prompt path sends chat.send without cwd. No merged replacement was established by the related-item review or targeted GitHub search. (src/acp/translator.session-lifecycle.ts:68, ec7fed214284)
  • Latest release behavior: The supplied latest release, v2026.9.4, also stores cwd only in ACP memory during newSession; the requested propagation is not present there. (src/acp/translator.session-lifecycle.ts:68, 3a9d69db306c)
  • Adoption preserves cwd but replaces its permission root: The newly introduced sessions.create call supplies the ACP request directory. The handler derives sessionRoot from that directory and forwards it. The service guards spawnedCwd with createdNewEntry but unconditionally spreads sessionRoot into the adopted row. (src/gateway/session-create-service.ts:1106, 6253b07cdc5e)
  • Permission-root change reaches filesystem enforcement: get-reply-run-execute passes persisted permissionMode and sessionRoot into the run; attempt-setup forms the session permission policy. Agent tool construction uses its root for containment. Existing agent-tools.session-permissions tests establish that guarded/workspace modes permit files inside this root and reject outside files. (src/agents/agent-tools.ts:528, 6253b07cdc5e)
  • Adoption regression coverage misses the coupled field: The new Gateway adoption test checks that spawnedCwd remains the owner's directory, but does not check sessionRoot or exercise a subsequent filesystem operation. The ACP fixture likewise models only spawnedCwd in the create response. (src/gateway/server.sessions.create.test.ts:2097, 6253b07cdc5e)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Preserve the adopted permission root and demonstrate allowed versus outside-root filesystem effects after adoption and reopen.
  • Resolve the explicit-session compatibility choice and update the PR body’s outdated degradation claims.
  • Reconcile the conflicts and rerun focused ACP lifecycle and Gateway session-create validation.

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 (26 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-16T10:23:40.655Z sha d3d2d28e83c46c6bc790a4283ccce80581a75b24 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-16T18:10:50.499Z sha b3dae5f82151c0f2fc5f735ad1d0b9cf5e2fe8a2 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-16T18:27:54.436Z sha e8e145d70b608d18ab361b3290456acf6b120187 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-17T13:06:56.247Z sha bcd10f409918fe3e5a24a4cdbbd4ed1a580ad21a :: needs maintainer review before merge. :: none
  • reviewed 2026-08-17T17:33:10.435Z sha 77c11b6ae722d9dc0500ff12d5b2dac9fd96cbcd :: needs maintainer review before merge. :: none
  • reviewed 2026-08-18T06:04:24.798Z sha 6253b07 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-23T03:58:30.265Z sha 6253b07 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-29T09:14:00.146Z sha 6253b07 :: needs maintainer review before merge. :: none

@Chinmayrawat15

Copy link
Copy Markdown
Contributor Author

Rank-up move addressed — the PR body now carries the requested real-behavior proof.

The ask was: "Add a redacted ACP stdio-to-isolated-Gateway transcript showing session/new, a prompt, the persisted Gateway row, and the observed agent cwd." All four are now in the Evidence section, and I ran the harness twice — once on this branch and once with only src/acp/translator.session-lifecycle.ts reverted to pre-fix and the dist rebuilt — so it is a before/after on the real boundary rather than an after-only capture.

Harness is all real processes: built openclaw acp stdio bridge → real Gateway on its own port with an isolated OPENCLAW_STATE_DIR → the repo's own mock provider (scripts/e2e/mock-openai-server.mjs via qa-lab buildQaGatewayConfig, providerMode: "mock-openai").

Observation Before After
Gateway RPCs on session/new + prompt sessions.list, chat.send sessions.create
session_nodes.entry_json.spawnedCwd None $ROOT/project
System prompt ## Workspace → Working directory: $ROOT/workspace $ROOT/project
Default-workspace hits in model payload 8 0
session/new with cwd: "relative/project" accepted rejected

The observed agent cwd is the decisive one. Pre-fix, the model receives two contradictory statements in the same turn — the bridge's message prefix says [Working directory: $ROOT/project] while the system prompt's own ## Workspace section says Working directory: $ROOT/workspace. That is the reported defect visible in the model's actual input, and it is what the fix removes.

Two notes on the evidence, for transparency:

  • My first end-to-end attempt could not complete a turn on this machine — the default route reached the Codex harness and failed on a missing @openai/codex-darwin-arm64 optional dependency, unrelated to this change. I moved to the repo's mock-provider harness rather than report a turn I had not actually observed.
  • An automated substring check initially reported the agent cwd as correct on the pre-fix run. That was a false positive: it matched the bridge's informational message prefix, not the system prompt's workspace section. The table above uses the ## Workspace line, which is the one derived from the Gateway's resolved cwd.

Remaining gap is stated in the PR body: pnpm check:changed routes to Crabbox, which is unavailable from this machine, so the static gates ran locally per AGENTS.md.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Aug 14, 2026
@Chinmayrawat15

Copy link
Copy Markdown
Contributor Author

Finding addressed: [P1] Provision non-existing explicit session keys — you were right, and the PR body is updated.

My earlier guard treated "explicit route" as a proxy for "operator-owned session already exists". That assumption is wrong: requireExisting defaults to false, so _meta.sessionKey / --session routes through unresolved and the row may not exist at all — leaving exactly the reported default-workspace behavior on that path. I had considered this case while scoping and talked myself out of it; the finding is correct.

The fix now branches on row existence rather than routing category, which covers both merge risks you listed:

  • row absent (bridge-minted key, or an explicit key that does not exist yet) → create it with the requested cwd.
  • row present (operator-owned) → leave untouched, so spawnedCwd is never overwritten.

newSession already fetched that row immediately afterwards via getSnapshot, just past the decision point and swallowing the miss. I made the non-throwing lookup the primitive (findExistingSnapshot), had getExistingSnapshot delegate to it, and reuse the fetched snapshot — so the routed path costs no extra Gateway round trip, and the duplicated snapshot-construction branch is gone.

Refreshed proof, as requested — same real harness (built openclaw acp stdio → real isolated Gateway → repo mock provider), now exercising both routes in one run:

Route Session key Persisted spawnedCwd System prompt Working directory: Turn
bridge-minted agent:qa:acp-bridge:72d8f8cd… $ROOT/project-a ✅ $ROOT/project-a ✅ end_turn
explicit _meta.sessionKey agent:qa:acp-explicit-proof $ROOT/project-b ✅ $ROOT/project-b ✅ end_turn

The default workspace appears in neither model payload, and the relative-cwd rejection still holds.

Two things I want to flag rather than leave implicit:

  • The [ws] gateway log records only failed or slow responses (ok === false || durationMs >= DEFAULT_WS_SLOW_MS, src/gateway/ws-log.ts:395, 50 ms). It shows one sessions.create 163ms for the cold create and nothing for the faster second one, so it is not a complete RPC census — the persisted rows and model payloads are the authoritative signal. I had cited that line in the previous body and did not want it over-read.
  • Test quality: my earlier mock returned { ok: true } for sessions.list, which does not match the shape the lookup path reads. It now returns a realistic payload, so the existence probe is genuinely exercised instead of stubbed past.

Production LOC is +24 / −3 (tests +87), above the net-≤0 default. Naming it rather than burying it: the growth is the ownership boundary — distinguishing an absent row from an operator-owned one is the correctness requirement here, and collapsing it into a smaller guard reintroduces one of the two failure modes. The getExistingSnapshot refactor gives part of it back. Two narrow accepted tradeoffs (a same-key concurrent-create window, and a rare inert orphaned row) are documented in the PR body with the reasoning for each.

Full ACP suite: 182 files / 1442 tests green. autoreview clean on both revisions.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 14, 2026
@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime labels Aug 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 14, 2026
@Chinmayrawat15

Copy link
Copy Markdown
Contributor Author

Finding addressed: [P1] Make routed session creation atomic — you were right that a check-then-create cannot hold this invariant from outside the Gateway, and the decision has moved inside the mutation exactly as you described.

sessions.create gains an opt-in cwdOnCreateOnly, applied where the mutation already computes whether it created the row — beside the existing rule that adoption must not stamp new-row facts (provenance, visibility, projectId). The bridge now calls create unconditionally with that flag:

  • new row → the requested cwd is persisted.
  • existing row → the owner's cwd is untouched, no matter when that row appeared.

This resolves all three merge risks together. A missing explicit key still gets its cwd; an operator-owned row is safe with no probe window; and because the bridge no longer reasons about existence at all, the ACP-side probe and the duplicate snapshot branch are deleted rather than added to — I also reverted the findExistingSnapshot refactor from the prior revision, since it stopped earning its keep. Callers omitting the flag keep exactly the previous behavior.

The race is now proven deterministically. A Gateway test creates a session with one directory, then issues a second sessions.create for the same key with a different cwd and the flag set — the interleaving where the row already exists by the time the create lands. Removing the guard fails it for precisely the right reason:

× sessions.create cwdOnCreateOnly leaves an adopted session's directory to its owner
AssertionError: expected '/tmp/acp-project' to be '/tmp/owner-project'

A companion test proves the flag still sets the directory on a genuinely new row.

Refreshed proof. I re-ran the real ACP-stdio → isolated-Gateway harness against this build (not the previous one), covering both routes in one run: bridge-minted → project-a and explicit _meta.sessionKey → project-b, each persisted and observed in the system prompt the model received, with zero default-workspace occurrences and the relative-cwd rejection intact.

Protocol follow-through: the field is additive and optional; I regenerated the Swift bindings (Bool? + coding key) in this PR. Kotlin and dist/protocol.schema.json were unchanged. It does not reach model-visible prompt text — the agent-facing session tool schema is declared separately in src/agents/tools/sessions-spawn-visible.ts, and no protocol-only field appears in the prompt snapshots. I ran the whole protocol gate locally, including the git diff --exit-code over all four generated paths; checks-fast-bundled-protocol is green on this head.

On the two points about the SDK contract and LOC:

  • The absolute-cwd wording is at @agentclientprotocol/sdk dist/schema/types.gen.d.ts:4649 — "The working directory for this session. Must be an absolute path." — cited in the body now that you noted it was not independently inspectable on your side. Agreed the Gateway enforces the same rule independently.
  • Production is +24 / −2. Still above net-≤0, and I would rather name it than bury it: the growth is the public protocol capability plus the ACP contract assertion. Moving the decision to the Gateway is what turned the ACP-side probe from an addition into a deletion.

One non-green check, and it is not this change: check-lint shows conclusion: cancelled, not failed, with its "Run check shard" step never completing. The previous occurrence logged every lane as finished with zero violations before the runner received a shutdown signal (exit 143 = SIGTERM) in oxlint:extensions, a lane this PR does not touch, while main was independently red at the same time. Every lint lane covering these files passes locally. I cannot re-run workflows from a fork — happy to push a no-op commit if you would rather re-fire it.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@Chinmayrawat15

Copy link
Copy Markdown
Contributor Author

Both findings answered. One is fixed; the second is the owner decision you asked for, and I have evidence that narrows it.

[P1] Reject or synchronize an adopted session's cwd — fixed

Good catch, and it is the original defect relocated rather than a new one: with the Gateway keeping an adopted row's directory, the bridge was still storing the requested cwd in its own session state, and both the visible [Working directory: …] prefix and the provenance receipt are built from that state. An adopted session would therefore tell the model one directory while running in another — the same false confirmation #123557 is about.

The bridge now reads the authoritative value back instead of assuming its request won:

const created = await this.gateway.request<{ entry?: { spawnedCwd?: string } }>("sessions.create", …);
const sessionCwd = normalizeOptionalString(created?.entry?.spawnedCwd) ?? params.cwd;

The Gateway owns the run directory, so the bridge records what the turn will actually use. Fresh sessions are unaffected (the row reports the requested cwd back). New regression test, failing pre-fix for the right reason:

× reports the directory the Gateway kept when it adopts an existing session
AssertionError: expected '/tmp/my-project' to be '/tmp/owner-project'

[P1] Negotiate the new Gateway request field — owner decision, with precedent

You flagged this as requiring an owner decision, so I am not going to bump PROTOCOL_VERSION unilaterally — AGENTS.md reserves that for explicit owner confirmation. What I can add is the repo's own precedent for this exact schema, because it makes the question narrower than it first looks:

So an optional additive request field on this schema has twice shipped without negotiation, and the older-Gateway exposure being described applies identically to projectId and cwd today. PROTOCOL_VERSION is 4 with MIN_CLIENT_PROTOCOL_VERSION 4, so the pairing at issue is same-version skew between builds, not a cross-version pairing.

I would rather state the residual risk plainly than argue it away: because the params object is closed, a Gateway built before this field would reject session/new outright rather than degrade. If you want that eliminated, the cheapest correct option is capability advertisement (send the field only when the Gateway announces it), and I am happy to implement whichever shape you prefer — I just did not want to invent a negotiation surface or advance a protocol version on my own judgment.

One thing I would push back on gently: dropping the field and returning to a caller-side probe would reintroduce the P1 race from the previous round, so "remove it" is not a safe resolution to this one.


Also still standing, and not caused by this change: check-lint reports conclusion: **cancelled**, not failed, with its "Run check shard" step never completing. The earlier occurrence logged every lane finished with zero violations before the runner took a shutdown signal (exit 143 = SIGTERM) in oxlint:extensions, a lane this PR does not touch. checks-fast-bundled-protocol is green after I regenerated the Swift bindings.

Full ACP suite 182 files / 1442 tests green; autoreview clean at 0.85.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 14, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

The bridge decided whether a Gateway row existed by probing sessions.list and
then calling sessions.create, so a row created between the probe and the write
was adopted and had its owner's spawnedCwd overwritten by the bridge's cwd.

sessions.create gains an opt-in cwdOnCreateOnly, applied where the mutation
already knows whether it created the row. The bridge now calls create
unconditionally with that flag, which removes the probe and the duplicate
snapshot branch while making absence a Gateway-owned decision.
Additive optional field on SessionsCreateParams; existing clients decode
unchanged.
When the Gateway adopts an existing session row it keeps that row's
spawnedCwd, but the bridge stored the requested cwd in its own session
state. The visible working-directory prefix and the provenance receipt are
built from that state, so an adopted session told the model one directory
while the turn ran in another.

The bridge now reads spawnedCwd back from the create response and records
that, falling back to the requested cwd when no entry is returned.
An adopted session key that carries no working directory runs in the agent
workspace. The bridge fell back to the requested cwd in that case, so the
visible directory prefix and provenance receipt claimed a directory the agent
never used - the same contradiction this fix removes elsewhere.

A create that passes a cwd always returns one for a new row, so a missing
spawnedCwd identifies that case. session/new now fails with what to do instead.

Shared translator test helpers model the sessions.create response the bridge
reads, so partial mocks stop hiding this path behind a bare ok payload.
sessions.create params are a closed schema, so an ACP bridge that always sent
cwdOnCreateOnly would make session/new fail outright against a Gateway built
before the field, turning a bridge upgrade into a hard error.

The Gateway now advertises sessions.create.cwdOnCreateOnly in its hello
capabilities, the client retains the advertised set per connection, and the
bridge sends the field only when it is offered.

Against a Gateway without it the bridge still provisions its own minted keys,
whose fresh ids cannot collide with an operator-owned row, and leaves
explicitly routed keys alone rather than risk overwriting someone else's
working directory.
The degraded path still started a session reporting the requested directory
while the turn could use an adopted row's own directory or the agent
workspace - the same contradiction this branch removes everywhere else.

Routing an explicit key with a cwd to such a Gateway now fails with what to
do instead. Bridge-minted keys are unaffected: nothing else can own a fresh
id, so applying the directory there is safe.
… cwd

Three related directory defects:

Reset ran inside session-key resolution, before the capability gate and the
create that carries the cwd. A requested reset could materialize a bare row
that the create then adopted without a directory, and a routed request could
be reset before being refused. Resolution no longer mutates; callers place
their own reset, and session/new resets only after the row carries its cwd.

loadSession and resumeSession stored the caller's cwd while attaching to a
Gateway row that owns a different one, so prompt text and provenance could
describe a directory the turn never used. Both now report the row's value.

The client also drops server capabilities when the connection closes, so a
reconnect onto an older Gateway cannot reuse the previous build's
advertisement before its hello arrives.
An adopted Gateway session often records no directory - a session created
without cwd, worktree, or project clears the field - so load and resume fell
back to the caller's path and presented it as the runtime workspace through
the prompt prefix and the provenance receipt.

Sessions now carry whether their cwd is the directory Gateway will run in.
Adoption keeps working and still reports the row's directory when it has one;
when it does not, the bridge omits the claim instead of substituting the
request. Refusing instead would have failed load and resume for ordinary
sessions, which record no directory by design.
main deleted the cleanup-only store seam in openclaw#124043 because each test builds
its own store. This branch predated that and its new cases still called it,
which broke the merged result at both type-check and runtime.
`translator.lifecycle.test.ts` landed upstream after this branch was cut,
and its gateway mocks return a bare `{ ok: true }` for every unstubbed
method. `session/new` now reads `sessions.create`'s `entry.spawnedCwd`
back to decide whether the Gateway kept the requested directory, so a
mock that does not model that response looks exactly like an existing row
with no directory, and the bridge correctly refuses the request.

`acpGatewayDefaultResponse` already exists for this — its docstring asks
partial mocks to fall through to it so they keep modelling the responses
they do not stub. These mocks predate it. Routing all twelve through it
fixes the failure and stops the next unstubbed Gateway shape from
breaking the file the same way.

Test-only; no production behavior changes.
`sessions.create` now lstats the requested cwd and rejects one that is
absent (openclaw#124909, "session permission modes with worktree-scoped
defaults"), so the two cwdOnCreateOnly tests failed on the rebase with
`cwd is unavailable: ENOENT` -- they passed fabricated /tmp paths.

Switched to `tempDirs.make()`, the auto-cleanup helper the rest of this
file already uses for real cwd cases. Also merged a duplicate import of
`translator.test-helpers.js` that the rebase surfaced.

No production change; the assertions are the same, against paths that
exist.
@Chinmayrawat15
Chinmayrawat15 force-pushed the fix/acp-new-session-cwd-gateway-persistence branch from 77c11b6 to 6253b07 Compare August 18, 2026 05:57
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 29, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Sep 17, 2026
@clawsweeper clawsweeper Bot added clawsweeper-recovery-stuck merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. clawsweeper-recovery-stuck labels Sep 18, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Sep 19, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Oct 3, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

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

Labels

app: web-ui App: web-ui gateway Gateway runtime merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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. size: L stale Marked as stale due to inactivity status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ACP session/new cwd is not propagated to Gateway chat.send; agent runs in default workspace

1 participant