Repository navigation
fix(dev): retain agent bundles while in use during watch invalidation - #1008
Merged
Merged
Conversation
Varun-S10
force-pushed
the
fix/issue-1002
branch
from
October 8, 2026 07:01
a6bb4b4 to
d7537cb
Compare
AmaadMartin
approved these changes
Oct 8, 2026
AmaadMartin
left a comment
Collaborator
There was a problem hiding this comment.
Approve. I checked the lease refcount, retire/dispose, and the preload generation guard against source at d7537cb. All request-path consumers now take a lease, and getRunner compares the loaded agent instance, which asRunnableRoot returns unchanged for agents and workflows, so the cache stays correct across reloads. The retain?.() optional chaining is load-bearing because the existing graph-endpoint mocks omit
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
When running
adk weboradk api_server, the server previously disposed the temporary compiled agent bundle right after loading the agent or immediately wheninvalidateAll()was triggered by a file change in watch mode. Because of this:import()orrequire()inside an agent or tool during/runfailed withERR_MODULE_NOT_FOUND/MODULE_NOT_FOUNDbecause the compiled.jsbundle file was already deleted from disk.invalidateAll()immediately deleted the bundle file that the active request was still using.invalidateAll(),AdkApiServercontinued reusing the old cachedRunnerinstance becauserunnerCacheonly checked the app name and not whether the loadedagentinstance had changed.Solution:
retain()andretire()) toAgentFile.await using _bundleLease = agentFile.retain?.()to active server requests inAdkApiServerinstead of disposing theAgentFileitself at the end of a request.AgentLoader.invalidateAll()to callretire()instead ofdispose(), so the old bundle stays on disk until all in-flight requests finish, and is then cleaned up automatically.preloadAgents()so bundles compiled before an invalidation are not cached as fresh.AdkApiServer.getRunner()to recreate the cachedRunnerwhen the loadedagentinstance changes after reload.Testing Plan
Unit Tests:
Also ran integration tests for
AgentLoader:Manual End-to-End (E2E) Tests:
import.meta.url/__dirnameand performs a dynamicimport()during/runexecution.AdkApiServerand sent aPOST /runrequest while triggeringagentLoader.invalidateAll()mid-request.HTTP 200and the old bundle stays on disk until the request finishes.POST /runrequests reload a fresh bundle and run the updated agent instance.Checklist
Additional context
N/A