Skip to content

refactor(sessions): retire runtime transcript sidecars - #117380

Merged
steipete merged 1 commit into
mainfrom
codex/goal100k-session-lock-owner-0801-2d45
Aug 1, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/goal100k-session-lock-owner-0801-2d45

Conversation

@steipete

@steipete steipete commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • make SQLite state leases the sole runtime owner for logical session transcript writes
  • keep the shipped file-artifact lock contract at the public Plugin SDK boundary
  • move retired .jsonl.lock inspection and repair behind doctor only
  • remove the gateway startup sidecar sweep, lock-derived restart markers, and the duplicate session storage lock implementation

Repair

Root cause: core had two ownership systems for one transcript: canonical SQLite state plus JSONL sidecar locks. Startup then rediscovered the sidecars, reclaimed them, and inferred restart recovery state from the cleanup result. This duplicated lifecycle policy and allowed lock files to become an indirect source of session truth.

Architectural owner: src/agents/session-write-lock.ts now owns logical session writes through the existing state-lease table. src/commands/doctor-session-lock-files.ts owns legacy sidecar diagnosis/migration. src/plugin-sdk/session-write-lock-runtime.ts is the compatibility boundary for shipped external file-artifact callers.

Canonical fix: runtime callers use one SQLite lease keyed by the typed transcript target. Gateway startup records orphan recovery directly from authoritative SQLite rows before channels start. Doctor can still inspect and identity-fence old .jsonl.lock removal. The SDK adapter preserves file locking, reentrancy, symlink canonicalization, stale recovery, abort admission, max-hold watchdog, and synchronous signal cleanup.

Removed paths:

  • gateway sidecars.session-locks startup sweep
  • lock-derived main-session restart marking
  • mixed core file-lock implementation and its startup/test APIs
  • duplicate src/agents/sessions/storage-lock.ts
  • two max-lines exemptions

Compatibility and contracts

  • no SQLite schema/version change
  • no config/default/environment/dependency change
  • no new public SDK export; the existing agent-harness-runtime signature remains the public seam
  • legacy .jsonl.lock repair remains available through doctor, and doctor intentionally ignores retired holder maxHoldMs
  • directly inspected @openclaw/fs-safe 0.5.0 file-lock, sync-lock, and sidecar-lock sources for payload factories, reentrancy, snapshot-fenced removal, and exit cleanup
  • directly inspected sibling Codex app-server turn submission at ../codex/codex-rs/app-server/src/request_processors/turn_processor.rs:477-617 and compaction submission at ../codex/codex-rs/app-server/src/request_processors/thread_processor.rs:1868-1878; the lease continues to surround the existing turn/compaction lifecycle rather than changing that protocol

LOC

Handwritten production: 862 added / 1,515 removed = net -653 LOC. Tests and generated manifests are counted separately.

Proof

  • 288 focused tests passed across session leases, Plugin SDK file compatibility, doctor cleanup, gateway startup, restart recovery, process argv classification, settings/auth sync locks, and sandbox migration
  • Plugin SDK adapter: 15/15; doctor: 12/12; session lease core: 13/13; gateway startup: 61/61; restart recovery: 145/145
  • pnpm check:changed passed, including core/extension types, SDK contracts, dead exports, database-first guard, import cycles, and lint
  • pnpm build passed
  • independent xhigh adversarial review: clean, no blocking or substantive public-compatibility findings
  • Blacksmith Testbox: https://github.com/openclaw/openclaw/actions/runs/30697289129

Current-main integration and review disposition

ClawSweeper's two rank-up moves are satisfied as follows:

  1. Rebase onto current main and refresh focused proof. A read-only merge of PR head f92449f6fba63c3ec54d1dda6d187510ee9a8182 with main checkpoint 142ad75c433692d8ffaf80585d6bb66a553c9cd2 was conflict-free and produced exact tree 692009100cbdaac5dedba1c4a0b00c2d39cc2058. That tree preserved both sides of the only overlapping production file (doctor-auth-migration-receipts.ts) and all four expected SDK baseline entries. On the exact combined tree, 297 focused tests, pnpm plugin-sdk:surface:check, and the full pnpm check:changed gate passed: Blacksmith Testbox run (tbx_01kyymm0yq1xhev0xzad6z7wsv). Main subsequently advanced to b5a59e0a7d948a8b9021b97ab5c66248f12303d2, with zero overlap across the 27 paths touched by this PR. No rebase or code-resolution commit is needed: the only relevant moving-main integration was already tested as an exact merge tree, and later drift is disjoint.
  2. Inspect the installed lock dependency and sibling Codex lifecycle. Completed directly. Installed @openclaw/fs-safe 0.5.0 preserves per-attempt payload creation, explicit-owner reentrancy, realpath canonicalization, O_EXCL acquisition, fsync, identity/snapshot-fenced release and stale reclaim, manager drain/reset, and synchronous exit cleanup. Sibling Codex routes both turns and compaction into the same session submission loop: codex-rs/app-server/src/request_processors/turn_processor.rs:339-355,476-619, codex-rs/app-server/src/request_processors/thread_processor.rs:1875-1886, codex-rs/core/src/codex_thread.rs:226-228,274-330,470-474, and codex-rs/core/src/session/mod.rs:766-837. This PR keeps the lease around that existing lifecycle; it does not alter Codex protocol/runtime behavior.

The merged-result proof specifically retained the PR's synchronous lock helper at the migrated doctor receipt call sites plus current main's recordLegacyMigrationRun / recordLegacyMigrationSource behavior. It also retained the expected agent-harness-runtime, channel-status, discord, and status-helpers SDK hashes.

Independent adversarial review additionally exercised separate real Node processes: a holder acquired the lock, a contender returned stable OPENCLAW_SESSION_WRITE_LOCK_TIMEOUT, the holder was killed with SIGKILL, and a fresh writer reacquired and released the UUID lease with zero .jsonl.lock files left behind. Hosted CI independently covers the state lease's spawned-child cross-process path.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime commands Command implementations agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Aug 1, 2026
@steipete
steipete marked this pull request as ready for review August 1, 2026 11:43
@steipete
steipete requested a review from a team as a code owner August 1, 2026 11:43
@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: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 9:02 AM ET / 13:02 UTC.

ClawSweeper review

What this changes

The branch moves runtime transcript-write coordination to SQLite leases, confines retired JSONL sidecar inspection to Doctor, and preserves file-lock behavior through the existing Plugin SDK runtime entrypoint.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

This PR is still necessary: current main retains JSONL sidecar lock ownership and the gateway startup recovery path that the branch removes. The refactor is coherent and its CI/proof context is strong, but it stays open for protected maintainer review because it changes persisted session coordination and a shipped Plugin SDK runtime seam; this review could not directly inspect the required sibling Codex checkout or installed @openclaw/fs-safe source.

Priority: P2
Reviewed head: f92449f6fba63c3ec54d1dda6d187510ee9a8182
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The branch has strong behavior and CI proof, but the uninspectable Codex and fs-safe contract gates prevent a higher-confidence merge assessment in this environment.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body reports an after-fix multi-process contention, SIGKILL recovery, and no-sidecar outcome, with linked Testbox and exact merge-tree validation; the remaining blocker is contract inspection rather than contributor behavior proof.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body reports an after-fix multi-process contention, SIGKILL recovery, and no-sidecar outcome, with linked Testbox and exact merge-tree validation; the remaining blocker is contract inspection rather than contributor behavior proof.
Evidence reviewed 7 items Current main retains the reported duplicate ownership: Current main describes session write locking as file-lock based and imports the file-lock manager. Gateway startup still loads markRestartAbortedMainSessionsFromLocks, confirming the central behavior is not already implemented on main.
Runtime callers already use a typed SQLite target: Current compaction resolves a session target, derives its canonical key, and acquires acquireSessionWriteLock with targetKind: "session-key"; the PR simplifies that coordinator to the state-lease path instead of introducing a parallel runtime mechanism.
Public SDK boundary remains the same export: openclaw/plugin-sdk/agent-harness-runtime is an existing package export and current main re-exports the lock helpers there. The PR reroutes that export to a dedicated SDK runtime adapter rather than adding a new public package entrypoint.
Findings None None.
Security None None.

How this fits together

Agent turns and compaction need an exclusive coordinator before they update a session transcript, while gateway startup marks interrupted main sessions for recovery. The branch makes the SQLite state lease the runtime coordinator, leaving legacy JSONL lock files only for Doctor repair and Plugin SDK file-artifact compatibility.

flowchart LR
  A[Agent turn or compaction] --> B[Session write coordinator]
  B --> C[SQLite state lease]
  C --> D[Transcript database write]
  E[Gateway startup] --> F[SQLite orphan recovery]
  G[Legacy JSONL lock file] --> H[Doctor inspection and repair]
  I[Plugin SDK file caller] --> J[File-lock compatibility adapter]
Loading

Decision needed

Question Recommendation
Should maintainers accept the compatibility-sensitive split in which OpenClaw runtime session writes use SQLite leases while the existing Plugin SDK lock helpers retain file-sidecar semantics through an adapter? Accept the ownership split after contract verification: Confirm direct Codex lifecycle and fs-safe file-lock semantics, then merge if the SDK adapter preserves the shipped file-artifact behavior.

Why: The branch changes both persisted session coordination and a shipped plugin-facing runtime contract. The implementation direction is coherent, but choosing and validating that enduring boundary requires maintainer intent plus the repository-mandated dependency/Codex inspection.

Before merge

  • Resolve merge risk (P2) - The refactor changes the runtime’s cross-process session ownership from JSONL sidecars to persisted SQLite leases, so upgrade, timeout, crash-recovery, and active-process semantics must remain compatible.
  • Resolve merge risk (P1) - The existing Plugin SDK export keeps its name but delegates to a new file-lock adapter; direct @openclaw/fs-safe source inspection is unavailable in this checkout, so semantic parity for third-party file-artifact callers is not independently established.
  • Resolve merge risk (P1) - Repository policy requires direct inspection of sibling Codex sources for the lifecycle claim in this PR, but ../codex is absent and the read-only/network-restricted review environment cannot clone it.
Agent review details

Security

None.

PR surface

Source -691, Tests -1533, Generated 0, Other -2. Total -2226 across 27 files.

View PR surface stats
Area Files Added Removed Net
Source 19 866 1557 -691
Tests 6 507 2040 -1533
Docs 0 0 0 0
Config 0 0 0 0
Generated 1 1 1 0
Other 1 0 2 -2
Total 27 1374 3600 -2226

Review metrics

None.

Stored data model

Persistent data-model change detected: durable storage schema: src/agents/sessions/storage-lock.ts, migration/backfill/repair: src/commands/doctor-auth-migration-receipts.ts, migration/backfill/repair: src/commands/doctor-session-lock-files.ts, migration/backfill/repair: src/commands/doctor-session-locks.test.ts, migration/backfill/repair: src/commands/doctor-session-locks.ts, migration/backfill/repair: src/infra/gateway-process-argv.test.ts, and 21 more. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Verify the two retained contracts before merge (recommended)
    Inspect the installed fs-safe implementation and sibling Codex lifecycle directly, then preserve merge-result proof for existing sidecars, contention, process termination, and restart recovery.
  2. Pause the migration boundary
    Leave the PR open rather than merging if maintainers do not want runtime transcript coordination to move to SQLite leases in this release window.

Technical review

Best possible solution:

Keep one canonical SQLite lease flow for runtime transcript writes, retain the public SDK file-artifact contract only at its explicit compatibility boundary, and obtain the required direct Codex and fs-safe contract checks before maintainer acceptance.

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

Yes for the source-level behavior: current main still acquires JSONL sidecar locks and gateway startup consumes sidecar cleanup for restart marking, while the branch removes those paths. A live upgrade run was not repeated in this read-only review.

Is this the best way to solve the issue?

Unclear pending maintainer acceptance and direct contract inspection. Reusing the existing SQLite lease primitive and isolating legacy artifacts behind Doctor is the cleaner owner boundary, but the SDK and lifecycle compatibility claims need the required source proof.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: The PR is a substantial but non-emergency refactor of session write coordination and restart recovery.
  • merge-risk: 🚨 compatibility: It reroutes an existing exported Plugin SDK runtime helper through a new implementation boundary.
  • merge-risk: 🚨 session-state: It changes the coordination and recovery facts that protect concurrent transcript updates and interrupted main sessions.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body reports an after-fix multi-process contention, SIGKILL recovery, and no-sidecar outcome, with linked Testbox and exact merge-tree validation; the remaining blocker is contract inspection rather than contributor behavior proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body reports an after-fix multi-process contention, SIGKILL recovery, and no-sidecar outcome, with linked Testbox and exact merge-tree validation; the remaining blocker is contract inspection rather than contributor behavior proof.

Evidence

What I checked:

  • Current main retains the reported duplicate ownership: Current main describes session write locking as file-lock based and imports the file-lock manager. Gateway startup still loads markRestartAbortedMainSessionsFromLocks, confirming the central behavior is not already implemented on main. (src/agents/session-write-lock.ts:1, f5989ea1f64c)
  • Runtime callers already use a typed SQLite target: Current compaction resolves a session target, derives its canonical key, and acquires acquireSessionWriteLock with targetKind: "session-key"; the PR simplifies that coordinator to the state-lease path instead of introducing a parallel runtime mechanism. (src/agents/embedded-agent-runner/compaction-session-execution.ts:119, f5989ea1f64c)
  • Public SDK boundary remains the same export: openclaw/plugin-sdk/agent-harness-runtime is an existing package export and current main re-exports the lock helpers there. The PR reroutes that export to a dedicated SDK runtime adapter rather than adding a new public package entrypoint. (src/plugin-sdk/agent-harness-runtime.ts:421, f5989ea1f64c)
  • Proposed runtime lease owner: The branch accepts only session-key targets in the core lock module, opens the resolved agent database, and acquires a bounded state_leases record with process identity; file-artifact locking is moved to the SDK adapter. (src/agents/session-write-lock.ts:277, f92449f6fba6)
  • State-lease behavior is an existing persistence primitive: The existing lease implementation checks process identity before the synchronous write transaction, stores the ownership row in state_leases, and has bounded release retry behavior. The branch reuses that primitive rather than adding a schema or migration. (src/state/openclaw-state-lease.ts:285, f5989ea1f64c)
  • Focused branch coverage exists: The proposed core tests cover SQLite serialization, intentional reentrancy, abort admission, live-owner handling, synchronous cleanup, and alias key normalization. The SDK adapter tests cover file-sidecar compatibility and explicit session-key delegation. (src/agents/session-write-lock.test.ts:56, f92449f6fba6)

Likely related people:

  • steipete: The supplied PR is authored by steipete, and local git shortlog reports substantial prior contribution across the current lock, gateway-startup, and SDK export paths. (role: recent area contributor; confidence: medium; commits: f92449f6fba6; files: src/agents/session-write-lock.ts, src/gateway/server-startup-post-attach.ts, src/plugin-sdk/agent-harness-runtime.ts)
  • zilokki-bot: git blame and latest-path history attribute the current sidecar lock implementation and gateway startup path to commit 0991fad3…. (role: introduced current behavior; confidence: high; commits: 0991fad3a34b; files: src/agents/session-write-lock.ts, src/gateway/server-startup-post-attach.ts)

Rank-up moves

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

  • Provide or repeat direct fs-safe and sibling Codex source checks in a review environment that has those checkouts.
  • Have a maintainer explicitly accept the runtime-versus-SDK ownership boundary before merge.

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-01T12:20:11.172Z sha f92449f :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 9214183 into main Aug 1, 2026
202 of 215 checks passed
@steipete
steipete deleted the codex/goal100k-session-lock-owner-0801-2d45 branch August 1, 2026 13:21
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

agents Agent runtime and tooling commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. 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: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL 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