Skip to content

fix(chat): preserve history cache correlation - #1130

Open
bkudiess wants to merge 5 commits into
openclaw:mainfrom
bkudiess:bkudiess-finalize-history-cache-correlation
Open

fix(chat): preserve history cache correlation#1130
bkudiess wants to merge 5 commits into
openclaw:mainfrom
bkudiess:bkudiess-finalize-history-cache-correlation

Conversation

@bkudiess

@bkudiess bkudiess commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Related to #894

Scope

This PR contains five focused layers across 11 files:

  1. History/cache correlation

    • Combine session and thread metadata caches chronologically using cloned entries.
    • Deduplicate only stable (RunId, ToolCallId, LegacyTurn) identities while preserving reused IDs across distinct runs and legacy turns.
    • Merge richer current-canonicalized identity and safe display arguments into the earliest chronological owner.
    • Revalidate cached names, labels, and display arguments through current sanitization on cloned reads without mutating persisted cache entries.
  2. Collision-safe history identity allocation

    • Reserve every verified structured history call/result ID before allocating synthetic IDs.
    • Centrally reserve history-tool-* IDs for flattened history and unkeyed structured fallbacks.
    • Prevent unverified positional cached RunId and ToolCallId values from correlating flattened output to an active structured row.
  3. Exact keyed structured-cache matching

    • Keyed structured calls and result-only rows consume only the earliest cached entry whose nonblank ToolCallId exactly matches using ordinal comparison.
    • A missing keyed match consumes nothing, so later flattened output retains its own cached tool identity, label, and safe arguments.
    • The bounded queue helper preserves every unmatched entry's relative order, including absent and middle-match cases.
    • Unkeyed structured history retains chronological positional fallback; paired results do not consume a second cache entry.
  4. Provider-backed production UI proof

    • Route the isolated collision fixture through OpenClawChatDataProvider.LoadHistoryAsync.
    • Use a deterministic fake IChatGatewayBridge history response and the real tool metadata cache path.
    • Render the provider-produced timeline through the production reducer, activity projection, Reactor renderer, UI Automation tree, and RenderTargetBitmap capture.
    • Require all three isolation gates: OPENCLAW_ACCESSIBILITY_TEST_CHAT=1, fixture history-collision, and an exact isolated OPENCLAW_TRAY_DATA_DIR match.
  5. Regression and provenance coverage

    • Prove structured history-tool-0 remains interrupted with no output.
    • Prove flattened output is owned only by generated history-tool-1.
    • Prove keyed structured A cannot consume flattened B metadata, keyed result-only A cannot consume B, exact matches consume once, reused IDs select the earliest match, and unmatched queue order is stable.
    • Accessibility fixture unit tests inject an environment lookup instead of mutating process-global variables, so the static logger cannot bind to a deleted test directory.
    • Natively accept machine-derived clean:tree=<tree> proof provenance while retaining validated dirty descriptors with arbitrary positive file counts.

hideFromChannelProgress remains intentionally out of scope.

Exact head and base

  • PR head: 72f81b76211828cba447148e69b35b98e83afd20
  • Five commits:
    • 3a03dfddbed6323fa5cd970f41b7bb0a0ab2ea0c fix(chat): preserve history cache correlation
    • 683517894bd13dfeeb9996d3934bdac5b4b4863b fix(chat): avoid synthetic history ID collisions
    • 128bc29b3adc7263d0ad60d3ef9af285c49078d9 test(chat): prove history ID collision rendering
    • 338f67575e259d132f0f1d44d8640e695f245bf2 test(chat): route collision proof through history provider
    • 72f81b76211828cba447148e69b35b98e83afd20 fix(chat): match structured history cache by call ID
  • Fully validated rebase base: 4712e227d110746400e93107c60616544d68f7b4
  • Current main target: 582a44713860409bc34c5acbf6da54a09cf2b10a
  • GitHub PR diff: 11 files, +1740/-52

main advanced after the completed rebase. GitHub reports the current PR mergeable; exact-head CI is the source of truth for the target merge result.

Validation

  • git diff --check: passed
  • .\build.ps1: passed, 5 of 5 projects
  • dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore: 3,631 passed, 0 failed, 32 skipped
  • dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore: 2,268 passed, 0 failed
  • Focused cache/history/provider tests: 43 passed, 0 failed
  • Deterministic cache ordering and non-collapse stress: 25 of 25 iterations, 200 of 200 aggregate tests passed
  • NativeToolIdentityScreenshotProofTests, HistoryCollisionScreenshotProofTests, and ReactorToolActivityProofTests: 3 passed, 0 failed with win-x64
  • Clean exact-head collision capture: 1 passed, 0 failed after the documented fresh-worktree restore

Real behavior proof

The isolated fixture makes one real RequestChatHistoryAsync call through OpenClawChatDataProvider.LoadHistoryAsync. The returned history contains an unfinished structured call with verified ID history-tool-0, followed by flattened tool output. The real metadata cache supplies the visible tool identities and safe arguments. The provider's allocator produces exactly two rows:

  • Structured history-tool-0: Interrupted, no output.
  • Synthetic history-tool-1: Done, owns flattened output owned by history-tool-1.

The screenshot and matching UIA diagnostics were generated from a clean detached checkout of exact product head 72f81b76211828cba447148e69b35b98e83afd20, tree 60079b82a853ab063407189c2d062372ac5f06c4. No harness patch was required.

Provider-backed collision proof

  • Screenshot
    • 1,722 x 330, 43,186 bytes
    • Hosted SHA-256 8D01DC46D02B2DFD3521FA442AB338C4DCDD90012E9B47B057138144B16F84C6
  • UIA diagnostics
    • Hosted SHA-256 D530A81D33C768672820BE5505A0B612A9E26941BDF93BE4C27AD02B92DAEE3D
  • Machine-derived provenance manifest
    • Hosted SHA-256 7343CFE624D263E5A51EC3020AA6319A83F37E8EC2D912D45C3E6BBB4A66551D
    • Product EXE SHA-256 A9041AACFA915B16A0E0CA30C8D6806C633B59F06EA9E178163D19AB1884C45B
    • Product DLL SHA-256 D98CB1DA8CC157931AEC424915E86DB180135F0CB86A0C2E2459380DCAF91440

All immutable raw URLs returned HTTP 200 with matching hosted bytes. The artifacts contain no blank media, credentials, user paths, real settings, or real Gateway data. No PR was opened from the proof-only branch.

Review

  • Fresh GPT-5.6 Sol/high rubber-duck review found one in-scope missing absent-match order assertion. It was added and all validation was rerun successfully.
  • A broader pre-existing same-ID result-only occurrence/turn scenario was consciously kept out of this surgical helper/call-site repair because resolving it requires reducer turn/correlation ownership changes and does not affect the verified keyed-A then flattened-B defect.
  • The bundled structured GPT-5.6 Sol/high autoreview built a complete immutable 29,784-character commit bundle, but the external Codex transport returned HTTP 401 twice before producing a result. No fallback model was used. Coordinator blind review remains the independent publication gate.
  • Older-head ClawSweeper findings and scores are not evidence for head 72f81b76211828cba447148e69b35b98e83afd20.

PR #1111 interaction

PR #1111 remains complementary and was not modified by this work. Its current head is 919ec7c0c74d2fff572c0405a99a93cf7720a703.

Its semantic patch owns persisted call ID aliases, message-level errors, string-encoded safe arguments, and failed-tool grouping. This PR owns positional cache correlation, flattened row identity, synthetic/structured ID collision handling, and exact keyed cache consumption. There is no direct changed-line overlap in the source or tests.

Release boundary

#894 is OPEN and remains open until the follow-up lands and a release includes #1078, #1114, and #1130. This PR does not close the issue and intentionally uses Related to #894 rather than a closing keyword.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 session-state 🚨 Merging this PR could lose, corrupt, stale, or mis-associate session or agent state. labels Aug 8, 2026
@clawsweeper

clawsweeper Bot commented Aug 8, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 10, 2026, 12:04 AM ET / 04:04 UTC.

ClawSweeper review

What this changes

The PR changes Windows native chat-history replay so cached tool metadata cannot make a flattened tool-output row correlate with a structured tool call.

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open for a maintainer merge decision. Current main still lets flattened history reuse cached IDs, while this head separates synthetic flattened IDs from verified structured IDs and supplies focused regression coverage plus visible isolated-app proof.

Priority: P2
Reviewed head: 72f81b76211828cba447148e69b35b98e83afd20
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has strong focused regression and visible proof, with normal maintainer review still warranted for persisted-history compatibility.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): The PR provides inspected current-head isolated-app UI proof showing two distinct tool rows with the flattened output attached only to the synthetic row.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): The PR provides inspected current-head isolated-app UI proof showing two distinct tool rows with the flattened output attached only to the synthetic row.
Evidence reviewed 5 items Current-main behavior: Current main assigns flattened history rows the cached ToolCallId and RunId, which can collide with an active structured history row.
PR-head repair: The proposed head reserves verified structured IDs, allocates separate synthetic IDs for flattened history, and consumes keyed cache records only by exact call ID.
Regression and UI coverage: The head adds provider/cache collision tests and an isolated accessibility test that asserts two distinct visible tool rows and that the structured row has no flattened output.
Findings None None.
Security None None.

How this fits together

The Windows tray chat provider combines Gateway history with locally cached tool metadata, then sends the reconstructed timeline to the native WinUI chat renderer. Correct identity matching keeps tool names, states, and output attached to the right historical row.

flowchart LR
  A[Gateway history] --> B[Chat history provider]
  C[Cached tool metadata] --> B
  B --> D[ID allocation and cache matching]
  D --> E[Timeline reducer]
  E --> F[Tool activity projection]
  F --> G[WinUI chat history]
Loading

Decision needed

Question Recommendation
Should this collaborator PR land independently now, with its keyed and unkeyed history-cache regressions retained alongside the adjacent open persisted-history work? Land after coordinated history review: Merge this focused repair after confirming its cache-consumption tests remain distinct from the adjacent persisted-history patch.

Why: The patch appears correct and proof-positive, but persisted-history behavior is compatibility-sensitive and sequencing adjacent work is a maintainer ownership decision.

Before merge

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test delta production +558, tests +1,169 The large test and proof investment covers a comparatively focused persisted-history correlation change.
Changed files 11 files The repair spans provider logic, isolated UI proof support, and focused regression coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #894
Summary: This PR is an evidence-backed candidate for one historical-tool correlation facet of the broader native chat discrepancy report.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Land with replay-boundary review (recommended)
    Review this PR's exact keyed and unkeyed cache-consumption behavior against the adjacent persisted-history work, then merge if those boundaries remain intact.
  2. Pause for a combined plan
    Defer the PR only if maintainers prefer a single coordinated decision for the adjacent persisted-history changes.

Technical review

Best possible solution:

Land the narrow cache-correlation repair while retaining exact keyed matching, synthetic flattened IDs, and the provider-to-UI regression coverage.

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

Yes. The added isolated provider/cache fixture gives a high-confidence path that reproduces the structured-ID plus flattened-output collision, though this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Separating synthetic flattened IDs from verified structured IDs and matching keyed cache entries exactly is a narrow repair that preserves the existing persisted cache format.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 582a44713860.

Labels

Label justifications:

  • P2: This is a bounded correctness repair for historical native chat rendering.
  • merge-risk: 🚨 session-state: The diff changes persisted chat-history replay and tool-row identity correlation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): The PR provides inspected current-head isolated-app UI proof showing two distinct tool rows with the flattened output attached only to the synthetic row.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides inspected current-head isolated-app UI proof showing two distinct tool rows with the flattened output attached only to the synthetic row.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR provides inspected current-head isolated-app UI proof showing two distinct tool rows with the flattened output attached only to the synthetic row.

Evidence

What I checked:

Likely related people:

  • bkudiess: Barbara Kudiess authored the merged native tool identity and correlation changes that form the immediate history-replay baseline. (role: introduced adjacent correlation behavior; confidence: high; commits: ad472243bcb8, a1d933a3c7b7; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)
  • calebeden: Caleb Eden authored the merged compact tool-activity work on the same provider and presentation path. (role: recent activity-projection contributor; confidence: medium; commits: aac07abb1fbd; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

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 (17 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-09T17:00:43.184Z sha 128bc29 :: found issues before merge. :: [P2] Route the collision UI fixture through history replay | [P2] Capture the visual proof from the final commit
  • reviewed 2026-08-09T22:27:48.019Z sha 128bc29 :: found issues before merge. :: [P2] Route the collision fixture through history replay | [P2] Regenerate proof from the final PR head
  • reviewed 2026-08-10T01:37:34.306Z sha 338f675 :: found issues before merge. :: [P2] Regenerate proof from the current provider-backed head
  • reviewed 2026-08-10T01:45:39.890Z sha 338f675 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-10T02:01:08.700Z sha 338f675 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-10T03:18:29.139Z sha 72f81b7 :: found issues before merge. :: [P2] Regenerate proof from the current head
  • reviewed 2026-08-10T03:33:38.086Z sha 72f81b7 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-10T03:37:41.090Z sha 72f81b7 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 9, 2026
bkudiess and others added 2 commits August 8, 2026 20:33
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@bkudiess
bkudiess force-pushed the bkudiess-finalize-history-cache-correlation branch from e1be9df to 128bc29 Compare August 9, 2026 08:50
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. labels Aug 9, 2026
@clawsweeper clawsweeper Bot added 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. and removed 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. labels Aug 9, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 10, 2026
@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 10, 2026
@bkudiess

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@clawsweeper clawsweeper Bot added 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. and removed 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. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. labels Aug 10, 2026
@bkudiess

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. 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. and removed 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 Aug 10, 2026
@bkudiess
bkudiess marked this pull request as ready for review August 10, 2026 04:01
@clawsweeper

clawsweeper Bot commented Aug 10, 2026

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 session-state 🚨 Merging this PR could lose, corrupt, stale, or mis-associate session or agent state. P2 Normal priority bug or improvement with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient Contributor real behavior proof is sufficient. 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