fix(agent): support explicit CLI session keys#85121
Conversation
|
Codex review: passed. Workflow note: Future ClawSweeper reviews update this same comment in place. How this review workflow works
Summary Reproducibility: yes. Current main's PR rating Rank-up moves:
What the crustacean ranks mean
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. Real behavior proof Risk before merge
Maintainer options:
Next step before merge Security Review detailsBest possible solution: Land the shared normalization/validation implementation after maintainers accept the documented session-key scoping contract, or request a narrow semantics-only adjustment before merge. 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, if maintainers accept the semantics. Reusing the existing Gateway field and centralizing legacy-key normalization in routing helpers is the narrow maintainable path; the only open question is the documented scoping policy. Label justifications:
What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against b8e9ab9385c0. |
|
ClawSweeper PR egg ✨ Hatched: 🥚 common Gilded Clawlet Hatch commandComment Hatchability rules:
Rarity: 🥚 common. What is this egg doing here?
|
|
@clawsweeper re-run |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper automerge |
|
🦞✅ Source: What merged:
Automerge notes:
The automerge loop is complete. Automerge progress:
|
34c87c2 to
2c76dd3
Compare
Problem
openclaw agentcan target an agent,--to, or--session-id, but it has no direct way to target a known session key. Operators and scripts that already have an exact stored key need to reverse-map through session ids or choose a less precise selector. PR #35241 tried to add this surface but appears abandoned; the CLI gap is still present.Change and value
This adds
--session-key <key>toopenclaw agentand carries that selector through Gateway dispatch, local embedded runs, and embedded fallback. Agent-prefixed keys are accepted as exact keys; malformedagent:keys and--agent/key mismatches fail before dispatch.Legacy bare-key behavior is kept predictable:
--agent, bare non-sentinel keys are scoped to that agent.--agent, bare non-sentinel keys are scoped to the configured default agent.globalandunknownremain unscoped when no--agentis provided, while store/fallback ownership uses the configured default agent.Implementation
--session-keyforopenclaw agentand forwards it through CLI options.agentCommandcallers.Verification
Local, after rebasing onto
origin/mainba06376c79550e52bfb51008a0622bed4dc53637:timeout 180s node scripts/run-vitest.mjs run --config test/vitest/vitest.commands.config.ts src/commands/agent-via-gateway.test.ts src/commands/agent.test.ts- 52 tests passedtimeout 180s node scripts/run-vitest.mjs run --config test/vitest/vitest.unit-fast.config.ts src/routing/session-key.test.ts- 70 tests passedtimeout 180s node scripts/run-vitest.mjs run --config test/vitest/vitest.cli.config.ts src/cli/program/register.agent.test.ts- 15 tests passedtimeout 120s node scripts/check-docs-mdx.mjs docs/cli/agent.md docs/tools/agent-send.md- passedtimeout 120s /home/captain/openclaw-source/node_modules/.bin/oxfmt --check --threads=1 ...- passed on the 11 changed filesgit diff --check origin/main...HEAD- passedtimeout 60s node --import tsx src/entry.ts agent --help- showed--session-key <key>timeout 60s node --import tsx src/entry.ts agent --message hi --session-key agent:main --json- rejected malformedagent:key before dispatchtimeout 60s node --import tsx src/entry.ts agent --message hi --agent ops --session-key agent:main:incident-42 --json- rejected--agent/session-key mismatch before dispatchRemote, exact pushed head
34c87c28a0736c1b782ad47a9df00ffcf0b395fdon GCP Crabbox Spote2-standard-8,us-east1-b, Nodev24.15.0, pnpm11.0.8, base/merge-baseba06376c79550e52bfb51008a0622bed4dc53637:pnpm check:changed- passednode scripts/run-vitest.mjs run --config test/vitest/vitest.commands.config.ts src/commands/agent-via-gateway.test.ts src/commands/agent.test.ts- 52 tests passednode scripts/run-vitest.mjs run --config test/vitest/vitest.unit-fast.config.ts src/routing/session-key.test.ts- 70 tests passednode scripts/run-vitest.mjs run --config test/vitest/vitest.cli.config.ts src/cli/program/register.agent.test.ts- 15 tests passednode scripts/check-docs-mdx.mjs docs/cli/agent.md docs/tools/agent-send.md- passedA broader
pnpm test:changedattempt on GCP also passed 139 of 140 files before failing two unrelatedsrc/gateway/server.preauth-hardening.test.tshandshake-timeout assertions. I reproduced the same two failures on a cleanorigin/maincheckout, so I am treating that as inherited or environment-sensitive, not caused by this patch.Real behavior proof
Behavior or issue addressed:
openclaw agentnow accepts an explicit--session-keyselector, validates malformed or mismatched agent-prefixed keys before dispatch, and routes exact keys consistently through Gateway, embedded, and fallback paths.Real environment tested: local PR-head worktree at
34c87c28a0736c1b782ad47a9df00ffcf0b395fd, rebased ontoorigin/mainba06376c79550e52bfb51008a0622bed4dc53637; remote GCP Crabbox Spote2-standard-8inus-east1-b, Nodev24.15.0, pnpm11.0.8, exact pushed head34c87c28a0736c1b782ad47a9df00ffcf0b395fd.Exact steps or command run after this patch: local focused Vitest/doc/format/CLI commands listed above; remote fresh-clone validation ran
pnpm check:changedplus the focused command/routing/CLI tests and docs MDX check. The local CLI proof commands were:Evidence after fix: copied terminal output from the exact PR-head worktree shows the new option and the two pre-dispatch validation errors:
Observed result after fix: the CLI exposes
--session-key, accepts the documented exact-key syntax, and rejects malformed or mismatched agent-prefixed keys before dispatch. Existing--to,--session-id,--agent, delivery, model override, and fallback behavior remains covered by the focused command/routing/CLI test set and the remotepnpm check:changedrun on the pushed head.What was not tested: I did not dispatch a live provider-backed agent turn or send a real channel delivery message; the changed behavior here is the selector surface and pre-dispatch routing/validation path, so validation used CLI output plus dispatch/local/fallback tests to avoid sending a real model/channel request from CI.