Repository navigation
fix(dev): retain shared agent bundles across API requests - #983
jabrailkhalil wants to merge 2 commits into
Conversation
|
@Varun-S10 I have a focused fix for #969 ready here, with 10 offline regression cases covering both module formats and all affected request paths. The Google CLA check passed; the validation workflows are currently marked |
There was a problem hiding this comment.
Thanks for the fix and the detailed regression test.
A few non-blocking notes:
- Related race (follow-up, out of scope here): in watch mode,
invalidateAll()still disposes bundles that an in-flight/runmay be using. A lazy import during that run would hit the same missing-package error. It's probably worth a separate issue (ref-counting, or deferring disposal until in-flight runs finish). - Test runtime: the new test runs 10 cases, and each one compiles with esbuild. Please confirm it stays within the
integrationproject's time budget invitest.configonce CI runs (the workflows are still waiting on approval).
| * Returns a shared file owned by this loader. Callers must not dispose it; | ||
| * its compiled bundle is cleaned up on invalidation or {@link disposeAll}. | ||
| */ | ||
| async getAgentFile(agentName: string): Promise<AgentFile> { |
There was a problem hiding this comment.
Optional: since AgentFile still implements Symbol.asyncDispose (needed by cli_run.ts), await using loader.getAgentFile(...) still type-checks, and the bug could come back unnoticed. You could return a non-disposable view/interface type from getAgentFile() so the compiler catches it rather than relying on this comment.
There was a problem hiding this comment.
Agreed. I’d keep narrowing the loader’s public return type in a separate change.
| recursive: true, | ||
| }); | ||
| await fs.symlink( | ||
| path.resolve('core'), |
There was a problem hiding this comment.
Nit: path.resolve('core') depends on the process cwd being the repo root, and it only works if core has been built (resolution goes through its exports/dist). Could you resolve it relative to this file (e.g. via import.meta.url) or add a short comment noting the build prerequisite?
There was a problem hiding this comment.
Fixed in 9787563: the core path now resolves relative to this test file, and I added the build prerequisite.
| ).rejects.toMatchObject({code: 'ENOENT'}); | ||
| } finally { | ||
| await server.stop(); | ||
| await loader.disposeAll(); |
There was a problem hiding this comment.
Nit: server.stop() / loader.disposeAll() run both in the body (L139-140) and here. That's fine because both are idempotent, but it's a bit confusing to read. Moving the fixture setup into a helper would also make this long single test body easier to follow.
There was a problem hiding this comment.
The first cleanup is asserted by the test; finally handles failures before that point. I kept both so the bundle-removal assertion remains meaningful.
|
I re-ran all 10 cases with the unchanged integration timeouts: the longest took 3.22s locally against the 60s per-test limit. CI timing still needs confirmation. I also reproduced the watch-mode race in both module formats and tracked it separately in #1002. |
|
Related to #1008 |
|
Thanks @jabrailkhalil for diagnosing #969, writing the thorough CJS/ESM integration test, and filing #1002 for the watch-mode invalidation race! Since #1008 builds on the same fix to also handle reference-counted bundle retirement during watch-mode invalidation (#1002) and runner cache invalidation on reload, we're going to consolidate onto #1008 and carry your |
|
Thanks for carrying my tests and credit into #1008. Consolidating the lifecycle fixes there makes sense. |
Problem and solution
Closes #969.
Opening the graph in
adk webcan break the next agent run: the request disposes the shared preloadedAgentFile, deleting the compiled bundle and itsnode_moduleslink. A package imported lazily afterward then fails to resolve even though it is installed.I removed request-scoped disposal from the structure-graph, event-graph and run handlers. The loader keeps ownership and cleans up the bundle during invalidation or
disposeAll(). I also documented that ownership ongetAgentFile().Testing
I added an offline HTTP regression test using real esbuild compilation, an
AgentLoader, anAdkApiServerand local fixture packages. It covers CommonJS and ESM afterbuild_graph,build_graph_image, an event graph,/runand/run_sse. Each case then imports two previously unused packages in successive runs and verifies that explicit loader disposal removes the compiled directory. No model credentials or external model calls are needed.npm run build,npm run ts:check,npm run ts:check:samples,npm run lint,npm run format:checkandnpm run docs:check: passed.Test environment: Windows, Node.js 22.21.1; dependencies installed with
npm ci --ignore-scripts, matching the repository's validation workflow.To reproduce the regression test locally after building:
Checklist