Skip to content

fix(extensions): allow final esbuild stop loss before close - #3732

Merged
kwakayama merged 2 commits into
mainfrom
fix/agent-run-exit-close-recovery
Aug 15, 2026
Merged

fix(extensions): allow final esbuild stop loss before close#3732
kwakayama merged 2 commits into
mainfrom
fix/agent-run-exit-close-recovery

Conversation

@kojiwakayama

@kojiwakayama kojiwakayama commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up to merged #3718. The original PR was merged and its source branch was deleted before the tested repair for the exit-before-close recovery race could be pushed.

This PR fixes the remaining esbuild child lifecycle race where a managed service can emit exit before close, leaving the dead child tracked while stop() consumes the final restart budget. The stop path now remembers whether the current stop call already charged the observed loss, so the final permitted loss is not converted into a permanent ownership failure before close clears tracking.

Verification

Red evidence on fresh origin/main before the fix:

  • Applied only the new regression test, then ran deno test --preload=src/testing/preload.ts --no-check --allow-all extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts
  • The new test failed with: Cannot verify closure of an externally owned esbuild service; restart the process

Green evidence on this branch:

  • deno test --preload=src/testing/preload.ts --no-check --allow-all extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts -> 8 passed (39 steps), 0 failed
  • deno test --preload=src/testing/preload.ts --no-check --allow-all extensions/ext-bundler-esbuild/src/binary.test.ts extensions/ext-bundler-esbuild/src/es-module-lexer.test.ts extensions/ext-bundler-esbuild/src/index.test.ts -> 4 passed (8 steps), 0 failed
  • deno check extensions/ext-bundler-esbuild/src/esbuild-bundler.ts extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts
  • deno lint extensions/ext-bundler-esbuild/src/esbuild-bundler.ts extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts
  • deno fmt --check extensions/ext-bundler-esbuild/src/esbuild-bundler.ts extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts
  • git diff --check
  • Full local pre-push hook passed before push: format check, lint, root typecheck, unit suite (3816 passed (28529 steps), 0 failed, 1 ignored), cwd tests (10 passed), cwd-exclusion tests (2 passed)

Note: the globbed command deno test --preload=src/testing/preload.ts --no-check --allow-all extensions/ext-bundler-esbuild/src/*.test.ts showed the tests passing but exited with Deno's pending-promise warning when those extension test files were run together. The same coverage passed when split as above.

Risk

Narrow lifecycle accounting change in the esbuild extension. PR is intentionally draft while remote CI runs.

Summary by CodeRabbit

  • Bug Fixes
    • Improved recovery when the bundling service stops unexpectedly during shutdown.
    • Prevented valid final recovery attempts from being rejected prematurely.
    • Ensured subsequent service failures correctly stop processing once the recovery limit has been reached.
    • Improved error handling and reliability for transformations following service interruptions.

A managed esbuild child can emit exit before close, leaving the dead child tracked while stop consumes the final restart budget. The stop path now remembers that it already charged that observed loss, so it does not immediately convert the final permitted loss into a permanent ownership failure before close clears tracking.

Constraint: PR #3718 was merged and its source branch deleted before this repair could be pushed.

Rejected: Recreate the deleted PR branch | the PR is already merged and branch recreation would mutate closed PR state outside the requested guarded push.

Confidence: high

Scope-risk: narrow

Directive: Keep stop budget accounting tied to whether the current stop call charged the observed service loss; do not latch on the post-decrement zero state for the same loss.

Tested: Red failure with esbuild-bundler.test.ts before implementation.

Tested: deno test --preload=src/testing/preload.ts --no-check --allow-all extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts

Tested: deno test --preload=src/testing/preload.ts --no-check --allow-all extensions/ext-bundler-esbuild/src/*.test.ts

Tested: deno check extensions/ext-bundler-esbuild/src/esbuild-bundler.ts extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts

Tested: deno lint extensions/ext-bundler-esbuild/src/esbuild-bundler.ts extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts

Tested: deno fmt --check extensions/ext-bundler-esbuild/src/esbuild-bundler.ts extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts

Not-tested: Full pre-push E2E gate; follow-up PR remains draft for CI.
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kojiwakayama, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 19 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 00bd3189-57d9-48ee-a6c2-db381c98fe6b

📥 Commits

Reviewing files that changed from the base of the PR and between 962d3b4 and 5c3e5e2.

📒 Files selected for processing (1)
  • extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6747c7e6-10a3-4f63-a464-c48f525dc49a

📥 Commits

Reviewing files that changed from the base of the PR and between b9042ee and 962d3b4.

📒 Files selected for processing (2)
  • extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts
  • extensions/ext-bundler-esbuild/src/esbuild-bundler.ts

📝 Walkthrough

Walkthrough

The change updates EsbuildBundler.stop() to handle the final restart-budget charge correctly. A lifecycle test covers service loss between the exit and close events, recovery, and subsequent budget exhaustion.

Changes

Esbuild restart recovery

Layer / File(s) Summary
Stop budget handling and lifecycle validation
extensions/ext-bundler-esbuild/src/esbuild-bundler.ts, extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts
stop() excludes its own restart-budget charge from the later exhaustion check. The lifecycle test verifies shutdown, recovery, and rejection after the next service loss.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 962d3

This narrowly fixes esbuild stop/close lifecycle accounting and adds regression coverage; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: kwakayama

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the fix for the esbuild stop-loss race before the close event.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/agent-run-exit-close-recovery

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

📦 Client bundle boundary

Entrypoint Modules Source size Server leaks
src/index.client.ts 454 3065 KiB ⚠️ 39 known

A server module in a client graph aborts hydration in the browser. New leaks fail CI; known leaks are tracked in scripts/lint/client-bundle-baseline.json to burn down.

@kojiwakayama
kojiwakayama marked this pull request as ready for review August 14, 2026 22:48
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Something went wrong. Try again later by commenting “@codex review”.

Unknown error
ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 962d3b429d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 962d3b429d

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts
@kojiwakayama
kojiwakayama marked this pull request as draft August 14, 2026 23:07
The follow-up recovery tests must use the repository assertion surface so Deno and Node test environments stay aligned. This changes only the assertion import and leaves the recovery behavior untouched.

Constraint: Codex review requires new assertions to come from #veryfront/testing/assert.ts rather than @std/assert.

Confidence: high

Scope-risk: narrow

Tested: PATH=/tmp/deno-2.7.7-aarch64-apple-darwin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/pmk/env/global/bin:/Library/Apple/usr/bin:/Applications/VMware Fusion.app/Contents/Public:/opt/homebrew/lib/node_modules/@openai/codex/node_modules/@openai/codex-darwin-arm64/vendor/aarch64-apple-darwin/codex-path:/Users/kojiwakayama/.codex/tmp/arg0/codex-arg0xChlGW:/private/tmp/claude-501/-Users-kojiwakayama-Documents-CODE-veryfront-platform-veryfront-code/9f9d23dd-dfdc-4463-9a99-bd5a663046c9/scratchpad/idx09/deno277/bin:/private/tmp/claude-501/-Users-kojiwakayama-Documents-CODE-veryfront-platform-veryfront-code/9f9d23dd-dfdc-4463-9a99-bd5a663046c9/scratchpad/idx13/deno277/bin:/private/tmp/claude-501/-Users-kojiwakayama-Documents-CODE-veryfront-platform-veryfront-code/9f9d23dd-dfdc-4463-9a99-bd5a663046c9/scratchpad/idx26-deno277/bin:/Users/kojiwakayama/Documents/CODE/agent-lab/.venv/bin:/Users/kojiwakayama/.veryfront/bin:/Users/kojiwakayama/.opencode/bin:/Users/kojiwakayama/.local/bin:/Users/kojiwakayama/.antigravity/antigravity/bin:/opt/homebrew/share/google-cloud-sdk/bin:/opt/homebrew/opt/openjdk/bin:/Users/kojiwakayama/.bun/bin:/Users/kojiwakayama/.krew/bin:/Applications/Visual Studio Code.app/Contents/Resources/app/bin:/Users/kojiwakayama/.nvm/versions/node/v24.18.0/bin:/Users/kojiwakayama/.cargo/bin:/Applications/Docker.app/Contents/Resources/bin/:/Users/kojiwakayama/.lmstudio/bin:/Applications/Warp.app/Contents/Resources/bin deno check extensions/ext-bundler-esbuild/src/esbuild-bundler.test.ts

Tested: git diff --check

Not-tested: Focused esbuild-bundler test completes assertions but exits with a pre-existing pending-promise teardown error on this machine; same failure reproduces with the original @std/assert import.
@kojiwakayama
kojiwakayama marked this pull request as ready for review August 14, 2026 23:28
@kojiwakayama

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 5c3e5e27f0

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@kwakayama
kwakayama added this pull request to the merge queue Aug 15, 2026
Merged via the queue into main with commit 19cf053 Aug 15, 2026
34 checks passed
@kwakayama
kwakayama deleted the fix/agent-run-exit-close-recovery branch August 15, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants