Repository navigation
fix(compaction): preserve chunk timestamps in staged-split merge messages - #100674
zhangqueping wants to merge 4 commits into
Conversation
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
Thanks for the context here. I swept through the related work, and this is now duplicate or superseded. Close as superseded: this timestamp-only PR still does not make chunk chronology visible to the merge model, while #100684 is an open, mergeable, proof-positive canonical PR that embeds chunk order and source time ranges in serialized content. Root-cause cluster Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Canonical path: Follow #100684 as the canonical fix, land LLM-visible chunk labels and source ranges after its own review, then close the linked issue when that PR merges. So I’m closing this here and keeping the remaining discussion on #100684. Review detailsBest possible solution: Follow #100684 as the canonical fix, land LLM-visible chunk labels and source ranges after its own review, then close the linked issue when that PR merges. Do we have a high-confidence way to reproduce the issue? Yes for source-level reproduction: current main builds final staged merge messages with raw summary content and timestamp metadata, while serializeConversation omits timestamps from the LLM-visible prompt. I did not run a live model-quality compaction session in this read-only review. Is this the best way to solve the issue? No. Preserving AgentMessage.timestamp alone is not the best fix because the merge LLM sees serialized content; the maintainable fix is to put chunk order and source range metadata into the content path, as the canonical PR does. Security review: Security review cleared: The diff touches only agent compaction code and a colocated test, with no dependency, workflow, lockfile, secret, permission, or supply-chain surface changed. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against 0c38082c6db9. |
cedd82d to
e68ddb4
Compare
…ages Use the first message timestamp from each chunk instead of Date.now() for synthetic merge messages in summarizeInStages. This allows the LLM merger to distinguish older history from newer history during the final merge pass, preserving chronological ordering. Fixes openclaw#100636
…patibility AgentMessage.timestamp expects number, but optional chaining through plan.chunks[i]?.[0]?.timestamp produces number | string | undefined. Use typeof guard to only pass number values, falling back to Date.now() for non-number timestamps.
…rge messages
Annotate each partial summary with [Chunk N/M] label so the LLM
merger can distinguish older vs newer history. Preserve the first
message timestamp from each source chunk instead of using Date.now()
for all merge messages.
Combined with the existing MERGE_SUMMARIES_INSTRUCTIONS
("PRIORITIZE recent context over older history"), this gives the
LLM merger both structured ordering and temporal context.
Fixes openclaw#100636
e68ddb4 to
9629657
Compare
…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
|
Thanks @zhangqueping. The canonical content-label fix has now merged in #100684 as This PR preserves timestamp metadata, but that metadata is not included in the serialized merge prompt; #100684 makes chunk order and source ranges visible in message content and carries the focused regression coverage. Closing this as superseded while preserving your contribution and the investigation here. |
Summary
Problem:
summarizeInStageswraps partial summaries into syntheticAgentMessageitems withtimestamp: Date.now(), causing all merge messages to share the same timestamp. The LLM merger loses chronological context and cannot distinguish older history from newer history during the final merge pass.Solution: Preserve the first message timestamp from each chunk and add
[Chunk N/M]order labels to merge messages. Combined with the existingMERGE_SUMMARIES_INSTRUCTIONS("PRIORITIZE recent context over older history"), this gives the LLM merger both structured ordering and temporal context.What changed:
src/agents/compaction.ts— replacedtimestamp: Date.now()with chunk first-message timestamps; added[Chunk N/M]prefix to each summary's content.src/agents/compaction.identifier-preservation.test.ts— added assertions for timestamp values (< 1e10, proving non-Date.now) and chunk label presence.What did NOT change: The merge instruction template, chunk splitting logic, identifier preservation, and all non-staged summarization paths.
Fixes #100636
What Problem This Solves
In staged compaction summarization, when the context is too large for a single pass,
summarizeInStagessplits messages into chunks, summarizes each chunk independently, then merges the partial summaries. The merge step creates synthetic messages:The LLM merger sees identical timestamps and cannot distinguish temporal ordering, leading to potential information loss when recent context should be prioritized over older history.
Root Cause
src/agents/compaction.ts:392—timestamp: Date.now()strips chronological metadata from all merge messages, replacing distinct chunk timestamps with a single value.Real behavior proof
Behavior addressed: Merge messages preserve chunk timestamps instead of all sharing
Date.now().Real environment tested: Linux x64, Node v24.13.1
Exact steps or command run after this patch:
After-fix evidence:
Full test suite (14/14 passed on actual compaction path):
Observed result after the fix: When
summarizeInStagessplits messages into chunks, each synthetic merge message now carries the timestamp of the first message in its corresponding chunk. The LLM merger receives distinct, chronologically-ordered timestamps. TheDate.now()fallback only applies when a chunk happens to be empty (which doesn't occur in practice).What was not tested: Full end-to-end agent compaction with real model backend — requires live API access.
Risk checklist
merge-risk: Low
plan.chunks[i]?.[0]?.timestamp ?? Date.now()— safe optional chaining