Skip to content

fix(agents): preserve prompt-released session metadata - #93194

Merged
steipete merged 22 commits into
openclaw:mainfrom
snowzlm:fix/session-takeover-concurrent-writes
Jun 16, 2026
Merged

steipete merged 22 commits into
openclaw:mainfrom
snowzlm:fix/session-takeover-concurrent-writes

Conversation

@snowzlm

@snowzlm snowzlm commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #93193.

Embedded attempts now preserve safe session rows appended while the prompt lock is released without treating them as a takeover or allowing a stale SessionManager rewrite to discard them.

  • Preserve delivery mirrors and global metadata as side appends without changing active model context.
  • Keep transcript navigation, checkpoints, forks, exports, and Codex history on the same leaf-controlled branch.
  • Track same-process nested publications until their physical writes drain.
  • Surface takeover after an otherwise successful outer write, while preserving an existing outer error.
  • Repair malformed legacy leaf state through openclaw doctor --fix.

Why this shape

Allowing more JSONL entry types at the fence is insufficient because an already-open manager can later rewrite accepted rows away. Reloading the whole manager is unsafe because it can drop prepared or not-yet-flushed active state. The final implementation keeps one canonical transcript graph, records side appends explicitly, centralizes leaf-controlled context selection, and carries owned-write facts through the lock scope instead of rediscovering them.

Verification

Final head: fe9695d717045ca156a45043793b9e097d2b65f7

  • Fresh Codex autoreview: no accepted/actionable findings, confidence 0.95.
  • Focused local matrix: 179 tests passed.
  • Final lock regression suite: 102 tests passed.
  • git diff --check: passed.
  • Public plugin SDK surface: no new branch-only export.

Exact-head AWS Crabbox run run_0496c4c08e6c:

  • AWS c7a.16xlarge, Linux, Node 24.16.0, pnpm 11.2.2.
  • Full production build passed.
  • Seven real session/lock/doctor scenarios passed.
  • 24-file matrix passed: 1,181 tests across eight Vitest shards, including the full context-engine integration that failed on the previous pushed head.
  • pnpm check:test-types reached the existing origin/main failure only:
    extensions/codex/src/app-server/bounded-turn.ts:223-224.

Run: https://crabbox.openclaw.ai/portal/runs/run_0496c4c08e6c

The final Crabbox checkout is rebased onto current origin/main at b5648b1d5ee0f21823ad5873f717a6532000b09a. Its type gate asserts that these are the only two type errors and fails on any additional error; this PR does not touch bounded-turn.ts.

Direct Codex contract inspection:

  • ../codex/codex-rs/app-server-protocol/src/protocol/v2/thread.rs:329-349
  • ../codex/codex-rs/core/src/session/session.rs:1068-1089
  • ../codex/codex-rs/app-server/src/request_processors/thread_lifecycle.rs:540-567
  • ../codex/codex-rs/app-server/src/request_processors/turn_processor.rs:736
  • ../codex/codex-rs/app-server-protocol/src/protocol/v2/thread.rs:1240-1243

These paths confirm that thread resume/fork/history use the selected persisted rollout path and that turn start consumes the resumed thread state; OpenClaw therefore must project the canonical active transcript branch consistently before handing history to Codex.

Real behavior proof

Behavior addressed: Prompt-time delivery mirrors, global metadata, side appends, and nested owned writes survive stale-manager operations without entering active model context or silently masking takeover.

Real environment tested: Linux AWS Crabbox using real session files, acquireSessionWriteLock, owned transcript publication, SessionManager, transcript navigation/checkpoints, Codex history projection, and the built openclaw doctor --fix CLI.

Exact steps or command run after this patch: pnpm crabbox:run -- --provider aws --class fast --market on-demand --idle-timeout 90m --ttl 240m --timing-json --preflight --script /tmp/pr-93194-crabbox-e2e.ts

Evidence after fix: Crabbox run run_0496c4c08e6c completed the production build, seven real scenarios, and 1,181 tests. The scenarios covered prompt-release delivery/global metadata, terminal side append after reopen, multi-controller publication, navigation/checkpoint/fork/Codex projection, malformed leaf controls, doctor repair, drained nested takeover propagation, and primary-error preservation.

Copied live terminal output:

OpenClaw PR #93194 synced source hashes match local head fe9695d717
Node v24.16.0
[build-all] phase timings: total 158.9s
CRABBOX_PHASE:real-session-e2e
PR #93194 real session E2E passed
[test] passed 8 Vitest shards in 168.06s
Test Files  31 passed (31)
Tests  1181 passed (1181)
Known origin/main bounded-turn typecheck baseline confirmed; no extra type errors
PR #93194 Crabbox validation passed

Observed result after fix: Active context retained the intended user/assistant branch; side deliveries and metadata persisted across reopen/rewrite; navigation and Codex history selected the same canonical branch; doctor removed invalid hidden runtime state; drained takeover rejected outer success; an existing outer failure retained precedence.

What was not tested: A live external channel/provider delivery using production credentials was not exercised. The real on-disk session, lock, publication, navigation, Codex projection, and doctor paths used by that delivery were exercised directly.

Release-note context

Fix embedded agent sessions losing or exposing concurrent prompt-time transcript updates when stale managers, transcript rewrites, or nested owned writes overlap. Thanks @snowzlm for the report and original fix.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 15, 2026
@clawsweeper

clawsweeper Bot commented Jun 15, 2026 •

Copy link
Copy Markdown
Contributor

ClawSweeper review: did not complete due to Codex infrastructure failure. Reviewed June 16, 2026, 2:06 AM ET / 06:06 UTC.

Summary
Review failed before ClawSweeper could summarize the requested change.

PR surface: Source +236, Tests +692. Total +928 across 4 files.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Review metrics: none identified.

Stored data model
Persistent data-model change detected: serialized state: src/agents/embedded-agent-runner/run/attempt.session-lock.test.ts, serialized state: src/agents/sessions/session-manager.ts, unknown-data-model-change: src/agents/sessions/session-manager.ts, vector/embedding metadata: src/agents/embedded-agent-runner/run/attempt.session-lock.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge readiness
Not assessed.
Failure reason: invalid structured output.

This is a ClawSweeper/Codex infrastructure failure, not a PR readiness or patch-quality verdict.
Keep any merge decision on the normal maintainer review path until ClawSweeper can complete a fresh review.

Risk before merge

  • [P1] No close action taken because the review did not complete.

Maintainer options:

  1. Decide the mitigation before merge
    Retry the Codex review after fixing the execution failure.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Next step before merge

  • Review did not complete, so no work-lane recommendation was made.
Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

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

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

AGENTS.md: unclear because the file could not be read completely.

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

Label changes

Label changes:

  • remove P2: Current review triage priority is none.
  • remove rating: 🐚 platinum hermit: Current review failed before PR readiness was assessed, so no rating label should remain.
  • remove merge-risk: 🚨 session-state: Current PR review selected no merge-risk labels.
  • remove status: 👀 ready for maintainer look: Current PR status no longer selects a status label.
Evidence reviewed

PR surface:

Source +236, Tests +692. Total +928 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 3 301 65 +236
Tests 1 693 1 +692
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 994 66 +928

What I checked:

  • failure reason: invalid structured output.
  • codex failure detail: Codex review failed for this PR with exit 0 and wrote invalid JSON or schema-invalid output to /home/runner/work/clawsweeper/clawsweeper/artifacts/event/codex/93194.json: decision.rootCauseCluster.currentItemRelationship fixed_by_candidate requires a canonical PR.
  • codex stderr: No stderr captured.
  • codex stdout: eaving proof for the accepted set.","category":"fix_before_merge","recommended":false,"automergeInstruction":""},{"title":"Pause For Session-State Redesign","body":"If prompt-released metadata should be owned by a broader session-state model, pause this PR and route the linked issue to that canonical design work.","category":"pause_or_close","recommended":false,"automergeInstruction":""}],"reviewMetrics":[{"label":"Prompt-Released Entry Boundary","value":"4 accepted categories, 7 rejected prompt-affecting categories","reason":"The diff deliberately changes which concurrent JSONL rows are benign, so maintainers should notice the accepted metadata set and rejected prompt-affecting set before merge."}],"labelJustifications":[{"label":"P2","reason":"This is a focused embedded-agent session-lock bug fix with clear session-state and reply-abort impact but limited blast radius."},{.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)
How this review workflow works
  • 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.

@openclaw-barnacle openclaw-barnacle Bot added proof: supplied External PR includes structured after-fix real behavior proof. and removed triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. labels Jun 15, 2026
@snowzlm
snowzlm force-pushed the fix/session-takeover-concurrent-writes branch from a2ed886 to e616863 Compare June 15, 2026 06:51
@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. P2 Normal backlog priority with limited blast radius. labels Jun 15, 2026
@snowzlm
snowzlm force-pushed the fix/session-takeover-concurrent-writes branch from e616863 to 1710152 Compare June 15, 2026 07:10
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 15, 2026
@snowzlm

snowzlm commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Addressed the review follow-up by extending the regression case to cover the remaining accepted control-entry branches (label and session_info) and updated the PR body with refreshed real-behavior proof for all five allowed metadata entry types. @clawsweeper re-review

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 15, 2026
@snowzlm

snowzlm commented Jun 15, 2026

Copy link
Copy Markdown
Contributor Author

Added a PR-body compatibility note clarifying that this does not introduce or migrate session JSONL types, and that prompt-content entries (message, custom_message, compaction, branch_summary, leaf, malformed, and unknown types) remain rejected while the prompt lock is released. @clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 15, 2026
@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. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 15, 2026
@snowzlm snowzlm changed the title fix(agents): allow prompt-released session control entries fix(agents): allow prompt-released session control metadata entries Jun 15, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 15, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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 Jun 15, 2026
@snowzlm
snowzlm force-pushed the fix/session-takeover-concurrent-writes branch from 1710152 to 7507d95 Compare June 15, 2026 07:54
@steipete

Copy link
Copy Markdown
Contributor

Land-ready verification for fe9695d717045ca156a45043793b9e097d2b65f7.

Branch-specific proof:

The six remaining failed checks exactly match main push run 27603384920: prod/test types, extension package boundary, additional boundaries A, core-fast SDK budget, and core security session-snapshot tests. This PR does not touch the hosted-search, SDK budget, or skills snapshot surfaces behind those failures.

Direct Codex contract checked:

  • ../codex/codex-rs/app-server-protocol/src/protocol/v2/thread.rs:329-349
  • ../codex/codex-rs/core/src/session/session.rs:1068-1089
  • ../codex/codex-rs/app-server/src/request_processors/thread_lifecycle.rs:540-567
  • ../codex/codex-rs/app-server/src/request_processors/turn_processor.rs:736
  • ../codex/codex-rs/app-server-protocol/src/protocol/v2/thread.rs:1240-1243

Known proof gap: no production-credential external channel delivery was run. The real filesystem, lock, publication, navigation, Codex projection, and doctor paths were exercised directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui commands Command implementations extensions: codex gateway Gateway runtime merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: supplied External PR includes structured after-fix real behavior proof. size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(agents): prompt-released session control metadata can trigger EmbeddedAttemptSessionTakeoverError

2 participants