Skip to content

fix(agents): seed fresh session identity before transcript append - #119473

Merged
Patrick-Erichsen merged 4 commits into
openclaw:mainfrom
jjjhenriksen:agent/fix-fresh-session-transcript-persistence
Aug 5, 2026
Merged

Patrick-Erichsen merged 4 commits into
openclaw:mainfrom
jjjhenriksen:agent/fix-fresh-session-transcript-persistence

Conversation

@jjjhenriksen

@jjjhenriksen jjjhenriksen commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where opening a genuinely fresh persisted session could leave its SQLite session identity row absent. The first transcript header and message append then failed with Session transcript header was not persisted before the model was called.

Why This Change Was Made

The session manager now creates a missing SQLite session identity row at the first real transcript write, immediately before the pending session header is appended. Opening a session for reading no longer creates or rewrites a session row, so existing metadata and session identity remain untouched on no-op probes and rollback paths.

User Impact

Fresh SQLite-backed sessions now persist their header and first user message reliably. Existing sessions, read-only session opens, and in-memory session behavior are unchanged. No configuration changes or data migration are required.

Evidence

Exact PR head: d7f4978be251da00f77c3a786d8d626a7a54591c (rebased onto origin/main at 0b68f8e1ed5).

Focused validation on that exact checkout:

  • node scripts/run-vitest.mjs run src/agents/sessions/session-manager.test.ts — 1 file, 25 tests passed.
  • node scripts/run-vitest.mjs run src/gateway/worker-environments/transcript-commit.test.ts — 1 file, 10 tests passed.
  • node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts test/pr119473-real-runtime-proof.e2e.test.ts — 1 real gateway test passed in 8.90s.
  • The session regression coverage verifies that opening an empty transcript does not create a row, that the first append creates the row and header, that opening an empty transcript does not rewrite an existing row, and that a stale appender cannot overwrite a rebound SQLite identity.
  • Direct oxlint on the changed session/persistence and runtime-proof files — passed.
  • Oxfmt check on the changed session/persistence and runtime-proof files — passed.
  • git diff --check — passed.
  • pnpm tsgo:test — passed across all 175 workspace projects.

Observed gateway proof trace

The test starts the actual gateway twice in isolated temporary state and asserts this live sequence:

first start: live loopback gateway + authenticated WebSocket client
chat.send(agent:main:pr119473-fresh-runtime): status=started, runId is present
agent.wait(runId): status=ok
gateway shutdown: completed
second start: live loopback gateway + authenticated WebSocket client
chat.history(agent:main:pr119473-fresh-runtime): PR119473_FIRST_USER_MESSAGE present

The model response comes from a real loopback OpenAI-compatible HTTP/SSE server, not a mocked gateway client. The passing runner output from the latest exact-head execution was:

RUN v4.1.10 /Users/jacquelinehenriksen/openclaw

Test Files  1 passed (1)
Tests       1 passed (1)
Start at    08:46:31
Duration    8.90s

AI-assisted: Yes. The implementation, regression tests, and gateway lifecycle proof were reviewed against the session persistence and transcript-write paths. The ChatGPT Codex connector review findings on the prior head were addressed by moving identity seeding to the first write and preserving existing rows.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. labels Aug 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 5, 2026
@jjjhenriksen
jjjhenriksen force-pushed the agent/fix-fresh-session-transcript-persistence branch from c7db975 to 0f4d222 Compare August 5, 2026 04:43

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c7db9757ce

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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. labels Aug 5, 2026
@clawsweeper

clawsweeper Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 5, 2026, 12:05 PM ET / 16:05 UTC.

ClawSweeper review

What this changes

The PR atomically creates a missing SQLite session identity immediately before a fresh session’s first transcript header is written, with unit and gateway-restart regression coverage.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

No blocking findings. This PR fixes a current fresh-session persistence failure at the SQLite identity owner, addresses the prior atomicity concern, and has focused plus gateway-boundary proof.

Priority: P1
Reviewed head: d7f4978be251da00f77c3a786d8d626a7a54591c

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The patch repairs the owning transaction boundary, covers the prior race concern, and provides focused plus gateway-boundary evidence.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body includes after-fix output from an isolated real gateway restart with an authenticated WebSocket client and a recorded persisted-history result.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body includes after-fix output from an isolated real gateway restart with an authenticated WebSocket client and a recorded persisted-history result.
Evidence reviewed 5 items Current-main failure path: Current main creates a pending in-memory header for an empty persisted session, while the synchronous SQLite transcript writer rejects an append without a matching session identity row.
Atomic owner-boundary repair: The PR’s SQLite owner conditionally inserts only an absent identity in one write transaction; a pre-existing rebound identity is retained rather than overwritten.
Independent stale-identity guard: The existing synchronous header writer rereads the canonical identity and rejects a missing or mismatched row before appending, preserving safety if a rebind occurs after seeding.
Findings None None.
Security None None.

How this fits together

The agent session manager turns chat activity into a persisted transcript. SQLite session identity establishes ownership for that transcript before its header and first message can be recorded.

flowchart LR
  A[Gateway chat request] --> B[Session manager]
  B --> C[Pending transcript header]
  C --> D[SQLite identity owner]
  D --> E[Transcript writer]
  E --> F[Persisted session history]
Loading

Before merge

  • Resolve merge risk (P1) - This changes live session identity creation, so normal exact-head mergeability gating should remain in place even though the patch adds no schema, config, or migration surface.
  • Complete next step (P2) - The submitted PR already owns the narrow repair and no concrete automated follow-up remains.
Agent review details

Security

None.

PR surface

Source +42, Tests +272. Total +314 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 5 42 0 +42
Tests 2 272 0 +272
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 314 0 +314

Review metrics

Metric Value Why it matters
Production versus regression LOC production +42/-0; tests +272/-0 The production growth is justified by the new atomic SQLite identity-owner operation, while most added code is focused regression and gateway-boundary coverage.

Stored data model

Persistent data-model change detected: serialized state: src/agents/sessions/session-manager-persistence.ts, serialized state: src/agents/sessions/session-manager.test.ts, serialized state: src/config/sessions/session-accessor.sqlite-entry.ts, unknown-data-model-change: src/agents/sessions/session-manager.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Land with normal exact-head gating (recommended)
    Retain the atomic insert and existing revalidation guards, then let GitHub confirm the reviewed head remains cleanly mergeable.

Technical review

Best possible solution:

Keep conditional identity creation in the SQLite session-entry owner, retain the transcript writer’s independent identity check, and merge once the exact head is confirmed mergeable.

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

Yes at source level: opening a fresh persisted session produces a pending header, then the current identity-gated writer rejects that header because no row exists. The PR body also supplies an exact-head gateway restart trace showing the repaired first turn survives restart.

Is this the best way to solve the issue?

Yes: conditional creation belongs in the SQLite identity owner immediately before the first real write; seeding during open would mutate no-op readers, while putting it in the generic transcript writer would blur ownership.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes after-fix output from an isolated real gateway restart with an authenticated WebSocket client and a recorded persisted-history result.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦞 diamond lobster, 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: A fresh persisted agent session can fail before the model runs because its first transcript header cannot be stored.
  • merge-risk: 🚨 session-state: The patch changes the write that establishes persisted session identity before transcript data is appended.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body includes after-fix output from an isolated real gateway restart with an authenticated WebSocket client and a recorded persisted-history result.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix output from an isolated real gateway restart with an authenticated WebSocket client and a recorded persisted-history result.

Evidence

What I checked:

Likely related people:

  • Cuttingwater: Introduced the current session-manager split and identity-gated SQLite transcript path later repaired by this PR. (role: feature introducer and recent area contributor; confidence: high; commits: f0a74970ecd8; files: src/agents/sessions/session-manager-core.ts, src/agents/sessions/session-manager-persistence.ts, src/config/sessions/session-accessor.sqlite-transcript-write.ts)
  • Chris Davidson: Recorded as a co-author signal on the area-introducing session persistence change. (role: adjacent contributor; confidence: low; commits: f0a74970ecd8; files: src/agents/sessions/session-manager-persistence.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 (1 earlier review cycle)
  • reviewed 2026-08-05T05:47:17.973Z sha b8cc6bbca630d4b40aca380394417ab3d51e3136 :: needs changes before merge. :: [P1] Create the missing session identity atomically | [P1] Pass a mutable key list to captureEnv | [P2] Cover setup with E2E cleanup

@jjjhenriksen
jjjhenriksen force-pushed the agent/fix-fresh-session-transcript-persistence branch from 31ff09a to d7f4978 Compare August 5, 2026 15:46
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 5, 2026
@Patrick-Erichsen Patrick-Erichsen self-assigned this Aug 5, 2026
@Patrick-Erichsen
Patrick-Erichsen merged commit 5ec4d9f into openclaw:main Aug 5, 2026
139 checks passed
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Merged via squash.

@jjjhenriksen
jjjhenriksen deleted the agent/fix-fresh-session-transcript-persistence branch August 5, 2026 23:14
vincentkoc added a commit to VACInc/openclaw that referenced this pull request Aug 5, 2026
…cope

* origin/main:
  perf(agents): isolate concurrency benchmark workers (openclaw#119749)
  fix(diagnostics): preserve OTEL startup failure (openclaw#119747)
  fix(agents): seed fresh session identity before transcript append (openclaw#119473)
  fix: steering reaches active runs across agent harnesses (openclaw#119594)
  fix(cli): report accurate filtered node totals (openclaw#119744)
  fix(skills): keep installed verdicts scoped to publisher (openclaw#119672)
  fix(diagnostics): honor signal-specific OTLP protocols (openclaw#119708)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 6, 2026
…enclaw#119473)

* fix(agents): seed fresh session identity before transcript append

* test(agents): prove fresh session persistence through gateway

* fix(agents): seed session identity on first transcript write

* fix(agents): atomically seed fresh session identity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M 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