Repository navigation
fix(cli): guard embedded agent state ownership for --local runs - #120896
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 9, 2026, 2:42 AM ET / 06:42 UTC. ClawSweeper reviewWhat this changesThis PR makes Merge readinessKeep this focused maintainer-authored repair open for normal review; current main still permits the concurrent state-owner path, and the branch adds the shared lock at the correct boundary without a source-proven regression. Priority: P1 Review scores
Verification
How this fits togetherThe agent CLI can either send a turn to the Gateway or run an embedded agent locally. Both paths use agent state under the configured state directory, so the shared Gateway lock determines whether a local turn may safely start. flowchart TD
A[Operator starts local agent] --> B[State directory lock]
B --> C{Live Gateway owns state?}
C -->|Yes| D[Actionable refusal]
C -->|No| E[Embedded agent turn]
E --> F[Release state lock]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +66, Tests +187, Docs +1. Total +254 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the exclusive state-directory ownership boundary and its documented Gateway-backed alternative before merging. Do we have a high-confidence way to reproduce the issue? Yes—current main's Is this the best way to solve the issue? Yes—the shared Gateway state-directory lock is the owner boundary for this conflict; the branch also distinguishes embedded owners from actual Gateways and handles the acquisition race. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against a3d2ac7dc887. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
ClawSweeper disposition:
|
|
Merged via squash.
|
What Problem This Solves
openclaw agent --localran an embedded turn against the same agent SQLite state a live Gateway owns, with no state-directory coordination — the only guard was the session-write lease, which is scheduled for removal. Concurrent local+gateway writers could interleave on one agent DB.Why This Change Was Made
This closes the cross-process hole at the correct ownership layer (the Gateway state-directory lock) before the session-write lease is deleted. It adds a new
agent-embeddedlock role:--localrefuses to run when a live Gateway owns the state directory, with an actionable pid/port message; otherwise it holds exclusive state ownership for the run and releases it on completion or SIGINT/SIGTERM unwind. Gateway-identity probes ignore the new role, and Gateway startup errors name the actual embedded holder instead of claiming a Gateway is running.User Impact
--localagainst a running Gateway now fails fast with remediation instead of silently double-writing. There is no change when no Gateway is running.Evidence
pnpm build: passed.Named follow-up surfaces (out of scope, coordinator-tracked):
agent exec --state-dir(src/commands/agent-exec.ts:562)src/tui/embedded-backend.ts:1428)models status --probe(src/commands/models/list.probe.ts:769)src/agents/command/attempt-execution.ts:523)