Repository navigation
Description
Description of the bug
When take_heapsnapshot writes a new capture to a .heapsnapshot path that an analysis tool has already loaded, every later analysis call on that path (get_heapsnapshot_details, query_heapsnapshot_objects, and the other tools that load a snapshot by path) silently returns results for the previous capture. The file on disk is the new capture, so the tools report data that no longer exists anywhere, with no warning. Only close_heapsnapshot followed by a new call makes the tools read the current file. This affects any workflow that reuses a file name across captures, such as repeated captures during a leak investigation.
Actual behavior
Observed with the fixture above on the release build:
details after 1st capture: Objects: 19797 / Total shallow size: 1,089 kB / 3,(array),69,137 kB,229 kB
evaluate_script: 500
take_heapsnapshot (2nd): Heap snapshot saved to <workspace>/snaps/same.heapsnapshot
details after overwrite: Objects: 19797 / Total shallow size: 1,089 kB / 3,(array),69,137 kB,229 kB
query after overwrite: 37255,LeakyThing,closure,7,0.0 kB,0.4 kB Showing 1-1 of 2
close_heapsnapshot: Closed heap snapshot: <workspace>/snaps/same.heapsnapshot
details after close: Objects: 21326 / Total shallow size: 3,114 kB / 3,(array),570,2,143 kB,2,235 kB
query after close: 48069,LeakyThing,object,6,0.0 kB,4.0 kB Showing 1-1 of 502
On the main build: 19376 objects before and after the overwrite and 20905 after close_heapsnapshot; the query matched 2 objects before closing and 502 after. The get_heapsnapshot_details call after the overwrite returned in 2-3 ms on both builds, compared with 121-150 ms for the first load and for the load after closing, consistent with no reload. No tool reported an error or warning. A larger fixture that also leaked detached DOM nodes, closures and listeners gave the same pattern on both builds (release: 19986 objects before and after the overwrite, 28801 after closing).
Reproduction
- Serve this page from a local HTTP server as
leak.html:
<!doctype html><title>Leak fixture</title>
<script>
class LeakyThing { constructor(i) { this.i = i; this.payload = new Array(1000).fill(i); } }
window.growing = [];
function leak() { for (let i = 0; i < 50; i++) window.growing.push(new LeakyThing(i)); }
</script>
- Send these tool calls in order on one server (both builds):
{"name":"new_page","arguments":{"url":"http://127.0.0.1:<port>/leak.html"}}
{"name":"take_heapsnapshot","arguments":{"pageId":2,"filePath":"<workspace>/snaps/same.heapsnapshot"}}
{"name":"get_heapsnapshot_details","arguments":{"filePath":"<workspace>/snaps/same.heapsnapshot","pageSize":1}}
{"name":"evaluate_script","arguments":{"pageId":2,"function":"() => { for (let i = 0; i < 10; i++) leak(); return growing.length; }"}}
{"name":"take_heapsnapshot","arguments":{"pageId":2,"filePath":"<workspace>/snaps/same.heapsnapshot"}}
{"name":"get_heapsnapshot_details","arguments":{"filePath":"<workspace>/snaps/same.heapsnapshot","pageSize":1}}
{"name":"query_heapsnapshot_objects","arguments":{"filePath":"<workspace>/snaps/same.heapsnapshot","className":"^LeakyThing$","pageSize":1}}
{"name":"close_heapsnapshot","arguments":{"filePath":"<workspace>/snaps/same.heapsnapshot"}}
{"name":"get_heapsnapshot_details","arguments":{"filePath":"<workspace>/snaps/same.heapsnapshot","pageSize":1}}
{"name":"query_heapsnapshot_objects","arguments":{"filePath":"<workspace>/snaps/same.heapsnapshot","className":"^LeakyThing$","pageSize":1}}
Expectation
take_heapsnapshot is documented as "Capture a heap snapshot of the target page", and each analysis tool is documented as "Loads a memory heapsnapshot and returns ..." for the given filePath. After the second capture replaces the file, the analysis tools should describe the file that is now at that path: the object count and shallow size should reflect the 500 retained LeakyThing instances and their arrays. close_heapsnapshot is documented only as "Closes a previously loaded memory heapsnapshot, freeing its memory", not as a step required to see a new capture.
MCP configuration
--headless --isolated --no-usage-statistics --no-performance-crux unless the reproduction states otherwise (update checks disabled with CHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS=1).
Chrome DevTools MCP version
1.10.1 (npm) and main 5ddb0a3 (local build)
Chrome version
154.0.8037.98 (stable)
Node version
v22.23.2
Operating system
macOS 27.0
Environment details
chrome-devtools-mcp1.10.1 from npm (the release build) and upstreammainat commit5ddb0a3110c5059f8e5513e566196cce2a35c6d1built from source (themainbuild).- Google Chrome 154.0.8037.98 (stable), Node.js v22.23.2, macOS 27.
- Server started with
--isolated --headless --no-usage-statistics --no-performance-crux --memoryDebuggingandCHROME_DEVTOOLS_MCP_NO_UPDATE_CHECKS=1, driven by a minimal stdio MCP client whose workspace root contains<workspace>/snaps/.
Evidence
- Expected source:
docs/tool-reference.mdMemory section on both builds (take_heapsnapshot"Capture a heap snapshot of the target page"; analysis tools "Loads a memory heapsnapshot and returns ...";close_heapsnapshot"Closes a previously loaded memory heapsnapshot, freeing its memory"); the upstreamskills/memory-leak-debugging/SKILL.mdtells agents to capture baseline, target and final snapshots and to compare them. - Failure source: my runs of the steps above on both builds, outputs quoted under Actual behavior; static breadcrumb on the
mainbuild:src/processors/HeapSnapshotManager.tsgetSnapshot()returns the entry cached under the resolved absolute path without checking the file, andtakeHeapSnapshotinsrc/tools/memory.tswrites the file without touching that cache. - Evidence provenance: observed
- Local verification: reproduced
- Reproduction completeness: complete
Fix check
Run the steps above. Failing: the get_heapsnapshot_details and query_heapsnapshot_objects calls made after the second take_heapsnapshot and before close_heapsnapshot return the same object count and matches as the first capture (about 19,000-20,000 objects, 2 LeakyThing matches). Passing: those calls describe the second capture (about 21,000 objects, about 3,100 kB shallow size and 502 LeakyThing matches, matching the post-close results) without calling close_heapsnapshot. Control: repeated analysis calls on an unchanged file still return identical results.
Additional context
The full open and closed issue and pull request corpus was screened as of 2026-10-06; no issue covers snapshot cache invalidation. Open pull request #2923 (deterministic aggregate IDs) changes the same manager but does not address reloading a replaced file. The same stale read also applies when a file is replaced by any other means, not only take_heapsnapshot; that case was not run.
Activity
docs: mention heapsnapshot being cached between runs (ChromeDevTools#…
chore(main): release chrome-devtools-mcp 1.11.0 (#2823)