Skip to content

fix(compaction): avoid timeouts from obsolete session history - #180836

Merged
steipete merged 6 commits into
openclaw:mainfrom
sukhdeepjohar:fix/compaction-hydration-budget
Oct 23, 2026
Merged

steipete merged 6 commits into
openclaw:mainfrom
sukhdeepjohar:fix/compaction-hydration-budget

Conversation

@sukhdeepjohar

@sukhdeepjohar sukhdeepjohar commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes compaction repeatedly timing out on long-lived sessions because every attempt hydrates obsolete history retained behind daily resets or /new.

Fixes #180514.

User Impact

Manual and automatic compaction load the complete current context, including the previous summary and boundary-retained messages, without loading obsolete archive history. A smaller foreground model does not discard older current messages or an oversized previous summary before summarization. Saved transcript rows, reset identity, retention, configuration, and the summarizer's existing input-budget policy are unchanged.

Why This Change Was Made

The manual preparation owner and automatic compaction opener requested full transcript hydration. That streamed all retained rows under the history worker's independent 60-second deadline, even though the compactor subsequently ignored obsolete history.

The maintainer rewrite uses the existing SQL and memory readers with a semantic-window selection: the latest boundary, its retained context, and following entries. Compaction retains custom messages and branch summaries in its kept tail; resets retain the existing paired message/tool-result subset. Complete prior summaries remain available regardless of ordinary replay byte limits. Existing ancestry metadata and the same selection survive manager reloads and writes.

This replaces the original attempt-window cap and removes its foreground/summarizer budget plumbing. Ordinary byte-capped turn reads keep their existing behavior. No schema, persistent state, config option, or new cache is introduced. A genuinely large current context can still require substantial work; this fix removes obsolete-history work without silently reducing summary coverage.

Simplification removed the model-budget fallback chain and the changes to ordinary replay reservation. Versus the merged main base, production is +242/-137 (net +105), tests +249/-2, and docs +2/-0. The remaining production growth carries an explicit complete-context selection through the existing SQL, memory, and reload owners; deleting those distinctions would reintroduce truncation or full archive reads. This uses the campaign LOC escape hatch.

Thanks @sukhdeepjohar for the original investigation, worker snapshot preparation, and regression intent. The contributor commits remain in this branch's history.

Evidence

  • Confirmed on main 5c24c3b645be001ccc34b213e9eac9933929d45c: session-manager.ts:475 passes undefined hydration limits, compaction-session-execution.ts:137 opens without limits, and session-transcript-worker-runtime.ts:159 defaults to 60 seconds.
  • The manual/Gateway and budget-triggered regression checks that only nine current entries are hydrated from an archive containing more than 80 entries, compaction completes, the previous summary reaches the summarizer, and all original rows remain stored. The prior summary exceeds the former foreground replay cap. On the base, the initial hydration reads the archive and fails the nine-entry assertion; the original capped proposal can drop the summary/current tail.
  • Memory-reader coverage checks both reset and compaction retention, including a large summary, custom messages, branch summaries, and ancestry. No timers or sleeps added.
  • Local dependency installation was attempted once on trusted main and refused: host Node 26.12.0 is below the required security-patched runtime. Local tests, lint, and typechecks were skipped per maintainer host policy; PR CI owns those checks. After CI identified two formatting differences, the existing trusted-checkout oxfmt binary formatted only those two files without installing dependencies or executing PR source. No engine bypass or runtime download was used.
  • Live Gateway/channel e2e was skipped per maintainer policy. Earlier contributor runs apply to the earlier capped implementation, not this rewrite. Local test wall times were not measured under that host restriction; CI job results provide the execution evidence.
  • Isolated Codex autoreview: scoped-clean through P2 on the complete rewrite and again on the mechanical CI repair; no accepted/actionable findings. Static review does not replace runtime proof. Exact-head PR CI 39904021898: success on 666f3feee0b4ec497441249fa67cd13a0da266c8, including changed Node tests, PostgreSQL conformance, lint, formatting, architecture guards, typechecks, and build. Fresh main was merged immediately before publication; it does not overlap the reviewed files.

The first rewrite CI run 39902689520 passed the changed Node test jobs and typechecks. It found formatting differences in two files and a raw-SQL justification comment attached to the return statement instead of the SQL expression. The follow-up changes only formatting/comment placement; SQL and runtime behavior are unchanged. The repaired exact head now passes the complete workflow; no inherited-failure exception is needed.

ClawSweeper reviewed the rewritten head 666f3feee0b4ec497441249fa67cd13a0da266c8 and found no actionable code defects; the earlier summary-coverage decision is resolved. Its sole remaining request is shipped-entry-point live proof. That proof-only hold is overridden by the explicit maintainer policy for this task: no local contributor-code execution, live Gateway/channel e2e, or remote leases; PR CI is the broad gate. This does not claim that CI supplies live-provider evidence. The single re-review request is complete.

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M labels Oct 22, 2026
@sukhdeepjohar
sukhdeepjohar marked this pull request as ready for review October 22, 2026 17:35
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Compaction reads the complete current semantic window instead of hydrating obsolete retained history.

Example: A Telegram session retains about 130,000 events across 19 resets, with about 2,400 events after the latest reset.

  • Before: Compaction hydrates retained archive history and can exhaust the independent 60-second history-worker deadline.
  • After: Compaction selects the latest boundary, its retained context and previous summary, and subsequent entries without applying ordinary replay byte caps.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused, owner-directed patch has useful regression coverage and no definite correctness finding, but the required shipped-entry-point proof does not cover the rewrite.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Long-lived conversations repeatedly fail compaction because obsolete retained history consumes the hydration deadline.
Reason: The area owner's rewrite resolves the earlier bounded-coverage choice by preserving complete current context and the summarizer's existing policy.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this PR addresses a source-confirmed compaction failure and preserves complete current-context coverage; no definite introduced defect was found.

Priority: P1
Reviewed head: 666f3feee0b4ec497441249fa67cd13a0da266c8

Before merge

  • Add real behavior proof - The SQL/memory semantic-window rewrite is covered by production-composition tests with mocked provider output and CI, while the PR explicitly excludes earlier live runs from this rewrite's proof. The PR owner should attach redacted terminal output or logs showing manual and budget compaction through a shipped entry point on the rewritten behavior, including complete prior-summary coverage and preserved stored history; redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Provide current-rewrite shipped Gateway or CLI evidence for manual and budget compaction over obsolete retained history, preserving the prior summary and stored rows; an observed red-base regression run is also not shown.
Agent review details

How this fits together

Gateway, automatic, and CLI compaction prepare a SessionManager through the existing durable or memory history owner, then summarize and persist a compaction boundary.

flowchart TD
A[Gateway or automatic compaction] --> B[SessionManager preparation]
B --> C[Existing history owner]
C --> D[Complete current semantic window]
D --> E[Existing summarizer]
E --> F[Existing transcript writer]
Loading

Technical review

Best possible solution:

Use the existing history owners to load complete semantic compaction context while preserving archive rows, reset identity, ancestry, and ordinary replay limits.

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

Current-main source confirms full retained-history hydration under an independent 60-second worker deadline, matching the linked release report; this read-only review ran no reproduction.

Is this the best way to solve the issue?

The rewrite repairs the read boundary through existing owners without changing reset identity or silently clipping summary coverage, and its added distinctions serve that invariant.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 804687a51137.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +105, Tests +247, Docs +2. Total +354 across 24 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 20 242 137 +105
Tests 3 249 2 +247
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 24 493 139 +354

Review metrics

Metric Value Why it matters
Production versus test changes Production +242/-137; tests and helpers +249/-2. The production growth carries semantic selection through existing SQL, memory, hydration, and reload contracts; the tests cover archive exclusion and distinct retention behavior.

Labels

Label changes:

  • add merge-risk: 🚨 compatibility: The additive selection variant reaches SDK-exported SessionManager methods; existing byte-limited calls remain supported, and the area owner's rewrite provides the narrow repair direction.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • remove proof: sufficient: Current real behavior proof status is mock_only, not sufficient.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🧂 unranked krab, so this older rating label is no longer current.
  • remove merge-risk: 🚨 session-state: Current PR review merge-risk labels are merge-risk: 🚨 compatibility.
  • remove status: ⏳ waiting on maintainer: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P1: The linked official-release report describes repeated failures of an established conversation and ineffective manual compaction recovery.
  • merge-risk: 🚨 compatibility: The additive selection variant reaches SDK-exported SessionManager methods; existing byte-limited calls remain supported, and the area owner's rewrite provides the narrow repair direction.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (2 earlier review cycles)
  • reviewed 2026-10-22T17:56:01.759Z sha 7bebc1c2338c1ef68abc6d5f06065ed6bb510660 :: needs real behavior proof before merge. :: [P1] Reserve the previous summary before trimming compaction history
  • reviewed 2026-10-22T22:12:19.888Z sha aa79227 :: blocked before merge. :: none

Reviewed October 23, 2026, 1:18 AM ET / 05:18 UTC (Revision 3).

Preflight, manual and CLI-harness compaction opened an unbounded SessionManager, so a
session that kept its id across resets hydrated its whole archive under the history
worker's fixed read budget and never compacted. Compaction now reads the same bounded
view an attempt or overflow recovery hydrates, and manual compaction reads its session
facts inside that bounded snapshot.

The bounded readers reserve the latest boundary ahead of the tail: when the newest
turns alone fill the byte cap, the oldest of them give way so the previous compaction
summary stays in the window that compaction summarizes.

Closes openclaw#180514
@sukhdeepjohar
sukhdeepjohar force-pushed the fix/compaction-hydration-budget branch from 7bebc1c to aa79227 Compare October 22, 2026 21:40
@sukhdeepjohar

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Oct 22, 2026
steipete and others added 2 commits October 22, 2026 21:50
…text

Read the complete semantic window through the existing transcript owners,
including the previous summary and reset/compaction retention. Preserve
ancestry and the same selection across reloads; leave replay byte limits,
stored history, schema, and reset identity unchanged.

Rework the contributor's bounded-window fix to preserve summary coverage.
Remove foreground/summarizer budget projection and ordinary replay changes.
Validation uses isolated autoreview and PR CI; local dependency installation
is refused by the host's older Node security patch level.

Fixes openclaw#180514
Co-authored-by: Sukhdeep Johar <[email protected]>
@steipete steipete changed the title fix(compaction): hydrate the bounded model-context view for compaction fix(compaction): avoid timeouts from obsolete session history Oct 23, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the gateway Gateway runtime label Oct 23, 2026
@steipete

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. status: ⏳ waiting on maintainer Only explicit maintainer approvals or decisions remain; merge is still blocked. labels Oct 23, 2026
@steipete
steipete merged commit c902f9a into openclaw:main Oct 23, 2026
171 of 173 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
…aw#180836)

* fix(compaction): hydrate the bounded model-context view for compaction

Preflight, manual and CLI-harness compaction opened an unbounded SessionManager, so a
session that kept its id across resets hydrated its whole archive under the history
worker's fixed read budget and never compacted. Compaction now reads the same bounded
view an attempt or overflow recovery hydrates, and manual compaction reads its session
facts inside that bounded snapshot.

The bounded readers reserve the latest boundary ahead of the tail: when the newest
turns alone fill the byte cap, the oldest of them give way so the previous compaction
summary stays in the window that compaction summarizes.

Closes openclaw#180514

* test(compaction): assert the prepared Gateway session through its typed shape

* chore(compaction): satisfy formatting and SQL guardrails

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: Sukhdeep Johar <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compaction always times out on long-lived sessions: reset keeps sessionId and compaction hydrates all pre-reset events under fixed 60s budget

2 participants