Skip to content

fix(codex): preserve live-thread ownership across same-build module copies - #160949

Merged
Patrick-Erichsen merged 5 commits into
openclaw:mainfrom
anyech:fix/codex-build-scoped-live-owner-157691
Oct 1, 2026
Merged

Patrick-Erichsen merged 5 commits into
openclaw:mainfrom
anyech:fix/codex-build-scoped-live-owner-157691

Conversation

@anyech

@anyech anyech commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Related: #157691

What Problem This Solves

Fixes lost Codex thread ownership when two copies of the same plugin build reuse one physical app-server client. Later copies could register duplicate handlers, miss retained subscriptions and rate-limit updates, or fail to retire a native child’s original parent custody.

Why This Change Was Made

Use the existing version-scoped build-state owner for the physical-client runtime, release-token maps, rate-limit snapshots, and native-child monitor. The original callbacks, auth identity, weak client keys, and thread-generation checks remain authoritative across module copies. This repairs ownership where it is created instead of adding a downstream unsubscribe fallback.

User Impact

Codex sessions keep their original subscription owner and current client-owned rate-limit information across same-build module copies. Native child retirement finds the original monitor and releases its parent pin exactly once. The native unload-confirmation guard, public API, configuration, and persistent storage are unchanged.

Evidence

Paired proof used pinned native Codex app-server 0.158.0, one real OpenClaw client, two independently evaluated runtime modules, and actual thread/start / thread/unsubscribe messages. It used isolated temporary state without credentials or model turns:

                             baseline     candidate
close-handler registrations  2            1
owner visible from copy B    false        true
original release calls       0            1
native unsubscribe status    not sent     unsubscribed

The native-child retirement regression fails on the original monitor runtime: copy B releases the original parent pin 0 times instead of 1. The same-copy control passes. The repaired monitor passes both cases and the permanent regression.

The repaired candidate passed 119 tests across eight files and two routed projects, including the temporary native proof drivers, client runtime, rate-limit cache, session retirement, build-state, and native monitor suites. The final type-only release callback alias followed that run; the final six-path changed gate subsequently passed with numeric exit 0. On resume, all six candidate file hashes still matched that successful gate. Fresh canonical isolated Codex autoreview of the entire candidate passed with no accepted/actionable P0 findings.

Production LOC: +24/-11 (net +13); tests +96/-1 (net +95). The three build-state registrations express the existing physical-client ownership boundary without introducing another runtime policy or fallback.

The quota path is proved with deterministic transport notifications; no authenticated quota update or provider inference is claimed. The native proof is terminal protocol evidence, not a Control UI or full Gateway flow. The related production incident in #157691 remains causally unproven; #153031 is a separate recovery proposal and is not established as redundant.

@clawsweeper

clawsweeper Bot commented Sep 29, 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.

@openclaw-barnacle openclaw-barnacle Bot added extensions: codex triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. size: S labels Sep 29, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 29, 2026
@clawsweeper

clawsweeper Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 1, 2026, 6:08 PM ET / 22:08 UTC (Revision 6).

ClawSweeper review

What this changes

The Codex plugin preserves thread subscriptions, quota snapshots, and native-child custody across copies of the same plugin build sharing one physical client.

Merge readiness

⛔ Needs changes before merge - 1 item remains

The repair remains necessary on current main and has sufficient native boundary proof. No introduced correctness or security defect was found, and the earlier merge-conflict blocker is resolved.

Priority: P2
Reviewed head: c14bcfd3ac47c243e8e68b95ef07445e61ff3f1a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership repair with strong native boundary evidence and no blocking code finding; required test-cost reporting remains.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Paired terminal evidence exercises the changed client owner through real OpenClaw transport and native Codex 0.158.0 thread/start and thread/unsubscribe, showing shared visibility and one original release after the fix. Native-monitor retirement has baseline/control evidence; quota coverage uses deterministic transport notifications. Integration preserves the introduced ownership behavior, and no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): Paired terminal evidence exercises the changed client owner through real OpenClaw transport and native Codex 0.158.0 thread/start and thread/unsubscribe, showing shared visibility and one original release after the fix. Native-monitor retirement has baseline/control evidence; quota coverage uses deterministic transport notifications. Integration preserves the introduced ownership behavior, and no stored-data contract changes.
Evidence reviewed 10 items Pinned introduced patch: The verified base-to-head delta shares three registries through the existing build-state owner. It preserves release logic and adds distinct regressions for retained ownership, quota notifications, and native-child retirement; no public API, configuration, dependency, or stored format changes.
Current main still needs this repair: Fetched main retains module-local configured-client and release-token maps. Its quota cache and native-monitor registry also remain module-local, despite the physical-client pool already using version-scoped state.
Latest release comparison: The v2026.9.7 source likewise declares the client ownership maps locally; the central repair is not already shipped in the supplied latest release.
Findings None None.
Security None None.

How this fits together

OpenClaw’s Codex plugin sends agent work to the native Codex app-server. Its client runtime tracks subscription ownership and child custody so subsequent turns and session retirement reach the original owners.

flowchart TD
  A[Plugin module copies] --> B[Version-scoped state]
  B --> C[Physical app-server client]
  C --> D[Thread ownership]
  C --> E[Native-child monitor]
  C --> F[Quota notifications]
  D --> G[Resume or release subscriptions]
  E --> G
  F --> H[Shared quota snapshot]
Loading

Before merge

  • Complete next step (P2) - Record per-file wall times for client-runtime.test.ts, rate-limit-cache.test.ts, and native-subagent-monitor.close.test.ts using the repository’s one-worker measurement command; include available CI seconds.
Agent review details

Security

None.

PR surface

Source +13, Tests +95. Total +108 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 24 11 +13
Tests 3 96 1 +95
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 120 12 +108

Review metrics

Metric Value Why it matters
Ownership repair growth production net +13 LOC; tests net +95 LOC Production growth is justified by three registrations with the existing state owner; regressions cover three distinct ownership failures.

Technical review

Best possible solution:

Keep one version-scoped owner for each physical client’s subscriptions, quota snapshots, and child custody while preserving account and generation isolation.

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

Yes: independently evaluated module copies reuse a build-scoped client but current main creates separate ownership registries. The supplied native baseline trace demonstrates the failure; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: extending the existing build-state owner repairs the producer boundary without adding competing recovery logic or weakening native unload confirmation.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This is a bounded Codex lifecycle repair with native proof, without an established urgent production regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): Paired terminal evidence exercises the changed client owner through real OpenClaw transport and native Codex 0.158.0 thread/start and thread/unsubscribe, showing shared visibility and one original release after the fix. Native-monitor retirement has baseline/control evidence; quota coverage uses deterministic transport notifications. Integration preserves the introduced ownership behavior, and no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. Paired terminal evidence exercises the changed client owner through real OpenClaw transport and native Codex 0.158.0 thread/start and thread/unsubscribe, showing shared visibility and one original release after the fix. Native-monitor retirement has baseline/control evidence; quota coverage uses deterministic transport notifications. Integration preserves the introduced ownership behavior, and no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced patch: The verified base-to-head delta shares three registries through the existing build-state owner. It preserves release logic and adds distinct regressions for retained ownership, quota notifications, and native-child retirement; no public API, configuration, dependency, or stored format changes. (extensions/codex/src/app-server/client-runtime.ts:51, c14bcfd3ac47)
  • Current main still needs this repair: Fetched main retains module-local configured-client and release-token maps. Its quota cache and native-monitor registry also remain module-local, despite the physical-client pool already using version-scoped state. (extensions/codex/src/app-server/client-runtime.ts:49, 6ced196f957f)
  • Latest release comparison: The v2026.9.7 source likewise declares the client ownership maps locally; the central repair is not already shipped in the supplied latest release. (extensions/codex/src/app-server/client-runtime.ts:48, c074824a27c9)
  • Native behavior proof: The captured body and Patrick-Erichsen’s October 1 verification comment report paired real OpenClaw-client/native Codex 0.158.0 thread/start and thread/unsubscribe traces: duplicate close handlers fall from two to one, copy B finds the original owner, and its original release executes once with native status unsubscribed. Native-monitor baseline/control evidence and deterministic quota notifications cover the additional registries. The proof uses isolated state without credentials or inference and does not claim full Gateway or authenticated quota coverage. (ee13ef63230d)
  • Personally inspected native dependency contract: The PR’s native thread/start and thread/unsubscribe claims establish the dependency signal. The sibling checkout is pinned to this SHA; its backing cache origin verifies openai/codex ownership. thread_unsubscribe_response_inner removes only the requesting connection, thread/start attaches that connection’s listener, and configuration-changing resume remains subscriber-sensitive. (codex-rs/app-server/src/request_processors/thread_processor.rs:1018, 064c6b8c737f)
  • Ownership and revocation remain enforced: State keys include the plugin version and WeakMaps remain keyed by the exact physical client. Reuse preserves the original auth store; claimed releases retain invalidation and generation checks. Session retirement reaches the original monitor, revokes child custody, and then releases the parent subscription. The diff does not introduce a new principal boundary or extend authorization lifetime. (extensions/codex/src/app-server/session-retirement.ts:43, c14bcfd3ac47)

Likely related people:

  • Srikalyan Swayampakula: Raw commit 3dd0be4 adds extensions/codex/src/build-state.ts:12 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3dd0be4132a5; files: extensions/codex/src/build-state.ts)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Record per-file measured wall times for the three changed regression suites.

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 (5 earlier review cycles)
  • reviewed 2026-09-29T04:20:42.500Z sha d83b7136a0dae149560839febfe74e9dd7b435dd :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-29T04:41:35.739Z sha d83b7136a0dae149560839febfe74e9dd7b435dd :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-29T05:40:21.499Z sha 4d18cc6 :: needs changes before merge. :: [P3] Wait for notification completion without polling
  • reviewed 2026-09-29T07:21:25.628Z sha dd67bf6 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-01T21:35:01.877Z sha ee13ef6 :: needs changes before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Sep 29, 2026
@anyech
anyech force-pushed the fix/codex-build-scoped-live-owner-157691 branch from d83b713 to 4d18cc6 Compare September 29, 2026 05:31
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. 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. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 29, 2026
@Patrick-Erichsen Patrick-Erichsen self-assigned this Oct 1, 2026
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Published repaired head: ee13ef63230d15504470ea2164e7aacc0da5fb95.

Maintainer repair and verification for the candidate based on dd67bf6a6c122621c4bd2b24b1217ccbedcf6de5:

The original PR repairs the live-thread and quota owners. Review found the same split in native-child retirement: the second module copy could not find the original monitor and left its parent pin retained. The repair moves that WeakMap into the existing build-state owner, preserving the original monitor and its exact custody. A repeated release-callback type is also deduplicated to satisfy the existing line limit without changing runtime behavior.

The paired native Codex 0.158.0 probe executed real thread/start and thread/unsubscribe through OpenClaw’s client, with isolated temporary state, no credentials, and no inference:

baseline: 2 close handlers; copy B owner invisible; original releases=0
candidate: 1 close handler; copy B owner visible; original releases=1
candidate native thread/unsubscribe: {"status":"unsubscribed"}

The native monitor regression fails against the original monitor runtime (0 parent-pin releases), while the same-copy control passes (1). The repaired candidate passes both and all 119 focused tests across eight files/two routed projects. Those tests include two retained temporary proof drivers; they are not 119 newly added tests. Quota notifications are deterministic transport proof, not authenticated live inference.

Final static verification completed with numeric exit 0 and unchanged six-file hashes:

node scripts/check-changed.mjs --base 1fdf41920c157a0156a101c613376ec33a1d9f7d -- \
  extensions/codex/src/app-server/client-runtime.ts \
  extensions/codex/src/app-server/rate-limit-cache.ts \
  extensions/codex/src/app-server/native-subagent-monitor-runtime.ts \
  extensions/codex/src/app-server/client-runtime.test.ts \
  extensions/codex/src/app-server/rate-limit-cache.test.ts \
  extensions/codex/src/app-server/native-subagent-monitor.close.test.ts

Fresh canonical isolated autoreview of the complete candidate also completed with exit 0 (gpt-5.6-sol, high reasoning, P0 scope; no rejected/filtered findings):

.agents/skills/autoreview/scripts/autoreview --mode local \
  --base 1fdf41920c157a0156a101c613376ec33a1d9f7d \
  --engine codex --model gpt-5.6-sol --thinking high

Personally inspected the pinned Codex source at 064c6b8c737f5b41d171fdda80bd9ef10ad06eb3: thread_processor.rs:1018 (connection-scoped unsubscribe), thread_state.rs:512 (remove requesting connection), thread_processor.rs:1574 (start listener), thread_processor.rs:4310 (subscriber-sensitive resume), account_processor.rs:1115 (authenticated quota read), and bespoke_event_handling.rs:1574 (quota notification producer), all under codex-rs/app-server/src/.

Production +24/-11 (net +13); tests +96/-1 (net +95). Reusing the existing owner needs three initializer registrations; the release-type alias and grouped registry keep the plumbing small. No config, protocol, schema, or persistence surface is added.

The previous ClawSweeper review had no remaining findings or rank-up moves. This repair adds native-monitor coverage after that older review, so a refresh is requested below. The incident in #157691 remains unproven, and #153031 is not established as redundant. No UI or full-Gateway proof is claimed.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Oct 1, 2026
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Completed the remaining test-cost request from ClawSweeper revision6 at c14bcfd3ac47c243e8e68b95ef07445e61ff3f1a. Each file ran separately and sequentially with node scripts/run-vitest.mjs <file> --maxWorkers=1, using temporary HOME/state and no credentials.

Changed file Passed Measured command wall Vitest duration Cold worker compilation
extensions/codex/src/app-server/client-runtime.test.ts 43 120.200s 84.90s 24.002s
extensions/codex/src/app-server/rate-limit-cache.test.ts 3 173.103s 158.96s 87.825s
extensions/codex/src/app-server/native-subagent-monitor.close.test.ts 5 62.685s 56.64s 20.224s

All51 passed, source hashes/head stayed unchanged, and every child process joined. Isolated cold compilation/module loading dominates local time. Available exact-head CI timing: the first two files are in changed-extensions-config-1 (93.07s shard,182s job); monitor.close is in changed-extensions-config-2 (90.80s shard within215s bundled job). Reported individual-case execution sums are1.329s,0.313s,0.628s respectively; these exclude setup/import and are not per-file wall times.

The three regressions cover distinct owner failures: original retained subscription, notification cache, native-child retirement. Existing paired real native Codex0.158.0 proof remains applicable; main integration preserves its ownership registrations and retains main's auth/test cleanup. All96 current checks are success/skipped, all3 commit statuses successful, and the required CI gate passes. The latest rank-up move is applied. This does not claim authenticated quota/provider completion or establish causation/redundancy for the related incident and recovery PR.

@Patrick-Erichsen
Patrick-Erichsen merged commit 7f60f5f into openclaw:main Oct 1, 2026
99 checks passed
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 2, 2026
…opies (openclaw#160949)

* fix(codex): preserve live thread owners across module copies

* fix(codex): share physical-client rate limits across module copies

* test(codex): await rate-limit notification without polling

* fix(codex): share native monitor ownership across module copies

---------

Co-authored-by: Patrick Erichsen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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.

2 participants