Skip to content

fix(gateway): retain CLI metadata after history dedupe - #130494

Merged
jalehman merged 15 commits into
mainfrom
fix/cli-backend-session-metadata
Sep 8, 2026
Merged

jalehman merged 15 commits into
mainfrom
fix/cli-backend-session-metadata

Conversation

@jalehman

@jalehman jalehman commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #130456. Claude native-history rows that exactly matched local rows were deduplicated without transferring their import provenance, so chat.history lost the bound CLI session ID.

Why This Change Was Made

The history merge owner now preserves validated native identity metadata on the surviving local row and reports incorporation correctly across paginated history. It does not synthesize IDs downstream, duplicate visible messages, or change persistence schemas.

Repeated-text matching preserves transcript-order identity assignment without assuming timestamps are chronological. A timestamp index retains eligible candidates behind future-dated rows and across timestamp-less fallbacks; consumed rows cannot be reused.

User Impact

CLI-backed sessions retain native session identity after local/native history deduplication, so resume and history consumers can continue using the authoritative Claude session metadata.

Evidence

  • Reproduced the latest review counterexample against f1f34f3a6cbf: two local rows with timestamps [600000, 0] and one matching import incorrectly produced three visible rows. The repaired candidate returns two rows and preserves the imported identity on the matching survivor.
  • Focused regressions cover nonchronological timestamps, repeated identities, order across candidate pools, timestamp-less fallback, exact-identity reservation, image deduplication, anchored metadata, and offset pagination.
  • The 20,000-row repeated-text regression completed in approximately 0.54 seconds locally.
  • Validation on 4b17af97b545be1811ae04ff3da6febb2105bfc0: 231 focused CLI history/Gateway tests passed; required check:changed passed; formatting and diff checks passed.
  • Repaired the exact-head ClawSweeper P2: an unmatched imported row no longer advances the synthetic role/text floor, so a later timestamp-consistent import can enrich the eligible local survivor instead of producing a duplicate third row.
  • Mandatory independent autoreview completed through P2 on the frozen candidate. Its only finding was explicitly INDEX-only and confirmed the working-tree repair was correct; staging the reviewed files resolved it before commit.
  • No live Claude subscription-backed trace was captured; validation uses the real history merge and Gateway test boundaries with synthetic transcripts.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label Aug 26, 2026
@jalehman
jalehman marked this pull request as ready for review August 26, 2026 23:38
@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 26, 2026
@clawsweeper clawsweeper Bot added 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: 🦐 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 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 8, 2026, 5:30 PM ET / 21:30 UTC (Revision 7).

ClawSweeper review

What this changes

Preserves Claude CLI session metadata on deduplicated chat messages while maintaining transcript order, anchored reads, and offset pagination.

Merge readiness

✅ Ready for maintainer review

This remains a useful fix: current main and v2026.9.3 still discard metadata-only imports. The latest commit resolves the previous duplicate-row finding, and no remaining blocking correctness defect was established.

Priority: P2
Reviewed head: 4b17af97b545be1811ae04ff3da6febb2105bfc0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful regression coverage and the previous blocker resolved; reported validation was not rerun in this read-only review.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied Repository State classifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply. Synthetic transcript tests exercise the merge owner and Gateway history responses; no live Claude after-fix trace is claimed, and the related image screenshots do not prove metadata retention.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied Repository State classifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply. Synthetic transcript tests exercise the merge owner and Gateway history responses; no live Claude after-fix trace is claimed, and the related image screenshots do not prove metadata retention.
Evidence reviewed 9 items Current main still needs the fix: The resolver accepts merged messages only when their count increases; metadata-only incorporation still returns the original local messages with imported=false. The current-main merge implementation also skips duplicates without transferring their identity fields.
Latest release has the same limitation: The v2026.9.3 resolver also decides incorporation solely from increased message count; the requested repair is not present in that release.
Previous blocker repaired: The exact-head commit removes order-floor advancement after appending an unmatched import. Its regression now expects two rows and the later imported identity on the matching local survivor, addressing the previous completed review.
Findings None None.
Security None None.

How this fits together

Gateway chat history combines OpenClaw’s stored messages with the bound Claude CLI transcript. Deduplication selects the visible messages, then display projection and pagination prepare responses for history consumers.

flowchart LR
  A[Stored OpenClaw messages] --> C[History merge]
  B[Bound Claude transcript] --> C
  C --> D{Matching local message?}
  D -->|Yes| E[Retain local content and native metadata]
  D -->|No| F[Include imported message]
  E --> G[Display projection and pagination]
  F --> G
  G --> H[Chat history response]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +433, Tests +826. Total +1259 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 494 61 +433
Tests 3 852 26 +826
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 1346 87 +1259

Review metrics

Metric Value Why it matters
Production versus regression coverage Production net +433 lines; tests net +826 lines Production growth supports consumable timestamp candidates and metadata-preserving pagination, with regressions covering their ordering and recovery invariants.

Technical review

Best possible solution:

Keep identity enrichment in the history merge owner and preserve local content, transcript order, and established paging behavior.

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

Yes, from source: matching local and imported messages are deduplicated on current main without transferring native identity, and unchanged row count causes the resolver to discard metadata-only results. This review did not execute a reproduction.

Is this the best way to solve the issue?

Yes. Repairing the merge owner and distinguishing metadata incorporation from added rows addresses the defect without synthesizing downstream IDs or changing stored schemas.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied Repository State classifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply. Synthetic transcript tests exercise the merge owner and Gateway history responses; no live Claude after-fix trace is claimed, and the related image screenshots do not prove metadata retention.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: Repairs native-session attribution in CLI-backed chat history with a limited affected surface.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied Repository State classifies this as a maintainer-authored PR, so the external-contributor proof gate does not apply. Synthetic transcript tests exercise the merge owner and Gateway history responses; no live Claude after-fix trace is claimed, and the related image screenshots do not prove metadata retention.

Evidence

What I checked:

  • Current main still needs the fix: The resolver accepts merged messages only when their count increases; metadata-only incorporation still returns the original local messages with imported=false. The current-main merge implementation also skips duplicates without transferring their identity fields. (src/gateway/cli-session-history.ts:64, 1d2cdf26138f)
  • Latest release has the same limitation: The v2026.9.3 resolver also decides incorporation solely from increased message count; the requested repair is not present in that release. (src/gateway/cli-session-history.ts:64, 1391f7cd2d40)
  • Previous blocker repaired: The exact-head commit removes order-floor advancement after appending an unmatched import. Its regression now expects two rows and the later imported identity on the matching local survivor, addressing the previous completed review. (src/gateway/cli-session-history.merge.ts:650, 4b17af97b545)
  • Metadata stays with the surviving message: Projection copies only missing importedFrom, externalId, and cliSessionId values, preserving local content and existing metadata. Candidate consumption and transcript-order floors prevent one local row from absorbing multiple distinct imports. (src/gateway/cli-session-history.merge.ts:490, 4b17af97b545)
  • Paging and recovery continuity: Metadata-only full merges reuse the normal local page and project identity onto it, preserving recovery filtering and pagination. Anchored reads retain the complete-merge path; focused handler tests cover anchors, advancing offsets, and recovered-failure suppression. (src/gateway/server-methods/chat-history-pages.ts:487, 4b17af97b545)
  • Proof scope and prior review continuity: The captured PR body reports 231 focused tests and check:changed passing on the reviewed head, including the previous counterexample and a 20,000-row repeated-text case. It expressly reports no live Claude subscription-backed trace. Source inspection confirmed meaningful assertions; no tests or repository review helpers were executed during this read-only review. (src/gateway/cli-session-history.test.ts:2180, 4b17af97b545)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • jalehman: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • vincentkoc: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (6 earlier review cycles)
  • reviewed 2026-08-26T23:46:07.040Z sha c6f531a :: needs changes before merge. :: [P2] Preserve metadata on anchored history reads
  • reviewed 2026-09-04T22:44:14.003Z sha c6f531a :: blocked before merge. :: [P2] Preserve metadata on anchored history reads
  • reviewed 2026-09-08T15:45:48.111Z sha 3fb8e82 :: blocked before merge. :: [P2] Preserve recovery context when projecting metadata-only offset pages | [P2] Avoid rescanning consumed repeated-text candidates
  • reviewed 2026-09-08T16:49:16.977Z sha 90af34f :: needs maintainer review before merge. :: none
  • reviewed 2026-09-08T17:16:42.940Z sha f1f34f3 :: needs changes before merge. :: [P2] [P2] Match timestamps without assuming transcript order is chronological
  • reviewed 2026-09-08T20:49:08.264Z sha ccb696e :: blocked before merge. :: [P2] [P2] Keep local matches eligible after appending an unmatched import

@jalehman

jalehman commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
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 the merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. label Sep 8, 2026
@jalehman

jalehman commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 8, 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 Sep 8, 2026
@jalehman

jalehman commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
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 the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Sep 8, 2026
@jalehman

jalehman commented Sep 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
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: 🐚 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. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 8, 2026
@jalehman
jalehman merged commit 533ea31 into main Sep 8, 2026
188 of 189 checks passed
@jalehman
jalehman deleted the fix/cli-backend-session-metadata branch September 8, 2026 21:46
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 9, 2026
* fix(gateway): retain CLI metadata after history dedupe

* fix(gateway): preserve CLI history metadata

* fix(gateway): harden CLI history deduplication

* fix(gateway): preserve CLI history paging invariants

* fix(gateway): preserve CLI history identity order

* fix(gateway): preserve CLI history match ordering

* fix(gateway): preserve CLI match order across candidate pools

* fix(gateway): keep CLI match floors monotonic

* fix(gateway): retain deferred CLI history matches

* fix(gateway): preserve local matches after imports
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

[Bug]: CLI history drops Claude session metadata when native rows deduplicate

1 participant