Skip to content

fix: compacted sessions incorrectly hit context read limits - #169723

Closed
evan-zhang wants to merge 2 commits into
openclaw:mainfrom
evan-zhang:codex/sqlite-compaction-read-window
Closed

evan-zhang wants to merge 2 commits into
openclaw:mainfrom
evan-zhang:codex/sqlite-compaction-read-window

Conversation

@evan-zhang

@evan-zhang evan-zhang commented Oct 12, 2026 •

Copy link
Copy Markdown

What Problem This Solves

Fixes long SQLite-backed sessions refusing further work or compaction with a truncated-context error even after compaction reduced the active context below the read limit.

User Impact

Users can continue a compacted session without starting over. Existing byte and event limits still reject genuinely oversized active context; no data migration or transcript rewrite is required.

Why This Change Was Made

The pressure counter used the latest logical compaction window while the bounded reader could still charge summarized ancestors against its limit. Both now select the same retained semantic tail and required state controls. Cache checkpoint recovery continues to use the existing projection-prefix owner.

An omitted assistant that supplies model identity now contributes detached model metadata rather than its old message body, with matching admission and acquisition costs. Appending a newer model carrier invalidates the old cached control facts. Ambiguous legacy role predicates conservatively retain raw accounting and acquisition together.

Related: #115904, #160149.

Evidence

  • Starting main pinned at 9ea2d5edd52ae727f4741aa5bb4dc47eecdcea1a. Indexed/unindexed minimal reproductions and the original native regression fail on that original runtime and pass with this repair. Additional indexed/unindexed discarded-assistant cases fail against the first PR head (32,563/32,524 bytes against a 20,000-byte budget); source hashes were restored exactly after runtime-only negative controls.
  • 232/232 public tests passed across 14 affected suites (158 infrastructure + 74 runtime/config), including bounded byte/event limits, read fences, reset retention, legacy navigation and duplicate keys, cache checkpoints, warm/fresh carrier invalidation, model restoration, and genuine overflow rejection.
  • The public native SQLite → SessionManager.openBoundedAsync → AgentSession.compact regression covers both old-user and discarded-assistant prefixes. Each performs three consecutive compact/reopen rounds, preserving seven task-state markers, the current tool call/result pair, and original stored-row digests. The deterministic provider only returns markers actually present in its request; the assistant variant also checks model identity on its first bounded open.
  • Separately revalidated an anonymous 47.1 MB / 7,500-event long-session structure through three native compact/reopen rounds, including cache restoration, all seven task-state markers, tool pairing, and unchanged original rows. Six deterministic offline summary calls; no real transcript is included in the PR.
  • Targeted typecheck/format, SQLite dialect and Kysely guards, database-worker and assertion-safety ratchets, unified runtime compilation: all passed. Final independent source review completed through P2 with no actionable findings; this is static review, separate from executed tests.

The initial PR CI identified assertion-safety and database-worker call-count issues, addressed in the follow-up without changing guard baselines (worker calls remain 599; dialect occurrences remain mechanical 6/design 44). Its uses a stale-version postimage failure was independently reproduced on pinned starting main and the candidate with the same SessionActorStaleVersionError; the affected actor/persistence/test files are unchanged. The built-CLI deletion lifecycle failure (agent.wait abort without the expected stop reason) remains unclassified. Current-head broad CI must still be evaluated; these are not reported as green checks.

Full build:runtime stops in the optional A2UI asset stage because that package/prebuilt bundle is absent in this isolated dependency setup. The official openclaw-unified runtime compiler passes. Tests use the official Vitest wrapper and database-worker lane. No live provider was called.

Before merge, the requested shipped CLI/Gateway compact-and-continue trace is still needed. The consecutive-compaction checks exercise native SQLite/SessionManager/AgentSession with a deterministic offline summary provider; they do not establish shipped-CLI behavior, live-provider summary quality, client delivery, or production soak stability.

@clawsweeper

clawsweeper Bot commented Oct 12, 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 agents Agent runtime and tooling size: L labels Oct 12, 2026
@evan-zhang
evan-zhang marked this pull request as ready for review October 12, 2026 07:37
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Align bounded session-context reads and byte accounting with the latest reset or compaction window while preserving required state.

Example: A session contains a discarded 32,000-byte assistant reply, a retained user request, and a small compaction summary under a 20,000-byte read budget.

  • Before: The discarded reply consumes the budget and bounded reopening reports truncated context.
  • After: Only its model metadata survives, allowing the retained request and summary to reopen within the budget.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused repair has no remaining static finding, but mocked inference does not satisfy the required shipped-flow proof gate.
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: A compacted long session can still refuse continuation because summarized history consumes its context-read budget.
Reason: Restoring continuation while preserving durable history, limits, and required state has clear value within the existing session contract.

Merge readiness

⛔ Blocked before merge - 2 items remain

This PR fixes a distinct defect still present on current main; the follow-up resolves the prior model-identity finding, and no new actionable code defect was identified.

Priority: P2
Reviewed head: 38f80eee18e94dd34718dfa1e83708fd054bfddd

Before merge

  • Add real behavior proof - The SQLite → SessionManager.openBoundedAsync → AgentSession.compact regression exercises native storage with a mocked offline summary provider; the complete body explicitly acknowledges that shipped CLI/Gateway proof is outstanding. Provide terminal output or logs showing compacted reopening and continued work with retained task state and model identity, redacting IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Complete next step - Have the CI owner classify the two detached-worker canonical-user-admission failures in checks-node-changed-compact-large-26 against the pinned base, assigning repairs only for a demonstrated diff-caused failure.

Findings

None.

Tests

  • Missing end-to-end proof: Missing a shipped CLI/Gateway compact-and-continue trace showing bounded reopening with retained task state and model identity.
Agent review details

How this fits together

SQLite transcript projections feed session hydration and compaction-pressure accounting, converting durable events into bounded context and byte/count facts.

flowchart TD
  A[SQLite transcript] --> B[Active branch projection]
  B --> C[Reset and compaction window]
  C --> D[Required state controls]
  C --> E[Bounded context acquisition]
  D --> E
  D --> F[Pressure accounting]
  E --> G[SessionManager and AgentSession]
Loading

Technical review

Best possible solution:

Use the existing boundary-window owner for both bounded hydration and pressure accounting while retaining detached model state and cache checkpoints.

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

Current-main source admits summarized ancestors into bounded acquisition while accounting excludes them; the added 32,000-byte-prefix regressions exercise that mismatch, but this read-only review ran no code.

Is this the best way to solve the issue?

The repair aligns the existing acquisition and accounting owners, preserves state through detached metadata, and avoids rewriting stored history or adding configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 7c4ff5ae0a4c.

Provenance checked

  • Bounded active-context selection changes intended behavior with a stated reason (e3ce08c: Explicit reset retention preserves paired entries despite ordinary exclusion; the PR explains why summarized ancestors must leave bounded acquisition.)
  • Reset and compaction pressure accounting keeps the original intent (b8d2ac7: Measure the logical model-context window instead of durable ancestry while preserving reset-only history visibility.)
  • Cache projection-prefix anchors keeps the original intent (0257a7d: Restore checkpoint dependencies through the existing prefix owner without enlarging navigable context.)
  • Detached metadata projection keeps the original intent (c09f136: Select model context before hydration and retain omitted assistant model identity without acquiring storage-only bodies.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

PR surface

Source +250, Tests +836. Total +1086 across 10 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 4 290 40 +250
Tests 6 845 9 +836
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 1135 49 +1086

Review metrics

Metric Value Why it matters
Production versus test LOC Production +290/-40; tests +844/-9 Production growth supplies shared control selection and detached model accounting; tests cover distinct indexed, imported, cache, and repeated-compaction contracts.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The defect blocks bounded reopening of long SQLite-backed sessions after compaction, with a limited affected surface.
  • 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 (1 earlier review cycle)
  • reviewed 2026-10-12T07:54:20.261Z sha ba94199 :: needs real behavior proof before merge. :: [P2] Preserve model identity without charging the discarded assistant body

Reviewed October 12, 2026, 4:56 AM ET / 08:56 UTC (Revision 2).

@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale after 7 days without qualifying human activity.
Without new human activity, Barnacle may close it as not planned 7 days after this message was posted. This is administrative inactivity cleanup, not a claim that the problem is fixed.
A human update restarts the inactivity clock; a new PR head also restarts it. A maintainer can add no-stale for a durable hold, or bad-barnacle to suppress Barnacle. Remove the hold when work can resume.

@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

@openclaw-barnacle openclaw-barnacle Bot closed this Nov 9, 2026
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. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XL stale Marked as stale due to inactivity 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.

1 participant