Skip to content

fix(sessions): identify refused transcript appends safely - #130997

Merged
obviyus merged 1 commit into
openclaw:mainfrom
qingminglong:fix/issue-130916-transcript-identity
Aug 29, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
qingminglong:fix/issue-130916-transcript-identity

Conversation

@qingminglong

@qingminglong qingminglong commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #130916

What Problem This Solves

Refused synchronous transcript appends had two unsafe outcomes. Event appends exposed raw session identities through their structured cause. Message appends returned undefined, which lost the refusal type and made a session rebound look like a generic storage failure.

Why This Change Was Made

The SQLite transcript-write owner now uses one commit-edge ownership check for event and message appends. Both paths return the existing Result shape with a session-rebound or session-entry-missing refusal. The refusal contains stable hashes for the agent, session key, expected session, and actual session instead of raw identifiers.

SessionManager preserves that safe refusal as the error cause. It no longer infers a refusal after the owner has dropped the reason.

This also removes two old type assertions from the shared owner path. Identity hashing runs only after a refusal, so successful append cost is unchanged.

User Impact

Operators can identify and correlate a refused event or message append without exposing channel peers, session identifiers, newlines, or terminal control characters. This also holds when a stale owned-writer claim rejects the append. Compaction keeps classifying the outcome as transcript_persistence_failed.

Evidence

Live red and green proof

  • Exact current-main revision tested before the repair: 69913572f4a84a79de1004a3a91fa87ced9cb95d.
  • Main result: event refusal exposed raw identities; message refusal had no cause. The real rebound row stayed authoritative and the transcript stayed unchanged.
  • First repaired head: e00284e318f1987b5d79e0134a80a9caa149ed88.
  • Correction red: its stale-writer path preserved SessionTranscriptWriterClaimReboundError but exposed the raw session key and lost the safe cause.
  • First corrected head: c9af0b263c9367f3a64d1777183e567f2c5c6f4b.
  • Consumer correction: exact-head CI found one reentrant test that still consumed the old direct message result. The test now unwraps the ok arm and checks the returned stored message.
  • Exact final head: 99282da3d2a60de485f3111f1583135082deb296.
  • Final result: normal and stale-writer event and message refusals returned session-rebound, contained the expected stable hashes, exposed no raw identities or control characters, preserved the named writer-claim error and rebound row, wrote no transcript event, and the reentrant direct-append consumer passed.

Tests and checks

node scripts/run-vitest.mjs run src/config/sessions/session-accessor.test.ts src/agents/sessions/session-manager.test.ts src/agents/embedded-agent-runner/compact-reasons.test.ts src/gateway/server-methods/chat.inject.parentid.test.ts src/agents/embedded-agent-runner/google-prompt-cache.test.ts src/agents/sessions/agent-session-code-mode-source.test.ts
Result: PASS — 6 files, 213 tests

node scripts/run-oxlint.mjs <8 changed TypeScript files>
Result: PASS

Focused format, conflict-marker, max-lines, assertion-safety, coercion-helper, deprecated-API, import-cycle, database-first, native-schema, and git diff checks
Result: PASS

Hosted CI owns the full type-check and build. No local type-check or full build ran on this host.

Change size

  • Production: +15 net lines.
  • Tests and test support: +74 net lines.
  • Safety ratchet: two obsolete assertions removed from the baseline.

The production growth is the internal message Result cutover, two caller unwraps, and the typed cause accepted by the existing writer-claim error. The shared owner predicate replaces the duplicated event and message validation branches.

Codex sibling contract

Direct source inspection at OpenAI Codex 6478a751fde8884b2fdc76486fe23175a8e795d4 confirms that native Codex rollout persistence is separate. Its recorder queues canonical items and retains failed writes for retry in codex-rs/rollout/src/recorder.rs, while the core session calls that native owner in codex-rs/core/src/session/mod.rs. This PR changes only OpenClaw SQLite transcript refusal outcomes.

@clawsweeper

clawsweeper Bot commented Aug 27, 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 agents Agent runtime and tooling size: S labels Aug 27, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 29, 2026, 4:53 AM ET / 08:53 UTC.

ClawSweeper review

What this changes

The PR makes refused synchronous SQLite transcript appends return redacted typed outcomes and carries those outcomes into session-manager errors.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

The prior Result-envelope finding is fixed, and the PR remains necessary because current main still returns raw identities for event refusals and drops message-refusal detail. The introduced shared commit-edge check redacts both refusal forms and preserves the cause through session-manager errors.

Priority: P2
Reviewed head: 99282da3d2a60de485f3111f1583135082deb296

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, owner-boundary repair with relevant regression coverage and supplied after-fix behavior evidence.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed production owner is the synchronous SQLite transcript writer; the PR body supplies an after-fix terminal trace for missing, rebound, and stale-writer refusals, with focused tests confirming redacted causes and unchanged transcript rows.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production owner is the synchronous SQLite transcript writer; the PR body supplies an after-fix terminal trace for missing, rebound, and stale-writer refusals, with focused tests confirming redacted causes and unchanged transcript rows.
Evidence reviewed 6 items Current-main behavior: The current-main owner still returns raw expected session, session key, and actual session identifiers for event refusals, while synchronous message refusal returns undefined.
Introduced owner-boundary repair: Both synchronous append paths now call one predicate that emits only stable redacted identifiers, and writer-claim failures retain that refusal as their cause.
Caller propagation and regression coverage: The session manager preserves a message refusal as Error.cause; focused tests cover missing/rebound message outcomes and ensure formatted errors exclude sensitive session text and control characters.
Findings None None.
Security None None.

How this fits together

SQLite transcript writes persist agent-session events and messages. Session managers and gateway callers use those outcomes to preserve transcript state and provide operator diagnostics.

flowchart LR
A[Agent or gateway append] --> B[Session manager]
B --> C[SQLite transcript writer]
C --> D{Session row and writer claim match?}
D -->|yes| E[Persist transcript entry]
D -->|no| F[Redacted refusal]
F --> G[Operator-visible error]
Loading

Before merge

  • Complete next step (P2) - No repair job is needed: the previously identified test consumer has been corrected, leaving normal exact-head CI and maintainer merge review.
Agent review details

Security

None.

PR surface

Source +15, Tests +74, Other 0. Total +89 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 7 75 60 +15
Tests 5 113 39 +74
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 13 189 100 +89

Review metrics

Metric Value Why it matters
Production versus test delta production +15, tests/test support +74, assertion baseline -2 The small production increase carries typed refusal causes through existing owner and caller boundaries while replacing duplicated validation logic.

Stored data model

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

Technical review

Best possible solution:

Land the unified typed-refusal owner change once the exact-head required checks and normal maintainer review complete.

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

Yes, by source: current main’s synchronous event path returns raw identity fields and its message path returns undefined on the same refusal predicate; the linked focused tests exercise missing and rebound rows.

Is this the best way to solve the issue?

Yes. A single commit-edge predicate is the narrowest maintainable owner-boundary repair because it keeps event and message refusal classification and redaction identical.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • 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. Sufficient (terminal): The changed production owner is the synchronous SQLite transcript writer; the PR body supplies an after-fix terminal trace for missing, rebound, and stale-writer refusals, with focused tests confirming redacted causes and unchanged transcript rows.
  • 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:

  • P2: This repairs session-persistence diagnostics and refusal handling without evidence of immediate data loss or availability impact.
  • 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. Sufficient (terminal): The changed production owner is the synchronous SQLite transcript writer; the PR body supplies an after-fix terminal trace for missing, rebound, and stale-writer refusals, with focused tests confirming redacted causes and unchanged transcript rows.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production owner is the synchronous SQLite transcript writer; the PR body supplies an after-fix terminal trace for missing, rebound, and stale-writer refusals, with focused tests confirming redacted causes and unchanged transcript rows.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: The fetched main tip is a session-focused change by Peter Steinberger; unavailable promisor history prevents a stronger ownership attribution for the older transcript-write implementation. (role: recent adjacent session contributor; confidence: low; commits: 1e42dbc945f2; files: src/config/sessions/session-accessor.sqlite-transcript-write.ts, 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 (6 earlier review cycles)
  • reviewed 2026-08-27T15:45:01.422Z sha d49b3614c7227f2247615527d0718c968b4ac871 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-27T18:51:41.662Z sha d49b3614c7227f2247615527d0718c968b4ac871 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-28T05:10:27.378Z sha 3e504d83afc51fcb096a375aaa0863aa89b27f3b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-28T05:35:41.205Z sha 3e504d83afc51fcb096a375aaa0863aa89b27f3b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-29T07:57:12.078Z sha e00284e318f1987b5d79e0134a80a9caa149ed88 :: needs changes before merge. :: [P2] Update the reentrant append assertion for the Result envelope
  • reviewed 2026-08-29T08:12:11.946Z sha c9af0b263c9367f3a64d1777183e567f2c5c6f4b :: needs changes before merge. :: [P2] Assert the reentrant append Result envelope

@openclaw-barnacle openclaw-barnacle Bot reopened this Aug 27, 2026
@qingminglong
qingminglong force-pushed the fix/issue-130916-transcript-identity branch from d49b361 to 3e504d8 Compare August 28, 2026 05:03
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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: 🦪 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 28, 2026
@obviyus
obviyus force-pushed the fix/issue-130916-transcript-identity branch from 3e504d8 to e00284e Compare August 29, 2026 07:39
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: M and removed size: S labels Aug 29, 2026
@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: 🦞 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. labels Aug 29, 2026
@obviyus
obviyus force-pushed the fix/issue-130916-transcript-identity branch from e00284e to c9af0b2 Compare August 29, 2026 08:03
@obviyus
obviyus force-pushed the fix/issue-130916-transcript-identity branch from c9af0b2 to 99282da Compare August 29, 2026 08:45
@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. labels Aug 29, 2026
@clawsweeper clawsweeper Bot removed the status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. label Aug 29, 2026
@obviyus

obviyus commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

Thanks @qingminglong!

Proof: At 99282da3d2a60de485f3111f1583135082deb296, I rebound the authoritative session row and retried event, message, and stale-writer appends. Every refusal returned session-rebound with stable hashes, exposed no raw identity or control characters, preserved the named writer-claim error, and wrote no transcript event. All 213 focused tests passed, and exact-head CI run 33243900574 passed.

  • Bug: Event refusals could expose raw session identities, while message refusals could lose the refusal type and look like generic storage failures.
  • Fix: The SQLite transcript owner now returns one hash-only typed refusal for event, message, and stale-writer paths.

Example

Before After
Message refusal had no cause; stale-writer errors included the raw session key. Every refusal keeps its type and uses stable identity hashes only.

@obviyus
obviyus merged commit d35dc5b into openclaw:main Aug 29, 2026
267 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 30, 2026
Refused SQLite transcript appends now return one stable hash-only typed outcome across event, message, and stale-writer paths. This keeps compaction diagnostics identifiable without exposing session identities or losing refusal classification.

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

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 P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

Transcript append refusal names the event id but never the session identity, so a misrouted sessionKey is indistinguishable from a store failure

2 participants