Skip to content

fix(gateway): keep side chat available for tool-heavy sessions - #127294

Merged
clawsweeper merged 1 commit into
mainfrom
openclaw/sidechat-bugged
Aug 21, 2026
Merged

clawsweeper merged 1 commit into
mainfrom
openclaw/sidechat-bugged

Conversation

@clawsweeper

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where users asking the session companion about a tool-heavy session could receive “Couldn't load this session's history” even though the session transcript was healthy and readable.

Why This Change Was Made

The companion now retains complete recent transcript pages when an older page reaches the bounded raw-read budget. It still rejects an incomplete newest page, stale projections, and snapshots that change during the read, so the existing fail-closed safety boundaries remain intact.

AI-assisted implementation; the complete owner path, regression fixture, and proof results were reviewed before publication.

User Impact

Side chat remains available on long, tool-heavy sessions and answers from the newest complete context instead of failing the whole request because older raw tool output exhausted the scan budget.

Evidence

Isolated Control UI proof

Copied the affected session databases into an isolated state directory, disabled channel startup, ran the exact committed Gateway on loopback, and routed the companion's model call to the repository's deterministic mock OpenAI server. No live provider credential or operator Gateway was used.

Session loaded with side chat available

Side chat loaded

Same question that previously produced the history-unavailable error

Side chat question

Answer returned through the real Gateway companion path

Side chat answer

sidechat-context-cap.webm

Regression and checks

  • Pre-fix owner-boundary regression: failed in both Gateway projects with expected 'unavailable' to be 'ready'.
  • node scripts/run-vitest.mjs src/gateway/session-companion-context.test.ts — 22/22 passed across both Gateway projects.
  • node scripts/check-changed.mjs -- src/gateway/session-companion-context.ts src/gateway/session-companion-context.test.ts — passed.
  • pnpm build — passed, including runtime postbuild, plugin SDK export checks, and Control UI build.
  • .agents/skills/autoreview/scripts/autoreview --mode uncommitted — clean; no accepted/actionable findings.
  • Production delta: +16/-2. Test delta: +28/-0.

@clawsweeper

clawsweeper Bot commented Aug 21, 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: XS labels Aug 21, 2026
@clawsweeper
clawsweeper marked this pull request as ready for review August 21, 2026 16:55
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 21, 2026
@clawsweeper clawsweeper reopened this Aug 21, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 21, 2026
@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 21, 2026, 1:03 PM ET / 17:03 UTC.

ClawSweeper review

What this changes

The PR lets the Gateway side-chat companion retain complete recent transcript pages when an older tool-heavy page reaches the bounded raw-read byte budget.

Merge readiness

⚠️ Ready for maintainer review - 4 items remain

Keep open for the maintainer merge decision: the patch correctly narrows the existing fail-closed rule so a later older-page byte cutoff no longer discards already-complete recent context, while retaining the snapshot fence and newest-page protection. GitHub reports the branch as mergeable but behind, with exact-head checks still running.

Likely related people: @vincentkoc (current reader path) and @shakkernerd (earlier companion safety invariants).

Priority: P2
Reviewed head: ef3461a10a5ea9ea57b6e375f3c9f227f1c9373c
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, source-supported repair with regression coverage and described isolated UI evidence; exact-head CI and merge freshness remain the remaining landing gates.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This is a maintainer/bot PR, so the external-contributor proof gate does not apply; its body nevertheless provides an isolated Gateway and Control UI after-fix run, though the linked attachments were not retrievable in this review environment.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a maintainer/bot PR, so the external-contributor proof gate does not apply; its body nevertheless provides an isolated Gateway and Control UI after-fix run, though the linked attachments were not retrievable in this review environment.
Evidence reviewed 8 items Current-main failure condition: Current main returns unavailable whenever a bounded page materializes fewer events than it scanned, so an older page that exhausts the byte budget rejects otherwise complete recent context.
Transcript-reader contract: The local bounded reader scans a tail-relative page, skips rows that exceed its byte allowance, and reports the full scanned count; this is the concrete source of the partial-page condition.
Patch preserves the owner safety boundary: The PR accepts a partial page only after complete newer context exists, stops before consuming its holes, and still compares the final fence with the snapshot from the complete pages.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs src/gateway/session-companion-context.test.ts

Result: FAIL (partial) — step 2 expect_output openclaw: expected terminal output was not visible within 30 seconds: "openclaw"

node scripts/run-vitest.mjs src/gateway/session-companion-context.test.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-127294-niIVnJ/target$ node scripts/run-vitest.mjs src/gateway/session-companion-context.test.ts
pnpm openclaw --help
[test] starting test/vitest/vitest.gateway.config.ts

 RUN  v4.1.10 /tmp/clawsweeper-live-proof-127294-niIVnJ/target

 ✓  gateway-server-isolated  ../../src/gateway/session-companion-context.test.ts (11 tests) 15459ms
     ✓ distinguishes a missing session from an empty selected transcript  402ms
     ✓ reads a bounded active SQLite tail without decoding old transcript rows  763ms
     ✓ pages past a tool-heavy tail while retaining the selected session's latest user turn  607ms
     ✓ keeps complete recent context when older tool rows exhaust the scan byte budget  805ms
     ✓ fails closed only when unsupported roles exceed the bounded scan (4095)  6038ms
     ✓ fails closed only when unsupported roles exceed the bounded scan (4096)  5740ms
     ✓ returns unavailable instead of backfilling past an oversized latest user message  394ms




































Assertions:

  • FAIL expect_output: openclaw
  • FAIL expect_output: keeps complete recent context when older tool rows exhaust the scan byte budget

How this fits together

The Gateway session companion reads a bounded tail of persisted transcript events and converts it into read-only context for Control UI side-chat questions. It must pass useful complete context to the model while rejecting an incomplete newest page or a transcript snapshot that changes during the read.

flowchart LR
  A[Persisted session transcript] --> B[Bounded tail reader]
  B --> C[Page completeness decision]
  C --> D[Companion context builder]
  D --> E[Snapshot fence]
  E --> F[Control UI side-chat answer]
Loading

Decision needed

Question Recommendation
After the branch is refreshed and exact-head checks are green, should this maintainer-owned change to the companion's fail-closed byte-boundary policy be landed? Land after exact-head validation: Accept the narrowly scoped behavior because complete recent pages and the snapshot fence remain intact.

Why: The patch changes observable Control UI side-chat availability while deliberately refining an existing safety boundary; the protected maintainer item requires a human landing decision rather than automated cleanup.

Before merge

  • Resolve merge risk (P1) - The bug fix has a net production delta of +14 lines; the explicit boundary state is justified because a net-neutral condition would conflate incomplete newest data with safely complete newer pages, but it should remain limited to that distinction.
  • Resolve merge risk (P1) - GitHub currently marks the branch behind its base despite reporting it mergeable, so the final landing decision should use a refreshed exact-head merge result and completed checks.
  • Complete next step (P2) - No mechanical repair is identified; a maintainer should decide on landing after the branch is refreshed and exact-head checks finish.
Agent review details

Security

None.

PR surface

Source +14, Tests +28. Total +42 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 16 2 +14
Tests 1 28 0 +28
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 44 2 +42

Review metrics

Metric Value Why it matters
Production versus regression-test delta production +14/-2; tests +28/-0 The production growth adds only the state needed to distinguish a safe older-page cutoff from an incomplete newest page; the added test covers that boundary.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/session-companion-context.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the explicit complete-newer-pages boundary and final snapshot fence, then land only after the branch is refreshed and exact-head checks confirm the reviewed behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the explicit complete-newer-pages boundary and final snapshot fence, then land only after the branch is refreshed and exact-head checks confirm the reviewed behavior.

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

Yes, source-reproducible: current main returns unavailable at src/gateway/session-companion-context.ts:166 when the bounded reader reports an older partial page, and the new 384-row fixture directly creates that condition. Read-only review rules prevented running the regression locally.

Is this the best way to solve the issue?

Yes. Keeping only already-complete newer pages and fencing their snapshot is the narrow owner-level repair; it does not treat an incomplete newest page as safe or add a fallback path.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 781ded80d624.

Labels

Label changes:

  • add P2: This is a focused reliability repair for Control UI side-chat context rather than an emergency availability or security incident.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer/bot PR, so the external-contributor proof gate does not apply; its body nevertheless provides an isolated Gateway and Control UI after-fix run, though the linked attachments were not retrievable in this review environment.

Label justifications:

  • P2: This is a focused reliability repair for Control UI side-chat context rather than an emergency availability or security incident.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a maintainer/bot PR, so the external-contributor proof gate does not apply; its body nevertheless provides an isolated Gateway and Control UI after-fix run, though the linked attachments were not retrievable in this review environment.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Current-main blame attributes the bounded companion-context loop and its partial-page fail-closed condition to this commit. (role: recent area contributor; confidence: high; commits: 67630f685426; files: src/gateway/session-companion-context.ts)
  • shakkernerd: History identifies this contributor's companion snapshot-fence and fail-closed work as the invariant the patch must preserve. (role: earlier safety-invariant contributor; confidence: medium; commits: 05d0d980d8ac, 8dc50164605e; files: src/gateway/session-companion-context.ts, src/gateway/session-companion-context.test.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Refresh the branch against current main and let the exact-head required checks complete.

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.

@clawsweeper

Copy link
Copy Markdown
Contributor Author

Land-ready evidence for source head ef3461a10a5ea9ea57b6e375f3c9f227f1c9373c:

  • Root cause / owner boundary: the companion treated any byte-capped transcript page as globally unavailable, even after collecting complete newer pages. The repair keeps only those complete newer pages, stops before the older page's holes, and preserves the newest-page and snapshot-change fail-closed fences.
  • Regression proof: the new tool-heavy boundary case failed on pre-fix main (unavailable instead of ready) and passes on this head. node scripts/run-vitest.mjs src/gateway/session-companion-context.test.ts passed 22/22 across both Gateway projects.
  • Local gates: node scripts/check-changed.mjs -- src/gateway/session-companion-context.ts src/gateway/session-companion-context.test.ts passed; fresh mandatory autoreview reported no accepted/actionable findings.
  • User-visible proof: the PR body contains inspected screenshots and a 5.08-second recording from an isolated Gateway using copied real session data with channels disabled. The same side-chat question returns an answer rather than “Couldn't load this session's history.”
  • Exact-head CI: CI run 32505502538 completed successfully on this exact head.
  • Native landing gate: OPENCLAW_TESTBOX=1 scripts/pr prepare-run 127294 passed; the prepared result was patch-identical against current main, with no push required.
  • ClawSweeper rank-up move: skipped rebasing solely for behind-main drift. Repository landing policy treats that drift as advisory, and the native prepare gate already verified the unchanged patch against newer main plus green exact-head CI. No behavior changed after review.
  • Delta: production +14 net; tests +28. The production state is the minimum explicit distinction between an unsafe incomplete newest page and a safe cutoff after complete newer pages.

Known proof gaps: none. Ready for guarded squash merge.

@clawsweeper
clawsweeper merged commit 0a861b4 into main Aug 21, 2026
332 of 378 checks passed
@clawsweeper

Copy link
Copy Markdown
Contributor Author

Merged via squash.

@clawsweeper
clawsweeper deleted the openclaw/sidechat-bugged branch August 21, 2026 17:20
@clawsweeper

clawsweeper Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(gateway): keep side chat available for tool-heavy sessions This is item 3/3 in the current shard. Shard 2/60.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

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 P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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.

2 participants