Skip to content

fix(sessions): write the transcript header when a reset lands on an empty window - #125336

Merged
obviyus merged 6 commits into
openclaw:mainfrom
kiranvk-2011:fix/reset-boundary-empty-transcript-header
Sep 4, 2026
Merged

obviyus merged 6 commits into
openclaw:mainfrom
kiranvk-2011:fix/reset-boundary-empty-transcript-header

Conversation

@kiranvk-2011

@kiranvk-2011 kiranvk-2011 commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

What problem this solves

A session row can exist before its transcript has any events. If a reset arrives then, the reset boundary takes sequence zero. Later message appends cannot initialize a header over that nonempty history. The next user turn fails before inference with Persisted legacy session transcripts require doctor/import migration before runtime use.

This retains Kiran V K's (@kiranvk-2011) header-first repair and all four contributor commits. The preparation consolidates the workspace input and verifies the complete reset-to-reply flow.

Root cause and fix

Both reset append owners now call the existing ensureTranscriptHeader inside their existing guarded transaction, before building and appending the reset boundary:

  • src/config/sessions/session-accessor.sqlite-lifecycle.ts: single-target reset.
  • src/config/sessions/session-accessor.sqlite-projection.ts: batched lifecycle write.

The prior row's spawnedCwd, then spawnedWorkspaceDir, owns the header workspace. The caller's resolved workspace covers rows that recorded neither. One SessionResetBoundaryWrite carries that required input through Gateway reset, reply initialization, runner reset, and stale cron reset. It replaces parallel optional workspace state and the duplicate cron writer declaration.

The reader remains strict. This does not reinterpret or repair existing malformed transcripts. There is no schema/version/table/index change, new persisted field, migration, backfill, protocol, permission, or configuration change.

Evidence

Baseline: 26f87a37009bb452afae8523cbaf4063fbca247e.
Product-tested candidate: 3f479d92481e5a8355c5a22be6ca2fe980cbe6ef.
Current head: d424ad6f14c6b80550322bd7d5bb1a9789d14374.
The complete difference is one package-test fixture line supplying its owned temporary workspace. All other tracked files are identical; product proof and build inputs are unchanged.

Real Telegram Test Server proof used an independently leased user and bot, a normally loaded Plugin SDK observer, and a real isolated inference provider. No channel, reset handler, delivery path, or model response was mocked.

Sequence Baseline Candidate
Bare /reset, then normal input in the same fresh session Reset is sequence zero; no header exists; next turn fails before inference Follow-up completes with “2 plus 3 equals 5.” and reaches the real Telegram user
Gateway restart, then reset with tail Not claimed as a separate baseline case /reset What is 6 plus 7? completes with “6 plus 7 equals 13.” as ordinary answer content
Installed CLI agent --deliver: /reset, then /new on an empty window Baseline header failure is retained above Empty precondition observed; existing v3 header is sequence zero and reset is sequence one
Installed CLI normal follow-up Not claimed as a separate baseline case Exit 0, status: ok, summary: completed, delivery sent; the user receives “9 plus 10 equals 19.”

The CLI follow-up uses its documented per-command --timeout 1800 for slow CPU inference. The earlier invocation hit the unchanged 600-second default, returned timeout/aborted, and visibly delivered its error. That failed attempt remains in the evidence. Product defaults, full prompts, tools, and the tested source did not change for the corrected invocation.

The final database backup and complete row capture retain schema 19, the existing v3 header, the reset, and the completed user/assistant exchange. Actual Gateway restart and the next completed turn exercise reopening. No separate old-reader or live ACP/Codex-backend claim is made.

Supporting verification:

  • Baseline regression: six failing cases and one populated-transcript control pass.
  • Candidate: 311 tests across ten files and five shards pass, covering both lifecycle writers, workspace precedence, runner/cron producers, and reset-race controls.
  • The corrected memory snapshot package fixture passes all five tests. Its populated-transcript hash-invalidation assertions are unchanged.
  • Focused lint, runtime/UI builds, package integrity, and installed package preparation pass.
  • All 37,652 tracked source blobs matched before and after the build.
  • Current main through dcdeede2fa47552f3c0dbd5208b5fbf52bb85323 has no change to the touched production files.

Limitations and review disposition

The successful CLI turn was followed by an auxiliary compaction attempt that hit its existing 180-second deadline. The owner logged continuing final delivery; the correct answer was delivered and the original transcript remained. This is not a compaction-success claim. Complete error events remain in the independent-review evidence.

Earlier setup, small-provider, observation-budget, and lease/control failures remain retained. Only the completed same-head sequences above are green. Owned temporary groups were reconciled and all leases released.

The separate reset-status marker repair remains in #124633. This header-only head still exposes the existing unmarked acknowledgements to the answer hook; it does not claim to fix that separate metadata defect.

ClawSweeper's prior workspace and lifecycle-owner findings are retained and addressed. The net-positive production risk is reduced from +94 to +49 by replacing parallel inputs with one required boundary shape. Production is +96/-47; tests are +478/-16. The remaining growth supplies the missing workspace through all four producers and initializes the existing header at both transaction owners. A reader fallback or skipped reset event would violate the existing contract.

Missing-header diagnostic wording remains the contributor's separate follow-up noted in this PR's discussion. Compaction policy is outside this ordering repair.

AI-assisted preparation. Independent exact-head review and current CI must pass before guarded landing.

@clawsweeper

clawsweeper Bot commented Aug 17, 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 the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 17, 2026
@kiranvk-2011

Copy link
Copy Markdown
Contributor Author

Pushed a second commit: session-accessor.sqlite-projection.ts has the same pattern — the batched lifecycle upsert appends a reset boundary to expectedEntry.sessionId with the identical empty-window hazard. Guarded it the same way, so both reset-boundary append sites are covered. Suites still green (146 tests).

@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: 🦪 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 Aug 17, 2026
@clawsweeper

clawsweeper Bot commented Aug 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 2:58 AM ET / 06:58 UTC.

ClawSweeper review

What this changes

The PR writes a session header before reset boundaries on empty SQLite transcript windows and forwards a workspace fallback from gateway, reply-runner, and cron reset paths.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open. Current main still permits a reset boundary to become the first event of an empty transcript, while this PR repairs both lifecycle writers and preserves the correct workspace metadata.

Priority: P1
Reviewed head: 9c00082c3156248ce77d3fc05823ec46ed50b962

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused durable-session repair with real after-fix behavior evidence and regression coverage across both lifecycle writers.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The changed production owners are the two SQLite lifecycle writers and their reset producers. The PR body provides a redacted real source-run trace in which the runner resets an empty stored window, observes a v3 header at sequence zero and reset at sequence one, then sends a real CLI turn that returns proof-ok; final-head tests cover the same storage invariant and workspace precedence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The changed production owners are the two SQLite lifecycle writers and their reset producers. The PR body provides a redacted real source-run trace in which the runner resets an empty stored window, observes a v3 header at sequence zero and reset at sequence one, then sends a real CLI turn that returns proof-ok; final-head tests cover the same storage invariant and workspace precedence.
Evidence reviewed 5 items Current-main defect: Current main constructs and appends a reset boundary without first ensuring a header in the single-target lifecycle writer; the analogous projection writer has the same ordering.
Header invariant: The header helper returns once any transcript row exists, and normal message appends call it before inserting a message; a reset at sequence zero therefore prevents later automatic header creation.
Lifecycle-owner repair: Both atomic lifecycle writers now ensure the header before constructing and appending the reset boundary, using the prior row's workspace before a producer fallback.
Findings None None.
Security None None.

How this fits together

Reset producers replace the live session row while appending a boundary to the prior transcript. Later agent runs load that durable transcript; its header supplies the version and working directory needed to resume safely.

flowchart LR
  A[Gateway, reply, runner, or cron reset] --> B[Session lifecycle write]
  B --> C{Prior transcript empty?}
  C -->|Yes| D[Write versioned session header]
  C -->|No| E[Keep existing header]
  D --> F[Append reset boundary]
  E --> F
  F --> G[Later agent run loads transcript]
Loading

Before merge

  • Resolve merge risk (P1) - This is a +94 net production-line change to durable session ordering and workspace metadata; it intentionally changes how previously empty historical windows are written.
Agent review details

Security

None.

PR surface

Source +94, Tests +428. Total +522 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 12 112 18 +94
Tests 3 429 1 +428
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 541 19 +522

Review metrics

Metric Value Why it matters
Production versus test delta production +94 net; tests +428 net The added durable-lifecycle propagation is covered by new boundary tests across both storage writers and reset producers.

Merge-risk options

Maintainer options:

  1. Accept the bounded durable-session change (recommended)
    Merge with the header-ordering and workspace-precedence tests plus the recorded reset-to-reply proof as coverage for the persisted-session risk.

Technical review

Best possible solution:

Retain the lifecycle-owned header-before-boundary invariant, with the prior session row as workspace authority and producer workspace only as the fallback.

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

Yes—source establishes the path: persist an existing session row with zero transcript events, append a reset boundary, then load the resulting non-header-first transcript. The supplied real CLI trace demonstrates the repaired sequence and successful subsequent reply.

Is this the best way to solve the issue?

Yes. Repairing both lifecycle owners before the boundary is appended is the narrow canonical fix; a later-load workaround could not restore the lost header ordering safely.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P1: A headerless persisted transcript can cause subsequent turns on an existing session to fail before a model reply.
  • merge-risk: 🚨 session-state: The PR changes atomic ordering and workspace metadata in durable session transcripts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The changed production owners are the two SQLite lifecycle writers and their reset producers. The PR body provides a redacted real source-run trace in which the runner resets an empty stored window, observes a v3 header at sequence zero and reset at sequence one, then sends a real CLI turn that returns proof-ok; final-head tests cover the same storage invariant and workspace precedence.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owners are the two SQLite lifecycle writers and their reset producers. The PR body provides a redacted real source-run trace in which the runner resets an empty stored window, observes a v3 header at sequence zero and reset at sequence one, then sends a real CLI turn that returns proof-ok; final-head tests cover the same storage invariant and workspace precedence.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vyctor H. Brzezowski: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vishal Doshi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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 (9 earlier review cycles; latest 8 shown)
  • reviewed August 20, 2026, 9:42 AM ET / 13:42 UTC sha unknown :: needs real behavior proof before merge. :: [P1] Preserve the session cwd in reset-created headers
  • reviewed 2026-08-22T01:14:13.834Z sha 392ca96ae46727e15e71c71bc978ec7b25331688 :: needs real behavior proof before merge. :: [P1] Propagate the workspace through agent-runner resets
  • reviewed 2026-08-22T14:04:34.127Z sha 392ca96ae46727e15e71c71bc978ec7b25331688 :: needs real behavior proof before merge. :: [P1] Forward the runner workspace into reset lifecycle
  • reviewed 2026-08-24T13:45:53.248Z sha 392ca96ae46727e15e71c71bc978ec7b25331688 :: needs real behavior proof before merge. :: [P1] Pass the runner workspace into reset persistence
  • reviewed 2026-08-30T14:44:00.527Z sha 392ca96ae46727e15e71c71bc978ec7b25331688 :: needs real behavior proof before merge. :: [P1] Pass the runner workspace into reset persistence
  • reviewed 2026-09-02T12:44:12.230Z sha 8e86f1a82692f7d43e3b1db495de802dd344ef69 :: needs changes before merge. :: [P1] Forward the cron workspace into reset-created headers
  • reviewed 2026-09-02T17:02:42.250Z sha 8c70cd5cb4a544f0df6ccb299a5f6a542c609157 :: needs real behavior proof before merge. :: [P1] Preserve the prior session CWD in reset-created headers
  • reviewed 2026-09-02T21:26:09.717Z sha 71566dc8c7061cc1c41ff5f0f74d44bf5af3e7cf :: blocked before merge. :: none

@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 20, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M and removed size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 22, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 22, 2026
@kiranvk-2011

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Both blockers from the last review are addressed on the branch (392ca96a):

  • [P1] cwd preserved: resetBoundaryCwd threaded through both reset-boundary append paths and populated from resolveAgentWorkspaceDir at the gateway-reset and reply-session-initialization callers; tests now pin the workspace value on both paths (3 passing).
  • Real behavior proof: reset-to-next-turn trace and five-day production soak added to the PR body.

@clawsweeper

clawsweeper Bot commented Aug 22, 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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 22, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 30, 2026
@kiranvk-2011
kiranvk-2011 force-pushed the fix/reset-boundary-empty-transcript-header branch from 8c70cd5 to 71566dc Compare September 2, 2026 21:20
@kiranvk-2011

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the remaining P1 (head 71566dc8c7, rebased onto current main afadc38436):

  • [P1] Preserve the prior session CWD: the lifecycle owner now picks the header cwd from the prior row (spawnedCwd → spawnedWorkspaceDir) via resolveResetBoundaryHeaderCwd, using the caller's resetBoundaryCwd only as a fallback, at both append sites; the runner no longer derives spawned precedence itself. Two new row-first tests (single-target + batched) fail with cwd=<agent default> when the selection is removed; runner custom-workspace test added.
  • Exact-head proof: redacted custom-workspace reset-to-reply trace in the PR body (row spawnedCwd=<state>/custom-ws ≠ run workspace → seq 0: session v3 cwd=<state>/custom-ws, seq 1: reset, then proof-ok, stopReason=stop).
  • Suites: reset-header 5/5, runner-reset 13/13, cron session-state 26/26, related session/gateway reset suites 247 passed; pnpm check:changed over all changed files exit 0.

@clawsweeper

clawsweeper Bot commented Sep 2, 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 proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 2, 2026
kiranvk-2011 and others added 4 commits September 3, 2026 05:44
…mpty window (openclaw#118675)

A session window can exist with a still-empty transcript when a reset
arrives (created moments earlier, before its first message). Appending
the reset boundary then makes seq 0 a `reset` event; ensureTranscriptHeader
only fires on an *empty* transcript, so the first message append skips it
and the window stays permanently headerless -- rejected on every later
load as a legacy transcript before the model runs.

Establish the header before the boundary at both reset-boundary append
sites (single-target lifecycle reset and the batched lifecycle upsert),
and record the session workspace in headers created this way: the value
is threaded as `resetBoundaryCwd` alongside the `resetBoundary` request
from the gateway session-reset and reply-session-initialization callers.

Rebased onto current main's `SessionResetBoundaryRequest` reset plumbing.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HspGQJnLGMcam6jCottM9v
…t headers

The agent-runner reset path called persistSessionResetLifecycle without a
workspace, so an empty-window reset from that producer stamped the new
header with the service process cwd. Forward the runner's effective
workspace (spawnedCwd, spawnedWorkspaceDir, or the follow-up run
workspace -- the same value the diff baseline settles against) and assert
the persisted header cwd in the runner-boundary test.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HspGQJnLGMcam6jCottM9v
The stale-cron reset producer appended its pending boundary through the
batched lifecycle upsert without a workspace, so a reset landing on an
empty prior cron window created the header from process.cwd() and
persisted the gateway process directory as the session workspace.

Forward the run's already-resolved workspaceDir as resetBoundaryCwd
alongside the pending cron-stale boundary. With this every resetBoundary
producer (gateway reset, reply-session init, agent-runner reset, cron
stale reset) supplies a workspace.

Tests: forwarding with a pending boundary, none without one, and an
end-to-end stale reset on an empty window against a real SQLite store
asserting seq 0 = session v3 cwd=<run workspace>, seq 1 = reset.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HspGQJnLGMcam6jCottM9v
The reset-boundary header is written for the prior row's session, so that
row's own workspace (spawnedCwd, then spawnedWorkspaceDir) must win; the
caller-supplied workspace is only a fallback for rows that never recorded
one. Gateway and reply initialization pass the configured agent workspace,
which mis-stamped custom-workspace sessions and was then preserved by
transcript cut/fork paths.

The agent runner no longer re-derives spawned precedence itself; it passes
the run workspace as the fallback only.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01HspGQJnLGMcam6jCottM9v
@kiranvk-2011
kiranvk-2011 force-pushed the fix/reset-boundary-empty-transcript-header branch from 71566dc to 9c00082 Compare September 3, 2026 06:22
@kiranvk-2011

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (35f324956f) to clear the merge conflict; no functional change. The only conflict was main's new assertCommitAllowed field beside the cron reset-boundary fields in run-session-state.ts. Suites: reset-header 5/5, runner-reset 13/13, cron session-state 26/26, gateway sessions.reset 67/67 + 4/4, sqlite session-accessor 250/250; pnpm check:changed over the 15 changed files exit 0. Head 9c00082c31.

@abacha

abacha commented Sep 3, 2026

Copy link
Copy Markdown

Production repro of the same defect, with an idle rollover instead of /new, in case it helps this land.

On 2026-08-08 a WhatsApp group session (SQLite store, stock schema) had its window created but no append landed yet — the session row existed with zero transcript_events rows. The idle rollover fired into that window and the boundary took seq 0:

{"type":"reset","id":"a8ba160a","parentId":null,"timestamp":"2026-08-08T13:02:11.647Z","reason":"idle"}

No {"type":"session"} row anywhere. The two inbound messages that followed (13:02:12.082Z, 13:02:48.705Z) both died before the model ran, with Persisted legacy session transcripts require doctor/import migration before runtime use, surfaced raw in the group. Final state: 3 rows, seq 0 the boundary, session_transcript_index_state.indexed_seq=2. Recovery was deleting the transcript rows plus the stale index row by hand so the zero-row branch of setLoadedSessionTarget would re-init a v3 header. Incidence: 1 session in 189, across 10 agent stores.

Re-verified on main 781f9639ce414316a70a467de9d4dd73e8dcc4f4: ensureTranscriptHeader (src/config/sessions/session-accessor.sqlite-transcript-store.ts:318-340) guards on any row existing rather than a header existing, so once the boundary holds seq 0 the first message append returns early and the transcript is header-less for the life of the session.

Worth flagging for triage: #127547 was closed as already implemented on the premise that "a reset on a missing session row no longer appends a reset boundary, and the first persisted event for a fresh transcript writes the version-3 header first". Both hold, and neither covers a row that exists with a zero-row transcript — that boundary is appended by the store lifecycle (session-accessor.sqlite-lifecycle.ts, and the batched path in session-accessor.sqlite-projection.ts), not by the session manager, so the header flush never runs. Which is what this PR fixes at both sites.

Second, smaller point on the same failure: header?.version ?? 1 in setLoadedSessionTarget turns absent header into version 1, so a transcript written minutes earlier by the current build is reported as legacy and sends the operator looking for a pre-v3 migration that never happened.

@kiranvk-2011

Copy link
Copy Markdown
Contributor Author

Thanks @abacha — that is the same defect from the other producer. Your idle rollover trace matches the two /new cases in the PR body exactly: session row present, zero transcript rows, boundary lands at seq 0, and ensureTranscriptHeader then sees "a row exists" and never writes the v3 header, so every later turn fails the legacy-transcript check. Both boundary append sites (lifecycle and the batched projection path) are what this PR guards, and the header cwd is now taken from the stored session row, so the idle-rollover path is covered by the same change (reason is irrelevant to the guard).

Agree on #127547: the two premises there hold, but neither covers an existing row with an empty transcript, because that boundary is appended by the store lifecycle rather than the session manager.

The header?.version ?? 1 point is real but separate (it turns an absent header into a misleading "pre-v3 migration" message). I have kept it out of this PR to keep the diff to the ordering fix; happy to follow up with a small PR that reports "missing header" distinctly once this lands.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L and removed size: M labels Sep 4, 2026
@obviyus

obviyus commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

The header-first repair is retained on 3f479d92481e5a8355c5a22be6ca2fe980cbe6ef, with all contributor commits preserved. The PR body now records independent main red, real Telegram follow-up/restart/reset-with-tail, installed CLI delivery, 311 passing tests, and the explicit compaction limitation. The workspace propagation now uses one required boundary shape; net production growth is +49. Exact-head independent review and CI are in progress.

@clawsweeper

clawsweeper Bot commented Sep 4, 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.

@obviyus
obviyus merged commit 62ff624 into openclaw:main Sep 4, 2026
209 of 211 checks passed
@obviyus

obviyus commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

Thanks @kiranvk-2011!

Landed as 62ff6248557c, preserving your primary credit and contributor history.

Proof: Real Telegram reset → normal answer, Gateway restart → reset-with-tail answer, and installed CLI delivery all completed. The empty-window capture now starts with the existing v3 header, then the reset boundary. The fixture-only final correction passed five package tests; the retained 311 focused tests and product proof remain valid. The exact-head CI run and independent P0 review passed before the guarded merge.

  • Bug: Reset could become the first event of an empty transcript, causing the next turn to fail before inference.
  • Fix: Both lifecycle writers initialize the existing header inside their guarded transaction before appending the boundary, preserving the prior session workspace.
Before After
Reset at sequence zero; missing-header rejection on the next turn Header at sequence zero; reset and later answers remain readable

No schema, migration, protocol, permission, or configuration change. The recorded slow-CPU CLI timeout and post-turn compaction timeout remain explicit limits of the proof; final answer delivery succeeded with the documented CLI timeout override.

The separate status-marker repair continues in #124633.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…penclaw#125336)

Initialize an empty transcript with its existing versioned session header before either lifecycle writer appends a reset boundary.

Keep the prior session row's workspace authoritative. Carry the caller's resolved workspace in the required reset-boundary write for rows without a recorded workspace. Preserve existing commit guards, reset reasons, session identities, and transaction order.

Proved the reset-to-next-turn failure on main, then verified real Telegram follow-up, restart, reset-with-tail, and installed CLI delivery on the repaired head. Focused coverage passes 311 tests. No schema, migration, protocol, permission, or configuration change.

Co-authored-by: Ayaan Zaidi <[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 gateway Gateway runtime 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. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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.

3 participants