Skip to content

fix(sessions): restore history while transcripts keep growing (#115908) - #116259

Closed
CanadaOrNaw wants to merge 2 commits into
openclaw:mainfrom
CanadaOrNaw:fix/session-projection-reconcile-livelock
Closed

CanadaOrNaw wants to merge 2 commits into
openclaw:mainfrom
CanadaOrNaw:fix/session-projection-reconcile-livelock

Conversation

@CanadaOrNaw

@CanadaOrNaw CanadaOrNaw commented Jul 30, 2026 •

Copy link
Copy Markdown

Related: #115908

AI-assisted: this revision was developed and reviewed with Codex plus an independent isolated second-model review. The final source, tests, and synthetic evidence were verified manually before publication.

What Problem This Solves

Fixes an issue where session history for a hot, growing transcript can remain unavailable while projection reconciliation repeatedly loses an exact-snapshot claim race. On current main, the Gateway can remain healthy while the affected session's history returns retryable 503 responses until writes stop.

Why This Change Was Made

Current main already prepares full projections in a Worker and commits them through bounded, yielding writer chunks. This revision therefore targets the remaining claim-time convergence failure rather than the original report's obsolete no-Worker/no-yield premise.

A prepared projection may now claim same-generation append-only growth only when the entire post-snapshot tail is contiguous and bounded to 512 rows and 256 KiB of serialized event_json. Finalize rereads the authoritative snapshot, rechecks the same bounds, and applies the existing live append inference before publication. Resets, generation changes, branches, side appends, leaf controls, parent mismatches, canonical/legacy ambiguity, and oversized tails remain dirty for the normal full-reconcile path.

History and transcript-search readers also avoid re-latching an owner that is already running; writer-owned dirty transitions still retain the existing pending-pass signal.

User Impact

Ordinary bounded appends that race Worker preparation can converge while the session is still receiving writes, instead of requiring a quiet period before history becomes available again. Unsafe or oversized tails keep the existing conservative retry behavior rather than publishing stale state.

This change does not claim to fix every historical multi-minute Gateway stall reported in #115908. The controlled reproduction proves a current-main session-history convergence defect and a bounded synthetic improvement; it did not reproduce an event-loop freeze.

Evidence

Reviewed source:

  • specified base: d0b362f2558e91e450124c8212c253a5bad316a8
  • fully tested review base: d03a43a820d0b7810435d3aa57906da7b54707a8
  • publish base: 1767639226bb3177f9f2c771d39de16fef2563aa (all touched source blobs were unchanged from the tested review base)
  • pushed candidate commit: 97be09b5a84858b0476a78a67ae01ac368f7611d
  • reviewed patch SHA-256: da990103a63f7ad6a9b78aba473b4b5a8daf62cbbb458838bb4d0e3c855a8e23
  • exact surface: 7 files, +797 / -139 (production +358 / -138; tests +439 / -1)

Focused validation:

  • 4 focused test files, 33 tests passed;
  • owner-level regression enters through startSessionTranscriptIndexReconcile, injects an append after Worker preparation and before claim, and converges with exactly one Worker process;
  • claim-time rejection tests cover both 513 rows and a tail exceeding 256 KiB before the prior projection is replaced;
  • finalize rejection covers reset visibility changes and transcript-generation rotation;
  • pnpm tsgo:core passed;
  • pnpm tsgo:test:src passed;
  • full pnpm build passed;
  • targeted oxfmt, oxlint, Kysely guardrails, and git diff --check passed;
  • required autoreview --mode uncommitted --max-priority P1 completed clean with no accepted/actionable findings.

Separate-process packaged-Gateway comparison under identical bounded-tail load (2,000 seeded 8 KiB events, then one 512-byte append every 20 ms for five seconds):

Measurement Clean current-main baseline Reviewed candidate rerun
/healthz 150/150 HTTP 200 150/150 HTTP 200
history HTTP 503 samples 22/60 4/60
unavailable samples 4.501s–9.756s 4.508s–5.263s
first observed clean/current state after onset 10.004s, after writes stopped 5.501s, while writes continued

The controller, Gateway, writer, and read-only projection probe ran as separate processes against isolated synthetic state.

An oversized high-throughput run exercised the fallback path. The reviewed candidate remained conservative and baseline-like (37/112 history 503 samples versus 36/112 on the supplied baseline), recovered only after writes stopped, and kept /healthz responsive for 280/280 probes.

Known limits:

  • no historical multi-minute event-loop stall was reproduced;
  • the patch bounds its new claim/finalize tail work, but does not redesign pre-existing global FTS/orphan maintenance scans elsewhere in reconciliation;
  • upstream CI is running on the exact pushed draft head and remains the final hosted verification gate.

@openclaw-barnacle openclaw-barnacle Bot added size: L triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Jul 30, 2026
@clawsweeper clawsweeper Bot added 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. 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. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Jul 30, 2026
@clawsweeper

clawsweeper Bot commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 5, 2026, 10:04 PM ET / August 6, 2026, 02:04 UTC.

ClawSweeper review

What this changes

This PR lets session transcript projection reconciliation absorb a bounded append-only tail so history can recover while transcript writes continue.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until real behavior proof is added - 3 items remain

Keep open: this draft is the active candidate fix for the linked sustained-write session-history defect, but it still lacks inspectable exact-head real-behavior proof required before merge.

Priority: P1
Reviewed head: c5a4aac635a37183978db52123df82b2f8ae7696

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch has focused claimed validation, but missing inspectable real-behavior proof is a merge gate.
Proof confidence 🧂 unranked krab (1/6) Needs real behavior proof before merge: The body reports a packaged-Gateway comparison but provides no inspectable exact-head trace, log, terminal capture, screenshot, recording, or linked artifact. 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.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The body reports a packaged-Gateway comparison but provides no inspectable exact-head trace, log, terminal capture, screenshot, recording, or linked artifact. 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.
Evidence reviewed 3 items Maintainer proof requirements: The maintainer comment requires bounded catch-up, an owner-level regression through the reconciliation starter, and a redacted packaged-Gateway causal trace under sustained writes; the supplied PR body contains claims but no inspectable artifact.
Prior exact-head review: The previous ClawSweeper review of this same head records that no exact-head trace, logs, terminal capture, recording, screenshot, or linked artifact was available.
Changed owner surface: The branch changes the projection rebuild, active-event reader, transcript index, and reconciliation-triggering search path.
Findings None None.
Security None None.

How this fits together

Transcript writes dirty a SQLite-backed session projection, while reconciliation rebuilds and publishes that projection for history and transcript-search readers. The PR changes the concurrent-write window between projection preparation and final publication.

flowchart LR
  A[Transcript writes] --> B[Dirty projection state]
  B --> C[Reconciliation owner]
  C --> D[Prepared projection]
  D --> E[Bounded append validation]
  E --> F[Published projection]
  F --> G[History and search readers]
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The body reports a packaged-Gateway comparison but provides no inspectable exact-head trace, log, terminal capture, screenshot, recording, or linked artifact. 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.
  • Resolve merge risk (P1) - Publishing an incorrectly inferred append tail could leave session history stale or inconsistent.
  • Resolve merge risk (P1) - The supplied comparison is not independently inspectable, so it does not establish Gateway responsiveness or the claimed recovery on the exact head.
Agent review details

Security

None.

PR surface

Source +220, Tests +438. Total +658 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 358 138 +220
Tests 3 439 1 +438
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 797 139 +658

Review metrics

Metric Value Why it matters
Production versus tests production +358/-138; tests +439/-1 The substantial production change alters the session-projection owner boundary and needs commensurate runtime proof.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-accessor.sqlite-active-events.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-active-events.ts, serialized state: src/config/sessions/session-transcript-index.ts, serialized state: src/config/sessions/session-transcript-projection-catchup.test.ts, serialized state: src/config/sessions/session-transcript-projection-rebuild.test.ts, serialized state: src/config/sessions/session-transcript-projection-rebuild.ts, and 4 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #115908
Summary: This PR is the candidate fix for the linked sustained-write session-projection defect.

Members:

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

Merge-risk options

Maintainer options:

  1. Add inspectable runtime proof (recommended)
    Attach a redacted exact-head packaged-Gateway trace showing sustained writes, reconciliation/finalize outcomes, history recovery, and loopback responsiveness.
  2. Pause the draft
    Keep the PR draft until the required causal trace and owner-level evidence can be supplied.

Technical review

Best possible solution:

Provide a redacted exact-head packaged-Gateway trace that correlates reconciliation/finalize outcomes with history recovery and loopback responsiveness, then re-review the owner-level regression and bounded transaction behavior.

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

No: the PR describes a controlled sustained-write reproduction, but no inspectable exact-head runtime artifact establishes it independently.

Is this the best way to solve the issue?

Unclear: bounded catch-up at the projection owner is plausible, but the required exact-head causal runtime proof is missing.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: The PR targets history returning retryable failures during active transcript writes.
  • merge-risk: 🚨 session-state: It changes persisted transcript projection preparation, tail inference, and publication.
  • merge-risk: 🚨 availability: The affected reconciliation path runs alongside Gateway history reads under sustained writes.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The body reports a packaged-Gateway comparison but provides no inspectable exact-head trace, log, terminal capture, screenshot, recording, or linked artifact. 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.

Evidence

What I checked:

  • Maintainer proof requirements: The maintainer comment requires bounded catch-up, an owner-level regression through the reconciliation starter, and a redacted packaged-Gateway causal trace under sustained writes; the supplied PR body contains claims but no inspectable artifact. (c5a4aac635a3)
  • Prior exact-head review: The previous ClawSweeper review of this same head records that no exact-head trace, logs, terminal capture, recording, screenshot, or linked artifact was available. (c5a4aac635a3)
  • Changed owner surface: The branch changes the projection rebuild, active-event reader, transcript index, and reconciliation-triggering search path. (src/config/sessions/session-transcript-projection-rebuild.ts:1, c5a4aac635a3)

Likely related people:

  • vincentkoc: Assigned this PR and recorded the concrete reconciliation-owner and packaged-Gateway proof requirements. (role: recent reviewer and assigned area contact; confidence: high; files: src/config/sessions/session-transcript-projection-rebuild.ts, src/config/sessions/session-accessor.sqlite-active-events.ts)

Rank-up moves

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

  • Attach a redacted exact-head packaged-Gateway trace showing recovery while writes continue and responsiveness remains intact.

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 (12 earlier review cycles; latest 8 shown)
  • reviewed 2026-08-02T00:53:21.666Z sha 97be09b :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-02T01:14:19.053Z sha c5a4aac :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-03T16:45:47.439Z sha c5a4aac :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-04T20:27:35.459Z sha c5a4aac :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-04T21:15:17.766Z sha c5a4aac :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-04T23:06:22.597Z sha c5a4aac :: needs real behavior proof before merge. :: [P2] Preserve pending work discovered by readers
  • reviewed 2026-08-04T23:20:06.401Z sha c5a4aac :: needs real behavior proof before merge. :: [P2] Latch reader-discovered dirty work
  • reviewed 2026-08-06T00:47:47.368Z sha c5a4aac :: needs real behavior proof before merge. :: [P2] Latch reader-discovered dirty work

@vincentkoc vincentkoc self-assigned this Jul 31, 2026
@vincentkoc

Copy link
Copy Markdown
Member

Maintainer routing note: the existing review already covers the missed follow-up pass. Three requirements still need an explicit record before this draft can advance:

  • Keep append catch-up off the Gateway's synchronous write path, or bound it by bytes as well as rows; the current 512-row finalize path parses JSON and updates search rows inside one main-thread transaction.
  • Add a regression through the real reconciliation owner (startSessionTranscriptIndexReconcile), not direct prepare/claim/finalize helpers, proving newly dirty work after a scan receives one bounded follow-up and converges.
  • Provide a redacted packaged-Gateway causal trace correlating reconciliation/finalize-abort data with event-loop or loopback-HTTP responsiveness under sustained writes.

No branch update or contributor-code execution is requested here.

@CanadaOrNaw
CanadaOrNaw force-pushed the fix/session-projection-reconcile-livelock branch from 962c7c4 to 97be09b Compare August 2, 2026 00:47
@CanadaOrNaw CanadaOrNaw changed the title fix(sessions): prevent projection reconcile relatch + bounded tail catch-up (#115908) fix(sessions): restore history while transcripts keep growing (#115908) Aug 2, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 2, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 6, 2026
@CanadaOrNaw CanadaOrNaw closed this Aug 8, 2026
@CanadaOrNaw
CanadaOrNaw deleted the fix/session-projection-reconcile-livelock branch August 9, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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: 🧂 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.

2 participants