Skip to content

fix(cli): retain local model resources through completion cleanup - #143302

Merged
steipete merged 1 commit into
mainfrom
codex/cli-model-completion-resources
Sep 9, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/cli-model-completion-resources

Conversation

@steipete

@steipete steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Related: #140674

What Problem This Solves

Local model commands release their prepared model generation before sending the request. Overlapping commands can rebuild the same catalog, and callback or response-cancellation work can outlive the command result without retaining that generation.

Why This Change Was Made

The local command uses the existing acquired model contract and admits its cleanup owner before preparation. It retains the lease through completion interpretation and actual callback/cancellation drainage. The existing command runtime owns that drainage independently of when the result becomes available.

User Impact

Local model commands reuse their active prepared generation and finish cleanup before its final release. Existing output, errors, model/profile selection, unsupported-runtime handling and Gateway behavior remain unchanged.

Evidence

  • Three native regressions reproduced premature generation release during overlap, response callback and response-body cancellation; the provider-error control passed. All four pass with the repair, including fresh generation creation after final release.
  • 277 relevant tests, the full changed-file gate and isolated Codex review through P2 passed. Build completed in 333.9 seconds.
  • The actual built CLI completed synthetic loopback success/error/success commands in 1.365/1.598/1.622 seconds. Source and 12,109 built artifacts stayed unchanged, and all managed process trees terminated.
  • Refreshed directly onto main, independently of the SDK PR: all three changed files are byte-identical to the reviewed/build-tested candidate, and 252 composition tests passed. General run-generation physical disposal remains a separate producer change.

@clawsweeper

clawsweeper Bot commented Sep 9, 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 cli CLI command changes size: M maintainer Maintainer-authored PR labels Sep 9, 2026
@steipete
steipete marked this pull request as ready for review September 9, 2026 17:51
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 9, 2026, 1:57 PM ET / 17:57 UTC (Revision 2).

ClawSweeper review

What this changes

The PR keeps local CLI model resources alive through response processing and callback or cancellation cleanup, with regression coverage for overlapping commands.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused fix: current main still releases preparation resources before completion. No blocking correctness defect was found, and the related aggregate is a draft reference rather than a replacement landing path.

Priority: P2
Reviewed head: 0b5e973c7d0cb600647f84601a50a749b0d07a3f

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with meaningful lifecycle coverage and no blocking finding.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. The body reports compiled CLI loopback runs plus targeted lifecycle regressions; the simple success/error runs alone do not demonstrate delayed cleanup ownership.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. The body reports compiled CLI loopback runs plus targeted lifecycle regressions; the simple success/error runs alone do not demonstrate delayed cleanup ownership.
Evidence reviewed 8 items Introduced production change: The complete introduced diff registers an outer cleanup owner before acquisition, resolves command output independently, and releases the acquired lease after the inner work scope drains.
Current main still needs the fix: Fetched main calls prepareSimpleCompletionModelForAgent before dispatch. That helper acquires and immediately releases its lease at lines 551–557. The release-tag source lookup failed because its required blob was unavailable; no shipped-fix claim is made.
Production cleanup integration: Commander parsing runs within the invocation resource owner. Its finalizer joins registered work before releasing resources; provider callback and cancellation promises enter the inner scope through observePendingProviderWork.
Findings None None.
Security None None.

How this fits together

Local model commands resolve an agent’s configured model and credentials, then send a one-shot provider request. Prepared runtime resources must remain available until both the response and its asynchronous cleanup finish.

flowchart TD
 A[Local model command] --> B[Acquire prepared model resources]
 B --> C[Send provider request]
 C --> D[Return output or error]
 C --> E[Drain callbacks and cancellation]
 E --> F[Release model resources]
 G[CLI invocation cleanup] --> E
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +23, Tests +298. Total +321 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 97 74 +23
Tests 2 310 12 +298
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 407 86 +321

Review metrics

Metric Value Why it matters
Production versus test growth Production net +23 lines; tests net +298 lines Production growth implements separate result and cleanup lifetimes; most growth exercises four resource-lifetime scenarios.

Technical review

Best possible solution:

Keep lease ownership at the local command boundary and let the existing invocation owner join cleanup without delaying the command’s result.

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

Yes, source establishes the premature release: main’s preparation helper releases its acquired lease before the local command sends its request. The supplied regressions exercise the resulting lifetime gaps; this review did not run them.

Is this the best way to solve the issue?

Yes. Reusing the existing acquired-model contract and asynchronous work owner repairs the caller’s lifetime boundary without changing public APIs, configuration, or provider selection.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs bounded local model resource retention and overlapping-command preparation without evidence of an urgent user-wide outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies a MEMBER-authored PR, so the external-contributor proof gate does not apply. The body reports compiled CLI loopback runs plus targeted lifecycle regressions; the simple success/error runs alone do not demonstrate delayed cleanup ownership.

Evidence

What I checked:

  • Introduced production change: The complete introduced diff registers an outer cleanup owner before acquisition, resolves command output independently, and releases the acquired lease after the inner work scope drains. (src/cli/capability-cli/model.ts:198, 0b5e973c7d0c)
  • Current main still needs the fix: Fetched main calls prepareSimpleCompletionModelForAgent before dispatch. That helper acquires and immediately releases its lease at lines 551–557. The release-tag source lookup failed because its required blob was unavailable; no shipped-fix claim is made. (src/cli/capability-cli/model.ts:196, 4fce9c9e6e33)
  • Production cleanup integration: Commander parsing runs within the invocation resource owner. Its finalizer joins registered work before releasing resources; provider callback and cancellation promises enter the inner scope through observePendingProviderWork. (src/cli/run-main.ts:1685, 0b5e973c7d0c)
  • Transport ownership contract: The in-repository AI transport reports pending callback and cancellation work to the host. This establishes the relevant dependency boundary; the unchanged Codex rejection branch does not depend on executing or inspecting the Codex harness. (packages/ai/src/transports/transport-stream-shared.ts:322, 0b5e973c7d0c)
  • Focused regression coverage: Read all four loopback scenarios: overlap, provider rejection, callback drainage, and response-body cancellation drainage. They exercise real model preparation and transport, check generation reuse while work remains active, and require a new generation after release. Tests were not executed during this read-only review. (src/cli/capability-cli/model.resources.test.ts:24, 0b5e973c7d0c)
  • Reported validation and review continuity: The supplied body reports three failing-before/passing-after lifecycle regressions, a provider-error control, compiled CLI loopback success/error/success runs, and 252 composition tests after refresh. These are author-reported results, not reviewer executions. The prior completed review covered this same head and recorded no findings. (0b5e973c7d0c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Ayaan Zaidi: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-09T17:50:01.622Z sha 0b5e973 :: needs maintainer review before merge. :: none

@steipete
steipete merged commit 0fadfb4 into main Sep 9, 2026
166 of 167 checks passed
@steipete
steipete deleted the codex/cli-model-completion-resources branch September 9, 2026 18:16
@steipete

steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

cli CLI command changes maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary 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.

1 participant