Skip to content

fix: use buildMtime for daemon stale detection, preserve port on restart#42

Merged
piotrski merged 1 commit into
mainfrom
fix/daemon-auto-restart-v2
Mar 17, 2026
Merged

fix: use buildMtime for daemon stale detection, preserve port on restart#42
piotrski merged 1 commit into
mainfrom
fix/daemon-auto-restart-v2

Conversation

@piotrski
Copy link
Copy Markdown
Collaborator

@piotrski piotrski commented Mar 16, 2026

Summary

Follow-up to #41 which introduced daemon auto-restart but had two bugs:

  1. Port lost on restartensureDaemon() restarted the daemon with port = undefined (most CLI commands don't pass a port), silently switching to 8097. Now preserves the original info.port.

  2. False restarts in CI — comparing daemon.js mtime against startedAt was fragile: when build and daemon start happened close together, filesystem timestamp precision could make them appear out of order.

New approach

The daemon now records daemon.js's mtime at startup as buildMtime in daemon.json. The CLI compares the file's current mtime against this stored value — if they differ, the file was rebuilt and the daemon restarts. No tolerance or clock comparison needed.

Changes

  • DaemonInfo gains optional buildMtime field
  • Daemon writes daemon.js mtime to daemon.json on startup
  • ensureDaemon() compares current mtime vs stored buildMtime
  • Port is preserved from info.port when restarting

E2E test

New daemon-auto-restart.test.ts uses the full CLI lifecycle (start/stop/get tree) to verify:

  • Daemon restarts (new PID, same port) when buildMtime doesn't match
  • Daemon stays alive when buildMtime matches

Test plan

  • 68 unit tests pass
  • 34 e2e tests pass (including new auto-restart tests)
  • CI green

🤖 Generated with Claude Code

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 16, 2026

⚠️ No Changeset found

Latest commit: 7c2373b

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Copy Markdown

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

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: 094a7c8f32

ℹ️ 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 packages/agent-react-devtools/src/daemon-client.ts Outdated
@piotrski piotrski force-pushed the fix/daemon-auto-restart-v2 branch 2 times, most recently from 3d68f26 to 1d2fd15 Compare March 16, 2026 14:55
@piotrski piotrski changed the title fix: preserve port on daemon auto-restart, add e2e tests fix: preserve port on daemon auto-restart, add tolerance and e2e tests Mar 16, 2026
@piotrski piotrski force-pushed the fix/daemon-auto-restart-v2 branch from 1d2fd15 to de204a2 Compare March 16, 2026 15:01
@piotrski piotrski changed the title fix: preserve port on daemon auto-restart, add tolerance and e2e tests fix: use buildMtime for daemon stale detection, preserve port on restart Mar 16, 2026
Copy link
Copy Markdown

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

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: de204a26fd

ℹ️ 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 packages/agent-react-devtools/src/daemon-client.ts Outdated
Instead of comparing daemon.js mtime against startedAt (which is
fragile due to filesystem timestamp precision), the daemon now records
daemon.js mtime at startup in daemon.json. The CLI compares the current
mtime against this stored value — if they differ, the file was rebuilt.

Also preserve the original port when auto-restarting so daemons on
non-default ports don't silently switch to 8097.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@piotrski piotrski force-pushed the fix/daemon-auto-restart-v2 branch from de204a2 to 7c2373b Compare March 16, 2026 15:21
@piotrski piotrski merged commit 7816ee1 into main Mar 17, 2026
4 checks passed
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.

1 participant