Skip to content

fix(compaction): annotate partial summaries with chunk order and source time range - #100684

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
zw-xysk:fix/issue-100636-chunk-labels
Jul 6, 2026
Merged

vincentkoc merged 2 commits into
openclaw:mainfrom
zw-xysk:fix/issue-100636-chunk-labels

Conversation

@zw-xysk

@zw-xysk zw-xysk commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

In summarizeInStages, partial summaries are wrapped into synthetic AgentMessage objects before the final merge pass. Previously each synthetic message used Date.now() as its timestamp and no ordering metadata was embedded in the content. Since serializeConversation (in agent-core) only preserves text content and discards timestamps, the LLM merger could not distinguish which summary chunk represented older vs newer history, making the "PRIORITIZE recent context" merge instruction ineffective. Fixes #100636.

Changes

src/agents/compaction.ts

  • New helper extractChunkTimeRange() — extracts the min/max timestamp range from each chunk of original messages and formats it as a human-readable time range.
  • Modified summarizeInStages — each synthetic merge message now carries a chunk label with chronological position and source time range embedded in its content (e.g., [Chunk 1 — oldest messages [2026-07-05 14:00 — 2026-07-06 09:30]]). Also sets proper monotonic timestamps from a single Date.now() capture.

src/agents/compaction.identifier-preservation.test.ts

  • Added assertions verifying that the merge messages receive the chunk ordering labels with time range during staged split+merge summarization.

Evidence

Unit tests (136/136 passed across 5 test files):

 Test Files  5 passed (5)
      Tests  136 passed (136)

Type check: pnpm tsgo:core:test — zero errors.

Real behavior proof (10/10 verification checks):

The proof script exercises the actual code paths with realistic multi-hour conversation data, showing labels are correctly constructed and serialized:

==============================================================================
  REAL BEHAVIOR PROOF  --  Issue #100636
==============================================================================
  Host : LIN-66D8BD4EA2C  PID : 2133662  Time : 2026-07-06T06:57:06Z
  Messages : 35  Tokens : ~4218

  Phase 1: Split plan - 3 chunks with distinct time ranges
    Chunk 1: [2026-07-06 11:57 -- 2026-07-06 12:13]
    Chunk 2: [2026-07-06 12:14 -- 2026-07-06 12:39]
    Chunk 3: [2026-07-06 13:57 -- 2026-07-06 14:38]

  Phase 2: Synthetic merge labels
    [Chunk 1 - oldest messages [2026-07-06 11:57 -- 2026-07-06 12:13]]
    [Chunk 2/3 [2026-07-06 12:14 -- 2026-07-06 12:39]]
    [Chunk 3 - most recent messages [2026-07-06 13:57 -- 2026-07-06 14:38]]

  Phase 3: LLM-visible serialized output (via serializeConversation)
    [User]: [Chunk 1 - oldest messages [...]]  ...
    [User]: [Chunk 2/3 [...]]  ...
    [User]: [Chunk 3 - most recent messages [...]]  ...

  Verification: 10/10 checks passed

Review

  • Manually reviewed and verified
  • AI-assisted: Yes

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS labels Jul 6, 2026
@zw-xysk
zw-xysk force-pushed the fix/issue-100636-chunk-labels branch from 3ada122 to e6d0919 Compare July 6, 2026 06:55
@zw-xysk
zw-xysk force-pushed the fix/issue-100636-chunk-labels branch from e6d0919 to 2a530f2 Compare July 6, 2026 06:57
@zw-xysk

zw-xysk commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 6, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@clawsweeper

clawsweeper Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 6, 2026, 3:49 AM ET / 07:49 UTC.

Summary
The PR adds LLM-visible chunk-order and source-time-range labels to staged compaction merge messages and updates the staged merge test assertions.

PR surface: Source +46, Tests +13. Total +59 across 2 files.

Reproducibility: yes. current main builds final staged merge messages as unlabeled user content with Date.now timestamps, and agent-core serialization emits user content without timestamps. I did not run a live model-quality compaction session in this read-only review.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #100636
Summary: This PR is the strongest current candidate fix for the open staged-compaction metadata issue because it makes chunk chronology visible in serialized merge content.

Members:

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

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P2] Rerun or classify the unrelated failing whole-shard tooling check before merge.

Risk before merge

  • [P1] One current broad CI shard fails in tooling/package-acceptance coverage outside this PR's changed files; it needs rerun or maintainer classification before merge, but I did not find a diff-caused compaction defect.

Maintainer options:

  1. Decide the mitigation before merge
    Land this content-label fix as the canonical staged-compaction repair once CI is green or the unrelated failing shard is classified, then close the linked issue and supersede timestamp-only sibling attempts.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • [P2] No automated code repair is indicated; maintainers should rerun or classify the unrelated failing CI shard and then handle normal merge review.

Security
Cleared: The diff changes agent compaction code and a colocated test only; it does not touch dependencies, lockfiles, CI, secrets, permissions, or supply-chain surfaces.

Review details

Best possible solution:

Land this content-label fix as the canonical staged-compaction repair once CI is green or the unrelated failing shard is classified, then close the linked issue and supersede timestamp-only sibling attempts.

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

Yes: current main builds final staged merge messages as unlabeled user content with Date.now timestamps, and agent-core serialization emits user content without timestamps. I did not run a live model-quality compaction session in this read-only review.

Is this the best way to solve the issue?

Yes: putting chunk order and source time ranges into the synthetic merge message content is the narrowest maintainable fix because the serializer drops timestamps. The timestamp-only sibling PRs are less complete because they do not make chronology visible to the merger model.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied live output from an after-fix proof script showing chunk labels and serialized merge input from the changed compaction path.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: This is a normal-priority agent compaction correctness PR with limited blast radius and no release-blocking or security signal.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes copied live output from an after-fix proof script showing chunk labels and serialized merge input from the changed compaction path.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes copied live output from an after-fix proof script showing chunk labels and serialized merge input from the changed compaction path.
Evidence reviewed

PR surface:

Source +46, Tests +13. Total +59 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 51 5 +46
Tests 1 13 0 +13
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 64 5 +59

What I checked:

  • Current-main behavior still loses LLM-visible chronology: Current main maps partial summaries to synthetic user messages with raw summary content and fresh Date.now timestamps before the final merge, so the central issue is not already implemented on main. (src/agents/compaction.ts:389, be48a430bfa6)
  • Serializer contract supports putting labels in content: The final merge path calls agent-core generateSummary, which converts messages and serializes user messages from content without including timestamp fields. (packages/agent-core/src/harness/compaction/compaction.ts:633, be48a430bfa6)
  • PR head makes chunk metadata model-visible: The PR prefixes each synthetic merge message content with a chunk label and source time range before passing it into summarizeWithFallback for the merge pass. (src/agents/compaction.ts:419, f7052bbbeb68)
  • Prior ClawSweeper finding was addressed: The latest head changed the added test from reading content on AgentMessage[] to an exact synthetic merge-message shape, resolving the previous type-check finding on this test. (src/agents/compaction.identifier-preservation.test.ts:123, f7052bbbeb68)
  • Related issue and sibling PR search: Live GitHub search found the linked open issue, this PR, one open timestamp-only sibling, and one closed timestamp-only sibling; no merged PR already owns the content-label fix.
  • History provenance for the staged merge path: git blame ties the current summarizeInStages merge-message construction to recent compaction work in commit 62d9576, while git log -G traces staged helpers back to ae0741a. (src/agents/compaction.ts:341, 62d957634c53)

Likely related people:

  • steipete: git blame ties the current staged summarizeInStages implementation to Peter Steinberger's recent compaction commit, and git log shows earlier staged helper work in the same file. (role: introduced behavior and recent area contributor; confidence: high; commits: 62d957634c53, ae0741a3466c; files: src/agents/compaction.ts, src/agents/compaction-planning.ts, src/agents/compaction-planning-worker.ts)
  • vincentkoc: The agent-core compaction serializer path that determines whether timestamps reach the prompt was introduced in commit e085fa1, and Vincent Koc is also co-authored on nearby recent compaction work. (role: adjacent compaction serializer contributor; confidence: medium; commits: e085fa1a3ffd, 62d957634c53; files: packages/agent-core/src/harness/compaction/compaction.ts, packages/agent-core/src/harness/compaction/utils.ts, src/agents/compaction.ts)
  • Ayaan Zaidi: History shows multiple compaction split/tool-turn repairs around the chunking invariant used before staged summarization. (role: adjacent compaction contributor; confidence: medium; commits: cde1e2d3a110, 3f7bd3bd7b6b, b1d853d88b88; files: src/agents/compaction.ts, src/agents/compaction-planning.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (1 earlier review cycle)
  • reviewed 2026-07-06T07:10:39.679Z sha 2a530f2b55a9714021b20cee7281b66c29ed83e3 :: needs changes before merge. :: [P2] Narrow merge messages before reading content

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. P2 Normal backlog priority with limited blast radius. labels Jul 6, 2026
@zw-xysk
zw-xysk force-pushed the fix/issue-100636-chunk-labels branch from 2a530f2 to 84be326 Compare July 6, 2026 07:13
@zw-xysk

zw-xysk commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 6, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@zw-xysk

zw-xysk commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 6, 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 repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

@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: 🦪 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. labels Jul 6, 2026
@vincentkoc vincentkoc self-assigned this Jul 6, 2026
zhangqueping added a commit to zhangqueping/openclaw that referenced this pull request Jul 6, 2026
…time ranges

Add extractChunkTimeRange helper that scans each chunk for min/max
timestamp bounds and formats them as human-readable date ranges.
Annotate each partial summary with [Chunk N — oldest/most recent
messages [YYYY-MM-DD HH:MM — YYYY-MM-DD HH:MM]] labels so the LLM
merger can distinguish old from new context. Use descending
timestamps for strict monotonicity across synthetic messages.

The label goes into message content because serializeConversation
preserves only text, discarding timestamps.

Co-Authored-By: PR openclaw#100684 approach

Fixes openclaw#100636
@vincentkoc
vincentkoc requested a review from a team as a code owner July 6, 2026 09:10
@github-actions

github-actions Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh /allow-dependencies-change comment after the guard blocks that new head SHA.

  • Current SHA: 20cc7a55aff567e619b0828efe8b88020824b9df

zw-xysk and others added 2 commits July 6, 2026 02:11
…ce time range labels

In summarizeInStages, partial summaries are wrapped into synthetic
AgentMessage objects before the final merge pass. Previously each
synthetic message used Date.now() as its timestamp and no ordering
metadata was embedded in the content. Since serializeConversation
(in agent-core) only preserves text content and discards timestamps,
the LLM merger could not distinguish which summary chunk represented
older vs newer history, making the "PRIORITIZE recent context" merge
instruction ineffective.

Fix:
1. Embed a chronological label with source time range in each summary
   content text (e.g. "[Chunk 1 - oldest messages [2026-07-05 14:00]]").
2. Extract actual timestamp ranges from original chunk messages via new
   extractChunkTimeRange() helper.
3. Assign ascending timestamps from a single Date.now() capture so
   relative order is preserved for code paths reading timestamp field.
4. Update test to verify merge messages receive the labels.
5. Add real behavior proof script (proof/issue-100636-chunk-labels.ts)
   with 10/10 verification checks.

Fixes openclaw#100636
@vincentkoc
vincentkoc force-pushed the fix/issue-100636-chunk-labels branch from 2f04290 to 20cc7a5 Compare July 6, 2026 09:11
@openclaw-barnacle openclaw-barnacle Bot added size: S and removed docs Improvements or additions to documentation channel: discord Channel integration: discord channel: telegram Channel integration: telegram app: android App: android app: ios App: ios app: macos App: macos app: web-ui App: web-ui gateway Gateway runtime extensions: memory-core Extension: memory-core cli CLI command changes scripts Repository scripts commands Command implementations docker Docker and sandbox tooling channel: feishu Channel integration: feishu extensions: anthropic extensions: openai extensions: qa-lab extensions: memory-wiki extensions: codex extensions: google extensions: openrouter size: XL labels Jul 6, 2026
@github-actions github-actions Bot removed the dependencies-changed PR changes dependency-related files label Jul 6, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer review complete on exact head 20cc7a55aff567e619b0828efe8b88020824b9df.

  • Repair: deterministic UTC chunk labels, invalid timestamp metadata omitted safely, monotonic synthetic timestamps retained.
  • Focused proof: 3 test files / 17 tests passed; formatter, linter, and git diff --check passed.
  • Review: fresh branch review found no correctness or security findings.
  • Hosted proof: exact-head CI completed with 64 passed, 0 pending, 0 failed, including the previously failing checks-node-compact-small-whole-2 shard.
  • Security: no dependency, workflow, credential, permission, or network-boundary changes; hosted security checks passed.

Known gap: no live provider/model-quality compaction session was run. The focused tests cover message construction, deterministic labels, and ordering. Ready to squash-merge.

@vincentkoc

Copy link
Copy Markdown
Member

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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]: summarizeInStages drops original message metadata and context bindings during summary merge passes

2 participants