fix(gateway): expose idempotencyKey in chat history metadata#96273
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 06166c700d
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
Fixed by preserving idempotencyKey on oversized transcript placeholders and added coverage. Targeted gateway test passed. |
|
Codex review: needs maintainer review before merge. Reviewed June 28, 2026, 8:05 AM ET / 12:05 UTC. Summary PR surface: Source +87, Tests +80. Total +167 across 7 files. Reproducibility: yes. From source, current main persists the user-turn Review metrics: 1 noteworthy metric.
Stored data model Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Land the focused Gateway projection fix after required CI and maintainer review, then let #79844 close from the merged fix. Do we have a high-confidence way to reproduce the issue? Yes. From source, current main persists the user-turn Is this the best way to solve the issue? Yes. The PR fixes the owner boundary by surfacing already-persisted Gateway metadata through the existing projection envelope instead of adding client heuristics, config, or a storage migration. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 08d15ec32db3. Label changesLabel justifications:
Evidence reviewedPR surface: Source +87, Tests +80. Total +167 across 7 files. View PR surface stats
What I checked:
Likely related people:
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. How this review workflow works
|
|
Addressed the ClawSweeper follow-up on the latest head (
Verification run after the patch: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
…ry-idempotency # Conflicts: # src/gateway/session-utils.fs.ts
|
Updated again after merging current Latest head: Additional verification after conflict resolution: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Fixed the CI build root cause from the previous head.
Latest head Local verification after this fix: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
…w#96273) * fix(gateway): surface idempotency key in history metadata * test(gateway): avoid unsafe optional chain * fix(gateway): preserve oversized transcript idempotency keys * fix(gateway): preserve oversized idempotency keys * fix(gateway): reuse transcript json helpers --------- Co-authored-by: 吴杨帆 <[email protected]>
…w#96273) * fix(gateway): surface idempotency key in history metadata * test(gateway): avoid unsafe optional chain * fix(gateway): preserve oversized transcript idempotency keys * fix(gateway): preserve oversized idempotency keys * fix(gateway): reuse transcript json helpers --------- Co-authored-by: 吴杨帆 <[email protected]>
…w#96273) * fix(gateway): surface idempotency key in history metadata * test(gateway): avoid unsafe optional chain * fix(gateway): preserve oversized transcript idempotency keys * fix(gateway): preserve oversized idempotency keys * fix(gateway): reuse transcript json helpers --------- Co-authored-by: 吴杨帆 <[email protected]>
…w#96273) * fix(gateway): surface idempotency key in history metadata * test(gateway): avoid unsafe optional chain * fix(gateway): preserve oversized transcript idempotency keys * fix(gateway): preserve oversized idempotency keys * fix(gateway): reuse transcript json helpers --------- Co-authored-by: 吴杨帆 <[email protected]>
Restored replacement for #94438 after the fork/head repository was recreated.
Summary
__openclawtranscript metadata during history hydrationsession.messagebroadcasts, and oversized history placeholderscontentcan appear beforeidempotencyKeyFixes #79844.
Verification
node_modules/.bin/vitest run --config test/vitest/vitest.gateway.config.ts src/gateway/session-utils.fs.test.ts --reporter=dotTest Files 3 passed (3)Tests 279 passed (279)node_modules/.bin/oxfmt --check --threads=1 src/gateway/session-utils.fs.ts src/gateway/session-utils.fs.test.tsAll matched files use the correct format.git diff --checkReal behavior proof
Behavior addressed: Clients can correlate optimistic user bubbles with hydrated or live Gateway messages via
__openclaw.idempotencyKeyinstead of text/FIFO heuristics.Real environment tested: Local OpenClaw checkout on this PR branch (
codex/chat-history-idempotency-key-79844-reopen-20260618, head14643e647e) running a real loopback Gateway process with a temporary home/state directory. Channels were skipped for isolation, and the Gateway usedauth noneon127.0.0.1only. The placeholder CLI token below only satisfies the CLI URL-override credential guard; it is not a real secret.Exact steps or command run after this patch:
Evidence after fix: Terminal output from the real Gateway RPC flow showed
chat.sendstart,agent.waitcomplete, andchat.historyreturning__openclaw.idempotencyKeymetadata. Thechat.historypayload below is trimmed to the relevant fields only.{ "runId": "proof-96273-idem", "status": "started" }{ "runId": "proof-96273-idem", "status": "ok", "endedAt": 1782646473456 }{ "sessionKey": "main", "sessionId": "9f903a13-93c6-4e2f-9de7-60f540ab4862", "messages": [ { "role": "user", "content": "/context list", "idempotencyKey": "proof-96273-idem:user", "__openclaw": { "id": "5ddebe51-952a-43b1-8a73-98bd2e8d3ffd", "idempotencyKey": "proof-96273-idem:user", "seq": 1 } }, { "role": "assistant", "idempotencyKey": "proof-96273-idem", "model": "gateway-injected", "__openclaw": { "id": "9e1d8024-44a5-41fe-9a07-22f924ccdbeb", "idempotencyKey": "proof-96273-idem", "seq": 2 } } ], "sessionInfo": { "hasActiveRun": false, "lastChannel": "webchat" } }Observed result after fix: A real local Gateway accepted
chat.send, completed the slash-command run, and returned hydratedchat.historymessages with the persisted idempotency keys in both the direct message field and__openclaw.idempotencyKey. The oversized production-order case is covered by the updatedsession-utils.fs.test.tsregression, which now writescontentbeforeidempotencyKeyand passed in the full file run above.What was not tested: Native/mobile/web UI rendering was not exercised, and no external model call was made;
/context listcompleted through Gateway's injected command path without provider credentials. The live proof covers the real Gateway RPC/history surface, while the oversized large-content edge case is covered by focused Gateway regression tests.Reopened after active-PR limit cleanup. Supersedes closed PR #94398.
What Problem This Solves
Clients that optimistically render user messages need the persisted user-message idempotency key to appear in hydrated
chat.historyresponses and live Gatewaysession.messagemetadata. Without that key in__openclaw, clients have to fall back to text ordering or FIFO heuristics to correlate optimistic bubbles with server messages.Evidence
After this patch, a real local Gateway
chat.send -> agent.wait -> chat.historyflow shows the persisted useridempotencyKeybeing surfaced in hydrated__openclawmetadata. Focused Gateway tests also cover inline SSE history state,session.messagemetadata, and oversized production-order transcript lines. Local validation ran formatting andgit diff --checksuccessfully.