Repository navigation
Description
Bug type: Bug (CLI write path fails; read path works)
Summary
On 2026.6.1, all CLI write commands fail. openclaw message send, broadcast, and probe crash the gateway's WS message handler during the connect handshake. Read commands (openclaw channels status) work fine. The gateway daemon itself is healthy (Telegram/WhatsApp/webchat all deliver normally).
Steps to reproduce
openclaw message send --channel telegram --account <acct> --target <id> --message "test"
Actual behavior
CLI output:
Bind: loopback); resolved command secrets locally.
gateway connect failed: Error: gateway closed (1000):
GatewayTransportError: gateway closed (1000 normal closure): no close reason
Gateway target: ws://127.0.0.1:18789
Source: local loopback
Bind: loopback
With --json/debug the CLI also prints:
[secrets] message: gateway secrets.resolve unavailable (gateway closed (1000 normal closure): no close reason ...); resolved command secrets locally.
Gateway logs (reproducible 100%, crash happens within ~milliseconds, NOT a timeout):
[gateway] parse/handle error: TypeError: Cannot read properties of undefined (reading 'trim')
[ws] ✗ parse-error error=TypeError: Cannot read properties of undefined (reading 'trim') conn=<id>
[ws] closed before connect conn=<id> peer=127.0.0.1:...->127.0.0.1:18789 ... code=1000 reason=n/a
Root cause (analysis)
- Write commands resolve SecretRefs via a
secrets.resolvecall against the gateway before sending (seedist/command-secret-gateway-*.js). Read commands do not, so they never hit the failing path. - The gateway's connect/message handler that prints
parse/handle errorlives atdist/message-handler-Du1uvc4A.js:1815. A.trim()is invoked on a field that arrivesundefinedwhile parsing the connect frame from the write path. Sibling fields (nonce, instanceId) are guarded withtypeof === "string"but this one is not, so the handler throws and the socket is closed with code 1000 before connect completes. - The CLI then falls back to
resolved command secrets locally, but without resolved secrets the send cannot complete.
Not the same as #47103
#47103 (gateway closed (1000)) had the same visible symptom but root cause = handshake timeout (fix = restore 10s timeout). This is different. Verified empirically: raising OPENCLAW_HANDSHAKE_TIMEOUT_MS=30000 and OPENCLAW_CONNECT_CHALLENGE_TIMEOUT_MS=30000 does NOT help — the crash still occurs in milliseconds with the same .trim() TypeError. This is an unguarded .trim() on an undefined connect-frame field, not a timing issue.
Environment
- OpenClaw version: 2026.6.1 (latest on npm at time of report)
- OS: Debian (GCP VM), Node v24.15.0
- Install: npm global
- Gateway bind: loopback,
gateway.auth.mode: token - Reproduces with token present in env (
OPENCLAW_GATEWAY_TOKEN, 64 chars) — not a missing-token issue.
Impact
All CLI-driven message sending is broken. Workaround: use native gateway delivery (session replies, cron delivery: announce) instead of the CLI. Read-only CLI commands are unaffected.
Suggested fix
Guard the .trim() at message-handler-Du1uvc4A.js:1815 (and the secrets.resolve connect path) with typeof === "string" like the sibling nonce/instanceId reads, and/or validate the connect frame field before trimming so a malformed/absent field returns a proper handshake error response instead of throwing inside the parse handler.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 5, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 15, 2026, 8:39 AM ET / 12:39 UTC.
Summary
Current main still contains the unguarded gateway handshake trim path, and the issue is already paired with an open, cleanly mergeable, proof-positive closing PR, so it should remain open until that PR merges or is rejected.
Reproducibility: yes. Current-main source still contains the unguarded trim paths, and the linked PR documents a real gateway WebSocket reproduction using malformed persisted pairing state.
Next step
Do not queue duplicate repair work because #92178 is already open, cleanly mergeable, and proof-positive.
Review details
Best possible solution:
Land #92178 after maintainer review, then close this issue with merge and release provenance.
Do we have a high-confidence way to reproduce the issue?
Yes. Current-main source still contains the unguarded trim paths, and the linked PR documents a real gateway WebSocket reproduction using malformed persisted pairing state.
Is this the best way to solve the issue?
Yes. The open linked PR fixes the runtime boundary in both the audit formatter and pairing merge helpers; earlier secrets.resolve-only attempts targeted the wrong layer.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning high; reviewed against d1b33a6040a4.
Label changes
Label changes:
issue-rating: 🦞 diamond lobster: Current issue advisory state selects this label.clawsweeper:source-repro: Current issue advisory state selects this label.clawsweeper:current-main-repro: Current issue advisory state no longer selects this label.issue-rating: 🦀 challenger crab: Current issue advisory state no longer selects this label.Label justifications:
P1: The issue blocks established CLI send, broadcast, and probe workflows for affected users.impact:message-loss: The gateway closes during connection setup before requested CLI outbound messages can be delivered.Evidence reviewed
What I checked:
item.trim()without a runtime type guard on current main. (src/gateway/server/ws-connection/message-handler.ts:1179, d1b33a6040a4)role.trim()andscope.trim()on persisted array entries without filtering non-strings first. (src/infra/device-pairing.ts:241, d1b33a6040a4)formatAuditListupgrade-audit path and unguarded pairing merge trim calls, so this is not already shipped fixed. (src/gateway/server/ws-connection/message-handler.ts:1119, 8c802aa68351)VISION.md:22, d1b33a6040a4)Likely related people:
src/gateway/server/ws-connection/message-handler.ts,src/infra/device-pairing.ts)src/gateway/server/ws-connection/message-handler.ts)src/gateway/server/ws-connection/message-handler.ts,src/infra/device-pairing.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.fix(gateway): guard secrets.resolve handler against undefined fields
wangmiao0668000666 commentedon Jun 11, 2026
I'd like to work on this. The fix is straightforward: add a
typeof item === "string"guard before calling.trim()in the gateway handshake audit formatter, matching the pattern already used for sibling fields like nonce/instanceId. I'll also add a regression test.11 remaining items
fix(gateway): guard formatAuditList against non-string items to preve…
fix(device-pairing): guard mergeRoles/mergeScopes against non-string …
fix(device-pairing): guard role normalization against non-string entr…
fix(device-pairing): guard role normalization against non-string entr…