Skip to content

fix(gateway): return one chat history entry per user turn - #169434

Merged
obviyus merged 2 commits into
mainfrom
fix/chat-history-duplicate-user-turn
Oct 12, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/chat-history-duplicate-user-turn

Conversation

@obviyus

@obviyus obviyus commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #168843

What Problem This Solves

Fixes duplicate user turns in chat.history when a message starts with an inline directive such as /think high and continues with an ordinary prompt.

User Impact

One chat.send produces one user-history entry, preserving the original prompt and its whitespace. Standalone slash commands, native command errors, and their delivered replies keep their existing history behavior. Existing transcripts are not rewritten.

Why This Change Was Made

Regression introduced by #169026 (289d859c2babddd9f5aee9dda96fbb94c5107f70): command mirroring classified a delivered inline acknowledgement by the inbound message's / prefix. The normal user-turn owner had already persisted <run>:user; command mirroring then persisted the same input again under command-input:[channel,account,conversation,run], with array content instead of string content.

The inline-reply producer now records private inlineCommandReply metadata. Both block and final transcript-mirror admission honor that ownership fact instead of creating another command exchange. There is no content-based dedupe or text-parser heuristic. A focused suite protects producer metadata and both delivery paths; its existing producer case moved out of an oversized suite without removing assertions.

Evidence

  • Before: the whitespace Gateway RPC test failed on main-based ed1bc51edb0, expecting one user message and receiving two identical prompts (string and text-block-array shapes). The two persisted identities were traced to normal turn admission and the command mirror introduced by fix: retain delivered slash commands in conversation history #169026.
  • After: preserves model-input whitespace independently from canonical chat history passed through the real Gateway and mock provider (two turns, exact whitespace assertions, one history entry per turn). The temporary fixture from fix: Gateway regression tests fail after runtime context labeling changes #168961 was used, with its replay assertion adjusted to the stable model-prompt projection introduced by perf(agents): keep enriched user prompt history stable #167938; none of those fixture changes are in this PR.
  • The other eight gateway-rpc-chat.e2e.test.ts cases passed in the full-file run.
  • Four focused unit suites passed: 202 tests, including producer metadata, block/final mirror exclusion, and existing standalone command coverage.
  • Runtime build, tsgo:core, formatting, line-cap growth ratchet, and oxlint on the other four changed files passed. The initial raw oxlint invocation reported the pre-existing over-cap dispatch-from-config.choose-route.ts; this file has no counted-line growth.
  • Independent source review: no remaining findings.

Merge danger: two-way door. Reverting restores the old inline-acknowledgement mirroring behavior. No schema, stored-data migration, or configuration changes; the blast radius is transcript mirroring of inline command acknowledgements.

@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus
obviyus marked this pull request as ready for review October 11, 2026 22:57
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 11, 2026
@clawsweeper

clawsweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

The PR marks inline command acknowledgements so transcript mirroring does not record their accompanying user prompt twice.

Example: Send /think high\nExplain this code. through chat.send.

  • Before: chat.history contains two user entries for the same prompt.
  • After: chat.history contains one user entry while the acknowledgement still delivers.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch has no identified correctness defect; available behavioral evidence remains Gateway test-harness output.
Proof confidence 🦐 gold shrimp (3/6) This collaborator-authored PR is outside the ordinary contributor proof gate; supplied terminal output supports the changed Gateway history behavior through a real Gateway with a mock provider, rather than independent live-use evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A prompt beginning with an inline directive appears twice in conversation history and can be replayed twice to the model.
Reason: This is a narrow repair of an evidenced transcript ownership regression, and collaborator authorship establishes direction.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR fixes a source-confirmed duplicate-history regression, with no actionable code findings.

Priority: P2
Reviewed head: 14784a2ef8ae29ee74427003fdd36ae73506f3f7

Before merge

None.

Findings

None.

Agent review details

How this fits together

The shared reply dispatcher delivers command and model replies and records eligible exchanges in the session transcript used by chat.history and later model turns.

flowchart TD
A[Inbound prompt] --> B[Inline action owner]
B --> C[Normal model turn]
B --> D[Marked acknowledgement]
C --> E[Session transcript]
D --> F[Reply dispatcher]
F --> G[Command mirror admission]
G --> E
Loading

Technical review

Best possible solution:

Keep normal turn persistence authoritative for inline prompts while preserving delivered-command recording for standalone exchanges.

Do we have a high-confidence way to reproduce the issue?

Current-main source exposes the second command-input writer, and the author reports a matching failing Gateway scenario; this review executed no target code.

Is this the best way to solve the issue?

Producer-owned metadata repairs the shown ownership error without text deduplication, changing stored formats, or broadening the patch into a dispatcher refactor.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b3c7dc2af7dd.

Provenance checked

  • Shared command transcript admission changes intended behavior with a stated reason (289d859: Retain successfully delivered standalone command exchanges in history and later model context.)
  • Inline acknowledgement metadata keeps the original intent (5621979: Preserve acknowledgement metadata and delivery during continuing model turns.)
  • Reply dispatch phase ownership keeps the original intent (127b781: Separate dispatch phases while preserving their behavior and shared prepared state.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +3, Tests +54. Total +57 across 5 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 3 12 9 +3
Tests 2 90 36 +54
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 102 45 +57

Review metrics

Metric Value Why it matters
Production versus test changes Production +12/-9; tests +90/-36 The small ownership repair covers both mirror paths and relocates an existing producer test without removing its assertions.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Inline directive prompts can duplicate stored user turns and subsequent model context, with a limited, identifiable trigger.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-11T23:04:29.995Z sha 3b36d1f :: needs changes before merge. :: none

Reviewed October 11, 2026, 8:01 PM ET / October 12, 2026, 00:01 UTC (Revision 2).

@obviyus

obviyus commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator Author

Runtime evidence for the Gateway scenario (test/e2e/qa-lab/runtime/gateway-rpc-chat.e2e.test.ts > "preserves model-input whitespace independently from canonical chat history"):

Before (main-based head ed1bc51): chat.history returned two user entries for one chat.send of /think high plus a prompt. Both had the same text; one was persisted under <run>:user, the other under command-input:[channel,account,conversation,<same run>] (rawSeq 1 and 5). The test failed at expect(userMessages).toHaveLength(1): received 2.

After (this head 3b36d1f, with #168961's fixture changes applied temporarily and removed before commit):

 ✓ test/e2e/qa-lab/runtime/gateway-rpc-chat.e2e.test.ts > Gateway chat RPCs > preserves model-input whitespace independently from canonical chat history 15144ms
 Test Files  1 passed (1)
  • Both turns pass, including user-message counts and byte-exact whitespace interiors.
  • The other 8 gateway-rpc-chat cases pass on the same build.
  • 202 unit tests pass in dispatch-from-config, inline-actions and reply-payload, covering standalone and native command history and validation-error history.

CI note: the checks-ui-e2e failures (board-mcp-app, chat-history-prepend-anchor, chat-scroll) also fail on unrelated branches right now (dbasync/discovery-images, solid2/w-chat-8a, fix/silent-reply-reasoning-closing-line, fix/whatsapp-canonical-turn-config). The failed jobs have been rerun once.

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 12, 2026
@obviyus

obviyus commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override (Ayaan approved landing): the only red job on this head (14784a2) is checks-ui-e2e (5/7), which is inherited from main, not caused by this diff.

  • The failing test is ui/src/e2e/tool-titles.e2e.test.ts > "renders recorded and live execution". It is a mocked-Gateway Control UI test that times out waiting for .chat-activity-group … .chat-tool-children .chat-tool-row--running, the nested activity rows that broke on main during the Solid migration. fix(ui): restore chat disclosure and media lifecycles #169468 restores them (its chat-activity-layout / chat-activity-disclosure repairs).
  • This PR touches only server-side auto-reply files (reply-payload.ts, dispatch-from-config.choose-route.ts, get-reply-inline-actions.ts + tests) and no UI code.
  • Its own regressions pass, and the Gateway gateway-rpc-chat whitespace scenario it fixes passes locally (evidence above). ClawSweeper is ready on this exact head.

@obviyus
obviyus merged commit 0b73362 into main Oct 12, 2026
114 of 127 checks passed
@obviyus
obviyus deleted the fix/chat-history-duplicate-user-turn branch October 12, 2026 00:16
obviyus added a commit that referenced this pull request Oct 12, 2026
…rns (#169475)

## What Problem This Solves

Fixes the WebChat media-artifact proof treating a revision of one user message as a duplicate user turn. This is an explicitly requested main CI repair.

## User Impact

No product behavior changes. The proof still rejects duplicate canonical user turns and still checks every supported/rejected media outcome.

## Why This Change Was Made

The user-turn owner publishes the initial transcript append and then a revision of that same message when its first-sent model prompt projection is captured. `session.message` therefore is not a one-event-per-message protocol. Check nonempty canonical message IDs and require one unique ID, and independently require one persisted user turn in `chat.history`.

This is not #169434: this scenario sends an ordinary `Reply exactly ...` request, not an inline slash-command acknowledgement.

## Evidence

Baseline: `5889e62f4902b8f3fa4b6eb2cecbbd26f5b8ceb0`.

- Before: `webchat-media-artifacts.e2e.test.ts` failed at `userEvents` length, expected 1 and received 2.
- Source: `capturePersistedModelPromptProjection` republishes the same transcript `entryId`; the UI already reconciles same-ID event revisions.
- Existing attachment-success, attachment-error, missing-file, mixed-batch and rendered-content checks remain intact.
- After: the complete WebChat media matrix passed (1/1), including the new canonical-ID and persisted-user-turn assertions.
- A loaded-host attempt timed out; an isolated run finished in 41.5 seconds without changing timeouts.
- Independent autoreview: scoped-clean at P2.
- Root test typechecks (all four shards), changed-file Oxlint/Oxfmt, and the line-cap ratchet passed.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…69434)

Related: openclaw#168843

## What Problem This Solves

Fixes duplicate user turns in `chat.history` when a message starts with an inline directive such as `/think high` and continues with an ordinary prompt.

## User Impact

One `chat.send` produces one user-history entry, preserving the original prompt and its whitespace. Standalone slash commands, native command errors, and their delivered replies keep their existing history behavior. Existing transcripts are not rewritten.

## Why This Change Was Made

Regression introduced by openclaw#169026 (`afb47c66b96d2408160ca91de63e3cd930403832`): command mirroring classified a delivered inline acknowledgement by the inbound message's `/` prefix. The normal user-turn owner had already persisted `<run>:user`; command mirroring then persisted the same input again under `command-input:[channel,account,conversation,run]`, with array content instead of string content.

The inline-reply producer now records private `inlineCommandReply` metadata. Both block and final transcript-mirror admission honor that ownership fact instead of creating another command exchange. There is no content-based dedupe or text-parser heuristic. A focused suite protects producer metadata and both delivery paths; its existing producer case moved out of an oversized suite without removing assertions.

No overlap with Pash/Sarah changes.

## Evidence

- Before: the whitespace Gateway RPC test failed on main-based `ed1bc51edb0`, expecting one user message and receiving two identical prompts (string and text-block-array shapes). The two persisted identities were traced to normal turn admission and the command mirror introduced by openclaw#169026.
- After: `preserves model-input whitespace independently from canonical chat history` passed through the real Gateway and mock provider (two turns, exact whitespace assertions, one history entry per turn). The temporary fixture from openclaw#168961 was used, with its replay assertion adjusted to the stable model-prompt projection introduced by openclaw#167938; none of those fixture changes are in this PR.
- The other eight `gateway-rpc-chat.e2e.test.ts` cases passed in the full-file run.
- Four focused unit suites passed: 202 tests, including producer metadata, block/final mirror exclusion, and existing standalone command coverage.
- Runtime build, `tsgo:core`, formatting, line-cap growth ratchet, and oxlint on the other four changed files passed. The initial raw oxlint invocation reported the pre-existing over-cap `dispatch-from-config.choose-route.ts`; this file has no counted-line growth.
- Independent source review: no remaining findings.

Merge danger: **two-way door**. Reverting restores the old inline-acknowledgement mirroring behavior. No schema, stored-data migration, or configuration changes; the blast radius is transcript mirroring of inline command acknowledgements.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 12, 2026
…rns (openclaw#169475)

## What Problem This Solves

Fixes the WebChat media-artifact proof treating a revision of one user message as a duplicate user turn. This is an explicitly requested main CI repair.

## User Impact

No product behavior changes. The proof still rejects duplicate canonical user turns and still checks every supported/rejected media outcome.

## Why This Change Was Made

The user-turn owner publishes the initial transcript append and then a revision of that same message when its first-sent model prompt projection is captured. `session.message` therefore is not a one-event-per-message protocol. Check nonempty canonical message IDs and require one unique ID, and independently require one persisted user turn in `chat.history`.

This is not openclaw#169434: this scenario sends an ordinary `Reply exactly ...` request, not an inline slash-command acknowledgement.

## Evidence

Baseline: `11f576b23cf70615ca4504eb12fdba93591b9c8f`.

- Before: `webchat-media-artifacts.e2e.test.ts` failed at `userEvents` length, expected 1 and received 2.
- Source: `capturePersistedModelPromptProjection` republishes the same transcript `entryId`; the UI already reconciles same-ID event revisions.
- Existing attachment-success, attachment-error, missing-file, mixed-batch and rendered-content checks remain intact.
- After: the complete WebChat media matrix passed (1/1), including the new canonical-ID and persisted-user-turn assertions.
- A loaded-host attempt timed out; an isolated run finished in 41.5 seconds without changing timeouts.
- Independent autoreview: scoped-clean at P2.
- Root test typechecks (all four shards), changed-file Oxlint/Oxfmt, and the line-cap ratchet passed.

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant