Commit Graph
2 Commits
Author SHA1 Message Date
yetone 1dc20e73fc sessions: a live Cursor's state.vscdb is read in place, not copied (#1988)
Beside a running Cursor, every listing, count, transcript and search
read the editor's state.vscdb from a copy in the temp folder, made again
each time Cursor had written since the last. The store is often several
GB, and on Windows, where no clone makes a copy free, Echo-Huang0010
measured ~10.6 GB written every few minutes.

While the store has a non-empty -wal and a -shm beside it, Cursor's own
processes share it as readers through the -shm, and magpie now opens it
the same way, mode=ro with a 3s busy timeout: no copy. Nothing magpie
shows comes from the store's file times (each chat carries
lastUpdatedAt), so a reader's mark in -shm changes nothing it lists.
With no -shm beside a live -wal, or if that open fails, it falls back to
the copy as before. CLI chat stores keep the copy path. OpenUntouched's
open is factored out as openSQLite.

Thanks to Echo-Huang0010 for the report and the measurements; their
patch capped the copy at 64 MiB, which would leave a larger history
unread, so this takes the in-place read instead.

The Cursor tests set TMPDIR only, which Windows' os.TempDir doesn't read
(TMP, TEMP), so TestCursorLeftCopiesSwept's folder landed in the real
temp folder and the next test counted it. cursorTempDir sets all three.

Run at this head:
- mote: go test -count=3 -run Cursor ./internal/sessions ok;
  go test -timeout 45m ./internal/sessions ./internal/agent ok;
  go vet ./internal/sessions for darwin, linux, windows ok; gofmt clean.
- xiaomi-gpu (win-run): go test -count=3 -run Cursor ./internal/sessions
  ok (red before cursorTempDir, from the stray folder).
- Broken by hand: in-place reads off, TestCursorEditorReadInPlaceWhileLive
  fails "a live state.vscdb was copied 3 times, want 0".
- Windows, two processes: a writer holding a WAL store (~40 MB) with
  busy_timeout(0) wrote 200 times while a magpie process listed 40 times
  and read transcripts. 0 failed writes, every list saw the latest title
  (40 of 40), 0 copies in the temp folder.

Not tried: a real Cursor install. Neither test machine has one, so the
writer was a stand-in process, not Cursor itself.
2026-10-28 14:09:05 +08:00
yetone 0e39c8e7e9 sessions: reading Cursor's history no longer writes its database to the temp folder again and again (#1988, kangxi94)
v0.1.1224 reads Cursor's editor chats from its global state.vscdb, which
is often several GB. A store with a live -wal is read from a copy, and
every listing, count, manage page, transcript, context read and each
chat of a search made a fresh full copy in $TMPDIR/magpie-cursor-*.
A visit to Sessions wrote the file out several times (28 in the test
below): heavy disk writes with low CPU, and Time Machine's local
snapshots can hold on to deleted copies' blocks, which would shrink free
space (not reproduced on the reporter's machine). A magpie killed mid-read also left
its copy behind for good.

- A store of 16 MB or more is copied once and the copy is shared by
  every reader while the store and its -wal keep their size and time;
  a change makes one new copy, and a copy goes 30s after its last reader.
- On macOS the copy is an APFS clone (clonefile), so it takes no space
  until Cursor writes; elsewhere, or when cloning fails, it is copied.
- The first copy a process makes sweeps magpie-cursor-* folders older
  than an hour (a shared copy is touched on every reuse).

Run:
- TestCursorEditorCopiedOncePerChange: 6 editor chats, list + Agents +
  transcript + search of each, twice: 1 copy (28 with sharing turned off
  by hand), 2 after one change, none left. TestCursorLeftCopiesSwept
  goes red with the sweep turned off.
- go test -race ./internal/sessions/ ok; -run TestCursor -race -count=10 ok.
- gofmt -l clean; go vet -tags nogui for darwin, linux, windows.
- Sandbox HOME with a 300 MB Cursor-shaped state.vscdb kept live by a
  writer every 5s: v0.1.1224 made 1-3 full copies per endpoint and 5
  for one search (11s, searched 0 of 30); this build made 2 over
  sessions, stats, overview, manage, context, two searches and a second
  listing (search 30 of 30 in ms), and removed a planted day-old
  magpie-cursor-* folder.
2026-10-13 18:16:18 +08:00