65cb76ca2e2b59892ecb41fd3fcf6dbe07dde1c3
353
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
c14fa0ce93 |
Bring back 919780414 and 88d2962e0, which 698ed4adb undid
|
||
|
|
db0c1b039d |
sessions: a ZCode session the CLI database lacks is named from the app's task index (Flandern1211 on X)
Titles named a ZCode session only from files in the CLI database
(~/.zcode/cli/db/db.sqlite). A session the app keeps only in its own
tasks-index.sqlite (a request names it without the sess_ prefix) had no file,
so the Context page showed the id's first eight characters. Titles now asks
the task index for each ZCode key still unnamed, by sess_<bare id>, skipping
default titles.
|
||
|
|
698ed4adb5 |
gateway: a busy port names the program holding it, and Tailscale's serve gets its fix (pluoki on X)
The Gateway page, `magpie serve` and the app log said only "port N is held by another program". pluoki's was `tailscale serve` on the same port number. proc.PortHolder reads the holder (lsof on the Mac, /proc on Linux, Get-NetTCPConnection on Windows). Tailscale's daemon is root's and often unreadable, so `tailscale serve status --json` is the fallback for the port. gateway.NoteHeld / PortHeld.Sentence say who holds it, and for Tailscale give `tailscale serve --https=<other> http://127.0.0.1:<port>`. Shown in the `magpie serve` standby line and bind error, the app log, `gatewayHeld` in /api/state (Gateway page) and Start's "taken" answer, in en, zh, zh-TW, ja, de. A holder that can't be read says nothing; the old wording stands. Nothing is killed or touched. Run: gofmt clean; go vet darwin, linux nogui, windows (mica); go test ./internal/proc ok; targeted holder/gateway tests on macOS (mica), Windows (win-run) and Linux (wsl-run); parser tests with real lsof output; GUI gateway-port-holder, gateway-takeover, gateway-older, gateway-skew, gateway-port, i18n-keys, i18n-en-no-cjk in chromium and webkit. Real run on WSL: a holder named tailscaled on the LAN address with magpie on 0.0.0.0 gives the Tailscale sentence at the bind error; a Python holder on loopback gives "held by python3.12 (pid N)". Broken by hand: each fix reverted in turn, its test went red. gateway-card.test.cjs is red on origin/main too (#6029). internal/gateway, gui and cli package runs were still going at push; the full suite follows the tag. Not tried: a real `tailscale serve` (changes live config), a real Windows holder end to end, the bind-error path on macOS (a wildcard bind coexists with a specific one there). |
||
|
|
88d2962e0c |
sessions: a file's head and prefix hashes are kept as 16 bytes, not hex (#2278)
Each kept file's state held its head hash as 64 hex characters and its
sampled prefix hash as "sample-v1:" and 64 more, two allocations of 64
and 80 bytes beside the state. They are only compared, so they are now
a digest: the first 16 bytes of the same SHA-256, inline in the state's
own 16 bytes where each string header was. The state's size class is
unchanged (416), and the 144 bytes a file are gone.
A cache written before reads as the same files: digest reads the old
hex (with or without "sample-v1:") as its first 32 characters, which
are what headDigest and prefixHash give now, so the first start after
the update reads nothing again. The call shards' gob keeps its string
fields, written and read through the digest, so a shard written before
restores the same too. File names still use hashHead's full hex.
Run, on a sandbox HOME holding the owner's real account history (18,346
session files), the same sessions.json before each run, web mode, at
120 s:
- w14 (main): live heap 88.8 MB, footprint 129 MB, 127 MB after GC,
CPU 2.35 s
- w15 (this): live heap 86.1 MB, footprint 124 MB, 121 MB after GC,
CPU 2.48 s; at 30 s 2.31 s of CPU against 2.15 s, so no file was read
again from the old cache
Broken by hand: digest no longer stripping "sample-v1:" turns
TestDigestReadsTheHashesWrittenBefore and
TestPrefixHashUnchangedAndUnbuffered red.
At the pushed head (rebased on
|
||
|
|
67d2df72d9 |
sessions: a range's stats are aliased once, as made, and kept aliased (#2278)
With any model alias set, every Stats read copied each kept range's
days and every session's summary into a second, aliased Stats, and kept
that copy (aliasedKept) beside the unaliased one. With a long history
(~14k sessions) the copy held ~5 MB of summaries for as long as the
kept ranges lived.
Now statsKept aliases a range's Stats in place right after
statsOfRange made it (aliasOwned: only st's own Days and Sessions
arrays are written; the usage, model and effort slices are replaced,
never written into) and keeps that one. keptStats carries the alias
names it was made under, so a changed alias makes the ranges again,
as a changed price or title already did. aliasedKept, aliasKept and
aliasStats are gone.
Tests: TestSessionsCountAliasedModelsAsOne now checks that the kept
range's summaries are the very ones the read returned. Broken by hand
(a copy of Sessions before keeping): it went red ("an aliased read
keeps a copy of its summaries beside the kept ones"), and so did
alias_kept_test's "range 0 named again with nothing changed".
TestAliasOwnedLeavesSharedSlicesAlone replaces
TestAliasStatsLeavesItsInputAlone.
Run at 846cc2b9b (rebased on
|
||
|
|
040debfb1e |
sessions: the kept parses' file is mapped, not read onto the heap (#2278)
A start read sessions.json whole onto the heap (24.6 MB on a real
history) and decoded it; then each `named` object was copied again by
gjson.ParseBytes before being read. Nothing decoded keeps a byte of
the file: json.Unmarshal, ccStr and unique.Make all copy, and the keys
are cloned.
On unix the file is now mapped read-only and unmapped once decoded (it
is only replaced by a rename, never written in place); elsewhere it is
read as before. `named` parses its bytes in place.
Run:
- go test ./internal/sessions (mica): ok 63s.
- GOOS=darwin/linux/windows go vet ./internal/sessions: ok.
- Broken by hand: read onto the heap again, TestCacheFileReadWithoutACopy
is red ("allocates 688976 bytes; want it mapped"); a key left
pointing into the file (no Clone) faults it with SIGSEGV after the
unmap. The fixture has plain and escaped names, since an escaped one
is unescaped into a copy anyway.
- Every custom UnmarshalJSON in internal/sessions read for bytes it
keeps: none.
- Real account, mote sandbox HOME, start to 50s (pprof alloc_space):
sessions.loadCache 29.5 MB -> 4.4 MB, os.readFileContents 46.7 MB ->
22.0 MB. Footprint peak unchanged (163 to 164 MB); it is set later.
Not tried: a real Linux start; Windows reads the file as before.
|
||
|
|
152734cd12 |
dirent: one probe vouches for every folder a poll watches (#2278)
A Sessions poll watched each Codex day folder and each Claude Code
project folder through dirent.Watch, and every call ran its own sync1
probe (a mkdir, an unlink and a wait for the write to be heard). On a
real history that was ~130ms of 1.47s CPU per 40 polls, and the
syscalls around it more. WatchSince(dir, mark) skips the probe when a
probe begun after mark was heard; sessions takes the mark when a hold
begins, so one poll makes one probe. A folder watched for the first
time still probes, since its watch hears only what comes after.
Run, real account (mote, the owner's Claude Code and Codex history,
40 back-to-back /api/sessions polls, sandbox HOME):
- CPU: w10 1.47s -> w11 0.54s; under sync1: 130ms -> 10ms.
- Allocated: 25.98 MB -> 25.08 MB.
Tests (mica): go test ./internal/dirent ./internal/sessions ok at the
pushed head. TestWatchesFromOneMarkProbeOnce is red with covered
forced false ("round 0: 3 probes from one mark") and green on this.
./internal/gui: TestPanelHiddenByWailsMarksPageOutOfSight fails under
-count=3 on an origin/main copy (
|
||
|
|
390341f9ed |
appdir: the homes look tells folders apart by inode, not EvalSymlinks (#2278)
ClaudeHomesIn and CodexHomesIn run on every Sessions poll, and keyed each folder they found by filepath.EvalSymlinks, which Lstats every part of the name: ~3 MB of garbage per 40 polls on a real home. On unix a folder is now keyed by its device and inode, which a link to it shares; a folder that can't be looked at is keyed by its name, and other systems keep EvalSymlinks. The folder checks use DirStat, moved here from internal/sessions so both share one. Run (mica, at this tree): go vet for darwin and windows of appdir, sessions, provider and gui, for linux of the first three (gui needs cgo there); GOOS=freebsd go build; go test ./internal/appdir ./internal/sessions ./internal/provider ok. TestHomesLookAllocatesLittle: 55 and 68 allocations a look now, 387 and 400 on the old code, which fails it. Real account (mote, 40 polls of /api/sessions): w9 31.28 MB allocated with os.lstatNolog 3 MB; w10 25.98 MB, lstat gone from the top list. CPU over 30s 1.47s, within noise of w8's 1.29s at mote's load. |
||
|
|
f8248ccd70 |
sessions: an unchanged folder's look allocates nothing (#2278)
readDirectory looked at each folder with os.Stat on every Sessions poll
to see whether its cached listing still held. os.Stat builds a FileInfo
and a name each time, ~6 MB per 40 polls on a real history. dirStat reads
the same mod time, size and kind with unix.Stat into a stack Stat_t;
other systems keep os.Stat.
Run (mica, at this tree): go vet ./internal/sessions for darwin, linux,
windows; GOOS=freebsd go build ./internal/sessions; go test ./internal/sessions
ok (61.8s). TestDirStatAsOSStat passes; with the old discovery.go it fails
("an unchanged folder's look allocated 2 times").
Real account (mote, 40 polls of /api/sessions): w8 34.16 MB allocated,
os.statNolog 6 MB; w9 31.28 MB, os.statNolog not in the top list.
|
||
|
|
10c3315312 |
sessions: an unchanged listing is the last one, not a new list (#2278)
Every 15 s Sessions poll built every Claude Code file's and Codex
rollout's list again, and merged and filtered them into more new
lists, while nothing on disk had changed. On the owner's real history
that was ~120 MB of garbage per 40 polls in listedRollouts,
claudeFiles, listCCFiles and filesKept.
Each lister now keeps its last list (listsKept). A listing walks the
folders as before and compares each file with the kept list's file at
the same place; while they match nothing is allocated, and the kept
list itself is returned. On the first difference it copies the matched
part and goes on, so a grown, new or gone file is listed as a fresh
listing has it, and the kept list is never written. listCCFiles reuses
its walk's scratch slice per lister. distinctPaths and
distinctCodexFiles return their input when nothing is dropped and never
filter in place; codexFilesIn's twin filter clones before deleting.
rolloutsSeen's day entry is its part of the kept list (clipped), not a
clone. The idle cache drop forgets all of it.
Measured on mote with the owner's real account (75 GB history),
40 /api/sessions polls, `magpie heap` before and after, alloc_space
diff:
before (w6): 155.7 MB; listedRollouts 42.8, claudeFiles 32.2 (71.1
cum), listCCFiles 31.0, filesKept.distinct 18.0
after (w7): 34.8 MB; none of the listers in the top; distinct 4.5,
provider.All 9.7 (next)
CPU over 30 s of polling: 1.79 s -> 1.37 s.
Tests: lists_kept_test.go, red on the old code (an unchanged listing
made a list of its own; distinctPaths wrote its input), green now.
TestClaudeFilesMadeAtTheirSize expects the clipped kept list.
Run on mica at this tree (rebased on
|
||
|
|
facc092d00 |
sessions: a ZCode name poll stamps a copy, not the kept file list
v0.1.3800 (729be88e1) has allFilesForTitles give back the list it keeps
from poll to poll, and other polls read it meanwhile. Titles then
wrote each asked ZCode session's message count and time into that list
in place (zcodeTitleStamps): a data race with any poll reading it, and
the kept list no longer matched the rows, so it was made again on the
next pass. The stamps now go in a copy made at the first one that
changes a file; a poll with nothing to stamp copies nothing.
Audited the other users of allFiles/allFilesForTitles and the
in-place writes in internal/sessions (&files[i], .w(), sort.Slice):
the rest write into lists of their own (byKey copies, traceLineFiles
concatenates, callSources goes through distinctOf).
Run (mica): go test -count=1 -timeout 45m ./internal/sessions/ ok;
go test -race -count=3 -run 'TestZCode|TestFilesKept|Titles' ok; vet
ok; gofmt clean. Broken by hand: stamping in place again makes
TestZCodeTitleStampsLeaveKeptListAlone red ("the kept list was
stamped in place: size 1, mod 1790496500000").
Not run: the full ./... and GUI suites (one package touched).
|
||
|
|
0b4b249e54 |
sessions: an unchanged Sessions poll keeps the last file list
Every 15 s poll made the whole deduped file list again (~1.5 MB on a
real history, distinctOf's 58 MB over 40 polls). allFiles and
allFilesForTitles now compare each pass with the last list, held
weakly so a magpie with the page shut keeps none of it, and give the
same array back while nothing differs. A changed or gone file makes a
new list; the old one is never written into (cap == len). An empty
pass is an empty slice, never nil: refresh reads nil as "not listed"
and kept the parses of deleted files (TestGoneAgentLeavesNoSession
went red on the first try, caught before commit).
Run (mica): go test -count=1 -timeout 45m ./internal/sessions/
./internal/dirent/ ok; go vet of both ok; gofmt clean.
Broken by hand: the nil return makes TestFilesKeptWhileTheSame ("an
empty pass: nil") and TestGoneAgentLeavesNoSession ("5 parses kept")
red; a fresh slice on every pass makes TestFilesKeptWhileTheSame red.
Real account on mote, 40 unchanged /api/sessions polls, alloc_space:
179.5 MB (v0.1.3794 build) -> 147.9 MB; distinctOf gone, the kept
list's own compare 12 MB. /api/sessions body sha identical on both.
Not run: the full ./... suite (mote over its cores; this touches the
sessions package only) and the GUI suite.
|
||
|
|
6f3e76626c |
sessions: an unchanged session folder isn't listed again on each poll (macOS)
Every 15 s Sessions poll listed every Codex day folder and Claude Code project again (~18k files in a few hundred folders on a real history), and those getattrlistbulk calls were ~63% of the poll's CPU while nothing had changed. dirent now keeps an FSEvents watch on the Codex and Claude Code homes, and Stats of a folder under one gives its last listing back unless the system said something in it changed since. What makes the word trustworthy: - FSEvents is a moment late, so each Watch (once per read) writes in a new folder of its own under the watch and waits for that write to be heard; events come in order, so every earlier change is heard by then. An earlier write's late word can't end a later wait: each wait has its own folder (an earlier version shared one, and the test went red 4 of 30 at load 73 on mica). - A write to a file held open is heard only when it closes, and Codex holds its rollout open. So a folder with a file written in the last 15 min is listed every time, a change in a home's own folder (history.jsonl, at each prompt) relists everything under it, and no listing is trusted past 2 min. - Dropped events, a moved root, a mount, a wait over 1 s, another volume, or no Watch in the last 2 s: the folder is listed. Linux and Windows have no watcher, so they list as before. Run: - mica: go test -count=30 of the dirent watch tests at load 73, green; with the shared probe folder put back by hand, 4 of 30 red. - mica: go test -count=1 -timeout 45m ./internal/dirent ./internal/sessions ./internal/gui, ok (sessions 253s, gui 159s), one change before the per-wait probe folder; dirent and the real-account checks after it. - go vet: darwin, GOOS=linux -tags nogui, GOOS=windows, CGO_ENABLED=0. - mote, real Codex + Claude Code account (sandbox HOME copy), 40 unchanged /api/sessions polls: 3.54 s CPU sampled on the base binary, 2.28 s with this; getattrlistbulk gone from the top. What is left is GC and os.Stat in claudeFiles. - Same account: an event with a new timestamp appended to the newest rollout changes the sessions tag on the next poll, as on the base. Not tried: Linux and Windows (no change there); a rollout held open by a real running Codex for more than 15 min without a prompt. |
||
|
|
4b1f3eca4a |
usage: a ZCode call magpie routed is not counted again as a local session's (nori_tsukiji on X)
With ZCode on the same computer as magpie, the Usage page's local session calls came out equal to the calls magpie had routed: each was counted twice. Cause: a ZCode request names its session without the sess_ prefix ZCode's database gives it (zcodeBareID; GatewayKeys, Titles and the Sessions list already knew). The Usage page pairs a gateway record with a session file's call by session, tokens and end time (matchedBlocks), and the calls read from ZCode's database kept sess_<id> / sess_subagent_agent_<id>, so they never shared a session with the gateway's records and were never paired. Leaving out calls whose providerID is "magpie" (ocGatewayProvider) only helps when ZCode writes that id beside a reply; with any other id the call was listed twice. Fix: readZCodeCalls gives each call the bare session id; zcode's call parse version is 3, so cached shards are read again. Claude Code, Codex, Pi, OpenCode, Kimi, dsh, grok, minimax, agy and WorkBuddy name their sessions as their requests do (raft.go's requestIDs has ZCode alone); not changed. Run on mote: go test ./internal/usage ./internal/sessions (ok; the zcode fork test's expected session ids are now the bare ones), gui and cli with -run 'ZCode|Zcode|Usage|Session' (ok), go vet darwin/linux/windows (clean), gofmt -l clean. TestZCodeCallsPairWithTheGatewaysRecords (a session, a provider id of ZCode's own, a subagent) was red on the old code: 4 rows for 2 routed calls, the local ones Session sess_7c1f against the gateway's 7c1f. Not tried: a real ZCode database (this computer has none, only the app's tasks index) and the full suite. |
||
|
|
12610cf2ff |
sessions: the Usage page's list leaves out sessions taken off the list of an uninstalled agent (_SekiBetu_ on X)
v0.1.3784 hid a forgotten session only on the Sessions manage page; /api/sessions still listed it. ForgottenOut drops those rows (only while the agent's command is gone, so Restore and a reinstall list them again), and the hidden list's stamp is part of the poll's tag so a Delete shows on the next poll. Run on mote: go test -count=1 ./internal/sessions ok; ./internal/gui fails only TestCoreScriptBudget, red on clean origin/main too (#6189); go vet darwin and windows ok; gofmt clean. Broken by hand: ForgottenOut never hiding turned TestUninstalledAgentSessionsAreForgotten red. Not tried: a real uninstalled OpenCode; the Usage page in a browser. |
||
|
|
fe20e4dbd8 |
sessions: an uninstalled agent's sessions can be deleted and are not offered Resume (_SekiBetu_ on X)
OpenCode (and Cline, Grok, Kimi, Hermes) keep sessions in their own database, so magpie never deletes them and they stay listed after the agent is uninstalled, with only Resume. When the agent's command is gone from PATH, its rows now get Delete (Forget: hidden through the gateway hidden list, a trash note marked forgot, the agent's files untouched, Restore unhides) and no resume command. Installed agents are unchanged. Run on mote: go test -count=1 ./internal/sessions ./internal/gui ok; go vet darwin, windows, linux -tags nogui ok; gofmt clean; GUI files sessions-forget (new, 5 languages x chromium+webkit), sessions-gateway-delete, sessions-manage, sessions-folder-delete, sessions-purge, sessions-row-narrow, i18n-keys, i18n-en-no-cjk all pass. Broken by hand: removing the hidden-row filter turned the gui Go test red; the old client.js turned sessions-forget red (5 of 5 chromium). Not tried: a real uninstalled OpenCode on a user's machine; the Usage page's /api/sessions list still shows a forgotten row (manage page only); the whole GUI suite and full go suite run after the tag. |
||
|
|
b0b995e085 |
sessions: a ZCode session is named as the ZCode app names it, from its task index (Flandern1211 on X)
ZCode's desktop app keeps the names it shows (and the user's renames) in ~/.zcode/v2/tasks-index.sqlite, tasks.title by task_id = the CLI database's session id. The CLI's own title is the model's guess or "default" (blank here), so the Context page showed a first prompt where ZCode shows a name. zcDB.info now takes the task's title when it has a non-default one; the task's updated_at counts toward the file's time so a rename, which touches no CLI row, is read again. The index is read once per change of the file or its -wal, and a failed read keeps the last good one. Run (mote): internal/sessions whole package ok under a sandbox HOME; gofmt clean; go vet darwin, linux nogui, windows ok. Broken by hand: the title overlay off -> new test red (title empty); updated_at bump off -> the rename step red (stale title). Not tried: a real ZCode with the CLI db (this machine has only the app's index, no cli/db), Windows with a moved data folder (ZCodeDataIn is the existing resolver). |
||
|
|
82f09e3248 |
sessions: Codex's leftover review threads are no rows, and its one-session folders are one group
Deleting a thread in Codex leaves its subagent rollouts behind: the
guardian's review threads, titled by the prompt it asks ("The following
is the Codex agent history whose request action you are assessing…"),
and the title threads it opens. magpie reads every rollout, so each was
a session of its own, and one whose thread was gone had nothing to hang
under. On this computer 642 Codex sessions held 422 subagent threads,
86 of them with their parent thread's file gone (and 2 more under one of
those): they filled folders of their own (Documents\Codex\2026-08-17\
shan, wang, wei…), and the bar counted 531 sessions made with another
provider, 371 of them review threads no one ever opened. Codex Desktop
also makes a folder for every chat started without a project
(~/Documents/Codex/<date>/<name>, its outputs/ and work/ in it, named
from the prompt): 36 of them here were 36 folders of one session each.
listAgentWith now drops a Codex subagent thread whose parent is not
listed, to a fixed point, so a chain of them goes too; the agent's tab
counts the rows it lists. The "Scratch sessions" group that commit
e373adddf gave ZCode's draft folders now holds Codex's own per-session
folders as well (that one, Documents\Codex\<date>, a probe in a temp
folder, worktrees, another app's hidden folder). The provider bar counts
Codex's own threads only (role main or unknown): 531 became 160 here.
And a gateway session no call of which was answered and which spent
nothing is no row either (usage.GatewaySession.SpentNothing): the three
empty rows under "Seen through the gateway" were Codex's failed
title calls (kind thread_title, 400/499, 0 tokens), their ids ones no
file of Codex's has.
Rows: 642 Codex sessions to 554 (88 review threads gone), 422 subagent
threads to 334; 36 folders (51 sessions) folded into Scratch sessions;
3 gateway rows to 0, so "Seen through the gateway" is empty here. Usage
still counts every one of those calls, and nothing was deleted.
Run:
- go test ./internal/sessions -run 'TestCodexSubagentWhoseParentIsGone|TestZCode' -count=1: ok.
- go test ./internal/gui -run 'Session|Gateway|Manage' -count=1: ok.
- go build ./...; go vet ./internal/gui ./internal/usage ./internal/sessions; gofmt -l; git diff --check; node --check client.js: clean.
- go test ./internal/sessions -count=1: the same failures as without this
change (TestAgySessions, TestAgyRowOnly, TestAntigravityAppFolder,
TestCCListingKeepsItsNames: path separators and allocation counts on
this Windows box).
- go test ./internal/usage -count=1: TestDesktopSessionAccountMetadata
fails without this change too.
Broken by hand:
- without keptSubagents the 86 rows come back
(TestCodexSubagentWhoseParentIsGoneIsNoRow fails);
- hiding a gateway session on "spent nothing" alone breaks
TestSessionsSameWithoutRows and TestGatewayConversationAPI: a call
answered with no tokens is still a session, so SpentNothing also asks
that none of its calls was answered;
- counting subagent threads in the provider bar says 531 here, 371 of
them review threads.
Not changed: the review threads' calls are still counted by Usage and by
the Sessions page's stats; their rollouts stay on disk (Deleting the
parent does not delete them); the scratch grouping is worked out on the
page (client.js), so Usage's folder filter still lists those folders by
their paths.
|
||
|
|
d7978141bb |
sessions: WSL sessions go when the last agent in a distro is uninstalled (_SekiBetu_ on X)
wslList kept every distro's listing, cold, whenever WSLHomes named no distro. That is also what it names once the last agent in WSL is taken away, so the sessions of a removed agent stayed listed for good, unopenable and undeletable. internal/agent now says whether wsl.exe answered the list of distros (sessions.WSLListed); an answer with no distro an agent is in drops the listings, no answer keeps them as before. Run (win-run, xiaomi-gpu; mote refused SSH all session): the new TestWSLAgentsGoneListingDrops and TestGoneAgentLeavesNoSession (native Claude and Codex folders deleted: nothing listed, no parse kept; green on the old code, so macOS/Linux/Windows native lists were already right), go test ./internal/sessions ./internal/agent, go vet on both. Broken by hand: with the WSLListed check turned off the new test is red (7 sessions listed after the agents were taken away). Not tried: a real WSL distro with a real uninstall; GUI; full suite. |
||
|
|
28ac12bc90 |
sessions: a pass's prices build the providers once, not once a model
A model's price looks its provider up among every provider (BasePriceIn → byIDOrWas → All), and with nothing held each look built every provider again from their files and accounts. keptStill checks every kept price on each 10 s refresh of the Sessions page, so this was the largest allocator left there: provider.All 59 MB cumulative, 40.5 MB of it from sessions.priceOf, in 4 minutes. pricer now holds the providers for a price it hasn't seen, and what a hold built stays for heldFor (1 s) after it, so the rest of the pass reuses it. Run: - TestPricerBuildsTheProvidersOnce (new) counts provider.AllBuilt across six models priced with the real priceOf. Fixed: pass. Broken by hand (Hold removed, in a copy): "built every provider 6 times". - mote: go test ./internal/sessions ./internal/provider ./internal/usage ./internal/gui ok; GOOS=windows go vet and GOOS=linux go vet -tags nogui ./internal/sessions clean; gofmt clean. - Real accounts (mote, sandbox HOME copy, ad4.sh: /api/sessions/stats for days 0, 7 and 30 every 10 s with X-Magpie-Had, heap at 120 s and 360 s): total allocated in the 4 minutes 294.3 MB (t68) → 210.1 MB (t69); provider.All cum 59.3 → 18.3 MB, allProviders 50.6 → 11.7 MB, sessions.priceOf 41.1 → 14.2 MB. Not tried: Windows and Linux runs of the package (vet only). |
||
|
|
71a68639b0 |
sessions: every Claude folder's files are listed into a slice made at their size
With more than one Claude folder (CLAUDE_CONFIG_DIR per account),
claudeFiles appended each folder's files to a slice grown file by file.
It runs on every pass over the session files, and the Sessions page's
ranges are refreshed every 10 s, so on the owner's real history it was
the largest single allocation of that refresh. The folders are listed
first now, and the answer made once at their total; with no Claude
folder the answer is nil, as before.
Run: TestClaudeFilesMadeAtTheirSize (new) passes; on the old code it
fails ("listed into room for 76, want the 41 listed"). go test
./internal/sessions ./internal/gui and go vet (darwin, GOOS=windows,
GOOS=linux -tags nogui) ok at
|
||
|
|
9cd4ef6a19 |
sessions: an aliased range is named once per change, not on every 10 s read
While the Sessions page is open, the GUI reads the 7, 30 and all-days
ranges again every 10 s. Those ranges are kept (keptStats), so a read
with nothing changed costs almost nothing, except when a model is
counted under another name (a usage alias, or a shared group's spelled
name). Then aliasStats copied every day's usage and every session's
summary of each range on each read: ~5 MB a read for the owner's real
history, which was then thrown away because nothing had changed.
aliasKept keeps each range's aliased Stats with the kept Stats it came
from and the names (provider.UsageNamesKey). When the kept Stats are the
same slices and the names haven't changed, it returns the same answer.
Kept Stats are never written, and MergeExternalStats copies before it
writes, so the answer can be shared. The memo is dropped with the kept
ranges (forgetKeptStats), so it never outlives them. UsageAliasKeyed
reads settings once for both the alias and its key.
Run: TestAliasedRangeMadeOncePerNames (new) passes. With the memo
skipped it fails at "named again with nothing changed". With the key
and source check removed it fails at "the old names' range given after
the names changed". go test ./internal/sessions ./internal/provider
./internal/gui and GOOS=windows / GOOS=linux -tags nogui vet: ok at
|
||
|
|
58e541faa9 | sessions: a session file whose stat fails for any reason but absence keeps its last size and time (@simonzyzy on X) | ||
|
|
e12244aca4 |
sessions: a folder that can't be read keeps its last listing, not none (@simonzyzy on X)
readDirectory took a failed stat or listing of a project folder as an empty folder. A refusal that passes (too many files open under a long history's parse, a sharing violation, a stalled network home) took every session in the folder off the Sessions page, and refresh let go their parses with them; a later poll read the folder again and parsed them anew, so sessions vanished and came back. A failed read is unknown: the last good listing stands. A folder that is gone still lists as none. Run (mote-run): TestUnreadableDirectoryKeepsItsLastListing red on the old code (listed 0 entries, want its last 2), green with the change; go test ./internal/sessions ok; gofmt clean; go vet on darwin, linux nogui and windows for internal/sessions clean. Not tried: the full suite before the tag (started after it); a real EMFILE; a per-file stat that fails for a moment (statFiles still drops that one file, filed in the report as open). |
||
|
|
bf0a1252fa |
codex: the chat open in the Codex app follows a provider switch (hubo31377762 on X)
Switching Codex between magpie and OpenAI left the chat that was open unusable. The Codex app holds the writer lock of every chat it has loaded, so no move touched that chat's row, and Codex 0.167 refuses to resume a chat whose provider isn't the configured one (modelProviderMismatch openai to magpie, modelProviderNotConfigured magpie to openai). Reopening it did not help. Just before magpie ends the Codex app's app-server for the route change, the held chats are now moved to the provider Codex is on: a paginated one by its row, a legacy plain rollout in place at equal id length (openai and magpie), packed legacy rollouts and other lengths left to the next sync (provider.CodexBeforeAppEnd, agent.codexRetagOpenThreads, sessions.RetagLoadedCodexThreads). The end is a clean SIGTERM and Codex writes nothing back. Run (mote-run): gofmt -l on the three packages; go vet for darwin, windows and linux with nogui over ./internal/...; go test internal/sessions, provider and agent. Real codex 0.167.1 app-server in a sandbox CODEX_HOME, both ways: no retag gives modelProviderMismatch (openai to magpie) and modelProviderNotConfigured (magpie to openai); with the row retagged and the app-server SIGTERMed, thread/resume succeeds on the new provider in both. Broken by hand: the hook call removed and the retag call emptied; both new tests go red (open chat stays on the old provider, order is [end] only). Not tried: the Codex app GUI itself, Windows runs, a packed legacy thread held open (left to the next sync). A resumed thread's sandbox falling back to config.toml's default happens with no provider change and is #6028. |
||
|
|
26d1c5619a |
sessions: every Claude Code folder is read, not only one (@fivesmallq on X)
Accounts run with their own CLAUDE_CONFIG_DIR (~/.claude-work beside ~/.claude) had only one folder's sessions and token use counted. Claude folders are now found as Codex's are (appdir.ClaudeHomes): the one in use, siblings named claude*/.claude* (or one level down) that hold projects/, and the folders of Claude accounts saved in magpie. The sessions list, calls (Usage), traces, the read-permission check, Dirs and a deleted session's companion folders (file-history etc., taken from the session's own folder) all go through it. A session id in two folders is kept once. No setting to add folders by hand and no GUI change: discovery needs no configuration; a folder with another name is not found. Run (mote): go test appdir, sessions, cli, usage ok; gofmt clean; go vet on darwin, linux and windows for appdir and sessions. New tests (TestClaudeHomesIn, TestCallsReadEveryClaudeFolder, TestListReadsEveryClaudeFolderOnce) fail on the old code for the second folder's sessions. Broke by hand: dropping the key dedupe in claudeFiles still passes, since the list and calls dedupe by key later; it is kept as a guard, not tested alone. Not tried: real second Claude account, Windows/WSL, GUI. |
||
|
|
0bb991b0da |
sessions: Claude Code's copied-session ids are kept as 16 bytes, and folder listings go with the idle parses
On a real history (~15k Claude Code sessions), the idle heap after one
visit to the Sessions page still held two things:
- ccUUIDMemo's set of message uuids per file, as map[string]bool with
the strings gjson copied out: ~5.1 MB. It is now a uuidSet,
map[[16]byte]struct{}: an 8-4-4-4-12 uuid (any case) is parsed into
its 16 bytes, anything else is hashed with FNV-128a.
- ccListed, every Claude Code folder's last listing (path and key per
file): ~2 MB, kept for the life of the process. dropIdleCache now
clears it with the other memos it lets go; the next listing builds it
again from the folder.
Run on mote (go1.26.8):
- go test -count=1 ./internal/catalog ./internal/sessions
./internal/provider ./internal/agent ./internal/codexcat: ok
(before the ccListed line); ./internal/sessions again after: ok.
- gofmt -l, go vet and GOOS=windows go vet for internal/sessions: clean.
- Broken by hand: with ccListed.Clear() commented out,
TestIdleParsesLetGoAndComeBackFromDisk fails ("3 Claude Code
listings kept").
Not tried: the real-account idle measurement of this change alone; it
runs with the catalog change's measurement.
|
||
|
|
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). |
||
|
|
4921bf5a97 |
usage, sessions: one model option for a found routing group's two ids (#5892, Norethcy on X)
A found routing group is called by its public id (auto/<model>) and is kept as group/auto-<slug>; calls recorded under either were counted as two models, so Usage › Sessions' model filter listed the same group twice and the ledger, summaries and session lists split its calls. Ported from NorethSea's 30d6261cd on their fork: UsageAlias names a found group by its public id before the user's alias (both spellings, old session files too), sessions' lists, the ledger keyer, the summary cache's key and Codex's model/effort read through it, and a cache keyed on the group names (UsageNamesKey) is read again when a group is renamed. A user's own provider named "auto" keeps auto/<model> (autoRefsOn). Changed in review: the patch's ledger filter compared every record with provider.SameRef, which reads the providers (customIDs, a stat of providers.json) for each record a filter passes over. FilterOf, the one place a Filter is made from a query, now canonicalizes the model once, and keepsRecord asks the providers only for an auto/ record under a group/ filter (sameGroupModel). Run (mote's sshd reset every connection all afternoon, so on the Linux box through wsl-run; the package run at base |
||
|
|
710a290e26 |
sessions: every session file's parse is let go three minutes after its last read
The parses of every session file (the sessions index, kept on disk as sessions.json) stayed in memory for the life of the process after one visit to the Sessions or Usage page, or the start's warm-up: ~23.5 MB of a 68 MB idle heap for a real history of 24.6 MB on disk. Now, once nothing has read them for cacheIdle (3 min), they are let go and the next read loads them from sessions.json, with no session file read again. They stay while a refresh is reading files, while glances are overlaid, while a save is not on disk yet (it is hurried first), and when the last save failed (writeCache now records that), so a let-go never means parsing a long history again. Measured on mote (macOS) with a copy of the real accounts, idle, no asks, 330 s, t51 = origin/main before this, t52 = this: footprint at the end 111 MB -> 96-100 MB Go heap at the end 68.05 MB -> 46.15 MB (decodeCache's 23.5 MB -> 0) Reads after 200 s idle (t52 had let go; t51 had not): /api/sessions 0.28 s -> 0.54 s /api/sessions/stats 0.19 s -> 0.36 s process CPU over the run 4.03 s -> 4.40 s A warm read is unchanged (0.24 s / 0.01 s). Run: go vet ./internal/sessions (darwin; windows and linux with CGO_ENABLED=0); go test ./internal/sessions ./internal/gui ./internal/usage on mote, all ok. TestIdleParsesLetGoAndComeBackFromDisk broken by hand twice: dropping the failed-save guard (red: "let go while the last save had failed") and not clearing the cache (red: "idle parses kept"). Not run: the full suite; Windows and Linux runs of the package. |
||
|
|
e7fe52fdc3 |
minimax: follow the data folder MiniMax Code Desktop moved, not ~/.minimax (YujunT46308 on X)
YujunT46308 on X (magpie 0.1.3519, MiniMax Code 3.1.13 CN): with the app's data folder moved to another parent (localRuntimeDataParentDir), magpie went on writing ~/.minimax/config.yaml, which the app no longer reads. How MiniMax Code 3.1.13 finds it, read from its own app.asar (dist/main/modules/local-runtime/data-dir.js, resolveLocalRuntimeDataDirSelection; @mavis/config's config.js for the runtime): MINIMAX_DATA_DIR, then MAVIS_DATA_DIR, then the desktop setting, then ~/.minimax. Settings' data-folder move keeps the parent as config.localRuntimeDataParentDir in its electron-store file (storage.ipc.js: minimax-agent-cn-config.json for the China build, minimax-agent-config.json for the global one) in Electron userData, named by app-identity.js: "MiniMax" (CN) / "MiniMax Agent". The data folder is <parent>/.minimax. What changed: - appdir.MiniMaxDirIn resolves the folder in that order, reading the store under ~/Library/Application Support on a Mac and %APPDATA% on Windows. A missing, unreadable or unparseable store, or a parent that isn't an absolute string, is ~/.minimax, as electron-store itself reads a file it can't parse as its defaults. - internal/agent's MiniMaxDir (detection, connect, restore, Sync, Check) and internal/sessions' MiniMaxDir (Usage's calls) both use it; the Library's skills follow a.Dir. WSL's mcode still uses the distro's ~/.minimax (no desktop app there). - MAVIS_DATA_DIR joins agentenv's variables, so tests sandbox it. - agent-wiring.md and reference.md say where the folder comes from. Run: - On mote, the real MiniMax Code 3.1.13 CN arm64 dmg: launched with no setting, userData was ~/Library/Application Support/MiniMax holding minimax-agent-cn-config.json; with config.localRuntimeDataParentDir set to a folder, the next launch created <parent>/.minimax/config.yaml. appdir.MiniMaxDir() against that real store printed <parent>/.minimax. (The test data I made on mote was removed after.) - mote-run go test -count=1 ./internal/appdir ./internal/agentenv ./internal/sessions ./internal/library: ok. ./internal/agent -run 'MiniMax|Minimax|WSL|Env|Spelled|Handwired': ok. - win-run go test -run MiniMax ./internal/appdir ./internal/agent ./internal/sessions: ok, TestMiniMaxDirIn and TestMiniMaxCodeMovedByDesktop ran (not skipped) with %APPDATA% paths. - gofmt -l clean; go vet of the touched packages for darwin, windows and linux (nogui, CGO off) ok. Broken by hand: with the desktop store read turned off, TestMiniMaxDirIn and TestMiniMaxCodeMovedByDesktop go red (the folder reads as ~/.minimax). Not tried: the Windows desktop app itself (userData %APPDATA%\MiniMax is Electron's appData plus the app name, the same rule seen on the Mac); the global build's store with a real install; a store mid-rollback (the app's guard writes the restored parent back to the same key on its next launch). A user who also runs the mcode CLI without MINIMAX_DATA_DIR has it on ~/.minimax, which magpie now leaves alone while the desktop folder is moved. |
||
|
|
53280aa08e |
sessions: the stats caches are let go two minutes after the page stops asking
The Sessions page polls /api/sessions/stats every 15 s. Each range it asked
for kept its Stats, the overview and tag sums, about 15 MB on a 14k-session
history, for as long as magpie ran, with the window closed too. Now a timer
armed on every ask drops them two minutes after the last one (not while a
read is busy), with the sessions package's kept ranges, then returns the
memory to the OS. The parsed files stay, so asking again sums them up
again without reading a file.
Measured on mote with a copy of the real accounts (14k sessions), the
statsIdle delay set to 20 s in a measuring build only:
- footprint after six stats asks: t47 (origin/main) 140 MB, t48 151 MB;
- 45 s later: t47 130 MB, t48 116 MB;
- asking again after the release: days=0 0.34 s (was 0.06 s while kept),
days=30 0.17 s.
Run on mote: go vet ./internal/gui ./internal/sessions; go test
./internal/gui ./internal/sessions ok. TestIdleStatsLetGo is red with
`statsMemo.m = nil` taken out ("2 ranges ... kept; want none").
The timer is off under go test, so other gui tests keep their memos.
Not tried: the GUI page itself; the full suite.
|
||
|
|
e4197144a8 |
perf: every package's package-level regexps compile on first use
v0.1.3516 made gateway's and redact's patterns lazy. The other 299 package-level regexp.MustCompile calls, in 148 files across agent, provider, gui, library, codexcat, sessions, usage, plugin and the rest, now go through lazyre.New too, so a launch that never reaches them (`magpie statusline`, run by Claude Code on every message) doesn't compile them. Fields, maps and params that held them are *lazyre.RE. Measured on mote (M5 Pro), sandbox HOME, v0.1.3516-equivalent build (t42) against this one (t43): - GODEBUG=inittrace=1 sum: 7.39 MB / 69,837 allocs -> 4.62 MB / 46,765 - `magpie statusline`, 3 runs each: instructions retired ~212M -> ~176M, peak memory footprint 19.2-19.4 MB -> 16.8-17.0 MB Run: go vet ./... (darwin) ok; GOOS=windows go vet on each of the 30 changed packages ok; GOOS=linux go vet ok except ., internal/cli and internal/gui, which stop in wails v3's cgo files when cross-compiled (the same at main). New TestAllLazyPatternsCompile at the root compiles all 574 registered patterns (ok), so a bad pattern fails a test rather than a first use. Not run before push: the changed packages' own test suites; they run on mote after it. |
||
|
|
1cfea01695 |
sessions: Codex's per-poll name and twin sets are kept from poll to poll (#2278)
Each Sessions poll lists every Codex rollout (~13k here) and made two maps over them anew: distinctCodexFiles' first file of each name, and codexFilesIn's set of plain rollouts a compressed twin defers to. Both are now taken from a shelf, as pathSets are, and given back cleared; the shelf lets them go after it idles. Run on mote (M5 Pro, macOS 27), with a copy of the real accounts: - go vet ./internal/sessions; go test ./internal/sessions: ok. - TestDistinctCodexFilesKeepsItsSet (new): a call over 4,000 rollouts makes at most 4 allocations. Broken by hand (a new map each call): 47, red. The twin set has no test of its own; it uses pathSet as is. - /api/sessions and /api/sessions/stats?days=30 from a fresh start, real history: byte-identical to v0.1.3503's code. - 40 /api/sessions polls with X-Magpie-Had: 185.5 MB allocated before, 152.4 MB with this; distinctCodexFiles is gone from the profile. |
||
|
|
7c0a103eb1 |
sessions: a file's modification time is unix nanoseconds, 80 bytes a file (#2278)
A Sessions poll copies every session file's `file` into several slices (distinctOf, listedRollouts, listCCFiles, distinctCodexFiles), and rolloutsSeen keeps one of every Codex rollout. Its time.Time was 24 of its 96 bytes. mod is now a modTime (int64 nanoseconds, 0 for none) with the few methods the package used; a time.Time going in is modOf(t), one coming out is .Time(). UnixNano keeps the zero time's own value, so a parse kept on disk for a file with no time still matches. Run on mote (M5 Pro, macOS 27), with a copy of the real accounts: - go vet ./...; GOOS=linux and GOOS=windows go vet ./internal/sessions: ok. - go test ./internal/sessions ./internal/gui ./internal/usage: ok. - TestFileFitsEightyBytes (new) holds the size and the round trip of a time and of none. - /api/sessions and /api/sessions/stats?days=30 from a fresh start, real history (~23k files): byte-identical to v0.1.3499's code (8,068,574 and 623,801 bytes). - 40 /api/sessions polls with X-Magpie-Had: 208 MB allocated before, 185.5 MB with this. |
||
|
|
dae104bfac |
capre: a length check, not an unrolled repeat, holds nine patterns
Go's regexp unrolls a bounded repeat into that many copies of its
class: [A-Za-z0-9.-]{0,254} (the session terminal's bundle id) was
89kB of program, kept from start to exit, and Codex's item-id refusal
`.{0,1000}?` 88kB. Measured one by one over magpie's 540 package-level
patterns (1.5MB in all), the nine largest bounded ones were ~440kB.
capre.MustCompile(expr, max) is the pattern with * or +, matching only
a string of max characters at most (rune count, so the (?i) Kelvin
sign and invalid bytes count as the regexp counted them). The nine:
settings' bundle id, library's name and agent id (now name@wsl:distro
cut in two), Anthropic tool names, the trace page's name and find,
access's MCP server, OpenClaw's profile and Codex's provider id. The
item-id refusal is a function: the tail within 1000 characters of a
head.
Run on mote (go1.26.8):
- go test ./internal/capre ./internal/access ./internal/settings
./internal/library ./internal/sessions ./internal/agent ./internal/gui
. : ok; ./internal/gateway -run 'ItemID|Undeclared|ToolName|Refus': ok
- TestCappedMatchesBounded holds each old pattern against its new one
over 14 units x 19 lengths (0..300, at each bound +-1); with the
length check taken out it is red (1586 mismatches).
TestItemIDRefusalAsTheRegexp holds the function against the old
regexp at 998..1002 characters of x, é, 日, \xff, \n; with 1001 it is
red. TestCappedIsSmall: 1304 bytes held, 49680 bounded.
- go vet native, GOOS=linux and GOOS=windows over the touched packages
(gui natively: its Linux build needs cgo); gofmt -l clean.
- Real build, GODEBUG=inittrace=1: magpie's own inits allocate
11.93MB -> 10.61MB.
- Idle on the real-account copy, 180s heap: regexp programs (sampled)
4.54MB -> 3.01MB.
Not tried: the full ./... suite; the gateway package beyond the run
above.
|
||
|
|
8d80f6bc0a |
sessions: the kept stats and listing hold an untitled id once, not a map entry
keptStats and keptList noted every answer Codex's titles gave in a map[id]string, to ask each again before the kept ranges are given out. Nearly every id has no title, and the map held 3.12MB on an 18k-file history. titleAnswers keeps the named ones in a map and the untitled ids in a slice, sorted, without repeats or slack once settled; still() asks each again as before. Both caches use it. Run (mote, real-account copy, idle 180s, network blocked): - statsKept.keptTitle.func4 3.12MB -> under the profile's cut; total inuse 107.40MB -> 104.23MB. - TestStatsKeptBetweenPolls now also names a Codex thread after the ranges were kept and checks the title reaches them. TestTitleAnswersSettled checks repeats and slack go. - Broken by hand (still() skipping untitled ids, settle not compacting): TestListKeptBetweenPolls, TestStatsKeptBetweenPolls and TestTitleAnswersSettled red; green on this code. - go test ./internal/sessions/ ok; go vet darwin, linux, windows ok; gofmt clean. Not tried: the full suite (only internal/sessions reads these caches). |
||
|
|
67d06c24ea |
sessions: a file's state fits the 416-byte size class, not 448
A state was 424 bytes, so each one decodeCache and parseRead make took a
448-byte slot. HeadSize is the length of a head of headLen (256) bytes
at most; as an int32 beside CdRead it saves 8 bytes, and a state is 416,
32 bytes less held per session file (~0.58MB for 18k files).
Run (mote, real-account copy, idle 180s, network blocked):
- decodeCache's inuse 26.01MB -> 23MB, reflect.unsafe_New 15.51MB ->
12MB. The profile samples every 512KB, so more than the ~0.58MB the
size class accounts for is sampling, not this change.
- TestStateFitsItsSizeClass: green; red on the old int by hand ("a state
is 424 bytes, over the 416-byte size class").
- go test ./internal/sessions/ ok; go vet darwin, linux, windows ok;
gofmt clean. The cache's JSON keeps head_size as a number, so an old
cache reads as before.
Not tried: the full suite (state is unexported, only internal/sessions
reads it).
|
||
|
|
cd0ba05c21 |
sessions: each day's usage and active rows are made to size
statsOfRange grew every day's Usage and Active rows by append, and the
overview keeps three ranges (7, 30, every day), each holding the slack
of every doubling. The rows are now counted per date first and made at
their length.
Run (mote, real-account copy, idle 180s, network blocked):
- statsOfRange's own inuse 9.90MB -> 8.37MB (-1.54MB in the diff
against the v0.1.3411 build's profile).
- TestStatsDayRowsHoldNoSlack: green; red on the old code by hand
("usage 5 of 8, active 5 of 8").
- go test ./internal/sessions/ ok; go vet darwin, linux, windows ok;
gofmt clean.
Not tried: the full suite (one package changed, nothing outside it reads
the rows' capacity).
|
||
|
|
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.
|
||
|
|
36ddd57619 |
sessions: the overview's active hours keep only the hours with time
Each range statsFor keeps holds an Active for every day, agent and folder, and each had a 24-int64 Hours (192 bytes), mostly zeros: 4.5 MB of statsOfRange's 13.5 MB in the idle heap on the owner's real cache (18,331 files). Active.Hours is now the same sparse hours a day keeps (hour<<58|seconds), and the act sums in statsOfRange use it too. Its JSON is the 24 numbers of seconds it was, which the Usage page's heatmap reads (a.hours.forEach). Run on mote at this head: - go test ./internal/sessions: ok - GOOS=darwin/linux/windows go vet ./internal/sessions: ok; gofmt clean - TestStatsHoursAndSessions now reads the hours through JSON, as the page does. Broken by hand (ms not turned into seconds): red, "the 20th by hour: [... 180000]". - Real-account copy (~/r2278/acct), idle heap at 180s: inuse 110.65 MB (v0.1.3402's tree) -> 100.21 MB at this head (sampled; 4.5 MB of it was the hours' own lists). |
||
|
|
f8186c6915 |
sessions: a day keeps only the hours it has time in
A day's hours were a [24]int64 (192 bytes) whether or not it had any. The owner's real cache has 18,331 files and 19,191 days; 13,406 days had hours, but only 19,107 hours across them had any time, so ~2.6 MB of zeros sat in the idle heap for good. hours is now a sorted []uint64 of hour<<58|ms, one entry per hour with time. Its JSON is still the 24-number array, so sessions.json reads and writes as before; an all-zero array read back keeps one zero entry so the day still counts as having hours. Run on mote at this head: - go test ./internal/sessions: ok - GOOS=darwin/linux/windows go vet ./internal/sessions: ok - gofmt -l: clean - Broken by hand: without hours.MarshalJSON, TestHoursKeepTheCacheShape is red (the packed entries went out as raw numbers). - Real-account copy (~/r2278/acct): idle heap at 180s, t1 (v0.1.3398's tree) vs this: inuse 112.94 MB -> 110.65 MB (-2.3 MB; the 2.6 MB estimate less sampling noise). |
||
|
|
fc8e98ba47 |
edit: Codex's thousands of [projects] tables are left out of the reads that don't want them (#2278)
Codex writes a [projects."…"] table for every project it is trusted in;
the owner's config.toml has 10,933 of them in 1.5 MB. go-toml's decoder
checks each table against its siblings one at a time, so every decode
of the file cost ~0.3s of CPU, and six readers decoded it again each
time Codex wrote it, plus a whole-file check before each write magpie
made to it.
- edit.TOMLWithout drops [projects…] tables in a single unstable.Parser
pass. The agent's codexTopOf, sessions' readCodexConfig, provider's
readCodexStoreSetting, library's rtk sandbox, hooks rekey and MCP
entries read through it. None of them reads projects. A file that
doesn't parse is passed through unchanged, so it still fails.
- validateTOML checks definitions with the rest of the file and the
projects decoded apart, 128 projects to a decode. A bare [projects]
table, a dotted projects.… key outside the tables, or any error
decodes the whole file, so the error is the one it gives.
Run on mote (M5 Pro):
- BenchmarkCodexConfigDecode (10,933 projects): 283ms -> 7.6ms a decode.
- BenchmarkValidateCodexConfig: 52ms (the whole decode was 283ms).
- Startup CPU profile, first 70s, the real-account copy (the real
1,524,099-byte config.toml): 2.76s -> 2.26s of samples; go-toml
0.32s -> none sampled.
- go test ./internal/edit ./internal/sessions ./internal/provider
./internal/library ./internal/agent: all ok.
- go vet of the same five on darwin, GOOS=linux and GOOS=windows; gofmt -l clean.
Broken by hand:
- Decoding the batches into struct{} instead of a map:
TestValidateTOMLDefinitionsInGroups went red ("a key twice", "a
subtable then its key"), so the check keeps maps.
Not tried:
- the whole suite. Only the five packages that read the file were run.
- Now that projects is left out, a project table defined twice no longer
fails these readers' decode. Codex itself refuses such a file.
|
||
|
|
7cabf0da98 |
sessions: one place says which ids a ZCode request names, and drafts are one group (#5754)
On top of Flandern1211's cherry-picked fix (the commit before this one).
GatewayKeys gave the bare id of a ZCode session (sess_<id> in ZCode's
database, <id> in the gateway's record), but NativeIDs kept its own copy
of the keys: the management page still counted every ZCode session sent
through the gateway as a gateway-only session, its delete listed them,
and its search read them a second time. requestIDs is now the one place
that says which ids a request names a session by; GatewayKeys (Sessions
list, its spend, the stats' native set, viaOf, the manage search) and
NativeIDs (the manage page's count and delete) both read it.
ZCode runs a session started without a project in a folder it makes for
that session alone: <workspaceDirectory>/draft-<id> or <ms>-<uuid>, with
workspaceDirectory = ~/.zcode/workspace (read from ZCode 3.17.2's
out/host/index.js, downloaded from cdn-zcode.z.ai; never the live
~/.zcode). The reporter's group is renamed from "Scratch sessions" to
"Draft sessions" (草稿会话 / 草稿會話 / 下書きセッション /
Entwurfssitzungen), after ZCode's own word for them, with a GUI test of
its own. Comments no longer quote "Seen through the gateway", which
i18n-keys' plugin-words guard read as the core saying the word.
Run (mote, at this tree, rebased on
|
||
|
|
a39b63e886 |
sessions: a ZCode session is listed once, and its draft folders are one group
A ZCode request names its session by the id its database gives with a prefix stripped (sess_…, a subagent's sess_subagent_agent_…: zcodeBareID, which Titles already used for names), while GatewayKeys kept only the prefixed id. MergeExternal therefore matched no native session for any ZCode session sent through magpie's gateway, and each was a row under its folder and again a row under "Seen through the gateway" with no files behind it. On this computer's database (1,105 sessions, 3,536 gateway records) that was 70 of 70 gateway rows: 38 top-level sessions, 9 forks, 23 subagents. A group already holds its forks' and subagents' files (ocRoots), and assembleListed counts every file's calls in the row, so each of the 70 counted the same calls a second time. GatewayKeys now gives the bare id of a ZCode session and of its forks and subagents; externalAdded reads GatewayKeys instead of keeping its own copy of the keys in pairs; idInFile names ZCode, so subIDs collects the ids their own rows give (their files are in the group, no row lists them apart). The Sessions page draws a ZCode session whose folder ZCode made for that one session (~/.zcode/workspace/<draft|time>-<uuid>, one for each session started without a project) in one "Scratch sessions" group after the projects: 42 of them here were 40 folders of one session under Other folders, and they are no projects of the reader's. cwd, files and usage are untouched; a row's tooltip gives the folder it ran in. The list went from 1,286 rows to 1,216 over the same 1,213 native ones; the 70 gateway rows had 34.3M input and 2.59M output tokens and $125.66 of the ledger's cost on top of the rows that already counted those calls. A ZCode row now prices its own calls from the catalog like every other agent's, and Usage keeps the ledger's figures. Run: - go test ./internal/sessions -run 'TestZCode' -count=1: ok. - go test ./internal/gui -run 'Session|Gateway' -count=1: ok. - go build ./...; go vet ./internal/sessions: ok. - gofmt -l; git diff --check; node --check on client.js and i18n.js: clean. - go test ./internal/sessions -count=1: the same failures as without this change (TestAgySessions, TestAgyRowOnly, TestAntigravityAppFolder, TestCCListingKeepsItsNames: path separators and allocation counts on this Windows box). - go test ./internal/gui -count=1: the same failures as without this change (lody's %AppData%, pageservice's symlink privilege here). Broken by hand: - dropping the bare key puts the 70 rows back under Seen through the gateway (TestZCodeGatewayRowIsTheSessionItself fails); - leaving ZCode out of idInFile keeps a fork's and a subagent's own rows as gateway rows while the group already counts their calls. Not changed: the scratch group is worked out on the page (client.js), so Usage's folder filter still lists the draft folders by their paths; the group is ZCode's only, and other agents' per-session folders are left as they were. |
||
|
|
b8270850df |
sessions: a kept parse's rarely set fields live in a StateMore made only when one is set (#2278)
Each of the ~18k files the Sessions cache keeps had a 760-byte state, and ~330 bytes of it were fields almost no file sets: the Codex spawn and agent maps, Named/Custom/First, the dsh and Claude conversation lists, Root/Leaf, Compacts, and the six per-agent tails (Grok, Droid, Kimi, Agy, Dsh, Cline). On the owner's real cache (18,331 files) Root and Leaf are set in 150, Named in 117, Compacts in 78, First in 35. They move to an embedded *StateMore, nil unless something is in it: reads go through more() (a shared empty one when nil), writes through own(). The JSON is the same (embedded fields are inlined), so the cache version stays. - parseWith drops an extra that only had empty values written to it, and share() drops one the decode made empty. - clone() deep-copies the extra, so growing a clone leaves the kept state alone. Copies that never write (withoutRevisions, the Agent rename) share it, as they shared the maps before. Run on mote at this tree: - gofmt -l internal/sessions: clean. go vet ./internal/sessions/ on darwin, GOOS=linux and GOOS=windows: ok. - go test -count=1 ./internal/sessions/: ok (26s). - Every selector was checked by renaming the embedding to a named field and compiling with -gcflags=-e until only the struct literals were left, so no field is reached through a nil *StateMore. - New tests in state_more_test.go: zero() knows every field (reflect), a read makes no extra and a write never reaches the shared empty one, a clone owns its extra, and a cache round trip keeps no empty extra. Broken by hand: dropping Cline from zero() and sharing the extra in clone() each turn their test red; restored. - Real-account idle heap (copy of the owner's config and 24.6MB sessions cache, gateway idle 180s, heap after GC): decodeCache's retained heap 35.0MB -> 22.5MB, reflect.unsafe_New 20.0MB -> 10.5MB. The total (128.7MB -> 133.6MB) moves by more than that between runs of one binary (118-140MB), from late passes that happened to be live. Not tried: the full ./... suite (state is unexported; only internal/sessions uses it, and the whole binary builds). |
||
|
|
2a64b4bcb7 |
library: a skill router, one magpie-skills skill listing an agent's skills
Like the MCP router, for skills. With the Skills tab's new "Skill router" switch on (off by default), each agent's skills folder gets one skill of magpie's, magpie-skills, in place of a link of each skill ticked for it. Its SKILL.md lists them, each with its description and the path of its SKILL.md, and the agent reads that file when a task fits. An agent then carries one skill's description in its prompt however many the Library gives it. - The entry is a link to <settings dir>/skill-router/<hash of the folder>/, which holds SKILL.md and a hidden .skills/<name> link of each listed skill (hidden, so Codex, OpenCode and Pi don't find a skill twice). Its description stays within 1024 bytes (Codex's limit), cut on a whole character. - Every skill is listed unless it is kept direct (a button on the skill, or `magpie library skill router <name> direct`; carried by a sync), is only for the user to type (disable-model-invocation), is in ~/.agents/skills, is blocked, or the agent has its own by that name. Those keep their own links. - An agent whose folder can't take it keeps every link, and the page says why: given copies, a live agent picking its own, the shared ~/.agents/skills, a Library skill called magpie-skills, or a magpie-skills of the user's (never written over). - Claude Code 2.1.316 asks before reading outside its project, its skills folder too, so magpie adds Read rules for the entry and the folders behind it to permissions.allow, records them, and takes out only its own when they go (as permissions.deny does). - The switch is this computer's alone; `magpie library skill router on|off` sets it from the CLI. - Sessions count a routed read of .skills/<name>/SKILL.md as <name> (Claude Code, Alma, Droid), and calling up magpie-skills itself as no skill, so a use counts once. - docs/subsystems/skill-router.md, with a row in the index. Run at this tree (rebased on origin/main |
||
|
|
16e79fc6b0 |
dsh: a request still answering shows under its fork, not its source (#5542)
The Routing page's live card for a dsh fork's request showed under the
source until the reply was written: it has no reply id yet, and the
opening it is keyed by is the one the fork copied. The messages of the
request's turn are in the branch's own session file before the request
goes out, so they name it:
- gateway: Route.LastConvs, the ids of the user messages the request's
turn carries, newest first (dshLastConvs, dsh only, at most 4);
- sessions: TurnConvs, the ids of the newest turn's user messages, reset
at turn/start, not kept from a fork's seed, at most 4 (dshTurnKept);
dsh's parse version goes to 3;
- gui: ownerBy asks the reply id, then the turn's messages, then the
opening (ownerOfRoute on the Routing page).
Changed from Flandern1211's patch (957caf84) in review:
- the turn lookup has the reply id's guard (forkedFrom): a "继续" in
another conversation's newest turn no longer takes a route;
- in dsh's captured requests (sessions/testdata/dsh-gateway) the newest
user message is the runtime context, the same for every session of a
folder, so it names no one: the gateway reads the whole run of the
turn's user messages (typed + context), and passes over Messages'
tool_result steps, where the patch returned nil;
- looseKeys asks for a turn's keys only while the route answers and for
convsKept, not for every older route: those keys are never listed
once a newer turn starts, and would relist every agent's sessions on
each 2s poll;
- one spelling per message and at most 4 kept (a v3 file has no
turn/start, so TurnConvs grew with every message, 3 ids each);
- no TurnConvs on Context's records (it counts done calls, named by
reply), LastConvs dropped from the history (saveRoute) and from what
the page is sent;
- dshLastConvs reads messages by their members, not decoded: 0.49 ms
on a 2.2 MB body of 800 tool steps (convOf 0.30 ms), 1.10 ms before.
Run on mote at 2be7aaeea (this change on 9730e0199; then rebased over
|
||
|
|
371b2b63a0 |
sessions: gateway mode lists the sessions the gateway counted
Usage › Sessions lists only the stats' keys, and the keys named only the agent files this computer reads. A Docker magpie in gateway mode reads none, so the sessions that came through the gateway were counted and not listed. MergeExternalStats now puts them in the keys too, in the list's order. Run (mote): go test ./internal/sessions ./internal/gui -run 'TestGatewayStats|TestGatewayMode' ok; GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./... clean, gofmt -l clean. Broken by hand: on the old code the unit test's keys are [claude:a] and the gui test's [] (gateway mode off, days=0). Not tried: a real Docker magpie; the full suite (mote rebooted mid-run). Reported-by: linkaww on Discord |
||
|
|
04aabf3a01 |
sessions: read Antigravity Insiders conversations (#5634)
Antigravity - Insiders keeps its conversations in a separate store, ~/.gemini/antigravity-insiders/conversations/<id>.db, with its own conversation_summaries.db beside it. Only the stable store was scanned, so Insiders sessions and their token use never reached Sessions or Usage. Both stores are now read under the existing antigravity agent and its session-reading choice. An Insiders-only install shows up in Found, and Dirs lists each store that exists. Each file takes its title and folder from its own store's summaries. Insiders session ids carry an "insiders-" prefix in magpie, so a UUID present in both stores stays two sessions with separate call ids; stable ids are unchanged and nothing on disk is renamed. Nothing maps a session id back to a path, so the prefix can't send a reader to the wrong file. Ported from BUKOWSKIREAL's branch (926d4fe50), unchanged. Ran (mote, at this head): - TestAntigravityInsidersSessions: green; red with the three source files put back (Insiders missing from Found, Dirs and List). - go test -count=1 ./internal/sessions ./internal/usage ./internal/usageapi ok; go vet ./internal/sessions for darwin, linux and windows ok; gofmt clean. - The author's own run: 42 real Insiders databases read in an isolated copy, 2,293 calls, each model's tokens matching an independent decoder. Not tried: a real Insiders install on our machines; the full suite. Co-authored-by: Ruijia Zhang <ruijiazhang76@gmail.com> Reported-by: zhang9083 (Discord #feedback) |