Repository navigation
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
82a001f to
0b68d26
Compare
|
Codex review: blocked before merge. What this changesThis PR records which native Claude turn a stored assistant aggregate represents and replaces covered aggregates with native history blocks. Example: Claude emits “Checking.”, calls Bash with “pwd”, then emits “Done.”
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial Merge readiness⛔ Blocked before merge - 3 items remain Keep this PR open: it addresses a confirmed history bug with meaningful unique work, but two correctness defects still block merging. Priority: P2 Before merge
Findings
Provenance
Tests
Agent review detailsHow this fits togetherThe CLI runner persists assistant aggregates; Gateway history combines those records with native Claude transcripts and returns display messages to chat clients. flowchart LR
A[Claude CLI turn] --> B[CLI runner]
B --> C[Stored aggregate and native reference]
A --> D[Native transcript importer]
C --> E[Gateway history reconciliation]
D --> E
E --> F[Control UI and native clients]
Technical reviewBest possible solution: Preserve producer identity through accepted preparation and reconcile complete turns within the current history indexes without discarding aggregate-owned media or legacy fallback rows. Do we have a high-confidence way to reproduce the issue? The producer joins assistant text while current history matching compares individual imported rows; supplied real-Gateway captures and release-specific reports independently establish the multi-block duplicate, without a new execution in this read-only review. Is this the best way to solve the issue? The producer-owned identity is the right repair boundary and avoids unsafe text/time inference, but this implementation remains incomplete at transcript preparation and attachment preservation and must move into current main's canonical indexes. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cd4a35072fb0. Merge-risk optionsMaintainer options:
Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +288, Tests +915, Other 0. Total +1203 across 8 files. Added test files: 0. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (32 earlier review cycles; latest 8 shown)
Reviewed October 17, 2026, 11:14 PM ET / October 18, 2026, 03:14 UTC (Revision 33). |
|
Follow-up on the last review — the outstanding items are now addressed. [P1] Consume each imported turn only once — fixed in [P2] Complete next step — both halves done: the matching defect is repaired above, and the client-visible proof is attached below. Real behavior proof — before/after Control UI screenshots are now in the PR body, captured on a real Gateway (
One finding worth recording for anyone reproducing this — the duplicate only manifests on turns with two or more assistant text blocks separated by tool calls. A turn whose text is a single final block after N tool calls never duplicated: the aggregate and the native block are byte-identical, so the pre-existing per-message equality dedupe already collapsed them. That is why a casual reproduction attempt tends to come back clean; it cost me several failed attempts before the shape became obvious. It is now documented in the PR body. @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
[P1] Restrict suppression to Suppression now requires the aggregate's own contract rather than its shape:
so the key is available at merge time and is authoritative. Any Verified against a live store that this narrows without regressing: all 118 [P2] Complete next step — done as the mechanical repair described, no product-direction change. On "behind current main" — validation was refreshed on the exact merge head: the branch was rebased onto One unrelated observation while validating: @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
91f8dcb to
b1aae1f
Compare
|
Last remaining item closed: the branch is now rebased onto current Validation re-run on that exact head (
No code changes since the last review; the three commits are the same work replayed on the new base. One pre-existing failure I am deliberately not fixing here, per the contributing guidance on known @clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
CI has finished on the rebased head ( Both reduce to one infrastructure event, not a code failure. From the Exit 143 is SIGTERM — the hosted runner was reclaimed ~5 minutes into the For what it is worth, A re-run of that job should clear both. I cannot trigger it myself — the API returns |
b1aae1f to
b64a712
Compare
|
Rebased onto current The conflictExactly one commit on Six commits replayed onto Real-Gateway Control UI proofThe earlier captures came from Two Gateways, each built from source and serving its own
Same Control UI on both sides, and that is checkable rather than asserted: this PR changes 0 files under The session shown is a real subagent run. Its local store holds two message events; the bound Claude transcript holds one assistant turn of 17 text blocks separated by 66 Base
|
| count | |
|---|---|
persisted cli-assistant: aggregates in the store |
428 |
| covered by an imported turn, i.e. replaced by this PR | 48 |
| retained as the durable fallback | 380 |
sessions bound to claude-cli |
29 |
| sessions whose rendered history changes at all | 15 |
So 11% of the aggregates are replaced and 89% survive. The session rendered above matches that scan: its covered aggregate is dropped, and an uncovered aggregate in the same session is still rendered by the head build.
Limits of this evidence, stated plainly
- One operator's store on one machine. It is a real production store rather than a fixture, but it is a single sample.
- The snapshot needed
openclaw doctor --fixto migrate its schema before either Gateway would open it. Both Gateways then read the identical migrated snapshot, so the migration cannot account for the difference between them. - The screenshots are cropped to the transcript pane to keep operator session titles and account identifiers out of frame. Nothing inside the pane is altered.
- No skill-invoking turn. You asked to see the skill case rendered once with its native cards. None of the 48 covered turns in this store invokes the
Skilltool — they areBash,Edit,Read,web_fetch,browser. I could stage one, but a staged turn is a fixture with extra steps, so I would rather report that the shape is absent from the real data available to me than present it as found evidence. The regressions in this PR still cover the harness-row contract at the importer level.
|
Rebased onto The fact the async projection has to carry is
|
|
CI on this head is green except one shard, and it is the same flake that was red on the previous head.
The same test, in the same shard, with the same timeout, failed on head
The run before the timeout is not a partial failure — the shard logs the preceding On the exact head the file is green locally: This PR changes 0 files under Everything else is passing. Final tally on this head: 205 green, 47 skipped, 0 pending, 2 red — that shard and |
|
Addressed. The P1 is real, and the answer is not a narrower heuristic — the merge no longer infers the relation at all, because the producer now records it. Why no text rule can be made safeThe counterexample does not need repeated aggregates or an unusual window. One local aggregate, one imported turn, identical text, same provider, correct ordering — and they are different turns. I checked whether requiring global uniqueness on both sides rescues it: it does not. That shape is globally unique on both sides and still crosses. Text, provider and time establish resemblance; nothing built from them establishes identity. The relation already existed in the data flow — it was just never persistedRun settlement is the one point that sees both the flattened aggregate and the native records it came from. It already resolves the native record id of the run's terminal assistant message, for resume ( So the producer records it ( cliNativeTurn: { cliSessionId, terminalRecordId }What the merge does now
The text comparison that remains is not an identity test any more. It runs on an already-identified pair and asks a different question: whether the import still carries the whole turn. A trimmed or partial import no longer covers the aggregate's text, so the aggregate is kept — the fail-open fallback you asked to preserve, now on a proven pair rather than a guessed one. Deleted: the five-minute window for aggregates, the text-and-provider keyed index, the ordered two-pointer pairing, and the nearest-turn selection. Fail-open by construction: an aggregate that names no turn is never replaced. That is every record persisted before this existed, every backend with no native transcript, and every run whose terminal record was not reported. The regression you asked for
Run against the previous matcher it fails, together with five other fail-open guarantees that matcher violated: All pass on this head. End to end, not just at the seamsA field lost between the producer and the merge would turn this into a silent no-op that unit tests still pass. Verification on the exact headTwo things I want to be explicit aboutThe Control UI capture in the PR body no longer demonstrates this head. It showed a legacy aggregate — persisted long before this field existed — being replaced. Under identity that aggregate is now correctly left alone. The "before" half still stands as evidence that the defect is real in production history; the "after" half is superseded and I have marked it so in the body rather than leave it reading as current proof. New live evidence needs a real CLI turn recorded by this build, which I have not run yet. This fix is forward-looking, deliberately. Aggregates already on disk carry no link and are never replaced, so the duplicate stays visible for existing history until those sessions produce new turns. Cleaning those up would require exactly the text-and-time inference this finding rejects. If you would rather have a one-time backfill, that is a separate decision with its own risk, not something I will smuggle in here. Production is +372/-82 across five files; tests +915. The producer commit stands alone and could ship separately if you would rather review it on its own. This comment is not a claim of a complete safety review. |
CLI backends persist each assistant turn twice: once as the synthetic `api: "cli"` aggregate whose text is the turn's text blocks joined, and again as the native blocks the Claude CLI transcript import brings back. Those are two shapes of the same turn, so per-message equality can never pair them and the turn renders twice (openclaw#123792). The merge owner now groups imported assistant messages into turns and pairs each turn with the persisted aggregate that duplicates it. Within one text and producer the two sides are matched in timestamp order: the aggregate is written once the turn completes, so the earliest turn that finished no more than the dedupe window before an aggregate owns it. Pairing is one-to-one, so two genuinely repeated replies with identical text are only both suppressed when the import actually holds both turns. An unmatched aggregate is retained, which keeps the durable fallback for an incomplete or trimmed import. `api: "cli"` alone is not unique to the aggregate — ordinary CLI assistant replies are persisted the same way. The producer stamps `idempotencyKey: "cli-assistant:<runId>"` and the transcript append spreads it onto the stored message, so that key is the discriminator; every other `api: "cli"` record is retained. Blocks of a turn that replaced an aggregate are flagged, because such a block is then the only surviving copy of its text and weak role/text dedupe must not discard it as well. A one-for-one replacement leaves the message count unchanged, so the resolver reports an import by identity rather than by length. Grouping needs every imported row prepared before the merge loop, which only pays for itself when a local aggregate could actually be covered. A session without one keeps the lazy, skip-on-identity path from openclaw#133316 untouched. `prepareComparableMessage` derives the turn facts from the single read it already makes of each field, so the added pass reads no raw property twice, and `resolveImportedExternalIdentityKey` reaches the same metadata through `asOptionalRecord` instead of four unchecked type assertions. Co-authored-by: Ayaan Zaidi <[email protected]> Co-Authored-By: Claude Opus 5 <[email protected]>
The async snapshot routes any JSONL line past 1 MiB through a bounded worker projection instead of the synchronous decoder. That projection rebuilds the entry from a fixed field list, so a turn-boundary fact the grouping reads has to survive it: a harness row dropped on one path and kept on the other would split the turn on that path alone, and the aggregate would stay beside the native blocks again. Both regressions run the real JSONL importer and the real resolver, not the merge helper: - An oversized `isMeta` skill instruction row projects to exactly what the synchronous reader produces, and the resolver replaces the aggregate with the two native text blocks. - An oversized compaction summary survives as the bounded placeholder, still ends the turn, and the aggregate is kept as the durable fallback. The first is load-bearing: dropping `isMeta` from the worker payload and its normalizer makes the async reader emit the harness row, and the parity assertion fails. Co-Authored-By: Claude Opus 5 <[email protected]>
A CLI backend persists one synthetic assistant message per run whose text is that run's assistant text blocks joined. The same turn also exists as native records in the backend's own transcript, and the Gateway imports those when serving chat history. Nothing linked the two, so every reader had to guess which imported turn an aggregate duplicated from its text, its provider and its timestamp. Run settlement is the one point that sees both at once. It already resolves the native record id of the run's terminal assistant message for resume, so it now records that id, with the native session that owns it, on the aggregate it persists. The link is absent whenever it cannot be established: a backend that writes no native transcript, a run whose terminal record was not reported, and every aggregate written before this existed. Readers then have no relation to act on, which is the safe direction. Co-Authored-By: Claude Opus 5 <[email protected]>
The merge paired a persisted aggregate with an imported turn by normalized text, provider and a five-minute window. That is resemblance, not identity: when either side of the history is partial, an unrelated turn with the same text can claim an aggregate whose own turn is missing from the import, and the only durable copy of a distinct assistant turn disappears from chat history. The producer now records which native turn each aggregate flattens, so the merge resolves that relation instead of inferring one. Imported turns are indexed by the native record their last message came from, and an aggregate is only ever replaced by the turn it names, in the native session it names. The text comparison that remains is no longer an identity test. It runs on an already-identified pair and asks a different question: whether the import still carries the whole turn. A trimmed or partially imported turn no longer covers the aggregate's text, and the aggregate is kept as the durable copy. An aggregate that names no turn is never replaced. That covers every record persisted before the producer recorded the link, so the fix applies to turns written from here on rather than deleting history on a guess about the past. This removes the dedupe window, the text-and-provider keyed index, the ordered two-pointer pairing and the nearest-turn selection. What is left is one lookup by native record id. Co-Authored-By: Claude Opus 5 <[email protected]>
|
This pull request has been automatically marked as stale due to inactivity. |
|
Closing due to inactivity. |





Closes #123792
What Problem This Solves
Claude CLI history could render one assistant turn twice in the Control UI and Android app. The rich imported turn appeared first with native tool cards. A flat persisted copy appeared below it.
Telegram delivery is not affected because it does not render merged history.
Root Cause
The CLI runner persists one synthetic assistant aggregate with
api: "cli"andidempotencyKey: "cli-assistant:<runId>". The Gateway also imports the bound Claude transcript as native text and tool-call blocks.The old merge compared one message at a time. It could not match one aggregate such as
text one\n\ntext twoto several imported blocks from the same turn.Underneath that, nothing linked the two shapes at all. Only the producer sees both the flattened aggregate and the native records it came from, and it recorded no relation, which left every reader inferring one from text, provider and timing.
Fix
The producer records the relation, and the merge resolves it instead of inferring one.
cliNativeTurn: { cliSessionId, terminalRecordId }, a declared field on the transcript message contract.toolcallIDs, names, and arguments.This removes the five-minute window for aggregates, the text-and-provider keyed index, the ordered pairing and the nearest-turn selection. The resolver uses result identity so a one-for-one replacement still counts as an import.
Fail-open by construction. An aggregate that names no native turn is never replaced. That covers every record persisted before this field existed, every backend that writes no native transcript, and every run whose terminal record was not reported. The consequence is deliberate: the duplicate stays visible for history already on disk until those sessions produce new turns. Removing those would require exactly the text-and-time inference this design rejects, because no rule built from text, provider and time can tell a true duplicate from a distinct same-text turn when either history is partial.
The async snapshot reader projects any JSONL line past 1 MiB through a bounded worker. That projection rebuilds the entry from a fixed field list, so the turn-boundary facts the grouping reads have to survive it; an importer/resolver parity regression covers both readers over the same oversized transcript.
The rebase onto current
mainintegrates #130463 and #133316, the commits that have touchedcli-session-history.merge.tssince this PR's original base. #133316's prepared-facts refactor is the base — its injected identity key, itslocalImageMediaCountsmap — and the aggregate/turn matching is layered on top, so its tests and this PR's regressions both hold. Preparing the whole import ahead of the merge loop is gated on the session actually holding a persisted aggregate, so a session without one keeps #133316's lazy, skip-on-identity path unchanged.Evidence
Head:
8a7447409ff9c3ae3118a029116e1ab7a83fa2c6, rebased onto43e9a3d817(currentmain). The evidence below was measured onb538e9752c, the same four commits before that rebase; the rebase carried them across 409 upstream commits with no conflicts and no diff change.Current-main reproduction, re-run on that exact base: applying this PR's regression file to
86b6ec0afaand leaving main's merge owner in place fails 11 tests.Four of them:
replaces a persisted aggregate with the imported native turn blocks— expected a length of 4, got 5. The persisted aggregate remains beside the imported native blocks.keeps a skill instruction row inside the turn it belongs to— expected 0 aggregates, got 1. fix(gateway): chat history shows injected skill instructions on claude-cli sessions #130269 already hides the skill instruction row on that base, and the turn still renders twice.projects an oversized skill instruction row exactly as the sync reader does— expected 0 aggregates, got 1. The same defect through the async snapshot's bounded worker projection.keeps the only local aggregate when the import holds a different turn with the same text— the aggregate is deleted. This is the crossed partial-history loss path, and it is the reason this PR resolves aggregates by recorded identity rather than by text and time.Focused proof on the head:
One of those,
carries the recorded native turn from the CLI producer through to the merge, drives the real producer, the real SQLite store, the real display projection, the real JSONL importer and the real resolver, so a field lost at any of those seams fails the suite instead of silently disabling the fix.Repo checks on the head:
pnpm tsgo:coreandpnpm tsgo:test:srcclean,run-oxlint src/gateway src/agents0 warnings and 0 errors, the assertion-safety and max-lines ratchets OK,oxfmt --checkclean. Thecli-session-history.merge.tsassertion-safety baseline entry shrinks6 → 1.The resolver test reads a real Claude JSONL fixture. It asserts the retained imported content is exactly the text block plus
{ type: "toolcall", id: "toolu_1", name: "Bash", arguments: { command: "pwd" } }. The UI normalization test confirms that shape remains a native tool card.Repeated-text benchmark with 24,000 imported turns and 24,000 aggregates. Measured on
6e25b0ae, an earlier head, and not re-run since:The Telegram fallback run, also on
6e25b0ae, recorded one deterministic direct-message turn because this history-only change is not Telegram-visible. The bot typed and returnedOPENCLAW_E2E_OK; the mock provider received onePOST /v1/responses.Control UI Proof
Measured on two live Gateways, each built from source and serving its own
chat.historyfrom the same store: a copy of a production OpenClaw agent store holding 878 persistedcli-assistant:<runId>aggregates. Only the commit differs, and the Control UI is byte-identical on both sides because this PR changes 0 files underui/.86b6ec0afab538e9752cThe turn was produced by running a real agent turn through the head build, not by editing a store: Claude CLI 2.1.250 on the
claude-clibackend, prompted for a line of text, thenpwdthrough Bash, then a closing sentence — the two-text-blocks-around-a-tool-call shape this bug needs. The producer recorded the relation on that run:terminalRecordIdis the turn's terminal native assistant record.86b6ec0afab538e9752cBashcardmsg:id:687e4295-…The durable fallback holds on that same head: a session whose aggregate predates
cliNativeTurnkeeps its 6,781-character aggregate, because it names no native turn. In that store 1 aggregate carries the relation and 877 do not, and none of the 877 can be replaced.Screenshots and the full measurement are in this comment, including what the capture does not cover: that store holds no
Skillturn, so the skill case stays covered by the regressions rather than by a capture.🤖 Generated with Claude Code