Repository navigation
Description
Follow-up to #314, which was closed as "tracked upstream — Bun runtime, not an opencodex leak." Per the closing comment's request for "a process.memoryUsage() sample (rss vs heapUsed) at high memory", here it is — and it points the other way.
The Windows Memory Growth doc states the attribution rule:
a rising
responseState.totalBytesunder a rising heap points at conversation retention (longstore:falsechains re-expanding each turn), whereas a flatresponseStateunder a rising RSS points back at the native runtime
By that rule this looks JS-heap-side, which the same page says is "an opencodex bug you should report."
Environment
| opencodex | 2.7.39, reproduced then upgraded to 2.7.40 |
| Bun (bundled) | 1.3.14 (0d9b296a) — unchanged between 2.7.39 and 2.7.40 |
| OS | Windows 11 Pro 26200 |
| streamMode | auto; eagerRelay: {useEagerRelay: false, reason: "auto-known-bad"} |
| Client | Codex CLI 0.144.5 through the proxy |
heapUsed runs consistently above RSS
From GET /api/system/memory on 2.7.39 after 22.9 h uptime, using the watchdog's own 60-sample ring (~1 h at 60 s):
| peak | notes | |
|---|---|---|
heapUsed |
5,729 MB | JSC heapSize; objectCount ~948k |
rss |
3,001 MB | min in the same window: 10 MB |
heapTotal |
57 MB | stays tiny throughout |
Point-in-time sample from that run: rss=929MB heapUsed=2398MB heapTotal=57MB.
heapUsed exceeding rss is the unusual part, and it's persistent, not a blip. During an idle stretch earlier that day:
17:35:34 rss=21 heapUsed=1572 heapTotal=52
17:40:34 rss=21 heapUsed=1572 heapTotal=52
17:45:34 rss=21 heapUsed=1572 heapTotal=52
17:50:34 rss=21 heapUsed=1572 heapTotal=52
17:55:34 rss=22 heapUsed=1572 heapTotal=52
18:00:34 rss=19 heapUsed=1572 heapTotal=52
18:05:34 rss=240 heapUsed=1789 heapTotal=52
18:20:34 rss=267 heapUsed=2036 heapTotal=52
18:25:34 rss=1702 heapUsed=3862 heapTotal=61
1.5 GB of JSC heap held flat for 25 minutes while the working set read 21 MB. Since heapUsed here is bun:jsc heapSize, some of that is GC-registered external memory rather than plain JS objects — you'll read that better than I can — but it is GC-visible retention, which is not the signature of an invisible native leak.
For scale, that day served 2,497 requests and the process reached ~16 GB RSS before I began restarting it.
The watchdog can't see this
src/server/memory-watchdog.ts compares RSS only:
if (s.rss >= warnThresholdBytes && (lastWarnAt === null || now() - lastWarnAt >= WARN_INTERVAL_MS)) {With the 4 GiB default, lastWarnAt was still null after 22.9 h — RSS peaked at 3,001 MB and never crossed it, while heapUsed went to 5,729 MB. So on Windows the built-in warning is silent in exactly the case it exists for. Anything keyed to RSS inherits this (see the workaround below — I made the same mistake).
responseState isn't in 2.7.40
The docs tell users to read responseState from /api/system/memory to attribute growth, but it isn't in the latest stable release:
$ grep -rn "responseState" --include=*.ts src/ # 2.7.40
(no matches)
The endpoint returns pid, bunVersion, bunRevision, platform, uptimeSeconds, rss, heapUsed, heapTotal, jscHeap, streamMode, eagerRelay, watchdog — no responseState. So I can't run your documented triage step. Is it preview-only (2.7.41-preview.20260726)?
Indirect signal instead: ~/.opencodex/responses-state.json swung from 25 B → 19,970,862 B → 25 B within minutes while the heap climbed. Three orphaned temp files were also left behind from the high-memory window, 20.4 MB / 23.1 MB / 24.3 MB (responses-state.json.ocx.<pid>.<n>.tmp) — they survived proxy restarts and aren't cleaned up.
Abort-teardown counts (correlation only)
~/.opencodex/crash.log, summing the xN multipliers:
| Date | benign-abort-teardown |
requests |
|---|---|---|
| 2026-07-20 | 149 | 338 |
| 2026-07-21 | 560 | 1,240 |
| 2026-07-22 | 475 | 1,186 |
| 2026-07-23 | 446 | 1,279 |
| 2026-07-24 | 472 | 1,177 |
| 2026-07-25 | 999 | 2,497 |
These come from cancelResponseBodyBestEffort(res) (src/lib/upstream-retry.ts:102) on the transient-5xx retry path — res.body?.cancel(). I initially thought aborts drove RSS independently of traffic, but the data doesn't support that: 07-25 was both the highest-abort and highest-traffic day, so the two are confounded here. Including the counts only as context in case the abort path is relevant to heap retention.
Workaround, for other Windows users
I understand from the docs that threshold auto-restart is deliberately not shipped; this is a user-side stopgap, not a request to change that.
A Task Scheduler job every 5 minutes polls /api/system/memory and runs ocx restart when heapUsed ≥ 5000 MB, or ≥ 2500 MB when idle (idleness = usage.jsonl mtime; ESTABLISHED connections on the proxy port are useless as a busy signal, since Codex holds keep-alive sockets open while idle).
The part worth passing on: my first version triggered on the Windows WorkingSetSize and was near-useless — it logged ok rss=21MB while the heap held 1,572 MB. Switching the trigger to heapUsed fixed it. Same reason the built-in watchdog stays quiet.
Happy to help
The proxy is now on 2.7.40 with a fresh process, so I can gather a clean long-uptime sample. I can also run streamMode: "eager-relay", a bun:jsc heap snapshot, or a preview build with responseState if that's more useful — just say which.
Unrelated packaging note: npm install -g @bitkyc08/[email protected] under npm's default allow-scripts policy silently blocks bun's postinstall, leaving node_modules/bun/bin/bun.exe as a 450-byte stub that errors with "Bun's postinstall script was not run". Fix is cd node_modules/bun && node install.js. May be worth a docs line, since it breaks the proxy on upgrade.
Activity
Wibias commentedon Jul 26, 2026
Thanks for the detailed samples — this is useful, but the conclusion that this is an opencodex JS-heap leak does not hold up against how these counters work on Bun/Windows.
Verdict
The Windows memory pain is real (same class as #314). The reading "
heapUsed ≫ rss⇒ JS-side opencodex bug" is not substantiated.Why the attribution rule does not apply that way
Doctor / docs JS-vs-native split requires high RSS first.
ocx doctoronly treats growth as "likely an opencodex bug" when RSS is already above the watch threshold and the JS share of RSS is large. Under the threshold it reports usage as normal. Your RSS stayed under the 4 GiB warn line while a broken-lookingheapUsedclimbed — that is not the documented "JS leak" shape.heapUsed≫heapTotal(~5729 MB vs ~57 MB) is a known Bun accounting bug, not evidence of multi-GB live JS objects. Bun previously sourcedheapUsedandheapTotalfrom mismatched JSC heaps, soheapUsedcan exceedheapTotalby tens of times (oven-sh/bun#33368). Treatprocess.memoryUsage().heapUsedon the bundled 1.3.14 runtime as unreliable for leak triage.Idle
rss≈21 MBwithheapUsed≈1572 MBfor ~25 minutes is almost certainly working-set / counter semantics, not 1.5 GB of resident retained objects. Real retention of that size would show up in the working set.API
heapUsedis notbun:jscheapSize./api/system/memoryexposes both:heapUsedfromprocess.memoryUsage(), andjscHeap.heapSizeseparately. Equating them overstates "GC-visible retention."responses-state.jsonswinging 25 B → ~20 MB → 25 B while the "heap" kept climbing argues against conversation retention as the multi-GB driver. The docs'responseStaterule needs a rising store under a rising heap.The ~16 GB RSS day still matches the 램 누수가 있어요 #314 / Bun Windows native pattern the troubleshooting page already describes.
What is real in this report
heapUsed ≫ rssresponseStateon 2.7.40responses-state.json.ocx.*.tmpallow-scriptsUseful next samples (if you can)
On 2.7.41+ (has
responseState), a long-uptime/api/system/memorysample with:rss,heapUsed,heapTotaljscHeap(heapSize,heapCapacity,objectCount)responseState(entries,totalBytes,largestBytes, age)Until the bundled Bun carries fixed
memoryUsageaccounting, please do not treatheapUsedalone as the leak discriminator on Windows. RSS (and, when present, a flat vs risingresponseState) remain the primary signals.github-actions commentedon Jul 26, 2026
DiNaSoR commentedon Jul 27, 2026
Thanks — you're right about the core inference, and I can now show why with a controlled test rather than more field samples. But two of the specific rebuttals don't hold, and the recommended fallback to RSS is the one signal that fails hardest on Windows.
Everything below is on the bundled Bun 1.3.14 (
0d9b296a), allocating a known quantity of provably-reachable memory and comparing every available counter against it.Conceded:
heapUsedis not a usable discriminatorheapUsedisHeap::sizeAfterLastEdenCollection(), and on this runtime it simply stops tracking. 1,800 MB retained in a rooted array, with a forced full GC in the middle:heapUsedis pinned at 946 MB while live retention grows to 1,800 MB. So my "JS-heap-side leak" conclusion doesn't stand — I withdraw it.It also explains the idle plateau I reported better than my reading did:
heapUsedsat at exactly 1572 MB for 25 minutes because an idle proxy allocates nothing, so no eden collection ran and the counter never refreshed. That's an artifact, as you suspected. (It's stale, not fabricated — 5729 MB means the heap did measure that after some collection — but as a live gauge it's unusable, which is the part that matters.)Your points 1 and 5 were fair too: the
responses-state.jsonswing argues against retention rather than for it, and I shouldn't have leaned on it.Not correct:
heapUsedvsjscHeap.heapSizeSeparately sourced in
system-routes.ts, yes — but they return the same value, byte for byte, on every sample:Bun implements
memoryUsage().heapUsedas the JSC heap size, so the two fields carry identical information on this build. It doesn't rescue my conclusion — both inherit the same eden-snapshot staleness — but the distinction can't be used to discount a reading.Not correct: the
heapUsed ≫ heapTotalratio as a phantom-number testoven-sh/bun#33368 is still open (not merged), and it fixes
heapTotal's sourcing — its own description keepsheapUsedassizeAfterLastEdenCollection(). So the ratio is meaningless, but that indictsheapTotal, not the heap figure.More directly: the same ratio appears with unambiguously live data. 1,500 MB of retained strings gives
heapUsed=976 / heapTotal=1— a 976× ratio, larger than the ~55× in the PR, on memory that is definitely reachable. A large ratio therefore can't distinguish real retention from a bad counter.The RSS fallback is the weakest of the three
This is the part I'd push back on hardest. 1,500 MB of retained
Uint8Array:process.memoryUsage().rssprocess.memoryUsage().externalWorkingSetSizePrivatePageCountRSS moved 13 MB for 1,474 MB of committed retention. For external/ArrayBuffer-backed memory — precisely what a streaming proxy accumulates — RSS is not conservative, it's blind.
And on working set specifically:
It doesn't. Same process, 1.5 GB live, after an explicit
EmptyWorkingSet:WorkingSet = 1 MB while 1,731 MB stays committed. Windows trims the working set freely; a process holding 1.5 GB of reachable data can read ~1 MB RSS. So
rss ≈ 21 MBnever established that retention wasn't there — it just wasn't evidence either way. The commit charge is what survives trimming.Concrete suggestion
externaltracked live retention exactly — 946 → 1200 → 1800 MB, matching what was actually held, and it comes from the sameprocess.memoryUsage()call the endpoint already makes./api/system/memorycurrently forwardsrss,heapUsed,heapTotalbut dropsexternalandarrayBuffers.Exposing those two fields would give Windows users a discriminator that works on the bundled runtime today, without waiting for #33368.
PrivatePageCountis the matching OS-level counter if you ever want a side-by-side.Repro, if useful:
Where this leaves the report
I'm not re-asserting a JS-heap leak — that inference is withdrawn, and by the corrected reading I have no evidence yet that distinguishes app-level retention from the #314 native pattern. What I'd ask is that the attribution guidance not rest on RSS either, since the measurements above show it under-reports this allocation class by more than an order of magnitude.
I've upgraded to 2.7.41 (thanks —
responseStateis there and populating) and restarted the clock. I'll follow up with a long-uptime sample carryingrss,heapUsed,heapTotal,jscHeap,responseState,PrivatePageCount, and active-vs-idle state, so the next round is measured against counters we both trust. Happy to have this retitled or narrowed to the observability points in the meantime.fix(memory): observe external Windows retention
lidge-jun commentedon Jul 27, 2026
Fixed on dev via PR #554: https://github.com/lidge-jun/opencodex/pull/554\n\nWhat changed:\n- /api/system/memory now exposes external, arrayBuffers, observedBytes, and observedMetric.\n- The watchdog and doctor now threshold against observed memory, defined as max(rss, external, arrayBuffers), so Windows/Bun external retention is no longer hidden behind RSS-only wording.\n- The GUI Memory card and docs/SOT now show the observed metric and include runtime counter caveats.\n\nVerification:\n- Local: memory-watchdog + doctor tests, GUI memory card tests, typecheck, GUI lint/build, privacy scan, diff check.\n- CI: Cross-platform CI ubuntu/macos/windows, npm-global matrix, React Doctor, enforce-target, label, and CodeRabbit all passed before squash merge.\n\nClosing this issue as the watchdog/observability gap is fixed. If a later long-running Windows sample shows a separate retention root cause, please open/reopen a focused issue with the new observed-memory counters.
fix(memory): observe external Windows retention