Skip to content

fix: resume Codex conversations after background cleanup settles - #187776

Merged
obviyus merged 4 commits into
openclaw:mainfrom
jjjhenriksen:fix/codex-background-policy-rotation-20261029
Oct 29, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
jjjhenriksen:fix/codex-background-policy-rotation-20261029

Conversation

@jjjhenriksen

@jjjhenriksen jjjhenriksen commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Current revision

Head e756e6ab7c86b766b61db4a34b176b0b384f03ee changes tests only from the proven runtime head. Whole-PR tests net -3 lines, no new allocations. Retained settlement/cancellation/deadline regressions fail on frozen main; candidate targeted files pass 15/15. Consolidation and exact commands: #187776 (comment)

The earlier test inventories below describe historical revisions and are superseded by this zero-growth consolidation. Production/native proof remains unchanged.

Related: #186524.

What Problem This Solves

Fixes: resuming a Codex conversation can fail with “claimed by active work” while a stopped turn’s background cleanup is still settling and refreshed creation instructions require unloading the retained subscription.

User Impact

Users can resume after background cleanup finishes without discarding the conversation. Foreground claims, sibling work, cancellation, and the existing cleanup deadline remain protected; unfinished work is never force-released.

Why This Change Was Made

Wait for unclaimed, background-only ownership to settle before the cold-resume unload, then recheck current authority and client state through the existing admission guards. Timeout remains a refusal, with an error that distinguishes unfinished background work from a foreground claim.

The ownership module owns the wait and its listener cleanup. Existing ownership and instruction helpers are reused rather than duplicated in the client adapter. This is separate from #186524’s explicit Goal Start/Resume admission fix and changes no configuration, permissions, persistence schema, or automatic-pursuit policy.

Evidence

  • Current pushed head: 2b62819f70eab6e5eca9490400c30c02f046961b. Production repair: 6b66ecfc61ea711cf01d788d7462514e48b14e67, based on 726705edca0. The follow-up changes only two tests and their 14-line test-budget allocation; runtime code is unchanged.
  • 11/11 lifecycle tests passed on production commit 6b66ecfc61e via node scripts/run-vitest.mjs run --config test/vitest/vitest.extension-database-workers.config.ts extensions/codex/src/app-server/thread-lifecycle.warm-cleanup.test.ts extensions/codex/src/app-server/thread-lifecycle.warm-cleanup.native.test.ts --maxWorkers=1 (38.25s Vitest). Regression coverage: settlement, cancellation, and deadline paths; native background-command cleanup followed by continuation; preserved sibling ownership. Native cases use a real Codex subprocess with a synthetic test provider, not a hosted model-quality evaluation. Windows skips the native-process suite.
  • Targeted six-file formatting, lint, and whitespace checks pass. The supported production extension typecheck also passes: node scripts/run-tsgo.mjs -p tsconfig.extensions.json --incremental --tsBuildInfoFile .artifacts/tsgo-cache/extensions.tsbuildinfo. An initial direct root-config typecheck failed on repository-wide JSX/rootDir/package-resolution configuration and is not claimed as passed.
  • Independent native Codex reviewer inspected the complete six-file parent-to-head range at P0–P2 and found no actionable defects. Static review only, without helper-owned isolation or structured validation; the configured shared autoreview installation was unreadable and no Codex CLI was available on PATH. This is not an autoreview-helper pass.
  • Live operational observation: after deploying the integrated repair bundle, the previously paused existing Goal accepted Resume and its session entered running state with the same identity and objective. The deployment also contained separate admission/continuation fixes; this observation is not isolated proof of this six-file patch and does not claim the underlying Goal is finished.
  • Simplification: ownership decisions and wait state remain with the existing thread-ownership owner; no second cleanup manager or forced release. Original production delta +104/-20; original tests +106/-2. The test-only follow-up adds +24/-8 including the allocation file.

Hosted CI has not yet been verified. No merge or release inclusion is claimed.

P2 test follow-up and fresh Gateway rerun (2026-10-29)

Pushed head: 2b62819f70eab6e5eca9490400c30c02f046961b.

  • Both outdated assertions reproduced before editing: 2 failures, 9 passes. Both now require AgentHarnessPreflightError and the exact background-cleanup refusal diagnostic. Protection, subscription, lifecycle, and turn-count checks remain; owner reentry now explicitly checks protection and absence of unsubscribe after refusal.
  • 11/11 follow-up tests passed across both changed files with pnpm test extensions/codex/src/app-server/run-attempt.native-background-outcome.test.ts extensions/codex/src/app-server/run-attempt-continuity.test.ts --maxWorkers=1 (32.37s Vitest; 37.21s command wall time). Targeted extension-test typecheck, oxlint, oxfmt, and whitespace checks passed. No production timeout or sleep changes; the existing protected-cleanup refusal budget remains.
  • Fresh isolated real-Gateway rerun reused the exact base and production-candidate builds above because this follow-up is test-only. Base again refused with “claimed by active work”; candidate waited 2,713 ms, resumed the same thread and client, and returned CLEANUP_RESUMED_OK. This is real native-runtime/subscription-model behavior, not a synthetic provider run.
  • Both test-owned Gateway processes stopped and both disposable state/auth homes were verified removed. The first rerun attempt hit the worker-compilation no-output watchdog before Gateway startup; the successful retry used the supported 300-second compilation deadline, with no production timeout change.
  • Earlier static review covers the original six-file repair, not an independent review of this test-only follow-up. Hosted CI for the new head is not claimed as verified; no merge, release inclusion, or new live deployment is claimed.

The detailed earlier run below is retained as prior-run evidence; its 2,463 ms wait is distinct from the fresh 2,713 ms rerun.

Isolated real-Gateway before/after proof (2026-10-29)

Fresh built Gateway processes, separate disposable state and ports, real native Codex runtime and subscription model. Production difference is only the six-file PR commit; no integrated deployment bundle is used.

Build Commit Second turn Cleanup wait
Base 726705edca0d8cc7e39b71f4a42e40369dda9384 Failed: claimed by active work No wait
Candidate 6b66ecfc61ea711cf01d788d7462514e48b14e67 CLEANUP_RESUMED_OK 2463 ms

Reproduction

  1. Start an ordinary concrete-model chat; launch a native shell command that prints BACKGROUND_READY and waits on finish-background, then finalize BACKGROUND_LAUNCHED without collecting it.
  2. Change only the model's authored contextTokens cap from 128000 to 127000; wait for Gateway hot reload. Use a route-neutral bundled-provider overlay with no API/base URL/auth override and the legacy context engine.
  3. Send the next message to the same session; the external driver releases the command after 3 seconds. Base refuses early. Candidate waits for cleanup and resumes the same thread and client.

Actual Gateway log excerpts

Synthetic session/run/thread identifiers are retained; private paths, model identity and authentication fields are omitted.

base

2026-10-29T09:07:15.216-07:00 [trace:codex-app-server] thread lifecycle: runId=c901b11c-e16e-4ebd-8798-7849ddfb40e6 sessionId=7684313e-b6b3-4ed8-838a-e232dd0fbbb5 sessionKey=agent:main:cleanup-proof-f038becf-c3f0-432e-820f-1b62715901e2 action=started totalMs=201 stages=legacy-dynamic-tools-fingerprint:2ms@2ms,dynamic-tools-fingerprint:0ms@2ms,web-search-plan:0ms@2ms,context-engine-binding:0ms@2ms,native-skill-isolation:9ms@12ms,effective-config-read:4ms@16ms,tool-policy-config-requirements-read:2ms@18ms,merge-thread-config:0ms@42ms,thread-start-params:0ms@42ms,thread-start-request:25ms@67ms,thread-start-mark-managed:7ms@77ms,thread-start-write-binding:124ms@201ms,thread-ready:0ms@201ms
2026-10-29T09:07:27.960-07:00 config hot reload applied (models.providers.openai.models)
2026-10-29T09:07:28.574-07:00 lane task error: lane=main durationMs=185 error="Codex thread 01a1886a-5f7a-7773-980c-35660f5b2115 is claimed by active work; stop it first."

candidate

2026-10-29T09:08:03.196-07:00 [trace:codex-app-server] thread lifecycle: runId=32e239b3-8830-49d4-a2e8-ef0bc05d275c sessionId=8bd50eb2-c0d5-40bf-85b6-fe3e8afc2af8 sessionKey=agent:main:cleanup-proof-f3b86093-f333-4d5b-9a0d-ff036ba2d772 action=started totalMs=97 stages=legacy-dynamic-tools-fingerprint:2ms@2ms,dynamic-tools-fingerprint:0ms@2ms,web-search-plan:0ms@2ms,context-engine-binding:0ms@2ms,native-skill-isolation:10ms@14ms,effective-config-read:5ms@19ms,tool-policy-config-requirements-read:1ms@21ms,merge-thread-config:0ms@40ms,thread-start-params:1ms@41ms,thread-start-request:22ms@63ms,thread-start-mark-managed:5ms@69ms,thread-start-write-binding:28ms@97ms,thread-ready:0ms@97ms
2026-10-29T09:08:15.997-07:00 config hot reload applied (models.providers.openai.models)
2026-10-29T09:08:19.259-07:00 [trace:codex-app-server] thread lifecycle: runId=9f00cbd1-4ef8-46c6-8413-d16b5aefddf2 sessionId=8bd50eb2-c0d5-40bf-85b6-fe3e8afc2af8 sessionKey=agent:main:cleanup-proof-f3b86093-f333-4d5b-9a0d-ff036ba2d772 action=resumed totalMs=2685 stages=legacy-dynamic-tools-fingerprint:1ms@1ms,dynamic-tools-fingerprint:1ms@2ms,web-search-plan:0ms@2ms,context-engine-binding:0ms@2ms,native-skill-isolation:0ms@3ms,effective-config-read:3ms@6ms,tool-policy-config-requirements-read:2ms@8ms,warm-thread-resume-params:1ms@21ms,thread-read-adoption-status:6ms@30ms,background-thread-cleanup:2463ms@2494ms,retained-thread-unsubscribe:3ms@2497ms,thread-resume-params:0ms@2497ms,thread-resume-request:121ms@2618ms,thread-resume-write-binding:43ms@2684ms,thread-ready:0ms@2684ms

Receipt checks

The first turn settled successfully on both builds with a native still-running command receipt. The candidate's final assistant reply and terminal receipt both contain CLEANUP_RESUMED_OK. Public thread_ready events match threadId and clientId across both candidate turns. Gateway log spans show the actual cleanup wait before unsubscribe and resume. Base has no successful second reply.

These are real Gateway and native-runtime/model runs, not a deterministic provider or mocked lifecycle. They do not claim all platforms/background-child variants, merge, release inclusion, or completion of the separate fine-tuning goal. Test-owned Gateway processes and disposable native auth homes are cleaned by the instance owner.

Public event and terminal-receipt excerpts

These are selected fields from the captured public Gateway events and receipts.

{"build":"base","at":"2026-10-29T16:07:15.308Z","stream":"codex_app_server.lifecycle","runId":"c901b11c-e16e-4ebd-8798-7849ddfb40e6","data":{"phase":"thread_ready","threadId":"01a1886a-5f7a-7773-980c-35660f5b2115","action":"started","clientId":"cbdde13f-2a6d-460d-bd40-08bcdab75391"}}
{"build":"base","at":"2026-10-29T16:07:28.623Z","runId":"f5c801bd-bb3c-46c5-b6c4-390683ab1424","status":"error"}
{"build":"candidate","at":"2026-10-29T16:08:03.224Z","stream":"codex_app_server.lifecycle","runId":"32e239b3-8830-49d4-a2e8-ef0bc05d275c","data":{"phase":"thread_ready","threadId":"01a1886b-1b4b-74e3-b518-a29539956806","action":"started","clientId":"61a454b7-fb6b-4019-96aa-d8b46ce4eaab"}}
{"build":"candidate","at":"2026-10-29T16:08:19.293Z","stream":"codex_app_server.lifecycle","runId":"9f00cbd1-4ef8-46c6-8413-d16b5aefddf2","data":{"phase":"thread_ready","threadId":"01a1886b-1b4b-74e3-b518-a29539956806","action":"resumed","clientId":"61a454b7-fb6b-4019-96aa-d8b46ce4eaab"}}
{"build":"candidate","at":"2026-10-29T16:08:22.654Z","runId":"9f00cbd1-4ef8-46c6-8413-d16b5aefddf2","status":"ok","terminalReply":{"disposition":"visible","text":"CLEANUP_RESUMED_OK"},"sourceReplyDelivered":true}

Maintainer isolated native proof

Built Gateway and real pinned Codex app-server with deterministic local provider: main twice refuses pending-background cold resume; candidate twice waits 2424/2514 ms before unsubscribe/resume and replies on the same thread. Foreground admission and no-pending controls, source citations, proof limits and simplification rationale: #187776 (comment)

Merge danger: two-way door; no persistent migration or new configuration. Blast radius: native Codex cold resume while unclaimed background-only work remains protected.

@clawsweeper

clawsweeper Bot commented Oct 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ⚠️ Failed 2026-10-29T15:55:59.092355Z
We couldn’t complete this review. Comment @codex review to try again.
6b66ecf PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 29, 2026
@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR waits for background-only Codex cleanup to settle before unloading and resuming a retained conversation.

Example: A native background command remains running when the model context limit changes from 128000 to 127000.

  • Before: The next message fails immediately with “claimed by active work.”
  • After: After the command settles, the same native thread resumes and returns CLEANUP_RESUMED_OK.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Focused owner-level repair with shipped-entry-point differential proof, retained red/green regressions, and no actionable findings; current-head CI remains unfinished.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): Built Gateway chat.send/agent.wait runs exercise real native background commands, policy-triggered cold resume, cleanup ordering, and successful same-thread continuation; body receipts additionally establish physical-client continuity, and later commits change tests only.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Continuing a preserved Codex conversation can fail even though its background cleanup would finish shortly.
Reason: The demonstrated failure is repaired within the existing lifecycle contract without changing permissions, configuration, persistence, or Goal eligibility.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it fixes a demonstrated Codex continuation failure that remains on main, with convincing native-runtime proof and no actionable findings; required CI is still pending.

Priority: P2
Reviewed head: e756e6ab7c86b766b61db4a34b176b0b384f03ee

Before merge

None.

Findings

None.

Agent review details

How this fits together

The Codex plugin translates Gateway turns into native app-server thread operations; its ownership registry protects subscriptions while foreground turns and background commands still need them.

flowchart TD
  A[Gateway continuation] --> B[Thread lifecycle]
  B --> C[Existing ownership registry]
  C --> D[Background cleanup settles]
  D --> E[Recheck authority and claims]
  E --> F[Unsubscribe and resume native thread]
Loading

Technical review

Best possible solution:

Land the existing bounded ownership wait once required CI passes, preserving refusal while work remains protected.

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

Current-main source still rejects this path immediately, and supplied differential Gateway logs reproduce it before the fix; this read-only review ran no target code.

Is this the best way to solve the issue?

The patch repairs the existing release owner with an event-driven, cancellable wait and preserves admission guards, avoiding polling, forced release, or a competing cleanup manager.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Warm subscription reuse and physical-client ownership keeps the original intent (92b4af2: Reuse matching live conversations while requiring safe release before applying changed creation policy.)
  • Protected-work refusal before cold resume changes intended behavior with a stated reason (20aecc9: Classify busy-thread refusal as coordination failure so model fallback cannot replace or retry against protected work.)
  • Background custody and context refresh keeps the original intent (29ed214: Permit context-only continuation while retaining the original background owner and refusing real policy changes until safe.)
  • Warm preparation recovery tests keeps the original intent (31f23a5: Preserve compatible follow-ups after publication failure without disturbing background work or sibling ownership; those cases remain in the native suite after consolidation.)
  • Cancellation during physical-client handoff keeps the original intent (0169c8a: A pre-write Stop must release the interrupted attempt while preserving the healthy client and predecessor writer fence.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit f5f44fa adds extensions/codex/src/app-server/thread-lifecycle-warm.ts:129 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f5f44faeca4e; files: extensions/codex/src/app-server/thread-lifecycle-warm.ts)
  • Jacqueline Henriksen: Raw commit 31f23a5 adds extensions/codex/src/app-server/thread-lifecycle-warm.ts:320 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 31f23a54ecaa; files: extensions/codex/src/app-server/thread-lifecycle-warm.ts)
  • LLagoon3: Raw commit 0169c8a adds extensions/codex/src/app-server/thread-lifecycle-warm.ts:175 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 0169c8acfbff; files: extensions/codex/src/app-server/thread-lifecycle-warm.ts)

PR surface

Source +84, Tests -3. Total +81 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 104 20 +84
Tests 3 64 67 -3
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 168 87 +81

Review metrics

Metric Value Why it matters
Production versus test changes Production +104/-20; tests +64/-67 Verified against the introduction base; production growth implements bounded observation and cleanup, while retained tests cover distinct settlement, cancellation, deadline, and consumer behavior without net growth.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: A demonstrated continuation bug affects the bounded case of background protection combined with a cold-resume policy change.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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 (3 earlier review cycles)
  • reviewed 2026-10-29T16:27:43.844Z sha 6b66ecf :: needs changes before merge. :: [P2] Update both continuity tests for the background-cleanup refusal
  • reviewed 2026-10-29T18:17:15.416Z sha 2b62819 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-29T18:33:50.727Z sha 82041a4 :: needs maintainer review before merge. :: none

Reviewed October 29, 2026, 2:48 PM ET / 18:48 UTC (Revision 4).

@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Built Gateway + real native Codex cleanup ordering

Candidate 2b62819f70eab6e5eca9490400c30c02f046961b; frozen main ae3561e289dc95232b362329bd7657ddc46adfe0. Both installed/built in secretless Node 24.22.1 Docker. Native subprocess is the actual pinned @openai/[email protected] (codex-cli 0.164.0), not a fake CLI, replayed lifecycle, or private-helper invocation. A deterministic loopback Responses provider chooses the shell action/final text; the real app-server owns subscriptions, thread resume, tools, command lifetime, inventory and notifications. No personal credentials or model-quality claim.

Native source personally inspected

Sibling ../codex checkout commit ce0323f2f2d3b25e82806cd555237da3db4e1897, codex-rs/app-server/src/request_processors/thread_lifecycle.rs:

  • lines 568–591: unsubscribed idle-thread shutdown pins the same shutdown future; 10 seconds bounds the warning, then it continues awaiting real cleanup. It does not cancel or prove cleanup complete.
  • lines 595–616: removal checks the exact native runtime and publishes thread/closed only after shutdown completes.

This source inspection explains why subscription detachment is not physical cleanup; the runtime proof below uses the installed pinned binary rather than claiming the inspected source checkout itself was compiled.

Actual shipped flow, repeated twice per snapshot

Actual chat.send and agent.wait Gateway RPCs create a normal native Codex conversation. The provider requests native exec_command to print BACKGROUND_READY and wait on a task-owned marker. Its subsequent real tool receipt reports “Process running with session ID …” and BACKGROUND_READY; the first native turn then returns BACKGROUND_LAUNCHED without collecting that command.

Change only authored model contextTokens from 128000 to 127000, allow Gateway hot reload, and continue the same session while the native command remains pending. The external driver releases that exact command after 3 seconds:

Snapshot Repeat Cold continuation Observed cleanup wait
main 1 error: native thread claimed by active work refused before release
main 2 same claimed-work error refused before release
candidate 1 CLEANUP_RESUMED_OK, same native thread 2424 ms, then unsubscribe, then resume
candidate 2 CLEANUP_RESUMED_OK, same native thread 2514 ms, then unsubscribe, then resume

Candidate production lifecycle spans explicitly order background-thread-cleanup → retained-thread-unsubscribe → thread-resume-request; terminal assistant idempotency receipts retain the original native thread ID. No replacement thread or forced release is used. Physical client-ID equality was not separately exported by this collector and is not claimed from timing alone.

Controls

  • No pending work: after releasing and settling the command, another authored-cap change and continuation succeeds on main and candidate in both repeats, returning CLEANUP_RESUMED_OK with the original thread.
  • Foreground work: a separate real native first turn is held at its loopback provider while another turn is requested after the policy change. On both snapshots, the second turn reports status:pending, timeoutPhase:queue, providerStarted:false while the original is active. Releasing the provider lets the original finish successfully. It is not interrupted/unsubscribed or replaced by the waiter. This proves normal Gateway foreground admission, not an artificial direct call to a private claimed-thread guard.
  • Task-owned state/config/profile paths are printed by the exact binaries. No live Gateway or native auth store is used. All task Gateway/native processes stopped after proof.

Simplification review: retained the existing ownership observer rather than adding polling or a second cleanup manager. Listener cleanup, caller cancellation, existing interrupt deadline, and post-wait authority/client/foreground checks each protect a distinct lifetime; no safe behavior-preserving reduction identified. Existing duplicated physical-client pin checks were consolidated by the contributor. Production +104/-20 (net +84); no additional production changes made by this worker. The test-only follow-up preserves both prior refusal consumers’ ownership/subscription assertions. Zero tests run. This does not claim separate live timeout, caller-abort, authority-revocation or sibling-owner fault-injection runs; those guards were source-inspected, not presented as exercised.

Revert fully undoes this lifecycle-wait change without data migration. Blast radius: native Codex cold resume when an unclaimed background-only owner remains protected; foreground/native ownership remains with its original owner.

@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added 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. and removed 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. labels Oct 29, 2026
@obviyus

obviyus commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator

Test-budget consolidation

No production source change. Whole-PR test delta against merge base 726705edca0d8cc7e39b71f4a42e40369dda9384 is +68/-71, net -3 lines. No new test allocations remain; config/test-lines-allocations/codex-background-cleanup-continuity-p2.txt removed.

The existing native warm-cleanup table retains real-process publication failure, protected publication failure, protected rotation, context refresh, command completion and sibling-ownership coverage. Removed the overlapping mocked publication-failure table and the separate new native cold-resume branch. The unit owner retains one three-row regression table covering settlement, caller cancellation and deadline, plus the original protected-policy refusal case. Typed refusal/protection/subscription assertions in both continuity consumers remain; the unsubscribe assertion is expressed once over the request list. No production timing, authority or foreground guard changed.

Focused secretless Docker proof:

  • Candidate: the three affected lifecycle/continuity consumer files 15/15 pass.
  • Frozen main production with the same retained warm-cleanup test file: 3 intended failures / 1 pass. Settlement rejects immediately with claimed-work instead of resuming; cancellation returns claimed-work instead of the caller reason; deadline returns old claimed-work instead of the background-cleanup refusal. The unchanged protected-policy case passes.

Commands/logs: consolidation-proof.sh, consolidation-candidate.log, consolidation-base.log. This demonstrates retained regressions fail on main, rather than merely assuming it from source. Original built Gateway/native Codex differential proof remains valid because production inputs are unchanged.

Final head e756e6ab7c86b766b61db4a34b176b0b384f03ee includes the required formatter-only import layout (+3 lines), keeping the whole PR at net -3 test lines. The prior check-lint failure was this formatting issue and has been corrected; no production or test behavior changed.

@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@obviyus
obviyus merged commit 4dc8e71 into openclaw:main Oct 29, 2026
109 of 110 checks passed
@obviyus

obviyus commented Oct 29, 2026

Copy link
Copy Markdown
Collaborator

Landed in 4dc8e71. Thanks @jjjhenriksen. Codex conversations can now be resumed after background cleanup finishes.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 30, 2026
…nclaw#187776)

fix(codex): wait for background cleanup before a cold resume of the thread

Resuming a Codex conversation could fail with "claimed by active work" while a stopped turn's background cleanup was still finishing and the resume needed to unload the retained subscription. A cold resume now waits for background-only, unclaimed ownership to settle within the existing cleanup deadline, rechecks current authority and client state, then unsubscribes and resumes the original thread. Foreground claims and sibling work are still refused, nothing is force-released, and a timeout is still a refusal with a clearer error.

Evidence: built Gateway with the pinned Codex app-server 0.164.0, a deterministic loopback provider and a real native background shell command. Main refused the cold continuation as claimed by active work (twice); with this change it waited about 2.4 to 2.5 s, then resumed the original thread (twice). No-pending continuation works on both refs, and during foreground work a second turn stayed queued without starting the provider. Checked against the codex app-server source at ce0323f2f2 (thread/unsubscribe and background-terminal handling). Details: openclaw#187776 (comment).

Thanks @jjjhenriksen.

Co-authored-by: Ayaan Zaidi <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 30, 2026
fix(codex): wait for background cleanup before cold resume

Backport of #187776 adapted to the release branch thread-state split after stable FRV exposed the Codex 0.164.0 active-writer race.

(cherry picked from commit 4dc8e71)

Co-authored-by: Ayaan Zaidi <[email protected]>

Co-authored-by: RomneyDa <[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: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M 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