Skip to content

fix(core): skip beforeClose hooks in metadataOnly mode#5904

Merged
killagu merged 6 commits intonextfrom
agent/egg-dev/rebuild-manifest-close
May 2, 2026
Merged

fix(core): skip beforeClose hooks in metadataOnly mode#5904
killagu merged 6 commits intonextfrom
agent/egg-dev/rebuild-manifest-close

Conversation

@killagu
Copy link
Copy Markdown
Contributor

@killagu killagu commented May 1, 2026

Summary

  • skip beforeClose callbacks when closing an app created with metadataOnly: true
  • cover both lifecycle beforeClose() and app.beforeClose() registrations with the metadata-only fixture
  • add a regression test to ensure metadata-only close stays side-effect free

Why

  • this is the local patch called out in the bundle validation thread: manifest-generation subprocesses should not trigger real app close hooks
  • rebuilding it as a clean PR on top of current next, instead of keeping it buried in the old split chain

Tests

  • pnpm exec vitest run packages/egg/test/start.test.ts

Refs EGG-4.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed metadata-only mode to properly skip beforeClose callbacks during application shutdown.
  • Documentation

    • Improved egg-bundler documentation with restructured table-based layouts for options and results.
  • Chores

    • Added Windows platform-specific optional dependency to improve system compatibility.

Copilot AI review requested due to automatic review settings May 1, 2026 14:53
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 1, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This PR implements conditional beforeClose handler execution based on metadata-only mode, skips beforeClose invocation when metadata-only is enabled, adds supporting test coverage with a fixture, updates egg-bundler documentation to tabular format, and adds a Windows-specific optional dependency.

Changes

Metadata-Only Close Behavior

Layer / File(s) Summary
Core Logic
packages/core/src/lifecycle.ts
Lifecycle.close() now branches on #metadataOnly: when enabled, clears #closeFunctionSet without invoking registered beforeClose functions; otherwise preserves reverse-order beforeClose execution with cleanup.
Test Fixture
packages/egg/test/fixtures/apps/metadata-only-app/app.js
Boot fixture now registers an app.beforeClose callback that appends 'app.beforeClose' to app.bootLog during shutdown.
Tests
packages/egg/test/start.test.ts
New test under "metadataOnly mode" suite verifies that closing a metadata-only app does not trigger beforeClose behavior, asserting app.bootLog remains ['loadMetadata'].

Documentation and Dependencies

Layer / File(s) Summary
Bundler Documentation
tools/egg-bundler/README.md
Options and Result sections restructured into Markdown tables for improved clarity and readability; option names and descriptions remain semantically unchanged.
Optional Dependency
package.json
Added Windows-specific optional dependency: @utoo/utoo-mingw64_nt-10.0-26100-x64 aliased to @utoo/utoo-win32-x64@1.0.28.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • jerryliang64

Poem

🐰 A lifecycle learns to skip with grace,
When metadata holds the quiet place,
No farewells for closing time,
Just bundled docs and deps so fine!

🚥 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 specifically describes the main change: skipping beforeClose hooks in metadataOnly mode, which is the primary behavioral modification across the codebase.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/egg-dev/rebuild-manifest-close

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 1, 2026

Deploying egg with  Cloudflare Pages  Cloudflare Pages

Latest commit: ca46307
Status: ✅  Deploy successful!
Preview URL: https://7fe3fcdb.egg-cci.pages.dev
Branch Preview URL: https://agent-egg-dev-rebuild-manife.egg-cci.pages.dev

View logs

@codecov
Copy link
Copy Markdown

codecov Bot commented May 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.03%. Comparing base (b25f913) to head (ca46307).
⚠️ Report is 4 commits behind head on next.

Additional details and impacted files
@@            Coverage Diff             @@
##             next    #5904      +/-   ##
==========================================
- Coverage   85.03%   85.03%   -0.01%     
==========================================
  Files         665      665              
  Lines       19104    19108       +4     
  Branches     3717     3719       +2     
==========================================
+ Hits        16246    16249       +3     
- Misses       2465     2466       +1     
  Partials      393      393              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 1, 2026

Deploying egg-v3 with  Cloudflare Pages  Cloudflare Pages

Latest commit: ca46307
Status: ✅  Deploy successful!
Preview URL: https://c159b383.egg-v3.pages.dev
Branch Preview URL: https://agent-egg-dev-rebuild-manife.egg-v3.pages.dev

View logs

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/core/src/lifecycle.ts`:
- Around line 257-265: The metadata-only early return in close() (when
this.#metadataOnly is true) skips running hooks but fails to clear the internal
close hook registry; update the metadata-only branch to also clear
this.#closeFunctionSet (and any related state if needed) before returning so
stale callback references are removed; locate the block checking
this.#metadataOnly in lifecycle.ts and add logic to clear this.#closeFunctionSet
(and/or reset its backing structure) alongside
removeAllListeners()/this.app.removeAllListeners() and setting this.#isClosed.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 08382e39-a703-4f35-975b-f7747387a01c

📥 Commits

Reviewing files that changed from the base of the PR and between 101ab97 and a6e2af4.

📒 Files selected for processing (3)
  • packages/core/src/lifecycle.ts
  • packages/egg/test/fixtures/apps/metadata-only-app/app.js
  • packages/egg/test/start.test.ts

Comment thread packages/core/src/lifecycle.ts Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR prevents beforeClose hooks from running when closing an app started in metadataOnly mode (used for manifest generation), and adds a regression test/fixture coverage to ensure metadata-only close remains side-effect free.

Changes:

  • Short-circuit Lifecycle.close() in metadataOnly mode to skip beforeClose callbacks.
  • Extend the metadata-only-app fixture to register an app.beforeClose() callback for regression coverage.
  • Add a test that asserts closing a metadata-only app does not trigger beforeClose callbacks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
packages/core/src/lifecycle.ts Adds an early-return close path for metadataOnly to skip beforeClose functions.
packages/egg/test/start.test.ts Adds a regression test for metadata-only close behavior (and adjusts surrounding tests).
packages/egg/test/fixtures/apps/metadata-only-app/app.js Registers an app.beforeClose() callback to validate the new close behavior.

Comment thread packages/egg/test/start.test.ts Outdated
Comment thread packages/core/src/lifecycle.ts Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the Lifecycle class to skip beforeClose functions when the application is in metadataOnly mode. It also includes a new test case to verify that these callbacks are correctly bypassed. A review comment identifies code duplication in the close method and suggests refactoring the cleanup logic into a common section to improve maintainability.

Comment thread packages/core/src/lifecycle.ts Outdated
Copilot AI review requested due to automatic review settings May 2, 2026 01:36
@killagu killagu force-pushed the agent/egg-dev/rebuild-manifest-close branch from 1ea1b61 to 6a9b5c9 Compare May 2, 2026 01:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread tools/egg-bundler/README.md
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@package.json`:
- Around line 87-89: The patchedDependencies entry currently pins "utoo@1.0.28"
which can be skipped if pnpm resolves a different 1.x version; update
consistency by either changing the catalog entry for utoo in pnpm-workspace.yaml
from "utoo: ^1" to an exact version "1.0.28" or by updating the
patchedDependencies key in package.json to match the actual resolved version
(e.g., "utoo@<resolved-version>"); ensure the symbol names to modify are
pnpm-workspace.yaml's utoo entry and package.json's patchedDependencies
"utoo@1.0.28" key so the patch is applied reliably.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 20466413-873f-44a6-a9af-73b307aba475

📥 Commits

Reviewing files that changed from the base of the PR and between 6a9b5c9 and 19c2696.

📒 Files selected for processing (2)
  • package.json
  • patches/utoo@1.0.28.patch
✅ Files skipped from review due to trivial changes (1)

Comment thread package.json Outdated
Copilot AI review requested due to automatic review settings May 2, 2026 02:37
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread packages/core/src/lifecycle.ts Outdated
Comment thread package.json
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
package.json (1)

85-87: Keep optionalDependencies version synchronized with the workspace catalog.

The aliased target @utoo/utoo-win32-x64@1.0.28 is published on npm and verified to exist. However, the hard-pinned version 1.0.28 in optionalDependencies is decoupled from the utoo: "catalog:" entry in devDependencies. When the catalog version of utoo is bumped, this entry must be updated manually or the mingw64 variant will ship with a mismatched binary version.

Add a comment to flag the sync requirement:

Suggested sync reminder
+  // NOTE: keep this version in sync with the `utoo` entry in the workspace catalog.
   "optionalDependencies": {
     "@utoo/utoo-mingw64_nt-10.0-26100-x64": "npm:`@utoo/utoo-win32-x64`@1.0.28"
   },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@package.json` around lines 85 - 87, Add an inline comment next to the
optionalDependencies entry for "@utoo/utoo-mingw64_nt-10.0-26100-x64" that
reminds maintainers to keep the aliased target version
"@utoo/utoo-win32-x64@1.0.28" in sync with the workspace catalog entry for
"utoo" in devDependencies (the catalog: version); mention that when the catalog
version is bumped the optionalDependencies alias must be updated to avoid
shipping a mismatched binary version.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@package.json`:
- Around line 85-87: Add an inline comment next to the optionalDependencies
entry for "@utoo/utoo-mingw64_nt-10.0-26100-x64" that reminds maintainers to
keep the aliased target version "@utoo/utoo-win32-x64@1.0.28" in sync with the
workspace catalog entry for "utoo" in devDependencies (the catalog: version);
mention that when the catalog version is bumped the optionalDependencies alias
must be updated to avoid shipping a mismatched binary version.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 79b45d94-332a-445b-a384-0da95126b63e

📥 Commits

Reviewing files that changed from the base of the PR and between 19c2696 and fdb7ecf.

📒 Files selected for processing (1)
  • package.json

@killagu killagu merged commit d73b90c into next May 2, 2026
36 of 38 checks passed
@killagu killagu deleted the agent/egg-dev/rebuild-manifest-close branch May 2, 2026 03:28
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