1ccacad63281094de8a3372d5a507d38f9969e5c
9
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
328dc97e28 |
dirent: Each lists a folder with nothing made an entry; Codex's idle check uses it
|
||
|
|
ccc96b4a73 |
sessions: Codex's identities, rollout listings and folder listings go with the idle parses
When nobody has read the session parses for three minutes they are let go (v0.1.3540), but the end heap of a real history still held ~10 MB made from them or from the folders, kept for the life of the process: - Codex's thread identities (codexIdentityMemo, ~3.5 MB); - each Codex day folder's rollouts as last listed (rolloutsSeen, ~1.5 MB); - every folder's listing given back to dirent (~4 MB of names and entries). dropIdleCache now lets them go too, and dirent.Forget empties the kept listings. Each is made again on the next read, from the parses and the folders, with no session file parsed. CC's per-file UUIDs (ccUUIDMemo) stay: letting them go would read every Claude Code file again. Run: - mote (macOS): go test ./internal/sessions ./internal/dirent ./internal/gui ./internal/usage ok; GOOS=linux and windows go vet ok. - Broken by hand (the three drops and Forget's body removed): red, "idle: 1 Codex identity lists and 2 folders' rollouts kept" and "9 kept after Forget". On Linux dirent.Stats lists nothing, so the test asks for rollouts kept before the drop only on macOS. - Real accounts (a copy of the owner's history on mote, 300 s each, the web app opened cold, order t53 t54 t54 t53): idle footprint 117 / 120 MB before, 103 / 85 MB after; end heap 53.3 / 50.9 MB before, 43.4 / 44.6 MB after. Peak unchanged (it is the start). Not tried: Windows and Linux at runtime (the change is the same code). |
||
|
|
217d778481 |
dirent: each folder keeps its listing before last as room for its next (#2278)
A Sessions poll lists every Codex day folder and Claude Code project. The few rooms given back were shared by all of them, so a small folder's room went to a large one and was grown again, entry by entry, on every poll: 78 MB of 40 unchanged polls with the real page's X-Magpie-Had, the largest single site. Each folder now keeps the listing before its last, cleared, as its own room (keepSpare), inside the same keptEntries bound; the shared rooms are left for folders seen the first time. Run on mote (M5 Pro, macOS 27), with a copy of the real accounts: - go test ./internal/dirent ./internal/sessions: ok. - TestListingsOfDifferentSizesMadeOnce (new): five folders of 1 to 600 files read ten times allocate under 64 KB. Broken by hand (taken never hands back the spare): 394,808 bytes, red. - 40 /api/sessions polls with X-Magpie-Had, real history (~23k session files): 282 MB allocated at v0.1.3492's code, 208 MB with this; the dirent.entry append is gone from the profile. Not changed: distinctOf's slice (1.6 MB a poll). Holding it would keep as much resident as it saves in garbage. |
||
|
|
195d79939e |
dirent: a listing's entry keeps its time as nanoseconds, 40 bytes not 56
Stat.Mod was a time.Time (24 bytes), so an Entry was 56 bytes. The
listings kept for a long history hold up to ~130k entries (keptEntries),
and on the owner's real cache they were the idle heap's 7.7 MB under
dirent.entry. Mod is now unix nanoseconds (int64) with ModTime() for the
three callers that want a time; getattrlistbulk's seconds and
nanoseconds are summed as time.Unix does. An Entry is now 40 bytes.
Run on mote at this head:
- go test ./internal/sessions ./internal/dirent: ok
- GOOS=darwin/linux/windows go vet ./internal/dirent ./internal/sessions:
ok
- gofmt -l: clean
- Broken by hand: a 16-byte pad in Stat makes TestEntrySize red
("an Entry is 56 bytes, want 40").
- Real-account copy (~/r2278/acct), idle heap at 180s: dirent.Stats
7.68 MB -> 4.20 MB (dirent.entry flat 5.68 -> 1.70 MB); Footprint
148 MB.
|
||
|
|
eadeb89c48 |
sessions, dirent: a poll's listings are kept across collections (#2278)
A full history's page polls listed the same folders every few seconds into a fresh slice, map and set each time: the sync.Pools meant to keep them were emptied by the collector, which runs about twice a second at this size, before the next poll took them. - sessions: listingBufs and pathSets are shelves (shelf.go), which keep up to four across collections. listCCFiles makes its slice with the room of the folder's last listing. - dirent: Stats keeps each folder's last listing (Listing.Done(dir)) and the room of the one before, up to 1<<17 entries in all. A name already in the folder's last listing is taken from it, not copied again. 1<<16 kept too little of ~23k session files and their folders: the first bench of this change (budget 1<<16) took dirent.entry from 67-102 to 80-100 MB a minute, no gain. Bench, mote, the real full history (52G Codex in 12,495 files, 13G Claude Code in 10,186), fullallogh.sh, alloc_space between the 50s and 110s heap profiles, MB per minute, before (v0.1.2132 equivalent) -> after: distinctOf 59 -> 22 listCCFiles 42 -> 17 dirent.entry 67-102 -> 55 dirent.nameOf 24 -> 5 Totals swing 400-1200 MB with mote's load (other sessions), so these are per function. Run at this head (rebased on |
||
|
|
7fd65aad56 |
sessions: a Codex listing reuses the last one's names, and dirent its room (#2278)
Each Codex listing (several a minute of the page's polls over a long history) made every rollout's path and key again, grew a new dirent.Listing an entry at a time for every day folder, and gave each rollout name a slice of its own in distinctCodexFiles: ~230 MB of a minute of polls, from 20k unchanged rollouts. - listedRollouts keeps each day folder's rollouts as its last listing found them; a rollout listed before keeps its path and key (made only from its folder and name) and takes its size and time now. A folder is kept again only when a rollout came or went. - dirent.Stats takes its listing from a pool and its callers (listedRollouts, statFiles) give it back with Done once read; Done clears it. getattrlistbulk's 64 KB buffer is pooled too. - distinctCodexFiles keeps a name's first file in a map of ints, and a slice only for names with more files. New tests: TestListedRolloutsKeepTheirNames (a grown, a removed and a new rollout; reused strings) and TestStatsAfterDone. Run on mote. Written on |
||
|
|
d4c6230964 |
sessions: a folder's listing is a sorted slice, and one Codex folder isn't copied
dirent.Stats returned a map per folder. Eight Sessions-page polls on the
owner's real ~/.codex and ~/.claude (copied into a sandbox HOME) spent
~90 MB of their 2.3 GB on those maps alone. It now returns a Listing
sorted by name, found with a binary search (Listing.Get), and
listedRollouts walks it in order instead of sorting the map's keys.
listCodexFiles took the one folder most users have into a fresh slice;
that copy was ~65 MB of the same polls, and the folder's own slice is
now kept.
Run at this head: go test ./internal/dirent ./internal/sessions
./internal/usage ./internal/usageapi ./internal/gui ok; gofmt clean;
GOOS=linux and GOOS=windows go vet -tags nogui on dirent, sessions,
usage and gui clean. stats_test checks the listing is in name order.
A/B on real session files (8 polls of the Sessions trio, 15 s apart,
v0.1.1661 vs this with the next commit): listCodexFiles 129 -> 89 MB,
listedRollouts 87 -> 76 MB, dirent.stats 44 -> 36 MB.
Not tried: the Linux and Windows readdir paths beyond go vet; they
build the same Listing through stats_other.go.
Rebased on
|
||
|
|
7b2a330a56 |
sessions: each session folder is read in one listing on macOS, not a stat() a file
Every 15 s Sessions poll (and every Requests page) lists every agent's session files and stat()s each one: on a real history of ~21.7k files in 462 folders that was ~21.7k lstat()/stat() calls, ~10 µs each on APFS, and the largest part of the poll's CPU. Codex's day folders were also read twice, once by WalkDir and once more for the stat()s. dirent.Stats reads a folder's names, kinds, sizes and modification times with getattrlistbulk, a few calls for the whole folder. statFiles looks each file up in its folder's listing and stat()s alone only a link it follows (ccFiles) or a folder that couldn't be listed so. Codex's rollouts are walked with the listings themselves (listedRollouts), in WalkDir's order, falling back to walkLinked and statFiles when a folder can't be read so. Other systems keep the stat()s as they were. Measured on the real history (~/.claude/projects and ~/.codex sessions, read only): - Stats against os.ReadDir + os.Lstat over all 21,672 entries in 462 folders: 0 mismatched kinds, sizes or times; 43 ms against 257 ms. - `magpie serve` on the real history (sandbox HOME, its projects a link to the real ones), /api/sessions asked back to back with X-Magpie-Had for a 20 s CPU profile: before, 177 ms a poll, process CPU 48.5 s for the run, 17.5 s of samples in statFiles; after, 157 ms, 34.3 s, and no per-file stat() in the profile beyond links. Tests: - TestStatsAsLstat: a file's size and time to the ns, a folder, links to a file, a folder and nothing, a unicode name, and 3000 long names (more than one call's 64 KB answer), each as os.Lstat says. - TestStatFilesAsStat: follow and not, the same files kept with the same sizes and times as os.Stat/os.Lstat; on macOS only the two links are stat()ed alone. Red (7 alone, want 0) with Stats turned off by hand. - TestListedRolloutsAsWalked: nested days, a folder and a link named as rollouts, a .zst, a non-rollout, and a sessions folder that is a link (#2233): the same rollouts, order, sizes and times as walkLinked plus statFiles. Red with the listing's sort taken out by hand. - TestCodexFilesStatInOrder (existing) passes on the new path. Run at this head: - gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui on internal/sessions and internal/dirent ok. - go test -tags nogui -count=1 -timeout 45m ./internal/dirent/ ./internal/sessions/ ./internal/usage/ ./internal/gui/: ok (2.4 s, 13.9 s, 15.9 s, 51.1 s). - go test -tags nogui -count=1 -timeout 45m at fe903798f, the packages that import sessions: agent 293s, cli 57s, davsync 73s, gateway 493s, library 192s, otlp 19s, tui 31s, tune 7s, all ok Not tried: Windows and Linux run the stat()s as before, so no change there; an SMB or other network volume on macOS, where getattrlistbulk fails and the per-file path is taken. |
||
|
|
2b0037f41d |
sessions: a Claude Code, Qoder or Cowork project folder, a session's folder or a Hermes profile behind a junction is read, not skipped (#2268, JasonBuildAI)
On Windows os.ReadDir lists a junction as ModeIrregular, neither IsDir nor ModeSymlink, so a reader that goes into only IsDir() entries, or IsDir() and ModeSymlink ones, walked past a folder kept on another drive with a junction left in its place. ccFiles (Claude Code's own store, Qoder's, Qoder CN's and Cowork's) skipped such a project folder whole, a session's own folder (its subagents) and a workflow run's; HermesDirs skipped such a profile. Sessions and Usage lost all of them, silently. #2233/#2250 fixed walk roots (walkLinked); this is the entry check one level in. dirent.IsFolder is the one check now: an entry is a folder to read into when it is one, or when it is a symlink or irregular entry that os.Stat follows to a folder. A link to a file, a broken link and other irregular entries are none. It follows only the entry asked about; none of its callers recurses through one, so no visited set is needed. Used at every reader of an agent's folder that picks entries this way: - sessions: ccFiles' project, session-folder and workflow-run checks, HermesDirs' profile check, agyCallFiles' conversation check (IsDir only before, so even a symlink was skipped); - agent: hermesProfiles and ompProfiles (IsDir only), so a linked profile still gets magpie's provider and its own row; - library: desktopSkillRoots' org and account folders (IsDir only). Left as they are, on purpose: WalkDir copies, hashes and deletes in library and sessions/manage.go (they must not follow links), the relocate code (it tells a link from a folder on purpose), library's linkEntry (asks "is this a link", not "is this a folder"), magpie's own folders (calls cache, gateway logs, OthersDir, backups, Bun, Devin homes), and install/version detection (claudecode versions, VS Code extensions, Desktop's folder name, Hanako's agents). The issue's patch had sessions' own copy of library's linkEntry without a Stat; this is a shared package and Stat-checked, so an irregular entry that isn't a folder (a dedup or cloud placeholder file) isn't read as one. docs/subsystems/gateway-sessions.md says how the readers treat links. Run: - New tests make real links, a junction (mklink /J) on Windows and a symlink elsewhere: TestIsFolder; TestClaudeProjectFolderBehindALink, TestClaudeSessionFolderBehindALink and TestHermesProfileBehindALink (the issue's), TestClaudeWorkflowRunBehindALink, TestAgyConversationBehindALink; agent's TestHermesProfileBehindALink and TestOmpProfileBehindALink; library's TestClaudeDesktopSkillRootsBehindALink. - Broken by hand on macOS (IsFolder = e.IsDir()): all nine fail. Broken as before on the Windows box (IsDir() || ModeSymlink, no Stat): TestIsFolder and all eight reader tests fail there (e.g. "Claude session files behind a link: [], want [...]", "Hermes sessions behind a link: 1, want 2", "agy calls behind a link: 3, want 5"); with the fix all pass. Windows test binaries cross-built with go1.26.8 (windows/amd64, nogui) and run on the box with a fresh sandbox USERPROFILE/HOME/APPDATA/LOCALAPPDATA/TEMP per run. - Whole packages on the Windows box: dirent and sessions pass. usage, agent and library each have reds that fail the same with binaries built from origin/main |