Skip to content

fix: retain side-question resources through runtime cleanup - #143366

Merged
steipete merged 1 commit into
mainfrom
codex/btw-prepared-resources
Sep 9, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/btw-prepared-resources

Conversation

@steipete

@steipete steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Related: #140674

What Problem This Solves

Resolves a lifetime gap where /btw keeps using a published runtime without retaining its resources through the side question and cleanup. That prevents safe retirement of managed generations while admitted side work is still running.

Why This Change Was Made

Acquire the exact generation at the synchronous published-owner read, then retain it through side-question output, harness cleanup, and tracked descendants. Existing publication, standalone activation, configuration replacement, model selection, and catalog policy remain unchanged. The shared read policy moves into one internal module.

Parent cancellation and normal cleanup run in the captured generation context. The caller can receive its result before physical cleanup finishes, while the parent work owner still joins that cleanup.

User Impact

Side questions retain their prepared resources until admitted work finishes, including during replacement and cancellation. This prepares the path for managed resource disposal; ordinary configured/raw producer disposal is not enabled by this PR. No public option, backend policy, or database schema changes.

Evidence

Four lifetime cases fail against both original production files with premature SQLite closure. The combined case uses a real acquired plugin registration, the actual published loader and BTW harness path, delayed cleanup, replacement, exactly-once disposal, and database reopening. A test-only input adapter selects the existing owned read-only source; it does not enable configured disposal.

Final validation passed 81 BTW/native tests, 156 affected sibling tests, source-affected type/lint/Knip and remaining guard coverage, fresh isolated Codex review through P2, and a full build in 243.30 seconds. Counts overlap. Regression coverage includes parent MCP cancellation and normal cleanup context.

A strict plain-Node compiled run passed in 2.886 seconds with 12,120 unchanged artifacts and no application TypeScript/source fallback. It exercises actual built BTW on normal standalone publication, cancellation and cleanup context, plus actual built owned read-only published borrowing with SQLite close/reopen. Combined managed-source BTW composition is covered by the maintained native test. Cold BTW admission measured 241.82 ms; a warm call plus cleanup took 3.69 ms. These are local samples, not a comparative performance benchmark.

After rebasing onto current main, all five source files match the reviewed proof and all 81 composition cases pass again. No real external provider, packaged CLI, or native Codex execution is claimed; existing Codex interrupt/unsubscribe contracts were inspected and backend behavior is unchanged.

@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 agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 9, 2026
@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, 4:32 PM ET / 20:32 UTC (Revision 2).

ClawSweeper review

What this changes

The PR retains side-question runtime resources through answer production and background cleanup, and consolidates published-runtime selection into one internal helper.

Merge readiness

✅ Ready for maintainer review

This focused lifetime repair remains useful: current main still borrows the snapshot without retaining its resources. No actionable patch defects were found, and the previous draft blocker is resolved.

Priority: P2
Reviewed head: e794c8ded20d52e5ac105479981cb83283121fb2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-boundary repair with meaningful lifetime regressions and no identified correctness or security blocker.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Its body reports compiled BTW cancellation/cleanup and SQLite borrow/reopen observations; native tests cover the combined managed-source path, and this review did not rerun either.
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 maintainer-authored PR, so the external-contributor proof gate does not apply. Its body reports compiled BTW cancellation/cleanup and SQLite borrow/reopen observations; native tests cover the combined managed-source path, and this review did not rerun either.
Evidence reviewed 8 items Current main still needs the repair: At the fetched main revision, runBtwSideQuestion calls loadPreparedModelRuntimeSnapshot and enters the generation scope without acquiring a resource claim. The new published-owner module is absent from that revision. Release inclusion was not established; reading the release blob failed, so no shipped-fix claim is made.
Synchronous acquisition and unchanged selection policy: The introduced acquisition projects the selected owner into a lease before the snapshot crosses an await. The extracted selector preserves replacement waits, configuration matching, refresh rejection, and published-owner lookup; the new function has no plugin SDK consumers or exports.
Cleanup and authorization boundaries: The wrapper captures generation context for cancellation and drainage, lets the answer settle independently, and releases resources after tracked work. Existing harness-host closure, admitted-run closure, and caller message-capability revocation remain unchanged; the claim retains physical resources rather than granting execution authority.
Findings None None.
Security None None.

How this fits together

Side questions use the current conversation and a prepared model runtime to produce a separate answer. The runtime supplies plugin resources that must remain available until the question and its cooperating cleanup finish.

flowchart TD
  A[Side question and session context] --> B[Select published runtime]
  B --> C[Retain generation resources]
  C --> D[Run side question]
  D --> E[Return answer]
  D --> F[Join tracked cleanup]
  G[Parent cancellation] --> F
  F --> H[Release resource claim]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +106, Tests +419. Total +525 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 160 54 +106
Tests 2 424 5 +419
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 584 59 +525

Review metrics

None.

Technical review

Best possible solution:

Keep exact-generation resource borrowing internal and release it only after admitted side-question work and cleanup settle.

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

Yes, at the source boundary: release an owned publication while its borrowed side question or cleanup still uses the database. The added composition coverage models that ordering; no tests were executed during this read-only review.

Is this the best way to solve the issue?

Yes. Acquiring a physical resource claim during the existing published-owner lookup repairs the lifetime gap without changing activation, model selection, public APIs, or disposal policy.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded resource-lifetime repair preparing safe runtime retirement, without evidence of an urgent shipped 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 maintainer-authored PR, so the external-contributor proof gate does not apply. Its body reports compiled BTW cancellation/cleanup and SQLite borrow/reopen observations; native tests cover the combined managed-source path, and this review did not rerun either.

Evidence

What I checked:

  • Current main still needs the repair: At the fetched main revision, runBtwSideQuestion calls loadPreparedModelRuntimeSnapshot and enters the generation scope without acquiring a resource claim. The new published-owner module is absent from that revision. Release inclusion was not established; reading the release blob failed, so no shipped-fix claim is made. (src/agents/btw.ts:739, 227e2f4fe1c2)
  • Synchronous acquisition and unchanged selection policy: The introduced acquisition projects the selected owner into a lease before the snapshot crosses an await. The extracted selector preserves replacement waits, configuration matching, refresh rejection, and published-owner lookup; the new function has no plugin SDK consumers or exports. (src/agents/prepared-model-runtime.ts:175, e794c8ded20d)
  • Cleanup and authorization boundaries: The wrapper captures generation context for cancellation and drainage, lets the answer settle independently, and releases resources after tracked work. Existing harness-host closure, admitted-run closure, and caller message-capability revocation remain unchanged; the claim retains physical resources rather than granting execution authority. (src/agents/btw.ts:721, e794c8ded20d)
  • Meaningful resource-lifetime regression coverage: The complete new composition test exercises published borrowing, delayed harness cleanup, parent cancellation, replacement, exactly-once SQLite disposal, and reopening. Its input adapter selects an owned read-only source; ordinary configured-resource disposal remains disabled. The additional BTW cases cover harness errors and transport descendants after visible output. (src/agents/prepared-model-runtime.published-resources.test.ts:47, e794c8ded20d)
  • Recorded proof and its limits: The supplied body snapshot, sourceRevision b4faed18bb4f737621c33064c538237a42ffdcb5bb3eb5eba55e43be1b0b9871, reports a compiled plain-Node run of actual BTW publication/cancellation/cleanup and owned read-only SQLite borrowing, plus native composition regressions. It explicitly excludes real external-provider and native Codex execution. These are author-reported observations; this read-only review did not execute them. (e794c8ded20d)
  • Previous blocker resolved: The previous completed review had no findings and requested leaving draft state. A fresh REST read confirms this PR is open, unmerged, and no longer a draft at the same reviewed head. (e794c8ded20d)

Likely related people:

  • Peter Steinberger: Raw commit 73b4086 adds src/agents/prepared-model-runtime.resources.ts:161 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 73b4086ff658; files: src/agents/prepared-model-runtime.resources.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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-09T20:15:30.314Z sha e794c8d :: needs changes before merge. :: none

@steipete
steipete marked this pull request as ready for review September 9, 2026 20:25
@steipete
steipete merged commit c3f242f into main Sep 9, 2026
246 checks passed
@steipete
steipete deleted the codex/btw-prepared-resources branch September 9, 2026 20:54
@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

agents Agent runtime and tooling 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: L 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