Skip to content

fix(sessions): keep admitted turns attached during retries - #119307

Merged
vincentkoc merged 1 commit into
mainfrom
fix/session-boundary-recorder-identity-20260804
Aug 4, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
fix/session-boundary-recorder-identity-20260804

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes an issue where an admitted user turn could be detached from the active
session transcript during an internal retry that intentionally omitted the
prepared user-message projection. A later turn could then fail with
Session transcript parent entry was not persisted instead of reaching the
provider.

The failure was observed on the exact main SHA
7a0a4c5f2a3b778deec2eacafbeffc45f24579cf:
https://github.com/openclaw/openclaw/actions/runs/30933537375/job/92074656753

Why This Change Was Made

The session boundary now uses the transcript recorder's persisted message as
the authoritative current-turn identity, with the prepared message retained as
the fallback. Reconciliation still requires an exact non-empty idempotency-key
match, so genuinely stale durable leaves continue through orphan repair.

This does not weaken SQLite idempotency or SessionManager parent validation and
does not change config, protocol, schema, or migration surfaces.

User Impact

Persisted user turns remain attached to the canonical transcript across
internal retries, allowing subsequent turns to continue instead of dead-ending
on a detached parent.

The vulnerable source path is present in v2026.7.2-beta.6 and
v2026.7.2-beta.7; stable v2026.7.1-1 and v2026.7.1-2 do not contain it.

Evidence

  • Added a regression that reproduces the missing prepared-message state while
    the recorder and durable leaf hold the same admitted turn. It triggered
    orphan repair before the fix and now preserves the leaf.
  • Strengthened the mismatch regression so recorder fallback still repairs a
    durable leaf with a different idempotency key.
  • 59 focused tests pass across session-boundary, runtime-prepare,
    SessionManager idempotency, and user-turn transcript coverage.
  • The complete core, coreTests changed-scope gate passes, including tsgo,
    oxlint, dead exports, plugin boundaries, import cycles, SQLite/storage
    guards, and auth guards.
  • git diff --check and targeted oxfmt --check pass.
  • Final branch autoreview is clean with no accepted/actionable findings.
  • The local execution-order E2E could not prepare its gateway because linked
    worktrees may not reconcile node_modules; that repository safety rule was
    not bypassed. Exact-head PR CI, including
    check-sqlite-session-flip-proof, is required before merge.

Provenance: #116924 introduced durable
leaf reconciliation while still depending on the prepared projection;
#117310 carried that assumption
forward. #117260 correctly rejects
detached keyed-row adoption and exposed the upstream ownership error.

AI-assisted: yes. The implementation, history, and proof were reviewed by the
maintainer.

Punchcard-Session: coral-workshop-workshop-3f

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S labels Aug 4, 2026
@vincentkoc vincentkoc self-assigned this Aug 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added the maintainer Maintainer-authored PR label Aug 4, 2026
Punchcard-Session: coral-workshop-workshop-3f
@vincentkoc
vincentkoc force-pushed the fix/session-boundary-recorder-identity-20260804 branch from eb43118 to 84146a5 Compare August 4, 2026 18:34
@vincentkoc
vincentkoc marked this pull request as ready for review August 4, 2026 18:38
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Aug 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 repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper re-review

@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. P1 High-priority user-facing bug, regression, or broken workflow. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 4, 2026, 4:08 PM ET / 20:08 UTC.

ClawSweeper review

What this changes

The PR makes retry-time session reconciliation use the transcript recorder’s persisted user message when prompt preparation intentionally has no user-message projection.

Regression provenance

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

Merge readiness

⚠️ Ready for maintainer review - 2 items remain

Keep open. Current main still routes a recorder-confirmed user turn to orphan repair when retry preparation omits its projection; this patch restores the recorder-owned identity without relaxing exact idempotency matching. No blocking correctness finding was found, but this member-authored, maintainer-labeled PR remains for normal maintainer landing review.

Priority: P1
Reviewed head: 84146a503630d29281a3e42e9792356768f8a66b

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is a focused owner-boundary repair with strong source and CI evidence; no correctness blocker was found.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: This is a member-authored maintainer PR, so the external-contributor real-behavior-proof gate does not apply; the supplied exact-head CI and focused regression are supplemental evidence.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This is a member-authored maintainer PR, so the external-contributor real-behavior-proof gate does not apply; the supplied exact-head CI and focused regression are supplemental evidence.
Evidence reviewed 7 items Current-main defect path: Current main derives reconciliation identity solely from the prepared projection; when that projection is absent, reconciliation cannot recognize an already-admitted durable leaf.
Retry can intentionally omit preparation: Internal prompts set skipPreparedUserTurnMessage, and session preparation therefore leaves the prepared message undefined while retaining the recorder.
Recorder is the persistence owner: The recorder exposes only a runtime-persisted message or the persisted transcript result, and reports persistence only for those states.
Findings None None.
Security None None.

How this fits together

The embedded agent runner prepares an active session before an attempt reaches the provider. It reconciles the admitted user turn, recorder state, and durable transcript leaf so a retry either retains the canonical turn or repairs a genuinely stale leaf.

flowchart LR
A[Admitted user turn] --> B[Transcript recorder]
A --> C[Prompt preparation]
B --> D[Session boundary]
C --> D
E[Durable transcript leaf] --> D
D --> F[Exact idempotency check]
F --> G[Provider attempt]
F --> H[Orphan repair]
Loading

Before merge

  • Resolve merge risk (P1) - Before landing, re-read the latest ClawSweeper comment and resolve any outstanding Rank-up moves; its body was unavailable during this read-only review.
  • Complete next step (P2) - No repair lane is needed: this is a coherent member-authored patch with no actionable finding; normal protected maintainer review should confirm the latest ClawSweeper guidance before landing.
Agent review details

Security

None.

PR surface

Source +3, Tests +58. Total +61 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 8 5 +3
Tests 1 60 2 +58
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 68 7 +61

Review metrics

Metric Value Why it matters
Production versus test delta production +4 net (8 added, 5 removed); tests +58 net (60 added, 2 removed) The small production increase is justified by moving current-turn identity to its recorder-owned persistence boundary; most added code is regression coverage.

Root-cause cluster

Relationship: canonical
Canonical: #119307
Summary: This PR is the canonical proposed repair for the omitted-projection retry case; earlier merged session repairs overlap in invariant but cover restart or durable-tail ordering cases.

Members:

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

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the recorder-backed exact-key reconciliation, retain orphan repair for mismatches, and land after the latest ClawSweeper guidance is confirmed addressed.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the recorder-backed exact-key reconciliation, retain orphan repair for mismatches, and land after the latest ClawSweeper guidance is confirmed addressed.

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

Yes—current source defines the retry path: internal prompt preparation omits the projection while the recorder retains the persisted user leaf, and current main then fails the existing identity check. The review was read-only, so no local execution was performed.

Is this the best way to solve the issue?

Yes—the recorder already owns the authoritative persisted current-turn fact, while the existing exact-key check and mismatch orphan repair remain intact; deriving identity only from the optional prepared projection is the failing alternative.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The retry ordering can dead-end an admitted agent turn before a later prompt reaches its provider.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a member-authored maintainer PR, so the external-contributor real-behavior-proof gate does not apply; the supplied exact-head CI and focused regression are supplemental evidence.

Label justifications:

  • P1: The retry ordering can dead-end an admitted agent turn before a later prompt reaches its provider.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This is a member-authored maintainer PR, so the external-contributor real-behavior-proof gate does not apply; the supplied exact-head CI and focused regression are supplemental evidence.

Evidence

What I checked:

Likely related people:

  • shakkernerd: Merged the earlier repair that established the durable-user reconciliation path in the same boundary and helper. (role: introduced related persisted-turn reconciliation; confidence: high; commits: 8fc43e187ae9; files: src/agents/embedded-agent-runner/run/attempt-session-boundary.ts, src/agents/embedded-agent-runner/run/pre-persisted-user-turn.ts)
  • steipete: Merged restart durable-tail adoption work that shares the exact-key session-state invariant. (role: recent adjacent session-state contributor; confidence: high; commits: ac2c9847c860, 6b43acf0629d; files: src/agents/embedded-agent-runner/run/pre-persisted-user-turn.ts, src/agents/sessions/session-manager-entries.ts)
  • vincentkoc: Authored the proposed repair and current history attributes the extracted boundary surface to their nearby session work. (role: recent session-boundary contributor; confidence: medium; commits: 84146a503630, 9d6d9af94135; files: src/agents/embedded-agent-runner/run/attempt-session-boundary.ts, src/agents/embedded-agent-runner/run/pre-persisted-user-turn.ts)

Rank-up moves

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

  • Before landing, verify the latest ClawSweeper comment has no remaining Rank-up move for this exact head.

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.

@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer review completed on exact head 84146a503630d29281a3e42e9792356768f8a66b.

I read the latest ClawSweeper comment in full and reviewed the current discussion, repo-native review artifacts, prepared head, exact-head CI, and focused regression coverage. No actionable correctness or security finding remains. The Rank-up move is satisfied: there is no code-changing move for this head.

The P1 merge risk is resolved by the patch's owner-boundary invariant: the transcript recorder supplies the authoritative persisted current-turn identity, adoption still requires a non-empty exact idempotency-key match, and mismatches still take orphan repair. The newly landed CLI diagnostics PR does not touch this session boundary.

Both ClawSweeper Before merge items are resolved. No waiver is needed.

@vincentkoc
vincentkoc merged commit 11027a3 into main Aug 4, 2026
260 of 265 checks passed
@vincentkoc
vincentkoc deleted the fix/session-boundary-recorder-identity-20260804 branch August 4, 2026 20:12
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Aug 4, 2026
Punchcard-Session: crisp-lantern-orchard-nv

* origin/main:
  fix(release): accept legacy empty core artifacts (#119337)
  fix(qa): carry selected runtime into flow scenarios (#119324)
  fix(ci): retry interrupted Windows dashboard release checks (#119095)
  fix(release): filter validation ancestry fetch (#119334)
  fix(release): accept trusted extended-stable validation evidence (#119264)
  fix(sessions): preserve recorder-owned user turns (#119307)
  perf(cli): split plugin registry startup timing (#119318)
  fix(qa): align release scenario setup and compaction proof (#119188)
  fix(ci): avoid duplicate Matrix release QA runs (#119171)
vincentkoc added a commit that referenced this pull request Aug 5, 2026
…time

* origin/main: (75 commits)
  fix(commands): restore tool inventory for dynamic models (#119306)
  fix(media): release rejected BytePlus and Runway video downloads under debug capture (#119257)
  docs: add ChromeOS (Crostini) platform install guide (#107663)
  test(msteams): serve JWKS from in-process server in auth coverage (#119354)
  fix(qa): enable OpenAI for stored audio scenario (#119349)
  test(agents): realpath apply-patch temp dir fixture (#119353)
  test(slack): drop redundant .js-suffixed system-event mock (#119352)
  fix(exec): leave safe builtins unrewritten in enforced mode (#119351)
  fix(sessions): keep gateway responsive while large transcript archives are built (#112424)
  fix(tui): restore provider auth in installed local mode (#119283)
  fix(release): accept legacy empty core artifacts (#119337)
  fix(qa): carry selected runtime into flow scenarios (#119324)
  fix(ci): retry interrupted Windows dashboard release checks (#119095)
  fix(release): filter validation ancestry fetch (#119334)
  fix(release): accept trusted extended-stable validation evidence (#119264)
  fix(sessions): preserve recorder-owned user turns (#119307)
  perf(cli): split plugin registry startup timing (#119318)
  fix(qa): align release scenario setup and compaction proof (#119188)
  fix(ci): avoid duplicate Matrix release QA runs (#119171)
  perf(agents): reuse provider policy manifest registry (#119305)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 5, 2026
Punchcard-Session: coral-workshop-workshop-3f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant