fix(cloudflare): ignore unchanged env watch events#631
fix(cloudflare): ignore unchanged env watch events#631shawnsw wants to merge 1 commit intodmno-dev:mainfrom
Conversation
|
|
Thanks! |
|
@shawnsw - I am having a hard time recreating the issue locally. Can you give repro steps? |
|
@theoephraim On macOS, That also explains why you may not reproduce it locally: if your machine does not emit those extra events, the loop does not happen. The fix is harmless: re-resolve env on each watch event, compare the serialized resolved graph, and only restart when it actually changed. Real env changes still restart Wrangler. Repro:
|
…unchanged Builds on PR #631 by @shawnsw which added the debounce + cache equality check. Adds a 5-second idle threshold: if no restart has happened in the last 5 seconds, a save event will trigger a restart even when the resolved env graph is identical. This handles the case where a user saves a file again after a long idle period and expects the dev server to reload. Co-authored-by: Shawn <shawn@docnow.au>" Agent-Logs-Url: https://github.com/dmno-dev/varlock/sessions/785c3bab-96c9-480b-bcab-ec417ac2c52e Co-authored-by: theoephraim <1158956+theoephraim@users.noreply.github.com>
…anged (#635) * fix(cloudflare): debounce wrangler restarts and skip when env is unchanged Agent-Logs-Url: https://github.com/dmno-dev/varlock/sessions/ef8b4df3-0fb0-4ccb-b2e2-c90dac16c7d6 Co-authored-by: theoephraim <1158956+theoephraim@users.noreply.github.com> * fix(cloudflare): force restart after idle threshold even when env is unchanged Builds on PR #631 by @shawnsw which added the debounce + cache equality check. Adds a 5-second idle threshold: if no restart has happened in the last 5 seconds, a save event will trigger a restart even when the resolved env graph is identical. This handles the case where a user saves a file again after a long idle period and expects the dev server to reload. Co-authored-by: Shawn <shawn@docnow.au>" Agent-Logs-Url: https://github.com/dmno-dev/varlock/sessions/785c3bab-96c9-480b-bcab-ec417ac2c52e Co-authored-by: theoephraim <1158956+theoephraim@users.noreply.github.com> * fix(cloudflare): fix restart loop detection and idle threshold init Initialize lastRestartAt to Date.now() so the idle threshold guard works correctly on first file change. Move restartTimeout = undefined to only the skip/error paths so the exit handler can distinguish restart-kills from voluntary exits. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: theoephraim <1158956+theoephraim@users.noreply.github.com> Co-authored-by: Theo Ephraim <theo@dmno.dev> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
Rolled this into #635 - should be out shortly. Thanks!! |
Summary
fs.watch()events invarlock-wrangler devwhen the resolved env graph is unchangedRepro
On macOS,
varlock-wrangler devcan receive repeatedfs.watch()events for env source files even when their contents have not changed.In our case this showed up under
portlessas repeated events forapps/api/.env.schema, causingvarlock-wranglerto restart Wrangler in a loop.Root cause
varlock-wrangler devcurrently restarts Wrangler on every watched env file event after re-resolving env.That assumes every watch event represents a semantic env change, which is not always true on macOS.
Fix
Cache the last resolved serialized env graph and compare it after each watch event.
Only restart Wrangler when the newly resolved env graph differs from the previous one.
Why this is safe
This does not change how env is resolved.
It only skips restarts when the resolved env output is identical, so real env changes still trigger the existing restart path.