Skip to content

edit_prediction leaks memory on every failed attempt when not signed in (12 GB MALLOC_SMALL after 30 h, macOS arm64, Zed 1.4.2) #57962

@mathieukubik

Description

@mathieukubik

Summary

A long-running Zed session (≈30 h) accumulated ~12 GB of MALLOC_SMALL in the main process while the user was not signed in for edit predictions. The Zed log shows a continuous stream of ERROR ... edit_prediction.rs:2215 not signed in (5951 occurrences in ~30 h, ~3.3 per minute), plus 421 related errors at lines 2214/2136 in the same file. The arithmetic (~2 MB per failed prediction attempt × ~6.4k attempts ≈ 12 GB) matches the observed footprint, suggesting the not-signed-in error path in edit_prediction does not drop the request/context state it allocated.

The footprint is invisible to ps (RSS ~120 MB) because macOS compressed/swapped most of it out, but vmmap/footprint confirms the process owns 12 GB of dirty memory. macOS eventually triggered its "force quit applications" dialog due to swap exhaustion.

Environment

  • Zed version: 1.4.2 (build 20260527.175424)
  • OS: macOS 26.3.1 (build 25D2128)
  • Architecture: arm64 (Apple Silicon)
  • Workload: editing LaTeX files (.tex, .bib) in a small project. Only LSP in use: texlab (separate process, ~7 MB RSS — not the culprit).
  • AI features: none used (no agent / chat / inline assist). User is not signed in.
  • Extensions installed: latex, html, log, make, toml, plus themes (alabaster, catppuccin, nord, rose-pine-theme).
  • Session uptime at time of diagnosis: ~30 h (started 2026-05-27 10:22, observed 2026-05-28 16:45).

Reproduction

I do not have a tight isolated repro, but the conditions appear to be:

  1. Launch Zed without signing in (so edit predictions cannot authenticate).
  2. Open and edit any project (in this case a small LaTeX project).
  3. Leave the session running for ~1–2 days while editing intermittently.

Expected: edit prediction fails gracefully without allocating unbounded state.
Actual: edit_prediction.rs:2215 logs "not signed in" continuously at ~3/min, and the process footprint grows linearly until macOS memory pressure triggers a force-quit dialog.

Diagnostic evidence

footprint -p <zed_pid> (truncated to top categories)

======================================================================
zed [26363]: 64-bit    Footprint: 12 GB (16384 bytes per page)
======================================================================

  Dirty      Clean  Reclaimable    Regions    Category
    ---        ---          ---        ---    ---
  11 GB        0 B          0 B       2964    MALLOC_SMALL
  96 MB        0 B          0 B        316    IOSurface
  47 MB        0 B          0 B        106    MALLOC metadata
  20 MB        0 B          0 B         11    MALLOC_LARGE
  13 MB        0 B          0 B        283    untagged (VM_ALLOCATE)
  11 MB        0 B          0 B         53    IOAccelerator (graphics)
  ...
  ---        ---          ---        ---    ---
  12 GB      34 MB      8320 KB      12363    TOTAL

Auxiliary data:
    phys_footprint:      12 GB
    phys_footprint_peak: 12 GB

phys_footprint == phys_footprint_peak indicates the process only ever grew — no memory was released back to the OS.

ps shows misleadingly low RSS

PID    %CPU %MEM    VSZ        RSS    STARTED   TIME      COMMAND
26363  7.8  1.3   460394784   121008  Wed10AM   21:19.57  /Applications/Zed.app/Contents/MacOS/zed

RSS of ~120 MB while footprint is 12 GB — the bulk of the leaked memory has been compressed/swapped by macOS but still counts against the app's footprint.

macOS VM state at time of diagnosis

vm.swapusage: total = 7168.00M  used = 6274.94M  free = 893.06M

Swap was 87 % full, which is what triggered the macOS "force quit applications" dialog. Quitting Zed immediately freed swap.

Log analysis (~/Library/Logs/Zed/Zed.log)

Total log lines:               7771
edit_prediction.rs:2215 errs:  5951   ("not signed in")
edit_prediction.rs:2214 errs:   326   (same code path, adjacent line)
edit_prediction.rs:2136 errs:    95   (same module)
                       Total:  6372 edit_prediction errors
First:                         2026-05-27T10:23:41+02:00
Last:                          2026-05-28T16:45:59+02:00

Non-edit-prediction errors are negligible (a handful from project::lsp_store, agent, gpui, fs_watcher — total < 50 over 30 h).

Suggested fix direction

The error site at crates/edit_prediction/src/edit_prediction.rs:2215 should be audited to confirm that all request state, prompt buffers, and surrounding-code snapshots allocated for the prediction attempt are dropped before/when the "not signed in" error is returned. The leak rate (~2 MB per failed attempt × ~3 attempts/min) means any user who launches Zed without signing in will run out of memory within a few days.

Additionally, it may be worth rate-limiting or short-circuiting edit-prediction attempts entirely when the user is known to be unauthenticated, so the failed path is not exercised on every keystroke / debounce tick.

Related (probably distinct) issues

These are all in different subsystems; the leak reported here is reproducible without using any AI/agent features and appears specific to the edit_prediction not-signed-in code path.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:ai/edit predictionUmbrella label for Copilot, Supermaven, etc. inline completions (non-Zeta-specific)area:performance/memory leakFeedback for memory leaksfrequency:uncommonBugs that happen for a small subset of users, special configurations, rare circumstances, etcpriority:P1Security holes w/o exploit, crash, install/update, sign-in, badly broken common featuresstate:needs reproNeeds reproduction steps and/or someone to reproduce

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions