Skip to content

Build: Retry-mechanism for dts bundle-generation#34212

Merged
yannbf merged 1 commit into
nextfrom
norbert/dts-sequential-generation
Mar 23, 2026
Merged

Build: Retry-mechanism for dts bundle-generation#34212
yannbf merged 1 commit into
nextfrom
norbert/dts-sequential-generation

Conversation

@ndelangen
Copy link
Copy Markdown
Member

@ndelangen ndelangen commented Mar 19, 2026

What I did

We run dts bundling on 5 entrypoints at a time.
This is usually fine, however occasionally we run into the problem where entrypoint A uses entrypoint B.
This is fine, of course, but then if entrypoint B is at that time getting generated, the file might be partially written.
When entrypoint A then tries to load the b.d.ts file it will error and yield a "not a valid module".

I've tried a few things to solve this, but ultimately landed on a retry mechanism, because everything else i tried to make the system more predictable had severe performance implications.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

I manually ran the compile step a few times, and I noticed no changes, no regressions.

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

Release Notes

  • Bug Fixes
    • Implemented automatic retry mechanism for type declaration file generation during the build process. Failed generation processes are now automatically retried up to two times with a 500-millisecond delay between attempts before the build fails, improving overall reliability when facing transient errors. Enhanced logging for retry events.

@ndelangen ndelangen self-assigned this Mar 19, 2026
@ndelangen ndelangen added build Internal-facing build tooling & test updates ci:normal labels Mar 19, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 19, 2026

View your CI Pipeline Execution ↗ for commit afe1be1

Command Status Duration Result
nx run-many -t compile -c production --parallel=1 ✅ Succeeded 5m 26s View ↗

☁️ Nx Cloud last updated this comment at 2026-03-20 09:40:33 UTC

} else if (!process.env.CI) {
console.log('✅ Generated types for', picocolors.cyan(join(DIR_REL, entryPoint)));
if (dtsProcess.exitCode !== 0) {
if (attempt < MAX_DTS_ATTEMPTS) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If you reach max attempts, could it be worth printing an error message that says "This part of the build is known to be flaky, but failed ${MAX_ATTEMPTS} times in a row. Consider re-running the CI job."?

It helps external human contributors if we point out, in CI failures, which ones we suspect to be flaky vs which ones are probably caused by their code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The build might also actually be broken @Sidnioulz

@yannbf yannbf added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Mar 20, 2026
@yannbf yannbf marked this pull request as ready for review March 20, 2026 09:25
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

Added bounded retry logic to TypeScript declaration file generation in generate-types.ts. The process now retries failed d.ts generation attempts up to 2 times with a 500ms delay between retries before executing the original failure behavior. Process cleanup and timeout handling remain unchanged.

Changes

Cohort / File(s) Summary
TypeScript Declaration Generation Retry Logic
scripts/build/utils/generate-types.ts
Implemented retry mechanism for per-entry d.ts generation with MAX_DTS_ATTEMPTS=2 and RETRY_DELAY_MS=500ms. On process failure, removes failed process from tracking list, waits, and retries. Preserves original failure handling (logging, process termination, exit code reporting) after exhausting retries. No public API changes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
📝 Coding Plan
  • Generate coding plan for human review comments

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

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 `@scripts/build/utils/generate-types.ts`:
- Line 70: The timeout branch currently calls dtsProcess.kill(408) using an
invalid numeric signal; update the timeout handler in generate-types.ts to call
dtsProcess.kill('SIGTERM') (use the string signal name) so the child is
terminated with a valid Unix signal; optionally follow up by checking the
process state or falling back to dtsProcess.kill('SIGKILL') if the graceful
SIGTERM does not stop the process.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7217d3aa-aca8-4202-b4cb-0004b116dec1

📥 Commits

Reviewing files that changed from the base of the PR and between 2121254 and afe1be1.

📒 Files selected for processing (1)
  • scripts/build/utils/generate-types.ts

}, 120000);
}),
]);
dtsProcess.kill(408); // timed out
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check if this pattern (kill(408)) exists elsewhere in the codebase and whether it's intentional
rg -n 'kill\(408\)' --type ts

Repository: storybookjs/storybook

Length of output: 156


🏁 Script executed:

cat -n scripts/build/utils/generate-types.ts | sed -n '50,85p'

Repository: storybookjs/storybook

Length of output: 1569


🏁 Script executed:

# Check Node.js documentation or comments about kill() and signal values
rg -B3 -A3 'kill\(408\)' scripts/build/utils/generate-types.ts

Repository: storybookjs/storybook

Length of output: 314


🏁 Script executed:

# Check if there are any TypeScript type definitions or comments in the file about process signals
rg -i 'signal|timeout' scripts/build/utils/generate-types.ts | head -20

Repository: storybookjs/storybook

Length of output: 273


Replace kill(408) with a valid Unix signal.

The value 408 is not a recognized Unix signal and will be silently ignored, causing the timeout mechanism to fail. Standard signals are 1–31 (e.g., SIGTERM = 15, SIGKILL = 9). Use 'SIGTERM' to gracefully terminate the process.

Suggested fix
-                dtsProcess.kill(408); // timed out
+                dtsProcess.kill('SIGTERM'); // timed out
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
dtsProcess.kill(408); // timed out
dtsProcess.kill('SIGTERM'); // timed out
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/build/utils/generate-types.ts` at line 70, The timeout branch
currently calls dtsProcess.kill(408) using an invalid numeric signal; update the
timeout handler in generate-types.ts to call dtsProcess.kill('SIGTERM') (use the
string signal name) so the child is terminated with a valid Unix signal;
optionally follow up by checking the process state or falling back to
dtsProcess.kill('SIGKILL') if the graceful SIGTERM does not stop the process.

@storybook-app-bot
Copy link
Copy Markdown

Package Benchmarks

Commit: afe1be1, ran on 20 March 2026 at 09:37:47 UTC

The following packages have significant changes to their size or dependencies:

@storybook/react-native-web-vite

Before After Difference
Dependency count 121 124 🚨 +3 🚨
Self size 30 KB 30 KB 0 B
Dependency size 23.54 MB 23.78 MB 🚨 +240 KB 🚨
Bundle Size Analyzer Link Link

@yannbf yannbf merged commit 7801015 into next Mar 23, 2026
138 of 143 checks passed
@yannbf yannbf deleted the norbert/dts-sequential-generation branch March 23, 2026 12:53
valentinpalkovic pushed a commit that referenced this pull request Apr 2, 2026
…eration

Build: Retry-mechanism for dts bundle-generation
(cherry picked from commit 7801015)
@github-actions github-actions Bot mentioned this pull request Apr 2, 2026
19 tasks
@github-actions github-actions Bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build Internal-facing build tooling & test updates ci:normal patch:done Patch/release PRs already cherry-picked to main/release branch patch:yes Bugfix & documentation PR that need to be picked to main branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants