Skip to content

fix(gateway): dedupe redacted local transcripts against full CLI imports - #112934

Closed
he-yufeng wants to merge 2 commits into
openclaw:mainfrom
he-yufeng:fix/cli-history-redaction-dedupe
Closed

he-yufeng wants to merge 2 commits into
openclaw:mainfrom
he-yufeng:fix/cli-history-redaction-dedupe

Conversation

@he-yufeng

@he-yufeng he-yufeng commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The gateway persists the redacted form of an inbound message to its local transcript (e.g. agent%…4000), while the bound claude-cli session file keeps the full text. isEquivalentImportedMessage in cli-session-history.merge.ts deduped the two histories on exact text equality, so the redacted local and the full import never matched and both survived the merge, rendering the message twice in the Control UI (#112930).

The fix also accepts the redacted form of the imported text as equivalent. Only the import side is transformed: masking is not idempotent (an already masked token degrades to *** on a second pass), so transforming both sides would break the comparison instead of fixing it. The exact-equality fast path is unchanged, so unredacted messages dedupe the same way as before.

Evidence

Two new cases in cli-session-history.test.ts: a redacted local plus the full import now merges to one entry, and a local entry that differs beyond redaction ((edited)) still merges as two, so the change does not over-dedupe. Suite is 123/123 green locally, oxlint and tsc clean.

Fixes #112930.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 23, 2026
@steipete steipete self-assigned this Jul 25, 2026
he-yufeng and others added 2 commits July 25, 2026 05:24
The gateway persists the redacted form of a message while the bound
claude-cli session file keeps the full text. mergeImportedChatHistoryMessages
deduped on exact text equality, so any message carrying a redactable
token survived the merge in both forms and rendered twice in the Control
UI. Also accept the redacted form of the imported text. Masking is not
idempotent, so only the import side is transformed; messages that differ
beyond redaction still merge as separate entries.

Signed-off-by: Yufeng He <[email protected]>
@steipete
steipete force-pushed the fix/cli-history-redaction-dedupe branch from e16c7f2 to f7fc964 Compare July 25, 2026 12:30
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 25, 2026
@clawsweeper

clawsweeper Bot commented Jul 25, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 5:55 AM ET / 09:55 UTC.

ClawSweeper review

What this changes

The PR updates gateway transcript merging to recognize redacted and full-text copies of the same CLI-bound message while retaining separate messages that differ for reasons other than redaction.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 5 items remain

This PR still addresses a real current-main gap: the existing merge logic requires exact text equality, so a redacted local transcript and the full CLI import remain separate. The branch’s collision-aware matching approach appears directionally correct and is linked to the canonical report, but it needs a clean rebase and visible after-fix behavior proof before merge.

Priority: P2
Reviewed head: f7fc964fb7f3bc259b5e05ed431570b6cf83289e

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch has focused safeguards and regression coverage, but test-only evidence does not clear the required real-behavior proof gate.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The PR body reports unit tests, lint, and type checks, but the available context has no after-fix proof from a real CLI-bound session and Control UI transcript. Add redacted terminal output, runtime logs, or a short recording; redact URLs, tokens, addresses, and other private details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The PR body reports unit tests, lint, and type checks, but the available context has no after-fix proof from a real CLI-bound session and Control UI transcript. Add redacted terminal output, runtime logs, or a short recording; redact URLs, tokens, addresses, and other private details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main behavior: Current main retains exact-text comparison in the CLI session-history merge path, so a masked local message and its unmasked imported counterpart do not match through the existing text branch.
Proposed repair and regression coverage: The PR head introduces a lossless-versus-lossy redaction match distinction, identity-conflict protection, and focused cases for matching redacted/full copies while preserving messages that differ beyond redaction.
Canonical report relationship: The PR body and timeline link this work to the open report describing duplicate Control UI messages after local redaction and CLI import; that report remains the canonical user-impact record.
Findings None None.
Security None None.

How this fits together

The gateway combines its local chat transcript with messages imported from a bound CLI session before the Control UI renders history. Local persistence redacts sensitive-looking text, while CLI imports can retain the full text, so the merge step must distinguish one logical message from genuinely distinct messages.

flowchart LR
  A[Inbound chat message] --> B[Gateway local transcript]
  A --> C[Bound CLI session]
  B --> D[Redacted local text]
  C --> E[Full imported text]
  D --> F[Transcript merge]
  E --> F
  F --> G[Deduplicated chat history]
  G --> H[Control UI]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The PR body reports unit tests, lint, and type checks, but the available context has no after-fix proof from a real CLI-bound session and Control UI transcript. Add redacted terminal output, runtime logs, or a short recording; redact URLs, tokens, addresses, and other private details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The PR changes transcript identity decisions for persisted/imported chat history; an overly broad lossy-redaction match could suppress a genuinely distinct message, so the collision guards require validation on the rebased head.
  • Resolve merge risk (P1) - GitHub currently reports the branch as dirty against current main, leaving the actual merge result and current-main test coverage unconfirmed.
  • Resolve merge risk (P1) - The available evidence is test-only; merge should wait for redacted real-session proof that the Control UI shows one message without exposing sensitive values.
  • Complete next step (P2) - The contributor needs to rebase the dirty branch and provide real behavior proof; no narrow automated code repair is identified from the reviewed context.
Agent review details

Security

None.

PR surface

Source +144, Tests +301. Total +445 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 152 8 +144
Tests 1 301 0 +301
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 453 8 +445

Review metrics

Metric Value Why it matters
Lossy match path 1 added redaction-equivalence match mode This new deduplication path can affect persisted chat-history identity and therefore needs both collision proof and upgrade-safe validation.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #112930
Summary: This PR is the candidate fix for the open canonical report about duplicate Control UI messages caused by redacted local and full CLI-imported transcript copies.

Members:

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

Merge-risk options

Maintainer options:

  1. Rebase and prove the real transcript path (recommended)
    Resolve the current merge state, rerun the focused merge coverage on the rebased head, and add redacted runtime evidence from a CLI-bound session before merge.
  2. Pause until runtime proof is available
    Keep the PR open if a real CLI-bound transcript cannot be captured without exposing sensitive data, rather than merging on unit coverage alone.

Technical review

Best possible solution:

Rebase onto current main, preserve the identity-conflict and non-redaction-difference safeguards, and attach redacted proof from a real CLI-bound conversation showing that reload/import produces one Control UI message.

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

No high-confidence executed reproduction was available in this read-only review. The current-main exact-text comparison and the linked report provide a clear source-level reproduction path using a redactable message in a CLI-bound Control UI session.

Is this the best way to solve the issue?

Unclear: matching a full import against its redacted representation is a narrow fix for the demonstrated divergence, and the branch adds collision safeguards, but rebased runtime proof is still needed to establish that this is the safest final rule.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The PR targets a bounded duplicate-message defect in a specific CLI-bound transcript path, with no evidence of outage, data loss, or security bypass.
  • merge-risk: 🚨 session-state: The changed matching rule decides whether local and imported transcript records survive as separate messages or one history entry.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR body reports unit tests, lint, and type checks, but the available context has no after-fix proof from a real CLI-bound session and Control UI transcript. Add redacted terminal output, runtime logs, or a short recording; redact URLs, tokens, addresses, and other private details. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current-main behavior: Current main retains exact-text comparison in the CLI session-history merge path, so a masked local message and its unmasked imported counterpart do not match through the existing text branch. (src/gateway/cli-session-history.merge.ts, 36440de61dc4)
  • Proposed repair and regression coverage: The PR head introduces a lossless-versus-lossy redaction match distinction, identity-conflict protection, and focused cases for matching redacted/full copies while preserving messages that differ beyond redaction. (src/gateway/cli-session-history.merge.ts:101, f7fc964fb7f3)
  • Canonical report relationship: The PR body and timeline link this work to the open report describing duplicate Control UI messages after local redaction and CLI import; that report remains the canonical user-impact record. (src/gateway/cli-session-history.test.ts:845, f7fc964fb7f3)
  • Recent branch provenance: The supplied PR history shows the collision-safety revision at the current head, authored by steipete with co-authorship attribution, after the initial contributor implementation. (src/gateway/cli-session-history.merge.ts:101, f7fc964fb7f3)
  • Proof gap: The PR body reports focused tests, lint, and type checks, but the available review context does not contain a redacted real CLI-bound session and resulting Control UI transcript, terminal output, recording, or runtime log proving the before/after behavior.
  • Merge freshness: GitHub reports the branch as dirty against main, so the collision safeguards and focused tests must be revalidated on a rebased head rather than relying on the older base. (f7fc964fb7f3)

Likely related people:

  • steipete: The current PR head is the collision-safety revision attributed to this contributor, and the timeline also records assignment and a force-push during the repair iteration. (role: recent area contributor; confidence: medium; commits: f7fc964fb7f3; files: src/gateway/cli-session-history.merge.ts, src/gateway/cli-session-history.test.ts)

Rank-up moves

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

  • Rebase the branch onto current main and resolve the reported dirty merge state.
  • Post redacted after-fix evidence from a real CLI-bound session showing the Control UI imports one message rather than two.
  • Update the PR body with the evidence; if review does not refresh automatically, ask a maintainer to comment @clawsweeper re-review.

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 (1 earlier review cycle)
  • reviewed 2026-07-25T12:36:17.118Z sha f7fc964 :: needs real behavior proof before merge. :: none

@steipete

steipete commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Thank you, @he-yufeng, for identifying and testing the redacted/full Claude-history mismatch. The linked issue #112930 is now fixed on main by #115597 (95f62ee): imported history passes through the existing canonical transcript sanitizer before the existing identity-aware deduplication. This fixes both the duplicate UI message and secrets present only in imported CLI history, without adding lossy transcript-identity heuristics.

I independently verified the exact behavior with a real Claude projects JSONL, the production gateway importer and merger, and actual Chromium: the pre-fix importer reproducibly returns three messages instead of two; the landed importer renders one masked user message, preserves the imported assistant UUID and untouched external JSONL, and never exposes the synthetic secret. Before/after proof: https://github.com/openclaw/openclaw/actions/runs/30426219625. Full importer, shared redactor, both gateway consumers, and Chromium history proof: https://github.com/openclaw/openclaw/actions/runs/30426091491.

Closing as superseded by the landed canonical fix. Thank you again for surfacing this and contributing the regression cases.

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

Labels

gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

2 participants