Skip to content

fix(chat): keep flattened tool results with the correct tool - #1298

Merged
shanselman merged 3 commits into
mainfrom
shanselman-transplant-history-correlation-fix
Sep 4, 2026
Merged

shanselman merged 3 commits into
mainfrom
shanselman-transplant-history-correlation-fix

Conversation

@shanselman

@shanselman shanselman commented Sep 2, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #894
Replaces: #1130

What problem this solves

Native Chat history could attach flattened tool output to the wrong structured tool row when cached metadata, reused call IDs, and generated history IDs collided.

What changed

  • ChatHistoryLoader reserves structured transcript IDs before allocating synthetic IDs.
  • ChatMetadataStore merges stable cross-key metadata and matches structured entries by exact ordinal call ID, choosing the nearest timestamp when IDs are reused.
  • A verified-ID miss now fails closed: positional cache enrichment becomes untrusted for the rest of that deterministic rebuild, preventing stale tool names or arguments from reaching later flattened rows.
  • Per-ID call/result occurrence tracking prevents normal pairs, result-before-call ordering, turn boundaries, and duplicate result blocks from creating false misses.
  • Flattened results always receive fresh synthetic IDs and never reuse unverified cached call or run IDs.

Ownership remains consistent with docs/ARCHITECTURE.md: history replay stays in ChatHistoryLoader, cached correlation stays in ChatMetadataStore, and OpenClawChatDataProvider remains the facade. Later PR #1301 changes provider snapshot publication/lifetime only; there is no production-file overlap or semantic ownership conflict.

User impact

Structured and flattened historical tool activity render as separate rows with truthful tool identity, sanitized arguments, status, and output ownership.

Required proof pools

  • windows-winui-interactive: current-head native Chat history identity, input, output, and accessibility proof.

Validation

Exact reviewed head: ea0dd548f459de8be3fea0c10408c353d66014c3 on base 585c1776e8900c22aa12c2be801db6d6e73ddf9e.

  • .\build.ps1: passed, 5 of 5 projects.
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: 3,915 passed, 0 failed, 32 skipped.
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: 2,852 passed, 0 failed.
  • Focused correlation/concurrency/cancellation/disposal selection: 11 passed, 0 failed.
  • Final correlation, reused-ID, result-before-call, duplicate-result, and stale-cache selection: 10 passed, 0 failed.
  • HistoryCollisionScreenshotProofTests with -r win-x64: 1 passed, 0 failed.
  • Hanselman dual-model review (Claude Opus 5 and GPT-5.3-Codex): one high-consensus stale-cache finding fixed; two follow-up false-latch cases fixed; both final reviewers report no actionable correctness findings.
  • One earlier Shared run transiently failed the unrelated McpHttpServerTests.Dispose_DuringInFlightHandler_DoesNotSurfaceObjectDisposedException; the isolated rerun and subsequent full required reruns passed.
  • Exact-head Build and Test workflow 33863943601, attempt 2: CI Gate passed. Core/CLI, Tray/setup/integration, UI/accessibility, proof contracts, release metadata, E2E, and publish smoke jobs passed.
  • Exact-head CodeQL workflow 33863943703: passed, including C# and Actions security.

Real behavior proof

  • Environment: Windows 11, isolated tray data, native WinUI app, and UI Automation.
  • Exact head tested: ea0dd548f459de8be3fea0c10408c353d66014c3.
  • Command: dotnet test .\tests\OpenClaw.Tray.UITests\OpenClaw.Tray.UITests.csproj -r win-x64 --filter "FullyQualifiedName~HistoryCollisionScreenshotProofTests".
  • UIA found Tool call Bash. Done. with input command: synthetic flattened id: history-tool-1 and output flattened output owned by history-tool-1.
  • UIA confirmed unverified-flat-id and unverified-flat-run were absent.
  • Screenshot: 3862 x 2499, 377,005 bytes, SHA-256 7621823E76A10109931DE83BDA6CB5DF8A2003DAD375AE3C99203A6B58AEF1FF.
  • Hosted screenshot bytes were fetched after upload and matched the local SHA-256.
  • Not verified / blocked: None.

Current-head native history collision proof

Security impact

  • New permissions or capabilities: No.
  • Secrets or token handling changed: No.
  • Network calls changed: No.
  • Command execution surface changed: No.
  • Cached display arguments remain allowlisted, sanitized, and bounded.

Compatibility and migration

Backward compatible. No configuration, environment, or migration changes are required.

Merge

Squash-merged from exact reviewed head as 8e5526bb4b72232cd84e6e1163f019037ff975ee on main.

@clawsweeper

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

@shanselman shanselman added P2 Normal priority bug or improvement with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. labels Sep 2, 2026
@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 6:40 AM ET / 10:40 UTC.

ClawSweeper review

What this changes

The branch changes native Chat history replay so flattened tool output receives a collision-free synthetic identity while structured tool calls retain exact cached metadata.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

This is a distinct, focused repair for native Chat history correlation. The reviewed patch has no supported correctness or security finding, and its collaborator author means it should remain open for ordinary maintainer landing review.

Priority: P2
Reviewed head: ea0dd548f459de8be3fea0c10408c353d66014c3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with substantial regression coverage and no supported correctness or security finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The author is a collaborator, so the external-contributor proof gate does not apply. The PR nevertheless supplies a current-head Windows UI Automation scenario through the provider, metadata cache, timeline, and visible tool row.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The author is a collaborator, so the external-contributor proof gate does not apply. The PR nevertheless supplies a current-head Windows UI Automation scenario through the provider, metadata cache, timeline, and visible tool row.
Evidence reviewed 5 items Collision-safe history replay: The introduced loader reserves every nonblank structured transcript call ID before allocating synthetic IDs. Flattened assistant and tool-result rows receive those fresh IDs instead of cached call or run IDs.
Exact cache correlation: The metadata store merges cache scopes by stable correlation identity and the keyed lookup uses ordinal call-ID matching while retaining unmatched queue order.
Focused regression coverage: New provider tests cover the keyed-call plus flattened-result collision, verified-ID cache miss behavior, paired duplicate results, and reserved synthetic IDs.
Findings None None.
Security None None.

How this fits together

The native tray Chat view loads gateway conversation history, correlates structured and flattened tool activity with cached display metadata, then projects that timeline into accessible WinUI tool rows.

flowchart LR
  A[Gateway history] --> B[History replay]
  C[Cached tool metadata] --> D[Tool correlation]
  B --> D
  D --> E[Chat timeline]
  E --> F[WinUI tool rows]
  F --> G[Accessibility proof]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production versus test delta production +556/-43, tests +828/-1 The larger test investment covers cache matching, replay edge cases, and an isolated native UI path for the history-correlation change.
Affected files 9 files: 4 production, 5 test The change remains confined to native Chat replay, metadata correlation, and its regression proof.

Technical review

Best possible solution:

Land the focused history-correlation repair after the normal current-head merge gates complete.

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

Yes, source-reproducible: the focused fixture constructs the structured-ID and flattened-output collision, and the base loader reused cached identities for flattened rows.

Is this the best way to solve the issue?

Yes: reserving transcript IDs and assigning flattened rows new synthetic IDs removes the shared identity while retaining safe cached display metadata.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 585c1776e890.

Labels

Label justifications:

  • P2: This is a bounded native Chat history rendering defect with limited blast radius.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The author is a collaborator, so the external-contributor proof gate does not apply. The PR nevertheless supplies a current-head Windows UI Automation scenario through the provider, metadata cache, timeline, and visible tool row.

Evidence

What I checked:

Likely related people:

  • shanselman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Barbara Kudiess: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Caleb Eden: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (3 earlier review cycles)
  • reviewed 2026-09-02T18:54:20.818Z sha b95d803 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-02T19:38:22.780Z sha b95d803 :: blocked before merge. :: none
  • reviewed 2026-09-04T10:19:32.871Z sha b95d803 :: blocked before merge. :: none

@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 2, 2026
@shanselman shanselman added the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 4, 2026
shanselman and others added 2 commits September 4, 2026 03:03
Preserve current ChatHistoryLoader and ChatMetadataStore ownership while correlating structured calls by stable IDs and assigning flattened results collision-free synthetic IDs.

Co-authored-by: Copilot App <[email protected]>
Use the replay timestamp to select the nearest exact cached identity while preserving unmatched metadata order.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Sep 4, 2026
Keep exact call/result lookups paired per occurrence and stop positional enrichment after a genuine verified-ID miss, without penalizing duplicate results or reused IDs.

Co-authored-by: Copilot App <[email protected]>

Copilot-Session: a73d1c86-3724-4651-aaf7-7578a6102976
@shanselman
shanselman force-pushed the shanselman-transplant-history-correlation-fix branch from b95d803 to ea0dd54 Compare September 4, 2026 10:35
@shanselman
shanselman merged commit 8e5526b into main Sep 4, 2026
33 of 37 checks passed
@shanselman
shanselman deleted the shanselman-transplant-history-correlation-fix branch September 4, 2026 11:03
@shanselman shanselman removed the status: 🚢 actively landing A maintainer or agent is actively driving this item through implementation, validation, or merge. label Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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