Skip to content

Preserve native tool identity in chat - #1078

Merged
bkudiess merged 6 commits into
openclaw:mainfrom
bkudiess:bkudiess-preserve-native-tool-identity
Aug 6, 2026
Merged

bkudiess merged 6 commits into
openclaw:mainfrom
bkudiess:bkudiess-preserve-native-tool-identity

Conversation

@bkudiess

@bkudiess bkudiess commented Aug 3, 2026 •

Copy link
Copy Markdown
Collaborator

Related to #894

Root cause

The issue screenshot reflects three losses in the native chat projection:

  • Gateway kind=tool items were reduced to the first token of a generic parent title.
  • Correlated kind=command children were ignored, so concrete identities such as Bash and Apply Patch never reached the native row.
  • Flattened history used broad heuristics that collapsed known browser, canvas, and command tools to generic identities.

command_output also appended output without preserving the richer child identity or safe command preview.

Behavior

  • Preserves canonical child and tool identity at the authoritative chat model and reducer boundary.
  • Projects bounded display previews only from allowlisted fields: command, path, file_path, query, url, and pattern.
  • Applies existing sanitization, redaction, and truncation before display.
  • Correlates calls by thread/session-local state plus gateway run ID and tool call ID when a run ID is available.
  • Constrains legacy calls without run IDs to an active turn generation so a reused ID cannot rewrite a terminal row from an earlier turn.
  • Supports child-before-parent, parent-before-child, duplicate replay, multiple children, late output, terminal precedence, disconnect/reconnect cleanup, and bounded retained state.
  • Keeps live projection, metadata cache persistence, cache migration, and history hydration aligned.
  • Normalizes missing, empty, and whitespace item IDs to the reducer's ID-less fallback so output and terminal status stay attached.
  • Uses the projector's canonical display-argument order in Reactor so allowlisted keys cannot drift between projection and rendering.
  • Renders canonical identity, safe preview, localized status, collapse/expand state, and accessibility text in the Reactor timeline without changing virtualization or follow behavior.

Security boundaries

  • Arbitrary provider command titles cannot become trusted prominent tool identities.
  • Trusted title promotion uses a strict canonical alias mapping.
  • Bidi controls, control characters, and confusable non-ASCII title forms do not bypass identity trust.
  • Arbitrary raw JSON, environment data, credentials, tokens, secrets, full output, and unbounded command text are never rendered as display arguments.
  • Error outcomes cannot be downgraded by later synthetic success completion.
  • Run IDs remain internal correlation metadata and are not exposed in visible or accessibility text.

Architecture

The chat event/model/reducer boundary owns correlation, deterministic outcome ordering, identity strength, and bounded replay state. NativeToolProjector is the authoritative pure owner for canonical identity, safe display arguments, payload extraction, and flattened-history classification. OpenClawChatDataProvider retains stateful live/history application, run/session/legacy-generation correlation, and metadata cache persistence and migration. Reactor remains the native presentation owner.

Synthetic screenshot orchestration is outside ChatPage. The generic VisualTestCapture helper responds only to explicit visual-test environment configuration after the Reactor ChatHost mounts.

This does not change browser routing, MCP routing, Gateway protocols, timeline virtualization, or follow behavior.

Validation

Current upstream/main at e9d571a9b39562d06d92e8212bfce0df31c2f7c1 was merged without rewriting history. The complete closeout matrix was rerun at current PR head 0b810b2f8dca801cabd996342f600a6c10cf8f19:

Command Result
git diff --check Passed
.\build.ps1 5/5 projects built
dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore 3,382 passed, 32 skipped
dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore 2,115 passed
dotnet build .\tests\OpenClaw.Tray.UITests\OpenClaw.Tray.UITests.csproj -c Debug -r win-x64 --no-restore Passed
Full Tray UI suite, Category!=Accessibility 100 passed
Full Tray UI suite, Category=Accessibility 20 passed
Focused malformed/missing ID and renderer-key regressions 5 passed
NativeToolIdentityScreenshotProofTests with composed PNG capture 1 passed

Real behavior proof

  • Exact issue sequence is covered: generic parent Tool, correlated Bash child, bounded safe PowerShell preview, output, then a native Bash row rather than Tool.
  • Apply Patch and known live tool stream identities preserve safe allowlisted previews.
  • Run-scoped calls with the same tool call ID create distinct rows and cache records, while same-run replay deduplicates.
  • Legacy active replay, terminal ID reuse, child-before-parent, late parent after turn end, late child output, multiple children, reversed arrival, duplicate events, error precedence, reconnect cleanup, and cache save/reload/migration have deterministic regressions.
  • Secret-bearing arguments, arbitrary JSON, bidi controls, confusable titles, and overlong values are redacted, omitted, or bounded.
  • Missing, empty, and whitespace item IDs converge on the ID-less fallback, preserve output, finish Success, and do not leave the turn active.
  • Full real-process non-accessibility and accessibility UI suites passed 100/100 and 20/20.

Current-head native screenshot

Native Chat tool identity proof at 0b810b2f

The image was captured at exact PR head 0b810b2f8dca801cabd996342f600a6c10cf8f19 from the actual isolated OpenClaw.Tray.WinUI.exe and Reactor ChatHost. The fixture uses synthetic Chat data only. It does not access real chats, browser/profile data, credentials, or the desktop.

The screenshot shows:

  • Generic parent Tool upgraded by its correlated child to Bash, with localized Done, localized Tool input, bounded powershell -NoProfile -Command Get-ChildItem .\src, and synthetic output.
  • Apply Patch with localized status/input and safe file_path.
  • An untrusted command title remaining prominently and truthfully Tool; its non-authoritative description is bounded and its command value is [redacted].
  • No opaque run ID, raw JSON, secret marker, environment data, or unbounded command text.

Reproduction:

$env:OPENCLAW_REPO_ROOT = (Get-Location).Path
$env:OPENCLAW_UI_PROOF_HEAD = '0b810b2f8dca801cabd996342f600a6c10cf8f19'
$env:OPENCLAW_UI_SCREENSHOT_PATH = '<output>\native-tool-identity-0b810b2f.png'
$env:OPENCLAW_UI_PROOF_ARTIFACT_PATH = '<output>\native-tool-identity-0b810b2f.txt'
dotnet test .\tests\OpenClaw.Tray.UITests\OpenClaw.Tray.UITests.csproj `
  -r win-x64 --no-build `
  --filter "FullyQualifiedName~NativeToolIdentityScreenshotProofTests"

UI Automation proof manifest records the exact head, expanded row names, safe visible inputs, absent run ID/secret markers, and passing result. The PNG SHA-256 is 6FF9AB89F080024E93ED2099CCA228271EFD5988BDFD6FD7C8268303AE8DD4DD; the manifest SHA-256 is 822611984CDEE2D38D33E7A39A98F83345323A01F6A3BBBB88160F7B037117AE. Both downloaded GitHub assets matched their local files byte-for-byte.

The prior standalone FunctionalHostControl capture path crashed in Microsoft.UI.Xaml/combase. The final proof instead uses the actual isolated app plus the repository's existing in-process RenderTargetBitmap visual-test capture after UI Automation expands the changed rows. No product behavior, virtualization, or safety boundary was weakened.

Review

Independent adversarial review findings were fixed for title spoofing, terminal precedence, command-end activation, deterministic child ordering, run ID collisions, retained child state, hard user boundaries, cache generation, late child output, reconnect teardown, terminal metadata reuse, and cap-evicted running rows.

The unchanged tool-identity core retains its 92% clean independent assessment. The proof fixture and capture changes received a 99%-confidence independent review. The final combined architecture closeout received a separate high-confidence read-only review with no significant issues. It confirmed pure projection moved to NativeToolProjector, provider state ownership stayed intact, screenshot orchestration left ChatPage, and both prior ClawSweeper architecture findings are addressed.

The two final LOW findings were fixed: unusable item IDs now enter the ID-less fallback, and Reactor consumes the projector's canonical display-argument key order. Focused tests passed 5/5, and an independent read-only review found no significant issue.

Structured autoreview bundled commit 0b810b2f8dca801cabd996342f600a6c10cf8f19, but the isolated Codex engine exited with failure and returned no finding. No reviewer engine or model substitution was used.

Residual proof gap

The bounded cap and chronological history behavior have deterministic unit coverage, but there is no practical runtime proof that exhaustively combines pathological maximum-cap churn with arbitrarily reordered flattened history from a real Gateway. The reducer and cache fail boundedly and preserve the newest retained state under tested cap and replay scenarios.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 session-state 🚨 Merging this PR could lose, corrupt, stale, or mis-associate session or agent state. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 8:27 PM ET / August 6, 2026, 00:27 UTC.

ClawSweeper review

What this changes

This PR preserves trusted native tool names and bounded safe argument previews when gateway tool events are correlated, cached, restored, and rendered in the Windows native chat timeline.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. Current main still ignores command-child events and derives generic tool names from parent titles; this PR supplies the missing projection, correlation, and native rendering. The patch appears correct with direct current-head UI proof, but a maintainer should explicitly accept the legacy cache restoration tradeoff before merge.

Priority: P2
Reviewed head: 0b810b2f8dca801cabd996342f600a6c10cf8f19
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong current-head UI proof and focused coverage support a good patch, with a maintainer compatibility decision remaining.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): The inspected current-head screenshot from the isolated native app directly shows the upgraded trusted identities, bounded inputs, and redacted fallback row.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): The inspected current-head screenshot from the isolated native app directly shows the upgraded trusted identities, bounded inputs, and redacted fallback row.
Evidence reviewed 6 items Current main still has the reported gap: Current main only handles item events whose kind is tool, so command children are ignored and parent titles remain the identity source.
PR adds child correlation at the provider boundary: The PR maps command children into a presentation event tied to the parent tool ID and carries the gateway run ID through the correlation path.
Projection has a narrow safety boundary: The new projector allowlists visible argument keys and sanitizes their values before they enter the chat model.
Findings None None.
Security None None.

How this fits together

Native chat receives gateway event streams, reduces them into per-thread timeline state, and renders tool-call rows through the Reactor native UI. This change sits at the event-correlation and history-cache boundary, affecting what users see for live and restored tool calls.

flowchart LR
  A[Gateway tool events] --> B[Chat data provider]
  B --> C[Timeline reducer]
  C --> D[Tool metadata cache]
  C --> E[Native tool projector]
  E --> F[Reactor chat timeline]
  D --> B
  F --> G[Native chat rows]
Loading

Decision needed

Question Recommendation
Is chronological restoration acceptable for existing tool-cache entries that predate run and legacy-turn correlation metadata? Accept scoped cache fallback: Merge with the documented behavior that unscoped historical cache entries are restored chronologically while newly recorded entries retain stronger correlation metadata.

Why: The code keeps old cache records readable, but their historic rows cannot be exactly correlated after restart, so accepting that compatibility behavior is a product and upgrade judgment.

Before merge

  • Resolve merge risk (P1) - Pre-existing tool-cache records have no run or legacy-turn scope, so restored historical rows continue to rely on chronological matching rather than exact correlation.
  • Complete next step (P2) - A collaborator-authored PR with a concrete cache upgrade tradeoff requires maintainer acceptance rather than an automated repair lane.
Agent review details

Security

None.

Review metrics

Metric Value Why it matters
PR scope 18 files, +3,443 / -464 lines The patch spans model state, reducer logic, persisted cache behavior, rendering, and UI proof.
Production versus tests production +1,772 / -436; tests +1,667 / -27 The substantial implementation is paired with similarly substantial reducer, provider, cache, and UI coverage.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #894
Summary: This PR is the candidate fix for the linked native-chat tool identity discrepancy.

Members:

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

Merge-risk options

Maintainer options:

  1. Accept scoped cache fallback (recommended)
    Accept chronological restoration for old unscoped cache rows while retaining stronger run-aware correlation for new live events.
  2. Add an upgrade regression
    Before merge, add a focused restore test for reused legacy IDs across historical turn boundaries.

Technical review

Best possible solution:

Land the pure projector and reducer ownership split only after accepting the backward-compatible chronological fallback for old cached tool metadata, with its upgrade behavior retained as an explicit tested contract.

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

Yes. Current main source ignores command-child item events and reduces parent titles to generic tool identities, which directly explains the reported native-chat behavior.

Is this the best way to solve the issue?

Yes, subject to the cache-compatibility decision. Moving pure identity and safe-argument projection into a dedicated projector is the narrowest maintainable repair while the provider retains stateful correlation and persistence.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded correctness improvement to native chat tool rendering.
  • merge-risk: 🚨 compatibility: The PR changes persisted tool metadata and its restoration path for existing conversations.
  • merge-risk: 🚨 session-state: The reducer now retains and correlates tool events across turn, replay, and reconnect boundaries.
  • 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 inspected current-head screenshot from the isolated native app directly shows the upgraded trusted identities, bounded inputs, and redacted fallback row.
  • proof: sufficient: Contributor real behavior proof is sufficient. The inspected current-head screenshot from the isolated native app directly shows the upgraded trusted identities, bounded inputs, and redacted fallback row.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The inspected current-head screenshot from the isolated native app directly shows the upgraded trusted identities, bounded inputs, and redacted fallback row.

Evidence

What I checked:

Likely related people:

  • Dallin Romney: Most recent main contributor to the chat provider area through flattened gateway classification work. (role: recent area contributor; confidence: high; commits: 23414509b9d0; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)
  • Karen: Introduced the Reactor migration that owns the native chat rendering surface touched here. (role: rendering-area contributor; confidence: high; commits: 9acafa606a4d; files: src/OpenClaw.Tray.WinUI/Chat/ReactorChatTimeline.cs)
  • Christine Yan: Introduced prior native chat tool-metadata cache behavior that this PR extends compatibly. (role: metadata-cache originator; confidence: medium; commits: 9478e953dc38; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)
  • Barbara Kudiess: Previously contributed merged chat-provider work and is also the current PR author. (role: adjacent chat contributor; confidence: medium; commits: 4806eaac7c24; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)

Rank-up moves

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

  • Accept or request stronger upgrade coverage for restoration of legacy unscoped cache records.

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 (13 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-04T09:22:13.037Z sha 7eb9183 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-04T09:39:04.877Z sha 7eb9183 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-04T11:09:23.009Z sha 7eb9183 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-04T16:02:29.950Z sha 7eb9183 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-04T18:27:30.766Z sha 7eb9183 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-04T22:04:30.395Z sha 7eb9183 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-05T06:28:15.974Z sha 7eb9183 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-05T07:02:17.272Z sha 7eb9183 :: needs maintainer review before merge. :: none

@bkudiess

bkudiess commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 3, 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 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 3, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 4, 2026
@bkudiess

bkudiess commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 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: sufficient Contributor real behavior proof is sufficient. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. labels Aug 4, 2026
@clawsweeper clawsweeper Bot added 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 4, 2026
@bkudiess

bkudiess commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 4, 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 rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 4, 2026
@bkudiess
bkudiess marked this pull request as draft August 5, 2026 06:23
@bkudiess
bkudiess marked this pull request as ready for review August 6, 2026 00:23
@bkudiess
bkudiess merged commit ad47224 into openclaw:main Aug 6, 2026
26 of 27 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. 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