Skip to content

fix(claude-cli): deduplicate live and imported assistant turns - #118309

Closed
clawsweeper[bot] wants to merge 2 commits into
mainfrom
clawsweeper/issue-openclaw-openclaw-118185
Closed

clawsweeper[bot] wants to merge 2 commits into
mainfrom
clawsweeper/issue-openclaw-openclaw-118185

Conversation

@clawsweeper

@clawsweeper clawsweeper Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #118185.

Summary

  • Carry the existing Claude native assistant UUID (resumeCheckpointId) and bound Claude session id onto the durable CLI assistant transcript record.
  • Let the existing CLI history merge deduplicate the durable and imported native representations by their shared authoritative identity, rather than rendered text.
  • Preserve imported-only rows, cross-session UUID protections, existing run-key idempotency, and the current importer fallback behavior.

Regression coverage

  • Add a focused fixture containing one durable Claude CLI assistant record and one imported native JSONL assistant row for the same native assistant UUID with deliberately unequal text; assert history renders one assistant message.
  • Assert the CLI durable writer records no Claude identity for non-Claude/identity-less output, and records the complete (importedFrom, cliSessionId, externalId) tuple only when both existing parsed facts are available.

Release-note context

This corrects a user-visible duplicate reply in Claude CLI WebChat history. Do not edit CHANGELOG.md; release automation owns it.

Required labels: clawsweeper:autogenerated, clawsweeper:autofix.

@clawsweeper clawsweeper Bot added clawsweeper Tracked by ClawSweeper automation clawsweeper:autogenerated PR created automatically by ClawSweeper clawsweeper:autofix Maintainer opted this PR into bounded ClawSweeper-reviewed autofix without merge labels Aug 2, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling labels Aug 2, 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Codex review: blocked before merge.

What this changes

This PR records Claude assistant UUIDs on saved replies and suppresses imported history records with matching identities.

Example: Claude session claude-session emits “leading text”, a Bash call, and “hello from Claude”.

  • Before: History retains the saved reply alongside unmatched native text and tool records.
  • After: The saved reply claims all three UUIDs, causing native content absent from that reply to disappear from history.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) Useful producer correlation is undermined by a concrete content-loss defect; the separate fixtures do not establish complete history preservation.
Proof confidence 🦐 gold shrimp (3/6) This bot-authored repair is outside the ordinary contributor proof gate; supplied fixtures exercise the mocked runner and importer separately, and no latest-stable upgrade/reload evidence establishes compatibility of persisted externalIds with existing transcript rows.
Patch quality 🧂 unranked krab (1/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: A single Claude generation appears as multiple competing assistant replies in chat history.
Reason: The reported problem merits repair, but suppressing unmatched native content does not satisfy the complete-history requirement.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep this PR open: it targets a confirmed history-duplication bug, but the previously reported content-loss defect remains unfixed.

Priority: P1
Reviewed head: bb567cd88c9f8f05db950a54d6ed40dc37f68561

Before merge

  • Preserve native content before claiming every assistant UUID (P1) - For a text → tool → final-text turn, this attaches every native assistant UUID to a saved message containing only flat text. The overlap matcher then suppresses the native tool-call row, including its coalesced tool result, despite neither being retained locally; leading text can disappear too when output selection retains only the final answer. The new reliability fixture demonstrates that mismatch, and the history fixture explicitly expects distinct fragments to vanish. Preserve complete native content or suppress only content represented by the surviving message. This repeats the still-unfixed prior finding.
  • Complete next step - Resolve the existing human-review repair pause with @fuller-stack-dev.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P1] Preserve native content before claiming every assistant UUID — src/agents/cli-runner.ts:389-392

Tests

  • Low-value test src/gateway/cli-session-history.test.ts: The added fragment test expects unequal native content to disappear; replace that expectation with assertions that complete text and tool content survive.
  • Missing end-to-end proof: No producer-to-store-to-history boundary run or latest-stable upgrade/reload scenario demonstrates complete content preservation for mixed existing and newly stamped rows.
Agent review details

How this fits together

The CLI runner persists assistant replies while Claude maintains native transcripts; Gateway history imports and merges those representations for chat clients.

flowchart TD
  A[Claude CLI turn] --> B[Output parser]
  B --> C[Saved assistant reply]
  A --> D[Native transcript]
  D --> E[History importer]
  C --> F[History merge]
  E --> F
  F --> G[Chat history]
Loading

Technical review

Best possible solution:

Record the native-turn relation at the producer and retain a complete representation before suppressing any matched content.

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

Source and the added fixtures establish the failure: a final-only saved reply claims leading-text and tool UUIDs, then the merger drops those richer native rows; no runtime reproduction was executed in this read-only review.

Is this the best way to solve the issue?

This is not the best fix as written: producer correlation is the right boundary, but observed UUIDs cannot stand for content the saved reply omits; preserve the identified native turn or prove coverage before suppression.

Full review comments:

  • [P1] Preserve native content before claiming every assistant UUID — src/agents/cli-runner.ts:389-392
    For a text → tool → final-text turn, this attaches every native assistant UUID to a saved message containing only flat text. The overlap matcher then suppresses the native tool-call row, including its coalesced tool result, despite neither being retained locally; leading text can disappear too when output selection retains only the final answer. The new reliability fixture demonstrates that mismatch, and the history fixture explicitly expects distinct fragments to vanish. Preserve complete native content or suppress only content represented by the surviving message. This repeats the still-unfixed prior finding.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced patch: The pinned introduction diff adds native UUID collection, persisted externalIds metadata, and overlap-based suppression; production grows by 64 net lines and tests by 158. (src/agents/cli-runner.ts:392, bb567cd88c9f)
  • Content does not cover claimed identities: The writer saves one text block but attaches every collected assistant UUID. The added reliability fixture explicitly saves only “hello from Claude” while claiming leading-text, tool-use, and final-text records. (src/agents/cli-runner.ts:371, bb567cd88c9f)
  • Suppression removes richer history: Any shared UUID with matching importer and session makes a native row equivalent. The importer coalesces adjacent matching tool results into assistant tool-call rows, so suppressing those rows also hides their results. (src/gateway/cli-session-history.merge.ts:105, bb567cd88c9f)
  • Current main still needs correlation: Current main persists flat assistant text without this native-turn relation. Its relocated history policy indexes singular external identities and otherwise matches comparable text, leaving unequal aggregates and fragments unmatched. (src/gateway/cli-session-history-index-policy.ts:133, ff908fed3f95)
  • Latest stable retains the relevant mechanism: The v2026.10.4 writer saves flat text without native correlation; its worker history index resolves singular externalId and falls back to text matching. (src/agents/cli-runner/cli-run-transcript.ts:197, 383c124cc32f)
  • Reporter corroboration and active ownership: The canonical report documents multi-block duplication, with independent confirmations from @ctbritt, @KCALLC, and later reporters. This PR remains assigned to @fuller-stack-dev, and its discussion explicitly pauses repair for human review.

Likely related people:

  • Peter Steinberger: Raw commit 97c5758 adds src/gateway/cli-session-history.merge.ts:104 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 97c57585a100; files: src/gateway/cli-session-history.merge.ts)
  • Vito Cappello: Raw commit 5ae8a4f adds src/agents/cli-output.ts:504 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 5ae8a4f4f98c; files: src/agents/cli-output.ts)

PR surface

Source +64, Tests +158. Total +222 across 6 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 92 28 +64
Tests 3 159 1 +158
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 251 29 +222

Review metrics

Metric Value Why it matters
Production versus tests production +64 net; tests +158 net Producer correlation warrants some growth, but the new assertions currently accept incomplete surviving content.
Persisted metadata 1 added field: externalIds This field changes which native records survive history merging after reload.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #118185
Summary: The canonical report describes unequal saved and imported Claude assistant representations; this PR remains an unmerged candidate repair.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P1: The linked report establishes duplicate Claude history for real users, and the proposed repair can silently hide native content.
  • merge-risk: 🚨 session-state: Persisted UUID claims suppress native text and tool details absent from the retained assistant reply.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🦐 gold shrimp and patch quality is 🧂 unranked krab.

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 (14 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-08T03:37:57.792Z sha bb567cd :: needs maintainer review before merge. :: none
  • reviewed August 15, 2026, 1:01 PM ET / 17:01 UTC sha unknown :: found issues before merge. :: [P1] Preserve complete assistant content before suppressing native rows
  • reviewed 2026-08-19T14:48:00.054Z sha bb567cd :: found issues before merge. :: [P1] Preserve complete assistant content before suppressing native rows
  • reviewed 2026-08-25T15:41:11.018Z sha bb567cd :: needs real behavior proof before merge. :: [P1] Preserve complete assistant content before suppressing native rows
  • reviewed 2026-08-29T16:36:56.189Z sha bb567cd :: blocked before merge. :: [P1] Preserve assistant content before suppressing imported rows
  • reviewed September 5, 2026, 4:16 PM ET / 20:16 UTC sha unknown :: blocked before merge. :: [P1] Preserve native content before marking every record as represented
  • reviewed 2026-09-26T19:05:30.269Z sha bb567cd :: blocked before merge. :: [P1] Preserve native fragments before suppressing their UUIDs
  • reviewed 2026-10-02T15:34:17.818Z sha bb567cd :: blocked before merge. :: [P1] Preserve native content before claiming all assistant UUIDs

Reviewed October 17, 2026, 12:26 PM ET / 16:26 UTC (Revision 15).

@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🦞🔧
ClawSweeper applied a repair to this PR branch.

Repair: kept the fix on this contributor branch instead of opening a replacement PR.
Validation: pnpm check:changed
Updated head: bb567cd88c9f
Run: https://github.com/openclaw/clawsweeper/actions/runs/30773797117

Current state: exact-head review queued immediately; GitHub checks and the review verdict gate final merge.

Automerge progress:

  • 2026-08-03 00:25:31 UTC review requested repair 7af056968b43 (structured ClawSweeper needs-human verdict with repairable P-severity findings...)
  • 2026-08-03 00:32:02 UTC review queued bb567cd88c9f (after repair)

@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🦞🧹
ClawSweeper autofix is enabled.

  • Head: 7af056968b43
  • Label: clawsweeper:autofix
  • Action: exact-head review queued (workflow sweep.yml, event repository_dispatch).
  • Flow: review this head, repair/rebase only if needed, then re-review the exact repaired head until no actionable findings remain.

This is fix-only; I will not merge this PR.

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 force-pushed the clawsweeper/issue-openclaw-openclaw-118185 branch from 7af0569 to bb567cd Compare August 3, 2026 00:32
@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. clawsweeper:human-review Needs maintainer review before ClawSweeper can continue 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 3, 2026
@clawsweeper

clawsweeper Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

🦞✅
ClawSweeper is pausing this repair loop for human review.

Source: clawsweeper[bot]
Reason: - [ ] Preserve native content before claiming all assistant UUIDs (P1) - For a text → tool → final-text turn, this stamps the flat saved reply with UUIDs for records whose content it does not retain. The introduced...; Review finding: [P1] Preserve native content before claiming all assistant UUIDs — src/agents/cli-runner.ts:389-392 (sha=bb567cd88c9f8f05db950a54d6ed40dc37f68561)

Why human review is needed:
ClawSweeper found a blocker that should be resolved or accepted by a maintainer before the repair or automerge loop continues.

What the maintainer can do as a next step:
If the maintainer accepts the current risk and wants ClawSweeper to continue merge gates, comment @clawsweeper approve. If more work is needed, resolve the blocker first, then comment @clawsweeper automerge to re-review and continue. If automation should stay paused, leave clawsweeper:human-review in place or comment @clawsweeper stop.

I added clawsweeper:human-review and left the final call with a maintainer.

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 8, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 15, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 29, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 17, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Sep 18, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 26, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the stale Marked as stale due to inactivity label Sep 27, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Sep 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@steipete

Copy link
Copy Markdown
Contributor

Thanks for the PR. We're closing older pull requests that have gone stale against current main.

This automated fix has been blocked since August on a review finding that it would hide native content from history, with no further commits. The underlying duplicate-transcript issue stays open for a correct fix.

If this change is still needed, please open a fresh PR against current main and we'll review it there.

@steipete steipete closed this Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling clawsweeper:autofix Maintainer opted this PR into bounded ClawSweeper-reviewed autofix without merge clawsweeper:autogenerated PR created automatically by ClawSweeper clawsweeper:human-review Needs maintainer review before ClawSweeper can continue clawsweeper Tracked by ClawSweeper automation gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M stale Marked as stale due to inactivity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: One claude-cli turn is written to the transcript twice by two writers that assemble the reply differently

2 participants