Repository navigation
Conversation
EhabY
force-pushed
the
feat/vsc-32-memory-pressure-warnings
branch
from
November 20, 2026 15:33
6dc9294 to
5e5cdbb
Compare
EhabY
force-pushed
the
feat/vsc-32-memory-pressure-warnings
branch
10 times, most recently
from
November 20, 2026 20:01
0c33f6b to
07f1a1e
Compare
EhabY
force-pushed
the
feat/vsc-32-memory-pressure-warnings
branch
from
November 20, 2026 21:05
07f1a1e to
4280c79
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes VSC-32.
Warns in the IDE before a workspace runs out of memory, with a way to act on it.
What users get
coder.memoryMonitor.warningThreshold(default 80%,0turns it off), or when memory pressure slows the workspace, it shows$(warning) Memory 92%on a warning background.$(error)on an error background.Memory: 6.12/16 GiB (38%), memory the kernel cannot reclaim, asfreeandtopcount it), then the warning with Top processes and Restart links.topsorted by memory.How it works
Two layers in
src/memory/, so the data source can be swapped:MemoryUsageSourcereturns one memory sample. Today's source,createRemoteFileUsage(remoteFiles.ts), reads cgroup and/procfiles over the window's existing remote connection, in one parallel batch per poll. It needs no template changes and runs no processes. It ports coder/clistat's memory reading at a pinned commit (see the file header), except that used memory excludes all reclaimable memory:MemTotal - MemAvailablewithout a limit, andmemory.current - active_file - inactive_file - slab_reclaimableunder one. clistat subtracts onlyinactive_file, which counts recently read file cache as used. It also finds cgroups through/proc/self/mountinfo(so a mount rooted at/docker/abcworks) and takes v1 parent limits fromhierarchical_memory_limit, where clistat reads fixed paths.MemoryMonitorpolls every 10s.MemoryPressureTrackerturns samples into states, warning on 2 of 3 samples and leaving after 10s of calm samples, so spikes don't flap and a quick re-read can't clear a warning. The status bar renders the result. None of these know where samples come from.Restarting the connected workspace queues the stop with the start behind it (servers >= 2.36), then reloads. The reconnect waits for that start instead of posting its own.
Future
GET /api/v2/workspaceagents/{workspaceagent}/resources/watch, a WebSocket that runs clistat in the agent only while someone listens. Supporting it means adding a source, picked inremote.tsby server version, and eventually deletingremoteFiles.ts. Nothing else changes.coder stat mem, the resources monitor and the API) adopts the same definition of used memory, so every client shows the same number.Implementation plan
VSC-32: In-IDE memory pressure warnings before crashes
Goal (from product)
before the workspace dies.
Constraints from us: non-invasive, few false negatives, still a reliable signal
(not noisy).
What exists today
src/inbox.ts(template ida9d027b4...)coder_agent.resources_monitoring.memory) and needs Coder notifications enabled. 20 samples x 10s window, 30 min debounce (coderd/agentapi/api.go:183). Plain info toast with no action. No public API for the values.src/api/agentMetadata.ts,remote.ts:1032(idagentMetadata)coder stat mem). Cannot be parsed reliably.Proposed approach
1. Data source: kernel memory files over the existing remote connection
The extension is
extensionKind: ui, but in a remote windowvscode.workspace.fscan readvscode-remote://<authority>/...URIs throughthe VS Code server that is already running:
/proc/self/cgroupmapped to directories through/proc/self/mountinfo.memory.current,memory.max(walk up to the limit with theleast room left),
memory.stat(active_file,inactive_file,slab_reclaimable),memory.pressure(PSI),memory.events(oom_kill).memory.limit_in_bytesandhierarchical_memory_limit,memory.usage_in_bytes,memory.stat,memory.oom_control./proc/meminfo(MemTotal,MemAvailable),/proc/pressure/memory,/proc/vmstat(oom_kill).Used memory is what the kernel cannot reclaim:
MemTotal - MemAvailablewithout a limit (what
freeandtopreport), andmemory.current - active_file - inactive_file - slab_reclaimableunder a cgroup limit. Thelimit and scope follow
coder/clistat(after CORE-693, usage is read at thelimit-owning ancestor so sibling cgroups count). clistat subtracts only
inactive_file, socoder stat memreads higher under a limit until clistatadopts the same definition (planned).
Non-invasive: no extra processes, no SSH exec, no template changes, nothing
installed on the workspace. A few small file reads per poll over an open
channel.
/proc/selfis the VS Code server, so we measure the cgroup where theeditor and terminals run (including dev containers).
Spike result (2026-11-20):
vscode.workspace.fs.readFile-> main threadFileService.readFile(unbuffered, sincedoReadFilesetspreferUnbuffered) -> remoteDiskFileSystemProvider.readFileon theserver -> Node
readFile(fd), which reads to end of file.stat.sizeisonly used for limit checks, so size-0 files are fine
(
src/vs/platform/files/common/fileService.ts:588-757,node/diskFileSystemProvider.ts:223).stat.size=0. cgroup v2 at0::/init,memory.maxismax(no limit),so
/proc/meminfois the source.memory.eventsand/proc/vmstathaveoom_kill./proc/pressure/memoryandmemory.pressure:ENOENT; kernel without PSI). PSI stays an optional signal; on such kernels
we rely on usage and the OOM counter.
Windsurf) during UAT. Fallback: B under "Alternatives".
Polling: every 10s, also while the window is not focused. Skip a tick while
the previous read is pending (reads stall under pressure).
2. Memory states
Three signals, with one clear rule per state:
some avg10>= 20%oom_killcounter went up during this sessionHigh, because the same exit rule applies.
0: High and Processes killed are never entered;the state is Normal or Unavailable. Usage is still shown.
state, they only show a notice (see 5).
3. Status bar: one item, two independent parts
The existing item keeps its name "Coder Agent Metadata" and id
agentMetadata. It shows two kinds of values, each computed on its own:today).
disk could be added later in the same part.
Because the parts are labelled separately, a template RAM value and the IDE
memory value can both appear. No RAM-entry detection is needed.
Text = metadata part,
·, memory part. Either part can be absent; theseparator appears only when both are present.
$(dashboard) <first value>(as today)$(warning) Agent Status Unavailable(as today)$(dashboard) Memory 41%when there is none$(warning) Memory 92%$(error) Memory 97%Rule: memory stays in the tooltip while Normal and moves into the text when
it needs attention (progressive disclosure). A warning is never color only:
it always has an icon, the word "Memory" and the value, plus the background.
and memory cannot be read).
Processes killed, none otherwise. A metadata error keeps its
$(warning) Agent Status Unavailabletext but loses the warningbackground (change from today), so a colored item always means memory.
Examples:
$(dashboard) 0.006/4 cores (0%)(Normal, as today)$(dashboard) 0.006/4 cores (0%) · $(warning) Memory 92%(warning background)$(dashboard) 0.006/4 cores (0%) · $(error) Memory 97%(error background)$(warning) Agent Status Unavailable(Normal, no background)$(warning) Agent Status Unavailable · $(warning) Memory 92%(warning background)$(dashboard) Memory 8%(template has no metadata)Tooltip: sections in this order, each omitted when it has no content.
Click: in High or Processes killed, runs
Show Top Processes.Otherwise no command (as today).
Code: a small pure function
(metadata, memory) -> item viewthat theexisting metadata watcher and the memory monitor both feed. Unit-test it for
every combination of the two part tables.
4. Actions (no notifications)
Notifications were dropped to keep the change small and quiet; the status
bar is the only warning.
one reused terminal on the remote running
top -o %MEM, falling back toplain
top(BusyBox, old procps) or a message whentopis missing.workspace. Restart runs
coder.workspace.restart, which goes through theWorkspaces panel's
WorkspaceActionRunner(same confirmation and builds).5. Removed from scope
disconnected" notice and its stored counter.
6. Setting (
"scope": "application")One setting, under
coder.memoryMonitor.*so settings added later (CPU,disk) group with it:
coder.memoryMonitor.warningThreshold: number, default80,0to99.Set to
0to turn off memory warnings; usage is still shown in thetooltip.
No visibility setting: memory is shown whenever it can be read. Users who do
not want the item can hide it with right-click, like any status bar item.
Read live through
watchConfigurationChanges; no reload needed.7. Inbox OOM notification
Kept separate and unchanged: different system (Coder notifications, not
always enabled), own threshold and debounce.
8. Telemetry, docs
memory.state_transitioned(state, trigger, percent, source, pressure) inEVENTS.md.CHANGELOG.mdentry. No README change (it does not list settings).Code layout
src/memory/usage.ts: reads and parses the files (pure, takes a reader).src/memory/pressure.ts: state machine with hysteresis (pure).src/memory/monitor.ts: 10s polling overvscode-remote://, telemetry.src/memory/topProcesses.ts: the reusedtopterminal.src/remote/agentStatusBar.ts: renders the metadata part and the memorypart; wired in
createAgentMetadataStatusBarinsrc/remote/remote.ts.Alternatives considered
template and needs notifications enabled. Left unchanged and separate.
coder ssh <ws> -- cat ...orcoder stat memover SSH: workswithout the remote FS, but starts processes on every poll. Fallback only.
invasive.
two labelled parts.
alwaysShowUsagesetting:needed RAM-entry detection and suffix rules to avoid duplicates, and hid
memory when metadata failed. Rejected for always showing both parts.
Relation to coder/coder work
Backlog since 2024-10, no comments or PRs. Admin-defined notifications
triggered through an API and delivered to IDEs. Would reach us through the
Inbox; we would only add its template ids to
src/inbox.ts. VSC-32 does notdepend on it and stays useful after it, since it needs no admin setup.
victim (high
oom_score_adj). Warnings must come before the kill, and readscan stall under pressure.
Threshold research
resources_monitoringdocs exampleOur "used" excludes reclaimable page cache (like working set). 80% is the
most common standard and gives the earliest window. The 2 of 3 rule and the
exit gap limit noise from large steady heaps.
Decisions
unchanged, with a server part (agent metadata) and a client part (measured
by the IDE). Memory is in the text only when it needs attention or there
is no metadata; always in the tooltip. Background reserved for memory, so
color appears only when the user needs to act (metadata errors keep their
text but lose the warning background).
coder.memoryMonitor.warningThreshold.action runner.
6.12/16 GiB (38%), the agent metadata format.topfor reduce load; poll while unfocused; disk out of scope; inbox OOMnotification stays separate.
Rollout
/procand/sysin VS Code, Cursor, Windsurf.stress-ng --vmin a container with a limit and in a KataVM without one; templates with and without RAM metadata.
Generated by Coder Agents on behalf of @EhabY.