Skip to content

Keep watch alive after rebuild errors - #8641

Open
fhammerschmidt wants to merge 6 commits into
masterfrom
fix/watch-rebuild-recovery
Open

fhammerschmidt wants to merge 6 commits into
masterfrom
fix/watch-rebuild-recovery

Conversation

@fhammerschmidt

@fhammerschmidt fhammerschmidt commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

A config or source-layout change that made full rebuild initialization fail caused watch mode to panic or exit. Initialization errors now propagate through the build lock, are reported to the user, and keep the watcher alive for recovery.

After initialization fails, later source edits retry full initialization until the current configuration can be loaded. They cannot emit outputs using the previous suffix, dependencies, or compiler options. Malformed dependency configs also return errors instead of exiting the process, retaining their resolved directory so the watcher can observe a correction to a newly added dependency. Dependency resolution failures retain their package-tree context and dependency name when propagated to the CLI.

Dependency resolution and configuration failures now return exit code 1 instead of 2 from rescript build, clean, and format, using the CLI's normal error path. Dependency errors are reported once, retaining their package-tree context.

Recovery limit: installing a missing dependency or replacing a non-local dependency directory does not itself trigger a retry. After installation or replacement, edit a watched source file or touch rescript.json to retry initialization. Automatic detection of these installation changes remains a follow-up.

Add regressions for editing a source while the root config is invalid, recovering with a changed suffix, and fixing only a newly added workspace dependency's config. The invalid-config test waits for the edited source's event to select full reinitialization and for an initialization failure after that event, so delayed config events cannot satisfy the assertion. The integration tests use the shared platform-aware polling helpers and stop cleanup if watcher shutdown fails.

Validation:

  • make passes with the native watcher backend.
  • cargo test --manifest-path rewatch/Cargo.toml passes: 145 tests.
  • All 41 build fixtures pass, including missing regular and development dependencies.
  • Clippy with all targets/features and warnings denied, Rust formatting, and shell syntax checks pass.
  • Both focused watcher integration scripts pass with an isolated polling-backend build that supplies native-style content-change events. Disabling full reinitialization after a source edit makes the strengthened invalid-config test fail and reproduces stale output. Native macOS filesystem events are unavailable in this environment, including outside the sandbox; native platform integration remains for CI.

@fhammerschmidt
fhammerschmidt marked this pull request as ready for review September 10, 2026 09:25
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T14:22:30.923223Z f83cd4f Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from 26da9d5 to 38467bf Compare September 10, 2026 10:58
@fhammerschmidt
fhammerschmidt changed the base branch from master to fix/clean-invalid-projects September 10, 2026 10:59
@fhammerschmidt
fhammerschmidt added this pull request to stack #8642 September 10, 2026 10:59
@fhammerschmidt
fhammerschmidt force-pushed the fix/clean-invalid-projects branch from 96c35a5 to 9760751 Compare September 10, 2026 11:16
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from 38467bf to 527e72a Compare September 10, 2026 11:16
@fhammerschmidt
fhammerschmidt force-pushed the fix/clean-invalid-projects branch from 9760751 to 9f7e428 Compare September 10, 2026 11:20
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from 527e72a to 95cbeca Compare September 10, 2026 11:20
@fhammerschmidt
fhammerschmidt force-pushed the fix/clean-invalid-projects branch from 9f7e428 to a90a656 Compare September 10, 2026 11:38
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from 95cbeca to 08c262a Compare September 10, 2026 11:40
@fhammerschmidt
fhammerschmidt force-pushed the fix/clean-invalid-projects branch from a90a656 to 766e69a Compare September 10, 2026 11:44
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from 08c262a to 23913a4 Compare September 10, 2026 11:44
@fhammerschmidt
fhammerschmidt force-pushed the fix/clean-invalid-projects branch from 766e69a to 35b5524 Compare September 11, 2026 13:46
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from 23913a4 to 4cc230a Compare September 11, 2026 13:46
@fhammerschmidt
fhammerschmidt force-pushed the fix/clean-invalid-projects branch from 35b5524 to 60b4bb6 Compare September 11, 2026 13:49
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from 4cc230a to 784f83f Compare September 11, 2026 13:49
@fhammerschmidt
fhammerschmidt force-pushed the fix/clean-invalid-projects branch from 60b4bb6 to 5cea2cf Compare September 11, 2026 14:03
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from 784f83f to bb678d0 Compare September 11, 2026 14:03
@fhammerschmidt
fhammerschmidt force-pushed the fix/clean-invalid-projects branch from 5cea2cf to 7132187 Compare September 11, 2026 15:38
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from bb678d0 to 52e838b Compare September 11, 2026 15:38
@fhammerschmidt
fhammerschmidt force-pushed the fix/clean-invalid-projects branch from 7132187 to a32a29e Compare September 11, 2026 16:41
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch 2 times, most recently from a4a65f3 to 3e45f81 Compare September 11, 2026 20:24
@fhammerschmidt
fhammerschmidt removed this pull request from stack #8642 September 11, 2026 20:25
@fhammerschmidt
fhammerschmidt changed the base branch from fix/clean-invalid-projects to fix/watch-config-test-timeout September 11, 2026 20:25
@fhammerschmidt
fhammerschmidt added this pull request to stack #8650 September 11, 2026 20:25
@pkg-pr-new

pkg-pr-new Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8641

@rescript/belt

npm i https://pkg.pr.new/@rescript/belt@8641

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8641

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8641

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8641

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8641

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8641

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8641

commit: fef2886

Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
@fhammerschmidt
fhammerschmidt removed this pull request from stack #8650 October 9, 2026 13:07
@fhammerschmidt
fhammerschmidt force-pushed the fix/watch-rebuild-recovery branch from 5e7c5a1 to 3377441 Compare October 9, 2026 13:09
@fhammerschmidt
fhammerschmidt changed the base branch from fix/watch-config-test-timeout to master October 9, 2026 13:10
@fhammerschmidt

Copy link
Copy Markdown
Member 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: 3377441a3d

ℹ️ 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 rewatch/src/watcher.rs
Comment thread rewatch/src/watcher.rs
Comment thread rewatch/tests/watch/07-watch-recovers-from-invalid-config.sh Outdated
Comment thread rewatch/tests/watch/07-watch-recovers-from-invalid-config.sh Outdated
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
@fhammerschmidt

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: f83cd4ffd8

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

Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
@github-actions

Copy link
Copy Markdown

@cknitt

cknitt commented Oct 13, 2026

Copy link
Copy Markdown
Member

🤖 This review was generated by Claude (Claude Code) on behalf of @cknitt.

Verdict: approve with nits. No correctness bugs found in the watch loop. Init errors propagate instead of panicking. initialization_failed forces a full re-init rather than an incremental build on stale state. Every fallible step in initialize_build runs before cleanup_previous_build, so a failed init leaves nothing half-cleaned. Both new tests fail without the fix.

  • Exit code change: the two process::exit(2) calls in packages.rs are gone and main.rs's exit_code returns 1. rescript build/clean/format now exit 1 instead of 2 when a dependency is missing or has a malformed config. weird_deps/weird_devdeps only assert != 0, so CI doesn't catch it. Please acknowledge it in the PR/changelog, or keep 2.
  • Missing dependency dir gets no recovery watch: only DependencyConfigError adds one. Example: a dependency added to rescript.json before npm install. Finishing the install produces no event, so watch stays failed until a .res file or rescript.json is touched. The same happens when a non-local dependency with a bad config is reinstalled, because the directory is replaced. Still far better than exiting; could be documented, or the root node_modules watched non-recursively while init is failing.
  • Duplicate test number: 07-watch-recovers-from-invalid-config.sh sits next to the existing 07-changed-interface-after-failed-implementation.sh. Renumber the new ones to 08/09.
  • Test 07 can pass without proving anything: if the mv of the invalid config spans two debounce windows, a second init failure can bump initial_errors before the Test.res edit is processed, and the "no marker in Test.mjs" check then passes trivially. This can't cause a flaky failure, only a false pass. Waiting for a marker tied to the edit would tighten it.
  • Nits:
    • With show_progress, dependency errors are printed twice (inspect_err in packages.rs, then eprintln!("{error:#}")).
    • The rustfmt re-indent in watcher.rs (~509-540) and packages.rs makes the diff noisier.
    • Out of scope, but other panics can still kill watch mode after a config change, e.g. "JSX version {v} is unsupported" (config.rs:834) and .expect("Could not canonicalize") (packages.rs:562). Possible follow-up.

Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>
@codecov

codecov Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.51%. Comparing base (8d51b9c) to head (fef2886).
⚠️ Report is 26 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8641      +/-   ##
==========================================
+ Coverage   80.40%   80.51%   +0.10%     
==========================================
  Files         447      447              
  Lines       60990    61060      +70     
==========================================
+ Hits        49042    49162     +120     
+ Misses      11948    11898      -50     

see 37 files with indirect coverage changes

🚀 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.

Log the source event path and its requested compile type once, then wait for the edited source to request full initialization and for an error after that event. Delayed config failures can no longer satisfy the recovery assertion before the edit is processed.

Signed-off-by: Florian Hammerschmidt <florianh89@gmail.com>

Copy link
Copy Markdown
Member Author

The follow-ups document the exit-code change and dependency-install recovery limit, renumber the tests, and remove duplicate diagnostics. The recovery regression now waits for the source event and a subsequent initialization failure; disabling recovery makes it fail and reproduces stale output. Automatic detection of newly installed or replaced dependencies remains a follow-up; editing a watched source or touching rescript.json triggers recovery. CI, including the package-installation checks, coverage, and changelog validation now all pass.

This branch has not been deployed

No deployments
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