Skip to content

improve(codex): safely reuse live app-server threads - #115089

Merged
steipete merged 1 commit into
mainfrom
codex/live-integration-performance-021e1457
Jul 28, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/live-integration-performance-021e1457

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #114907

What Problem This Solves

Fixes an issue where ordinary multi-turn Codex conversations unsubscribe and resume an already-loaded app-server thread after every successful turn, needlessly discarding live thread and response-session reuse. Fresh real-provider measurements also showed that isolated mock timings were insufficient evidence for a runtime speed claim.

Why This Change Was Made

Retain at most one successfully completed ordinary persistent Codex thread per physical app-server client and skip the next resume only when the persisted owner and the complete native resume identity match. Fingerprint requested and effective models/providers, authentication profile, approvals, sandbox, permissions, service tier, base/developer instructions, effective thread configuration, and canonical dynamic-tool schema. Consume thread ownership transactionally; explicitly release or retire an unsafe subscription on cancellation, binding conflicts, changed settings, or eviction. Keep incognito, context-engine, supervision, native-preserved, ring-zero, transient, and one-shot threads on their existing lifecycle.

The mismatch fallback follows upstream Codex itself: codex-rs/app-server/src/request_processors/thread_processor.rs shuts down and removes a mismatched idle loaded thread after its last subscriber leaves before cold-resuming with the new settings. The warm implementation is isolated in extensions/codex/src/app-server/thread-lifecycle-warm.ts so the existing lifecycle remains below the repository line-limit gate.

Includes the minimal same-PR fixture repairs needed to keep the actual current Codex baseline green: create canonical SQLite session entries using the real SDK contract, and freeze/restore the clock in the oversized image-timeout regression.

User Impact

Repeated ordinary Codex turns can reuse the live native conversation and its cached responses without crossing accounts, changing approval/sandbox policy, exposing secret-bearing configuration, or retaining transient sessions. Native apply_patch, approvals, instruction follow-through, and source discovery remain operational. No new configuration, environment variable, persistent schema, or compatibility layer is introduced.

Evidence

  • AI-assisted; upstream Codex implementation, lifecycle, loaded-thread resume behavior, and response-session reuse inspected directly.
  • Genuine OpenAI API-key live runs through 1Password (op), not mock AI: all five matched OpenClaw/Codex scenario pairs passed, including native apply_patch, approval follow-through, source/docs discovery, instruction follow-through, and a 20-turn conversation.
  • Matched real 20-turn Codex baseline: 25,662 newly processed input tokens and 441,785 cache-read tokens.
  • Matched real optimized 20-turn Codex run: 793 newly processed input tokens and 467,307 cache-read tokens: 96.9% fewer newly processed input tokens. Live wall-clock varied with provider/bootstrap load (baseline 66.790 s; optimized measured 215.955 s), so this change explicitly does not claim a repeatable wall-clock or aggregate speedup.
  • Focused regression proof: 163 tests covering native model/provider identity, account rotation, service-tier null/omission, approval policy, sandbox, instructions, changed dynamic tools, cancellation, eviction, binding conflicts, transient nonretention, context-engine exclusion, and native patch/hook behavior.
  • Full Codex plugin lane and complete changed-file gate executed on a fresh Blacksmith Testbox; production and test typechecks, formatting, full plugin lint, plugin boundaries, SDK baseline, database-first guard, and import-cycle guard pass.
  • Fresh independent GPT-5.6 review: no accepted/actionable findings.

@steipete
steipete marked this pull request as ready for review July 28, 2026 08:45
@steipete
steipete force-pushed the codex/live-integration-performance-021e1457 branch from 7f086ff to ba6cb76 Compare July 28, 2026 08:50
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed July 28, 2026, 4:55 AM ET / 08:55 UTC.

ClawSweeper review

What this changes

The PR retains one compatible persistent Codex app-server thread per physical client so the next ordinary turn can reuse its live subscription instead of resuming it from storage.

Merge readiness

⛔ Blocked by patch quality or review findings - 7 items remain

Keep this PR open: the warm-reuse optimization bypasses an upstream resume safety check because its new compatibility fingerprint omits the working directory and runtime workspace roots. A subsequent turn on the same physical client can therefore keep operating with the prior workspace identity instead of forcing the existing safe resume/reload path. Likely related people: steipete (high confidence, recent Codex lifecycle contributor).

Priority: P1
Reviewed head: ba6cb7636d269e2f3fd61d9a668da53944864ca9

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The submission has useful real-provider evidence, but a high-impact workspace-identity omission blocks merge readiness.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The PR body supplies after-fix real-provider scenarios and measured 20-turn before/after token results; the missing workspace-switch case is a correctness gap to fix, not an absence of general real-behavior proof.
Patch quality 🦪 silver shellfish (2/6) Security review found an item that needs attention.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body supplies after-fix real-provider scenarios and measured 20-turn before/after token results; the missing workspace-switch case is a correctness gap to fix, not an absence of general real-behavior proof.
Evidence reviewed 4 items Current-main lifecycle: Current main only returns an already-live binding for incognito sessions; an ordinary persistent binding proceeds through resumeExistingCodexThread, which preserves the upstream resume validation path. (raw.githubusercontent.com)
Incomplete warm identity: The proposed fingerprintCodexThreadConfig hashes models, auth profile, approvals, sandbox, instructions, config, and dynamic tools, but its changed projection does not include cwd or runtimeWorkspaceRoots, even though the warm path uses that fingerprint to skip resume.
Upstream Codex contract: Upstream Codex treats both requested cwd and runtime_workspace_roots differences as loaded-thread resume mismatches. Skipping thread/resume when either changes bypasses that contract. (raw.githubusercontent.com)
Findings 1 actionable finding [P1] Fingerprint workspace identity before reusing a live thread
Security Needs attention Warm reuse can retain the previous workspace boundary: Upstream checks requested working directory and workspace roots when a loaded thread is resumed, but the new reuse fingerprint does not include either input and can skip that validation.

How this fits together

The Codex extension maps an OpenClaw session binding to a native Codex app-server thread. On each turn it decides whether to start, resume, or reuse that thread, and that choice controls the active workspace, tools, approvals, and sandbox context used by the native runtime.

flowchart LR
  A[OpenClaw session turn] --> B[Stored Codex thread binding]
  B --> C[Lifecycle compatibility checks]
  C --> D{Retained live thread matches?}
  D -->|Yes| E[Reuse existing subscription]
  D -->|No| F[Resume or start native thread]
  F --> G[Upstream validates workspace and settings]
  E --> H[Run Codex turn]
  G --> H
Loading

Before merge

  • Fingerprint workspace identity before reusing a live thread (P1) - tryReuseCodexLiveThread relies on this projection to skip thread/resume, but it omits cwd and runtimeWorkspaceRoots. Upstream treats both as mismatches for a loaded thread; on a same-client workspace switch this can retain the old thread instead of unloading/recreating it, so the next turn keeps the old workspace boundary. Add both fields to the fingerprint and cover the switch with a regression.
  • Resolve security concern: Warm reuse can retain the previous workspace boundary - Upstream checks requested working directory and workspace roots when a loaded thread is resumed, but the new reuse fingerprint does not include either input and can skip that validation.
  • Resolve merge risk (P1) - Merging without workspace identity in the warm-match key can run a later turn against the prior thread's working directory or workspace-root set, bypassing the upstream mismatch path that would otherwise unload and recreate the loaded thread.
  • Complete next step (P2) - A narrow repair is clear, but the protected maintainer label and workspace-security impact require explicit maintainer handling before any automated repair or merge action.
  • Improve patch quality - Include cwd and runtime workspace roots in the warm compatibility identity.
  • Improve patch quality - Add a focused same-client workspace-switch regression that proves the retained subscription is not reused.
  • Improve patch quality - Re-run the affected real-provider or controlled app-server scenario and post redacted evidence of the workspace-switch behavior.

Findings

  • [P1] Fingerprint workspace identity before reusing a live thread — extensions/codex/src/app-server/thread-fingerprints.ts:93-120
  • [medium] Warm reuse can retain the previous workspace boundary — extensions/codex/src/app-server/thread-fingerprints.ts:93
Agent review details

Security

Needs attention: The warm-path identity omits upstream workspace fields, creating a concrete risk that a retained thread continues under the prior workspace boundary.

PR surface

Source +456, Tests +647. Total +1103 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 7 486 30 +456
Tests 7 669 22 +647
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 1155 52 +1103

Review metrics

None.

Merge-risk options

Maintainer options:

  1. Complete the native resume identity (recommended)
    Include cwd and runtime workspace roots in the retained-thread match and add a same-client workspace-switch regression before merge.
  2. Pause the optimization
    Do not merge the warm path if it cannot match every upstream field that determines whether a loaded thread is safe to reuse.

Technical review

Best possible solution:

Extend the warm-thread compatibility identity to include every upstream resume-visible workspace field, at minimum cwd and runtime workspace roots, and add a regression proving a same-client workspace change cannot reuse the retained subscription.

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

Yes, from source: retain a completed ordinary thread, then issue the next turn through the same physical client with a different cwd or runtime workspace-root set. Current main calls native resume, whereas the proposed matching fingerprint can reuse the loaded thread without comparing either field.

Is this the best way to solve the issue?

No: retaining a live thread is a reasonable optimization, but the current fingerprint is not the complete native resume identity. The safe implementation must include the upstream workspace mismatch inputs or deliberately fall back to resume whenever those values are not provably identical.

Full review comments:

  • [P1] Fingerprint workspace identity before reusing a live thread — extensions/codex/src/app-server/thread-fingerprints.ts:93-120
    tryReuseCodexLiveThread relies on this projection to skip thread/resume, but it omits cwd and runtimeWorkspaceRoots. Upstream treats both as mismatches for a loaded thread; on a same-client workspace switch this can retain the old thread instead of unloading/recreating it, so the next turn keeps the old workspace boundary. Add both fields to the fingerprint and cover the switch with a regression.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.97

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P1: The patch can make an ordinary persistent Codex turn continue under a different workspace identity than the caller requested.
  • add merge-risk: 🚨 compatibility: Existing workspace-switch behavior currently reaches native thread/resume validation, while the new reuse path can skip it.
  • add merge-risk: 🚨 security-boundary: The omitted fields participate in Codex workspace and sandbox context, so reuse can retain the previous workspace boundary.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix real-provider scenarios and measured 20-turn before/after token results; the missing workspace-switch case is a correctness gap to fix, not an absence of general real-behavior proof.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body supplies after-fix real-provider scenarios and measured 20-turn before/after token results; the missing workspace-switch case is a correctness gap to fix, not an absence of general real-behavior proof.

Label justifications:

  • P1: The patch can make an ordinary persistent Codex turn continue under a different workspace identity than the caller requested.
  • merge-risk: 🚨 compatibility: Existing workspace-switch behavior currently reaches native thread/resume validation, while the new reuse path can skip it.
  • merge-risk: 🚨 security-boundary: The omitted fields participate in Codex workspace and sandbox context, so reuse can retain the previous workspace boundary.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🐚 platinum hermit and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The PR body supplies after-fix real-provider scenarios and measured 20-turn before/after token results; the missing workspace-switch case is a correctness gap to fix, not an absence of general real-behavior proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body supplies after-fix real-provider scenarios and measured 20-turn before/after token results; the missing workspace-switch case is a correctness gap to fix, not an absence of general real-behavior proof.

Evidence

Security concerns:

  • [medium] Warm reuse can retain the previous workspace boundary — extensions/codex/src/app-server/thread-fingerprints.ts:93
    Upstream checks requested working directory and workspace roots when a loaded thread is resumed, but the new reuse fingerprint does not include either input and can skip that validation.
    Confidence: 0.97

What I checked:

Likely related people:

  • steipete: Authored the merged related Codex app-server work and the current lifecycle-reuse proposal, providing the clearest available ownership trail for this subsystem. (role: recent Codex lifecycle contributor; confidence: high; commits: 27f62f3e8e22, ba6cb7636d26; files: extensions/codex/src/app-server/thread-lifecycle-run.ts, extensions/codex/src/app-server/thread-fingerprints.ts, extensions/codex/src/app-server/thread-lifecycle-warm.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.

@steipete
steipete merged commit 92b4af2 into main Jul 28, 2026
98 of 105 checks passed
@steipete
steipete deleted the codex/live-integration-performance-021e1457 branch July 28, 2026 09:08
@steipete

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

extensions: codex maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant