Skip to content
This repository was archived by the owner on Oct 16, 2026. It is now read-only.

fix(dev): zero-downtime rebuilds, reliable watching, no orphans, real logs and errors - #63

Merged
kody-bot merged 4 commits into
mainfrom
cursor/kody-dev-correctness-logs-354f
Oct 15, 2026
Merged

kody-bot merged 4 commits into
mainfrom
cursor/kody-dev-correctness-logs-354f

Conversation

@kentcdodds

@kentcdodds kentcdodds commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Stack: #63 → #58 → #61 → #59 → #60

Intent

Fix the kody dev correctness and logging problems found by hands-on testing on @kentcdodds/asteroids with --target mock (CLI 1.23.0, package-app-dev.js). First of five stacked PRs: correctness + logs → live reload → agent/JSON → ports/assets/speed → polish.

Door: two-way

Cleanup: none

Summary

  • No 503 on rebuild. Each rebuild starts a new workerd "generation" in its own dir. The proxy switches over only once the new one is listening. The old one drains in-flight requests (10s cap) and is then stopped. Requests that arrive mid-rebuild wait for it (10s cap), so a save never gets a 503 or the previous bundle.
  • Watcher no longer stalls. fs.watch recursive is replaced by chokidar v4, which re-arms when files are replaced (sed -i, cp, atomic saves). A 1s stat poll (ino:size:mtime) over the files in the current bundle graph backs it up.
  • No orphaned workerd. SIGINT/SIGTERM/SIGHUP and exit stop workerd and remove the kody-dev-* temp dir. A small detached /bin/sh reaper, fed tracked pids over a pipe, kills them and removes the dir if the CLI is SIGKILLed. Each start sweeps dirs and orphaned workerd left by dead CLI runs (owner.json), including older CLI versions.
  • App console.* always streams, tagged by request ([GET /scores #12] saved 3 rows). The app entry wraps console under AsyncLocalStorage. warn and error go to stderr.
  • Build errors carry file:line:col and a code frame. The header says "Could not bundle …" instead of "for local execute". Until the next good build, every request gets a dev 500 page (HTML for browsers, text otherwise, x-kody-dev-error: build), so a stale worker no longer keeps answering 200.
  • Runtime errors: esbuild source maps are kept in memory and stacks are mapped back to .ts (@jridgewell/trace-mapping). Runtime wrapper frames and workerd C++ prefixes and addresses are stripped. Uncaught errors become a dev-only 500 page with the stack.
  • New modules live under src/dev/: workerd-process, process-reaper, dev-watcher, dev-bundler, stack-trace, error-page, dev-events, dev-protocol. New dependencies: chokidar, @jridgewell/trace-mapping.

Testing

  • npm run validate passes.
  • New test/dev-server.test.ts covers: no non-200 responses while three rebuilds swap workerd; build error page with app/message.ts:1:24 and code frame, then recovery; tagged logs; a source-mapped runtime error; stack mapping; stderr cleanup; watcher ignore rules; the reaper killing pids and removing its dir when the pipe closes; and the stale-dir sweep.
  • Manual testing against the built CLI on a demo app:
    • Over 15 saves, 1.23.0 returned 64–70 non-200 responses; this branch returned 0.
    • Five break/fix cycles via sed -i and via cp + mv all recovered.
    • An edit after 70s idle was picked up.
    • /boom showed at Object.fetch (app/entry.ts:9:41).
    • SIGKILL of the CLI left no workerd and no temp dir.
    • A legacy orphan (ppid 1, two-hour-old dir) was reaped on the next start.

Runtime error page with the stack mapped to app/entry.ts

Open in Web Open in Cursor 

Note

Medium Risk
Large refactor of the local dev server (proxy, subprocess lifecycle, and workerd entry), but changes are confined to kody dev and not published runtime paths.

Reviewed by Cursor Bugbot for commit 755198d. Bugbot is set up for automated code reviews on this repo. Configure here.

… logs and errors

- Start the new workerd and swap only once it listens; drain the old one.
  Requests during a rebuild wait for it instead of getting a 503.
- Watch with chokidar plus a stat poll over the bundle graph so replaced
  files (sed -i, cp, atomic saves) can never leave a stale bundle serving.
- Detached sh reaper kills workerd and removes the work dir if the CLI dies;
  startup sweeps kody-dev-* dirs and orphaned workerd from dead CLIs.
- Stream app console.* (workerd stdout) tagged by request.
- Build errors carry file:line:col + code frame, drop the 'for local
  execute' wording, and are served as a 500 page until fixed.
- Uncaught handler errors return a dev-only 500 with the stack mapped to
  .ts sources; native frames and workerd C++ addresses are stripped.
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread src/package-app-dev.ts
Comment thread src/package-app-dev.ts Outdated
Comment thread src/dev/dev-watcher.ts Outdated
cursoragent and others added 2 commits October 15, 2026 06:09
…errors, watcher ready rejects

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor 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.

Stale Bugbot comment from a previous run.

Comment thread src/dev/dev-watcher.ts Outdated
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor 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.

Stale Bugbot comment from a previous run.

…y rejection

Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor 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.

Stale Bugbot comment from a previous run.

@kentcdodds

Copy link
Copy Markdown
Owner Author

bugbot run

@cursor cursor 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.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 755198d. Configure here.

@kody-bot
kody-bot merged commit 8744280 into main Oct 15, 2026
7 checks passed
@kody-bot
kody-bot deleted the cursor/kody-dev-correctness-logs-354f branch October 15, 2026 06:23
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 1.23.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants