#15611: fix(gateway): invalidate hook transform cache on config reload
gateway
stale
size: XS
Cluster:
Hook and Gateway Improvements
## Summary
- The `transformCache` Map cached loaded transform functions forever
- Editing hook transform JS files on disk had no effect until gateway restart
- Node.js `import()` also has its own module cache
## Fix
- Clear `transformCache` when hook mappings are re-resolved during config reload
- Use cache-busting query parameter on dynamic `import()` URL to bypass Node.js module cache
## Test plan
- [x] Existing hooks-mapping tests pass
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR addresses hot-reloading of hook transform modules by (1) clearing the in-memory `transformCache` when hook mappings are re-resolved and (2) adding a cache-busting query param to the dynamic `import()` URL to bypass Node’s own module cache. It also aligns config default application in `readConfigFileSnapshot` and adds a test ensuring `clearCommandLane` rejects queued promises.
Main concern is the new `?t=${Date.now()}` import specifier: combined with clearing `transformCache` on reload, repeated config reloads can accumulate distinct module entries in Node’s module map over time. There’s also an unused exported `clearTransformCache()` helper that currently isn’t wired into the reload path.
<h3>Confidence Score: 3/5</h3>
- This PR is close to safe but has a real risk of memory growth in long-running gateways with repeated config reloads and hook transforms enabled.
- The functional intent (hot-reloading hook transforms) is clear and tests were added for the command queue behavior, but the `import()` cache-busting strategy uses ever-unique module specifiers (`?t=${Date.now()}`), which can accumulate in Node’s module cache across reloads once `transformCache` is cleared. Fixing the import invalidation approach (and/or limiting reload frequency/uniqueness) would improve safety.
- src/gateway/hooks-mapping.ts
<sub>Last reviewed commit: 234e8cf</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#16960: perf: skip cache-busting for bundled hooks, use mtime for workspace...
by mudrii · 2026-02-15
78.7%
#9603: fix: initialize global hook runner on plugin registry cache hit
by kevins88288 · 2026-02-05
77.3%
#10679: fix(hooks): invoke gateway_start and gateway_stop in lifecycle
by yassinebkr · 2026-02-06
77.0%
#20541: fix(hooks): clear internal hooks before plugins register
by ramarnat · 2026-02-19
75.4%
#7747: Gateway: add zero-latency hot-reload for agent bindings
by NikolasP98 · 2026-02-03
75.1%
#8121: fix(gateway): remove query parameter token support for hooks
by yubrew · 2026-02-03
73.5%
#13178: fix: dedup mapped hook dispatches to prevent Gmail Pub/Sub retries
by striking · 2026-02-10
73.4%
#13144: harden archive extraction, auth tokens, hook transforms, and queue ...
by qxlsz · 2026-02-10
72.8%
#22720: fix: notify sessions on invalid config during hot-reload
by jayleekr · 2026-02-21
72.7%
#6853: fix: fire internal hooks on sessions.reset RPC (TUI/webchat /new)
by hamiltonchua · 2026-02-02
72.6%