Skip to content

fix: keep side chat available for large session tails - #130285

Merged
VACInc merged 3 commits into
mainfrom
openclaw/fix-issue-130188
Aug 29, 2026
Merged

VACInc merged 3 commits into
mainfrom
openclaw/fix-issue-130188

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #130188

AI-assisted: yes (Roboclaw)

What Problem This Solves

Fixes an issue where Control UI Side chat reported “Couldn't load this session's history” when an older large transcript message caused the first 1 MiB bounded page to omit rows, even though a valid recent user/assistant suffix was available.

Why This Change Was Made

The SQLite bounded reader now records how many returned events form a contiguous newest suffix before the first byte-budget omission, while preserving its intentionally sparse results for session-memory salvage callers. The companion consumes only that suffix, stops at the gap, and retains the existing newest-message fail-closed behavior, projection completeness validation, 4,096-message scan bound, and final snapshot fence.

The production delta is +26/-11 (net +15). The growth is the explicit producer-owned contiguous-tail fact plus a projection-integrity check; this avoids duplicating position inference in consumers or changing the sparse reader contract used by session memory. Complete pages reuse the existing event array, so the common path does not add an avoidable copy.

User Impact

Operators can use Side chat and /btw on large, long-running sessions when recent context fits the hard read budget, even if an older message in the first candidate page is oversized. A newest message that cannot fit remains a retryable history failure rather than silently backfilling stale context.

Evidence

  • Pre-fix regression:
    • node scripts/run-vitest.mjs src/gateway/session-companion-context.test.ts -t 'uses the contiguous newest suffix when an older message exceeds the read budget'
    • Failed with { kind: "unavailable" } instead of the expected recent suffix.
  • Post-fix focused suites:
    • node scripts/run-vitest.mjs src/gateway/session-companion-context.test.ts — 12 passed, repeated 3 times.
    • node scripts/run-vitest.mjs src/gateway/session-companion.test.ts — 21 passed, repeated 3 times.
    • node scripts/run-vitest.mjs src/config/sessions/session-accessor.sqlite-active-events.test.ts — 16 passed, repeated 3 times.
  • Static proof:
    • node scripts/check-changed.mjs -- <changed files> — green after refreshing the current-main dependency install.
    • Final core production and src test typechecks — green.
    • Targeted Oxlint and git diff --check — green.
  • Fresh autoreview:
    • .agents/skills/autoreview/scripts/autoreview --mode local
    • Clean: no accepted/actionable findings; overall patch correctness 0.99.
  • Independent owner-boundary review confirmed the sparse-reader sibling contract, newest-message rejection, zero-contiguous later-page behavior, and snapshot fence are preserved.

The final performance-only follow-up adds no SQL query, retry, timer, subscriber, UI action, or repeated request; it only avoids copying the event array for complete pages.

Provenance: the unconditional partial-page rejection was introduced in #122380; #127294 narrowed it for later pages but retained the first-page failure covered here.

Worked on by


View the OpenClaw team session

Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: bd0dd9d5-f93e-476f-8325-192392de4d8b
@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Aug 26, 2026
@roboclaw-bot
roboclaw-bot marked this pull request as ready for review August 26, 2026 18:22
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 9:46 PM ET / August 27, 2026, 01:46 UTC.

ClawSweeper review

What this changes

The PR records the contiguous newest SQLite transcript suffix before a byte-budget omission so Side chat can use safe recent context instead of rejecting the whole session.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for explicit maintainer handling: current main still rejects a partial first bounded page, while this focused patch moves the byte-gap fact to the SQLite reader and preserves the snapshot and newest-message fail-closed boundaries.

Priority: P1
Reviewed head: 1c01367d27c2a16716783cd72338bc663488e25b
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has a clean owner boundary and focused regression coverage, with credible supplemental runtime evidence but no independently observed UI capture.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This member/bot-authored PR is exempt from the external contributor proof gate; its supplied real-SQLite before/after regression and documented current-head media infeasibility remain useful supplemental evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This member/bot-authored PR is exempt from the external contributor proof gate; its supplied real-SQLite before/after regression and documented current-head media infeasibility remain useful supplemental evidence.
Evidence reviewed 6 items Current-main failure predicate: Current main still returns unavailable before consuming a partial first page when admitted events are fewer than scanned positions, so the central user problem is not already implemented.
Producer-owned repair: The branch adds an explicit newest contiguous suffix count in the bounded SQLite reader and rejects incomplete projection metadata before the companion consumes the result.
Companion and sibling contract: The companion slices only the newest contiguous events before sanitizing context, while session memory remains the sole sibling that intentionally consumes sparse page events for salvage.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/session-companion-context.test.ts -t 'uses the contiguous newest suffix when an older message exceeds the read budget'

Result: PASS (completed)

[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130285-8k3LLQ/target

 ✓  gateway-core  ../../src/gateway/session-companion-context.test.ts (12 tests | 11 skipped) 647ms
     ✓ uses the contiguous newest suffix when an older message exceeds the read budget  643ms

 Test Files  1 passed (1)
      Tests  1 passed | 11 skipped (12)
   Start at  01:47:45
   Duration  11.09s (transform 8.18s, setup 1.04s, import 8.97s, tests 647ms, environment 0ms)

[test] passed 1 Vitest shard in 17.96s
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130285-8k3LLQ/target

 ✓  gateway-core  ../../src/gateway/session-companion-context.test.ts (12 tests | 11 skipped) 596ms
     ✓ uses the contiguous newest suffix when an older message exceeds the read budget  593ms

 Test Files  1 passed (1)
      Tests  1 passed | 11 skipped (12)
   Start at  01:48:04
   Duration  5.26s (transform 2.55s, setup 426ms, import 3.99s, tests 596ms, environment 0ms)

[test] passed 1 Vitest shard in 11.92s

Assertions:

  • PASS expect_output: uses the contiguous newest suffix when an older message exceeds the read budget

How this fits together

Control UI Side chat sends a companion request through the Gateway, which reads an active SQLite transcript projection before calling the utility model. This change determines which bounded transcript events become the companion’s prompt context.

flowchart LR
  A[Control UI Side chat] --> B[Gateway companion request]
  B --> C[SQLite active transcript page]
  C --> D{Byte-budget gap?}
  D -->|No| E[Complete recent page]
  D -->|Yes| F[Contiguous newest suffix]
  E --> G[Companion prompt context]
  F --> G
Loading

Decision needed

Question Recommendation
Should this maintainer-labeled PR adopt the contiguous newest suffix as valid Side chat context when an older event exceeds the first page’s byte budget? Accept the bounded-tail behavior: Merge the producer-owned suffix approach, which retains newest-event, projection-completeness, and snapshot fail-closed checks.

Why: The patch intentionally changes session-context selection semantics, and the protected maintainer label requires an explicit human disposition despite focused source and test evidence.

Before merge

  • Resolve merge risk (P1) - This deliberately changes which persisted session messages reach the companion; correctness depends on keeping the suffix boundary producer-owned and retaining the snapshot fence.
  • Resolve merge risk (P1) - Production code grows by 15 lines for an internal bounded-page contract; the growth is justified by the explicit fact needed to avoid consumer-side position inference.
  • Complete next step (P2) - A member-authored PR carrying the maintainer label needs explicit maintainer disposition; no discrete mechanical repair remains.
Agent review details

Security

None.

PR surface

Source +15, Tests +57. Total +72 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 25 10 +15
Tests 2 62 5 +57
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 87 15 +72

Review metrics

Metric Value Why it matters
Production versus test delta production +25/-10; tests +62/-5 The net production growth carries the bounded-page continuity fact and its consumer check; test growth exercises both older-gap acceptance and newest-message rejection.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.sqlite-active-events.ts, serialized state: src/gateway/session-companion-context.test.ts, serialized state: src/gateway/session-companion-context.ts, unknown-data-model-change: src/gateway/session-companion-context.test.ts, vector/embedding metadata: src/config/sessions/session-accessor.sqlite-active-events.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #130188
Summary: This PR is the active candidate fix for the canonical large-session Side chat bug; earlier merged companion fixes overlap but do not cover the first-page gap.

Members:

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

Merge-risk options

Maintainer options:

  1. Accept the bounded-tail contract (recommended)
    Land only with the producer-owned contiguous-count and final snapshot fence retained, so omitted older content cannot be mistaken for usable history.

Technical review

Best possible solution:

Retain the reader-owned contiguous-tail fact and land the patch after a maintainer accepts bounded recent context as the intended Side chat behavior.

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

Yes—current main’s partial-page condition and the branch’s SQLite-backed regression define a high-confidence reproduction path; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes—the bounded reader is the right owner for continuity information, and the companion remains responsible only for consuming that fact and enforcing its snapshot fence.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member/bot-authored PR is exempt from the external contributor proof gate; its supplied real-SQLite before/after regression and documented current-head media infeasibility remain useful supplemental evidence.
  • remove rating: 🦐 gold shrimp: 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:

  • P1: The current behavior deterministically blocks the Side chat workflow on affected large sessions.
  • merge-risk: 🚨 session-state: The patch changes which persisted transcript events become model-visible companion context.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This member/bot-authored PR is exempt from the external contributor proof gate; its supplied real-SQLite before/after regression and documented current-head media infeasibility remain useful supplemental evidence.

Evidence

What I checked:

  • Current-main failure predicate: Current main still returns unavailable before consuming a partial first page when admitted events are fewer than scanned positions, so the central user problem is not already implemented. (src/gateway/session-companion-context.ts:170, 2f1ea328b34e)
  • Producer-owned repair: The branch adds an explicit newest contiguous suffix count in the bounded SQLite reader and rejects incomplete projection metadata before the companion consumes the result. (src/config/sessions/session-accessor.sqlite-active-events.ts:650, 1c01367d27c2)
  • Companion and sibling contract: The companion slices only the newest contiguous events before sanitizing context, while session memory remains the sole sibling that intentionally consumes sparse page events for salvage. (src/hooks/bundled/session-memory/handler.ts:172, 1c01367d27c2)
  • Boundary regression coverage: The focused SQLite-backed test covers an oversized older event followed by a user/assistant suffix, and the adjacent test retains rejection for an oversized newest user message. (src/gateway/session-companion-context.test.ts:235, 1c01367d27c2)
  • Historical provenance: The first-page partial-page rejection is present in the merged historical implementation associated with the companion hardening work; the PR narrows that specific behavior rather than introducing a parallel reader. (src/gateway/session-companion-context.ts:170, 8efbefe4f645)
  • Release context: The latest supplied stable release commit predates the August companion fixes, so this review treats the remaining behavior as current-main work and makes no shipped-fix claim. (0790d9f593ad)

Likely related people:

  • Peter Steinberger: Current-main blame attributes the retained partial-page condition to a recent commit carrying this Gateway source. (role: recent area contributor; confidence: medium; commits: e9dc4b9d1a58; files: src/gateway/session-companion-context.ts, src/config/sessions/session-accessor.sqlite-active-events.ts)
  • shakkernerd: The merged companion hardening PR contains the historical partial-page guard that this patch narrows. (role: companion hardening author; confidence: high; commits: 8efbefe4f645; files: src/gateway/session-companion-context.ts)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-26T18:29:51.129Z sha 1fd7091 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-26T18:51:31.454Z sha 1fd7091 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-27T00:38:20.450Z sha 1c01367 :: found issues before merge. :: [P2] Attach current-head Side chat proof
  • reviewed 2026-08-27T00:56:11.076Z sha 1c01367 :: found issues before merge. :: [P2] Attach current-head Side chat proof

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Aug 27, 2026
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Current-head verification for 1c01367d27c2a16716783cd72338bc663488e25b is complete.

I am explicitly accepting the focused production-path proof instead of attaching a Side chat screenshot/video:

  • No Control UI code changed. A mock-gateway capture would prove only UI request wiring and would bypass the SQLite bounded-reader behavior being fixed.
  • A real UI capture would add an external model run and a contrived 1 MiB persisted transcript; that is weaker evidence for this deterministic owner-boundary defect and introduces unrelated provider/runtime variables.
  • The SQLite-backed regression directly calls the production defaultSessionCompanionContextReader over the real active transcript projection. It fails on the pre-fix behavior ({ kind: "unavailable" }) and passes on this head with only the contiguous recent user/assistant suffix.
  • The oversized-newest-message case remains fail-closed, the sparse session-memory sibling remains unchanged, and the final snapshot fence remains covered.
  • Focused suites passed three consecutive times: companion context 12/12, companion behavior 21/21, active transcript accessor 16/16.
  • node scripts/check-changed.mjs -- <four changed files> passed.
  • Exact-head CI run 33027056539 completed green, including openclaw/ci-gate, security scans, typechecks, lint, SQLite lifecycle, CodeQL, and OpenGrep.
  • The final follow-up commit adds no SQL query, retry, timer, subscription, UI action, or repeated request; it avoids copying complete bounded pages.

Known proof gap: no screenshot or recording. For this backend-only boundary repair, the failing/passing real-SQLite regression plus exact-head CI is the more direct evidence, so I am not adding proof theater or broadening the change.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Current-head visible-proof attempt for 1c01367d27c2a16716783cd72338bc663488e25b:

  • Started the repository QA harness with an isolated Gateway and deterministic local mock-openai provider.
  • Seeded the real SQLite active transcript with the exact four-event reproduction: stale user turn, 1 MiB older assistant event, recent user turn, recent assistant turn.
  • Restarted the Gateway after the state mutation, served the built current-head Control UI, and reached gateway.snapshot.phase === "connected" on the exact session.
  • The repository Playwright binary was absent; the managed OpenClaw Chromium binary worked. Video capture was unavailable because ffmpeg is not installed in the isolated test home, so the attempt switched to the permitted screenshot path.
  • The 1 MiB transcript keeps the headless chat layout surface unstable: Playwright could render the session and session controls, but the Side panel never mounted. This remained true after waiting for the exact visible session pane and invoking its production requestSessionRail("open") owner method. Therefore no honest screenshot could be captured on this host.
  • I did not substitute a mock-gateway screenshot, because that would bypass the SQLite reader and would not prove this fix.
  • The proof-only E2E file and artifacts were removed; the worktree is clean.

This is the concrete infeasibility for current-head media proof. I am explicitly selecting the review's Accept the owner-boundary evidence option: the real-SQLite failing/passing regression, ClawSweeper's own two exact-head executions, the direct producer/caller/sibling review, and exact-head green CI are sufficient for this deterministic backend repair. There are no code or security findings to address.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 27, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 27, 2026
@VACInc VACInc self-assigned this Aug 28, 2026
@VACInc

VACInc commented Aug 29, 2026

Copy link
Copy Markdown
Member

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Aug 29, 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 exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@VACInc
VACInc merged commit f265c0d into main Aug 29, 2026
237 checks passed
@VACInc
VACInc deleted the openclaw/fix-issue-130188 branch August 29, 2026 19:28
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
* fix: keep side chat available for large session tails

Worked on by:
- @hannesrudolph

Co-authored-by: hannesrudolph <[email protected]>
OpenClaw-Publication: bd0dd9d5-f93e-476f-8325-192392de4d8b

* perf: avoid copying complete companion pages

Worked on by:
- @VACInc

Co-authored-by: VACInc <[email protected]>

---------

Co-authored-by: roboclaw-bot <[email protected]>
Co-authored-by: hannesrudolph <[email protected]>
Co-authored-by: VACInc <[email protected]>
Co-authored-by: Vito Cappello <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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]: Side chat rejects valid large-session tails when the 1 MiB page budget omits messages

2 participants