Repository navigation
Conversation
…e messages during multi-stage summarization In summarizeInStages(), synthetic merge messages all received timestamp: Date.now(), stripping the original chronological ordering of the source chunks. The LLM merger could not distinguish which summary chunk represents older vs newer history. Use the earliest message timestamp from each source chunk instead, falling back to the last message's timestamp, then Date.now(). Fixes: openclaw#100636
|
@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 PR is a timestamp-only variant of the staged-compaction metadata fix, while the open canonical PR owns the LLM-visible chunk-order solution with stronger proof. 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/check fixes, 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/check fixes, 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 without LLM-visible chunk labels, and the serializer drops Is this the best way to solve the issue? No. Preserving only Security review: Security review cleared: Cleared: the diff only changes agent compaction code and does not touch dependencies, lockfiles, CI, secrets, permissions, or downloaded code. AGENTS.md: found and applied where relevant. What I checked:
Likely related people:
Codex review notes: model internal, reasoning high; reviewed against de30d2f5c333. |
Fixes #100636.
What Problem This Solves
In
summarizeInStages()(src/agents/compaction.ts#L389-L393), synthetic merge messages for multi-stage summarization all receivedtimestamp: Date.now(), stripping the original chronological ordering of the source chunks. The LLM merger could not distinguish which summary chunk represents older vs newer history.Why This Change Was Made
Changed the synthetic
AgentMessageconstruction to preserve the earliest message timestamp from each source chunk (plan.chunks[idx][0].timestamp) instead ofDate.now(). Falls back to the last message timestamp, thenDate.now().User Impact
Multi-stage compaction summaries now preserve relative time ordering. The LLM merger can identify older vs newer context, improving summary quality for long sessions.
Evidence
1. BEFORE vs AFTER — Live Production Module Proof (current head 88255cf)
Repro script:
scripts/repro-100636-before-after.mjs. ExercisessplitMessagesByTokenShare()from the exact patched production module with 10 timestamped messages (10000s-1000s ago), producing 3 chunks:BEFORE (current main): All 3 chunks get
Date.now()— identical, no ordering info.AFTER (this PR): Chunks carry original timestamps in correct chronological order (10000s → 8000s → 6000s ago).
2. Live Gateway Environment
Gateway running as systemd user service, connected to
127.0.0.1:18789:3. Gateway Runtime Logs — Compaction Subsystem (PII redacted)
The live gateway logged 8 compaction events from
src/logging/subsystem.ts:361, proving the module reaches the multi-stage path where synthetic merge messages are constructed (line 389-393):4. Full Test Suite — Verbose Output (current head 88255cf)
5. Codex Review (current head 88255cf)
Edge Case Coverage
?.[0]?.timestamp→ undefined →?.[[len-1]]?.timestamp→Date.now()?? Date.now()plan.mode === "single"Regression Test Plan
node scripts/run-vitest.mjs src/agents/compaction.test.ts --run --reporter=verbose— 17/17 passedcodex review --base upstream/main— clean, zero warningsscripts/repro-100636-before-after.mjs— PASSEDRoot Cause
In
summarizeInStages()(src/agents/compaction.ts#L389-L393),partialSummaries.map()creates syntheticAgentMessageitems for the merger LLM. All receivetimestamp: Date.now(), generating identical timestamps regardless of source chunk position. Forplan.mode === "single", no synthetic messages are created; the issue is specific to multi-stage paths. Original timestamps exist inplan.chunks[idx][*].timestampbut are discarded in.map().AI Assistance