CLI: add --session-key flag to openclaw agent#35241
Conversation
Greptile SummaryThis PR adds a The change is well-scoped and correctly threads the new option through the type definition ( Key observations:
Confidence Score: 4/5
Last reviewed commit: 16a2dc8
|
| const localOpts = { | ||
| ...opts, | ||
| agentId: opts.agent, | ||
| sessionKey: opts.sessionKey, | ||
| replyAccountId: opts.replyAccount, |
There was a problem hiding this comment.
Unnecessary explicit field mapping
The sessionKey field name is identical in both AgentCliOpts and AgentCommandOpts, so the ...opts spread on line 185 already carries the value into localOpts — the explicit mapping on line 188 is a no-op.
This differs from agentId: opts.agent and replyAccountId: opts.replyAccount, which are necessary because the CLI prop names differ from the command type field names. Since the field is named identically in both types, the explicit assignment can be removed.
| const localOpts = { | |
| ...opts, | |
| agentId: opts.agent, | |
| sessionKey: opts.sessionKey, | |
| replyAccountId: opts.replyAccount, | |
| const localOpts = { | |
| ...opts, | |
| agentId: opts.agent, | |
| replyAccountId: opts.replyAccount, | |
| }; |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/commands/agent-via-gateway.ts
Line: 185-189
Comment:
**Unnecessary explicit field mapping**
The `sessionKey` field name is identical in both `AgentCliOpts` and `AgentCommandOpts`, so the `...opts` spread on line 185 already carries the value into `localOpts` — the explicit mapping on line 188 is a no-op.
This differs from `agentId: opts.agent` and `replyAccountId: opts.replyAccount`, which are necessary because the CLI prop names differ from the command type field names. Since the field is named identically in both types, the explicit assignment can be removed.
```suggestion
const localOpts = {
...opts,
agentId: opts.agent,
replyAccountId: opts.replyAccount,
};
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 16a2dc84bd
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| .requiredOption("-m, --message <text>", "Message body for the agent") | ||
| .option("-t, --to <number>", "Recipient number in E.164 used to derive the session key") | ||
| .option("--session-id <id>", "Use an explicit session id") | ||
| .option("--session-key <key>", "Use an explicit session key") |
There was a problem hiding this comment.
Validate --session-key before exposing it on CLI
Adding --session-key here makes malformed keys user-reachable, but the local execution path still does not validate key shape (src/commands/agent.ts:343-373) while the gateway path explicitly rejects malformed agent: keys (src/gateway/server-methods/agent.ts:296-306). In practice, openclaw agent --session-key agent:main ... can fail gateway validation, fall back to embedded mode, and then create/use an invalid session key, causing inconsistent behavior between normal and fallback runs and potentially orphaned session history.
Useful? React with 👍 / 👎.
|
This pull request has been automatically marked as stale due to inactivity. |
|
+1 from a downstream integration. We have a near-identical use case that would benefit from this flag merging: Use case: an external agent harness (
This gives us (and presumably anyone doing per-thread/per-room isolation — agentgram, xenia, or similar) a clean namespace like Two small suggestions if the author is still around:
Would like to see this unstaled. If @zhangzhejian is unavailable, I'm happy to pick up the rebase / address review comments. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Thanks for the context here. I did a careful shell check against current Current main already carries the useful So I’m closing this older PR as already covered on Review detailsBest possible solution: Keep the current main implementation from the merged replacement PR and close this stale branch instead of trying to rebase its smaller, older diff. Do we have a high-confidence way to reproduce the issue? Not applicable as a feature PR rather than a bug report. Source inspection confirms current main now exposes and routes Is this the best way to solve the issue? Yes for current main, not for this branch. The merged replacement PR is the maintainable solution because it adds shared validation, embedded-path parity, docs, tests, and proof beyond this older two-file plumbing branch. Security review: Security review cleared: The stale branch only adds TypeScript CLI option plumbing and the superseding implementation does not introduce dependency, workflow, secret, install, or package-resolution changes. What I checked:
Likely related people:
Codex review notes: model gpt-5.5, reasoning high; reviewed against bb5010b89a5a; fix evidence: commit eb7f3b7b50c5, main fix timestamp 2026-05-22T03:08:25Z. |
|
ClawSweeper PR egg 🎁 Pass real behavior proof to wake the egg and unlock a hatchable treat. Where did the egg go?
|
|
ClawSweeper applied the proposed close for this PR.
|
Summary
--session-key <key>option toopenclaw agentCLI for explicit session key routingsessionKeythroughAgentCliOpts, validation guard,resolveSessionKeyForRequest(), and the--localfallback pathagentgram:<room_id>for per-room session isolationTest plan
pnpm tsgo— no new type errorspnpm test -- src/commands/agent/session.test— all 8 tests passopenclaw agent --session-key "agentgram:test-room" --message "hello" --json🤖 Generated with Claude Code