Skip to content

fix(codex): keep local threads across Codex and OpenClaw version upgrades - #206089

Open
NaturalMatchaKing wants to merge 1 commit into
openclaw:mainfrom
NaturalMatchaKing:fix/codex-local-thread-version-custody
Open

NaturalMatchaKing wants to merge 1 commit into
openclaw:mainfrom
NaturalMatchaKing:fix/codex-local-thread-version-custody

Conversation

@NaturalMatchaKing

@NaturalMatchaKing NaturalMatchaKing commented Nov 26, 2026 •

Copy link
Copy Markdown

Related: #200018

What Problem This Solves

After a routine local Codex CLI or OpenClaw update (for example from 0.172.0 to 0.172.1), OpenClaw replaces active local Codex threads on the next user turn even when the local CODEX_HOME directory, rollout files, endpoint, auth identity, and plugin policy did not change. Users lose native thread continuity, drop pending native subagent recovery metadata, and pay a cold prompt-cache rebuild across active sessions after every patch release.

Three persisted local custody behaviors caused this loss:

  1. buildCodexAppServerRuntimeFingerprint hashed transient appServerVersion, serverVersion, and userAgent strings into local-loopback thread bindings.
  2. buildCodexPluginThreadConfigInputFingerprint hashed the full versioned pluginAppCacheKey (containing openClawVersion, codexPluginVersion, appServerVersion, serverVersion, and userAgent) into pluginAppsInputFingerprint.
  3. When a legacy local binding resumed and wrote the updated version-free appServerRuntimeFingerprint, preserveNativePendingAssignments and preserveCodexNativeSubagentSubmissions hashed the raw runtime fingerprint string, saw a connection mismatch, and dropped both pending nativeSubagentAssignments and unmatched nativeSubagentSubmissions from the committed binding row.

User Impact

Local Codex sessions (connectionClass: "local-loopback") resume their existing native thread across Codex CLI and OpenClaw version upgrades, including sessions whose bindings were persisted by an earlier release before this fix. Pending native subagent assignments and unmatched submission receipts survive the first legacy upgrade resume and migrate their connection ownership hash atomically in place.

Supervised connection fingerprints introduced by #104045 (buildCodexAppServerConnectionFingerprint, containing top-level codexHome, homeScope, and cwd without runtimeIdentity) stay strictly exact and are never normalized by normalizeCodexAppServerLocalRuntimeFingerprint. Remote Codex connections still require exact runtime and app-cache fingerprint matches, in-memory app-inventory caches stay versioned across upgrades, and local sessions still rotate threads and clear stale recovery metadata cleanly whenever codexHome, endpoint, authProfileId, account, desktop generation, supervision scope, or plugin policy changes. No configuration changes or manual migrations are required.

Why This Change Was Made

Local loopback restarts after an in-place Codex or OpenClaw upgrade keep the same CODEX_HOME and native rollout store on disk. Separating local runtime fingerprints from transient patch-version strings, keeping supervised connection fingerprints exact, and migrating compatible local recovery ownership atomically inside the binding store preserves active threads and in-flight subagent recovery across routine upgrades without loosening any custody boundary.

Evidence

Red-on-base regression verification (0632420a317)

  • Local 0.172.0 to 0.172.1 thread custody check on baseline 0632420a317 fails as expected: startOrResumeThread rotated to a new thread (lifecycle.action: "started") instead of resuming thread-existing-local.
  • Cold SQLite pending recovery retention test (native-subagent-submission-store.test.ts, upgrading a legacy 0.172.0 local binding to 0.172.1) fails on baseline 0632420a317 with AssertionError: expected [] to deeply equal [ ... ] because patching appServerRuntimeFingerprint dropped both nativeSubagentAssignments and nativeSubagentSubmissions.
  • Both regressions pass cleanly on candidate cdd316973ce.

Automated test, typecheck, lint, and ratchet checks (cdd316973ce)

  • All 9 focused Vitest files pass with --maxWorkers=1 across 2 shards (9 files, 318 tests passed on cdd316973ce: 5 files / 102 tests in extension-codex and 4 files / 216 tests in extension-database-workers):
    • extensions/codex/src/app-server/plugin-app-cache-key.test.ts
    • extensions/codex/src/app-server/thread-binding-policy.test.ts
    • extensions/codex/src/app-server/thread-lifecycle.version-bump.test.ts
    • extensions/codex/src/app-server/session-binding.test.ts
    • extensions/codex/src/app-server/native-subagent-inventory.test.ts
    • extensions/codex/src/app-server/native-subagent-submission-store.test.ts
    • extensions/codex/src/app-server/thread-lifecycle.binding.test.ts
    • extensions/codex/src/app-server/native-tool-catalog.test.ts
    • extensions/codex/src/app-server/plugin-thread-config.test.ts
  • Typechecks pass with zero errors: pnpm tsgo:core, pnpm tsgo:extensions, pnpm tsgo:extensions:test.
  • Scoped lint, formatting, ratchets, and merge verification pass with zero issues across all 17 touched files:
    • node scripts/run-oxlint.mjs --tsconfig extensions/tsconfig.json (0 problems in 17 files)
    • oxfmt --check (all 17 files formatted cleanly)
    • node scripts/check-line-cap-ratchet.mjs --base 0632420a317 (0 new violations or over-cap growth)
    • git diff --check 0632420a317..cdd316973ce (clean, empty .github/ diff)
    • git merge-tree --write-tree --merge-base=0632420a317 origin/main HEAD (clean 0-conflict merge against origin/main 8e2c8f5b57a)
  • Full runtime build (pnpm build:runtime) passes on both baseline (0632420a317) and candidate (cdd316973ce).

Isolated CLI and native Codex proof

Verified offline on exact head cdd316973ce versus baseline 0632420a317 with both built runtimes (openclaw.mjs agent --local) driving the real native codex binary (0.172.0) through a transparent JSON-RPC stdio wrapper and a loopback-only synthetic 127.0.0.1 Responses server, using isolated temporary OPENCLAW_HOME, OPENCLAW_STATE_DIR, and CODEX_HOME directories with zero real credentials and blocked non-loopback proxies. The wrapper logged every initialize, thread/start, and thread/resume call verbatim and rewrote only the initialize response version string (0.172.0 -> 0.172.1 -> 0.172.2) to simulate local CLI upgrades against the same rollout store.

After Baseline Turn 1 persisted its legacy 0632420a317 SQLite binding row, schema-valid pending nativeSubagentAssignments (1 entry) and unmatched nativeSubagentSubmissions (1 receipt) keyed to the legacy connection fingerprint were seeded directly into openclaw.sqlite (plugin_state_entries), and the state and rollout store were snapshotted and restored in place before Candidate Case A to verify real cold SQLite migration.

Scenario Built Runtime Codex Version CODEX_HOME Observed Native RPC Observed Thread Cold SQLite Recovery Metadata Outcome
Baseline Turn 1 Baseline (0632420a317) 0.172.0 CODEX_HOME_A thread/start (1 start, 0 resume) thread-1 Seeded 1 assignment + 1 submission (legacy hash) Initial thread created and legacy binding persisted
Baseline Turn 2 (control) Baseline (0632420a317) 0.172.1 CODEX_HOME_A thread/start (1 start, 0 resume) thread-2 0 assignments, 0 submissions (dropped) Rotated to fresh thread and dropped recovery metadata
Candidate Case A (legacy migration) Candidate (cdd316973ce) 0.172.1 CODEX_HOME_A thread/resume (0 start, 1 resume) thread-1 1 assignment + 1 submission (migrated hash verified) Resumed legacy thread and migrated binding + recovery ownership
Candidate Case B (consecutive upgrade) Candidate (cdd316973ce) 0.172.2 CODEX_HOME_A thread/resume (0 start, 1 resume) thread-1 1 assignment + 1 submission (migrated hash verified) Resumed same thread and retained recovery metadata
Candidate Case C (negative control) Candidate (cdd316973ce) 0.172.2 CODEX_HOME_B thread/start (1 start, 0 resume) thread-3 0 assignments, 0 submissions (dropped) Rotated thread and cleanly dropped stale recovery metadata

Scope note: this offline loopback proof verifies real built-OpenClaw thread custody continuity, legacy binding and subagent recovery ownership migration, and CODEX_HOME rotation boundaries against the native Codex binary and SQLite store. It does not claim or measure live upstream provider prompt-cache hit rates or billing.

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 26, 2026
@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

Preserves local Codex threads and pending recovery metadata across version-only upgrades while retaining stricter connection-change checks.

Example: Codex changes from 0.172.0 to 0.172.1 with the same CODEX_HOME and connection.

  • Before: The supplied baseline observations show thread-1 replaced by thread-2 and both recovery inventories emptied.
  • After: The supplied candidate observations show thread-1 resumed with one assignment and one submission receipt retained.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation repairs the earlier defects and has useful boundary coverage, but required upgrade evidence and transition direction remain unresolved.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: Routine local updates replace native conversations and remove pending recovery metadata despite an unchanged rollout store.
Reason: Continuity has clear user value, but an area owner must approve treating local version-only changes as compatible; the broader accounting question in the linked issue remains outside this PR.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep open: current main retains the reported version-triggered rotation path, and this PR contains meaningful unique work. The revised implementation resolves both earlier findings; no additional definite code bug was established.

Reviewed head: cdd316973ce87f4b13643c2d330aed1912767e3d
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should local version-only changes preserve native thread custody and migrate pending recovery ownership as this PR proposes?
  • Recommendation: Approve local version-only continuity: Treat unchanged local home, endpoint, and durable identity as the same connection while retaining exact remote and supervision boundaries.
  • Why: The existing connection guard deliberately requires exact identity, and the linked report leaves preservation versus explicit non-delivery unresolved without a recorded human owner decision.

Before merge

  • Add real behavior proof - The reviewed-head CLI observations exercise real native Codex and SQLite with simulated version changes and show resumed custody plus migrated recovery hashes, but synthetic model responses and a development-base transition do not satisfy the repository's real-model and latest-stable upgrade requirements for plugin_state_entries binding and recovery-owner fields. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Provide redacted terminal output or logs from an isolated Gateway with a real agent/model and a v2026.11.10-to-head upgrade showing the existing thread, settings, assignments, and submission receipts survive; redact credentials, IPs, phone numbers, and non-public endpoints.
Agent review details

How this fits together

The Codex plugin converts initialized connection facts and plugin policy into persisted thread bindings, then uses those bindings to resume native conversations and recover pending subagent work.

flowchart TD
  A[User turn] --> B[Codex startup facts]
  B --> C[Runtime and policy fingerprints]
  C --> D[Thread lifecycle]
  D --> E[Native Codex thread]
  D --> F[SQLite binding and recovery metadata]
Loading

Technical review

Best possible solution:

Preserve version-only local continuity through the existing fingerprint and binding-write owners once the transition contract and upgrade compatibility are established.

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

Current-main fingerprint construction, lifecycle rotation, and recovery preservation guards establish the reported path, corroborated by the supplied baseline observations; no target code was executed during this review.

Is this the best way to solve the issue?

Separating versioned inventory identity from durable local custody addresses the producer and its consumers coherently, but preservation changes the existing transition contract and covers only the local version-only portion of the linked report.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against a320c352377e.

Provenance checked

  • Runtime fingerprint identity changes intended behavior with a stated reason (bc5081c: Merged feat(codex): support remote app-server plugins #94203 captured initialized runtime identity for remote app-server support and stale remote-binding rotation.)
  • Supervised source connection identity keeps the original intent (f94a7dc: Merged feat(codex): supervise native Codex sessions #104045 bound native supervision to its configured source connection and home.)
  • Pending recovery preservation boundary changes intended behavior with a stated reason (6652f7e: The Tasks removal retained assignments on existing bindings and explicitly preserved them through native rotation only within the same connection; this PR explains its narrower local version-only compatibility exception.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +448, Tests +1412. Total +1860 across 17 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 12 489 41 +448
Tests 5 1414 2 +1412
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 17 1903 43 +1860

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production versus test changes Production +489/−41; tests +1,414/−2 Growth covers legacy fingerprint reconstruction, recovery-owner migration, and distinct lifecycle, supervision, and SQLite persistence boundaries; no test deletion had an established surviving witness.

Labels

Label changes:

No label changes.

Label justifications:

  • merge-risk: 🚨 session-state: The change rewrites persisted binding identity and pending recovery owner hashes; ordinary CI alone cannot establish existing-state upgrade compatibility.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-26T18:33:47.413Z sha 1c61961 :: needs real behavior proof before merge. :: [P1] [P1] Migrate recovery ownership with the legacy runtime fingerprint | [P2] [P2] Keep supervised connection fingerprints exact

Reviewed November 26, 2026, 2:31 PM ET / 19:31 UTC (Revision 2).

…pgrades

Exclude transient Codex app-server version and user-agent fields from
local-loopback runtime fingerprints and local binding plugin-app input
fingerprints so routine local Codex CLI and OpenClaw patch upgrades resume
existing native threads instead of rotating to fresh threads.

Keep supervised connection fingerprints exact (preserving codexHome,
homeScope, and cwd isolation), keep in-memory plugin-app inventory caches
versioned, keep remote runtime matching exact, and migrate pending native
subagent assignments and unmatched submission receipts cleanly when a
legacy local runtime fingerprint upgrades in place while still clearing
recovery metadata on codexHome, authProfileId, endpoint, or remote changes.
@NaturalMatchaKing
NaturalMatchaKing force-pushed the fix/codex-local-thread-version-custody branch from 1c61961 to cdd3169 Compare November 26, 2026 19:22
@NaturalMatchaKing

Copy link
Copy Markdown
Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Nov 26, 2026

This branch has not been deployed

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

Labels

extensions: codex impact:session-state Session, memory, transcript, context, or agent state can drift or corrupt. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant