ec396be60c8f3fac2f1a270bc43586fee0b0ebed
3948
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
ec396be60c |
sessions: a dsh session read for calls is read on, not whole
dsh's calls were read by a whole-file reader: each reply appended to a
session made Usage's ledger read the whole file again and, packed,
decompress every frame of it. parseDsh already reads on from the frame
it left off in (frames.go, 827c304d9); the call reader now does too.
readDshCalls is handed what the last read came to and reads on from its
tail (scanFrames for a packed file, scanAt for a plain one), carrying
dsh's header in dshCarry. It says how many of the calls it gives were
kept from before, so only the new ones are appended to the disk shard
(resumeCallReaders in call_cache.go). The carry is kept in the shard's
state as JSON (callDiskState.Dsh), since the in-memory read is let go
after packing. A fork's inherited end-seed met in a later read drops
what was counted before it and rewrites the shard whole, as the whole
read did by cutting at the last one. A file cut short or replaced
(tail.holds) is read whole. One change from before, as for parseDsh: a
last line not ended by a newline waits for it.
Measured (CPU, getrusage; 50 MB of events, ~3600 calls, a reply
appended between reads; packed: frames of 200 lines; the old reader
measured from a worktree at 432a2ba5e with the same harness; machine at
load ~500):
plain before: 91-109 ms CPU, 0.5-1.3 s wall per read after an append
plain after: 0.6-7.7 ms CPU, 2-129 ms wall
packed before: 214-230 ms CPU, 3.5-4.8 s wall per read after an append
packed after: 1.2-1.5 ms CPU, 13-46 ms wall
first read unchanged (plain ~60-105 ms, packed ~195-215 ms CPU)
Tests: TestDshCallsReadOnlyWhatWasAppended (packed dsh-a) checks where
each read starts (scanHook) and its calls: a frame appended is read
alone; half a frame waits; a frame ending inside a line is read on from
that frame; after resetCalls() the read goes on from the disk shard;
cut short reads from 0. TestDshCallsEndSeedAcrossReads: dsh-c's
end-seed arriving in a later read drops the seeded call, its own is
read on, and the shard holds only that after resetCalls().
Broken by hand: no resume -> both red ("read from 0, want 654"); the
carry not written to the shard -> both red (same); the end-seed not
rewriting the shard -> red ("the fork's own ...: [50 100]").
Run: go test ./internal/sessions -run 'Dsh|Call|Usage|Pi' -count=1 ok;
gofmt -l and go vet ./internal/sessions clean. The full-suite record is
in the last commit of this series.
|
||
|
|
da9fc17eb6 |
sessions: a Pi or omp session file read for calls is read on, not whole
Pi's and omp's calls (#1951) were read by a whole-file reader: every time a session file grew by one line, Usage's ledger decoded the whole file again, its header and every message, and rewrote its disk shard. Pi and omp only append to a session file, a line an entry, as Kimi Code's wire file is. Pi and omp are now line readers (lineCallReaders): a file that only grew is read on from the last whole line, and only the calls it adds are appended to the shard. What a later line's call is read with is carried in piCarry on the callFile: the header's cwd, a fork's start (what came before it is its parent's), and the provider and model in use for a compaction's or tool result's usage. That carry is kept in the shard's state too, flat (callDiskState.Pi*), as the in-memory read is let go after packing: a carry that lived only in memory made every append read from 0 again. A shard written before has no carry (piCallsKept false) and its file is read whole once more. Cut shorter, written over, or grown at a changed head: read whole again (prepareCalls' head and prefix hashes, as for Kimi). Measured (CPU, getrusage; one 50 MB Pi session, ~3500 calls, a call appended between reads; the old reader measured from a worktree at 432a2ba5e with the same harness; machine at load ~500): before: 112-153 ms CPU, 1.0-2.5 s wall per read after an append after: 1.1-3.1 ms CPU, 5-57 ms wall per read after an append; first read ~95 ms CPU, as before Test: TestPiCallsReadOnlyWhatWasAppended (a fork, its model set once at the top, compaction usage) checks where each read starts (scanHook) and the calls it gives: an append with a half line after reads from the old end and leaves the half line; finished, it is read; a line older than the fork's start is left out after a resume as on a whole read; the model, provider and cwd stay right on calls read on; after resetCalls() the read resumes from the disk shard; cut shorter and written over read from 0. Broken by hand: piCallsKept always false -> red ("read from 0, want 686"); the carry not written to the shard -> red (same); begin run on every read, the carry lost -> red ("calls [1 2], want [1 2 3]"). Run: go test ./internal/sessions -run 'Pi|Omp|OMP|Call|Usage' -count=1 ok; gofmt -l and go vet ./internal/sessions clean. The full-suite record is in the last commit of this series. |
||
|
|
1f411802b8 |
sessions: Droid's and Grok's listings open only the files that changed
Droid's listing opened every transcript to read its first line, for
whether it is a subagent's (callingSessionId), and Grok Build's read and
decoded every session's summary.json for its session_kind and parent.
The listing runs on every 15s poll of Sessions and Usage, so with
thousands of sessions each poll opened thousands of files that had not
changed.
listMemo (listmemo.go) keeps what a listing read from each file by that
file's own size and mtime, not the folded size the listing gives the
session. A listing is a round: a file not seen in it (a session deleted)
is dropped when it ends, so the memo never outgrows the sessions there
are. A read that failed, such as a transcript whose first line is still
being written, is not kept, and the next listing reads it again: a
failed read means unknown, not "nobody's". Reset clears both memos.
Measured (3000 sessions each, one listing after another, CPU by
getrusage, the machine at load ~500):
Droid before: 1103 ms CPU / 8.3 s wall per listing
Droid after: 27-47 ms CPU / 0.05-1.0 s wall (first listing 1166 ms)
Grok before: 649 ms CPU / 4.2 s wall per listing
Grok after: 252-295 ms CPU / 1.8-2.2 s wall (first listing 707 ms)
What Grok's listing still spends is its globs and two stats a session
(updates.jsonl, summary.json), not reads.
Tests: TestDroidListingReadsOnlyChangedTranscripts counts transcript
opens (scanHook): a second listing opens only the half-written one,
appending reopens only that file, a finished first line is then kept,
and a transcript written over without a caller is its own session.
TestGrokListingReadsOnlyChangedSummaries counts summary reads
(grokSummaryHook): none when nothing changed or only the updates grew,
one when the summary is written over, and the key follows it.
Broken by hand: the memo never hit -> both red ("nothing changed: read
map[...all...]"); failed reads kept -> Droid red ("nothing changed: read
map[], want only the half-written one again").
Run: go test ./internal/sessions -run 'Listing|Droid|Grok' -count=1 ok;
gofmt -l and go vet ./internal/sessions clean. The full-suite record is
in the last commit of this series.
|
||
|
|
11b42c0e2e |
sessions: a Kimi Code wire file read for calls is read on, not whole
Kimi Code's calls (#1607) were read by a whole-file reader: every poll of Usage after a session's wire.jsonl grew decoded the whole file again for the one or two records added. Kimi only appends to that file, a record a line, so its calls now go through the line path Claude Code's and Codex's take: lineCallReaders gives readCalls a begin (the session id) and a line reader, and prepareCalls reads a grown file on from where the last read left off, writing only the added calls to the disk shard. A half-written last line waits for the rest; a file cut shorter, or written over, fails the head and prefix checks and is read whole again. That alone did not resume for any main session: Kimi's listing folds state.json's size into the main wire file's, so the prefix hash, taken over the listed size, ran past the end of the file and came back empty, and an empty hash never matches. The hash is now taken over the bytes the reader consumed (Off) rather than the listed size; for a Claude or Codex file with no partial tail the two are the same, so their shards keep their hashes. A title change in state.json still re-lists the file, and now costs a resume, not a whole read. TestKimiCodeForkCountsOnce wrote its subagent files without a final newline, which a line reader keeps as an unfinished line; real wire files end in one (all nine of the reporter's do), so the fixture now does too. Measured (CPU, getrusage; one 50 MB wire.jsonl with a state.json beside it, one record appended between reads, readCalls alone; machine loaded): before: 40-90 ms CPU, 240-980 ms wall per read after an append after: 0.9-1.1 ms CPU, 10-21 ms wall per read after an append; first read ~40-55 ms Test: TestKimiCodeCallsReadOnlyWhatWasAppended (state.json present) checks where each scan starts and what calls come back: appended with a half line after, the half line finished, cut shorter, written over. Broken by hand: no resume for kimi -> red ("read from 0, want 567"); resume without the size/prefix checks -> red ("cut shorter: read from 945, want 0"); the hash over the listed size again -> red ("read from 0, want 567"). Run: go test ./internal/sessions -run 'Kimi|Call|Codex|Claude|Long|Grow| Append|Resume|Prefix|Hash' -count=1 ok (359s); gofmt -l and go vet ./internal/sessions clean. The full-suite record is in the last commit of this series. |
||
|
|
6d3caf6fa4 |
sessions: a Cline session whose manifest alone changed is not read again
Cline keeps a session's messages in one JSON document, rewritten whole,
and its title, start and fork in a manifest beside it, whose size and
mtime are folded into the session file's. Cline rewrites that manifest
on its own (a title given, the session's status touched), and every such
rewrite made the Sessions and Usage pages decode the whole messages file
again, though nothing in it had changed.
parseCline now keeps what its messages were counted from: the messages
file's own size and mtime, and the start and fork time the manifest gave
then, with the first prompt that names the session. When the messages
file is as it was and the manifest still gives the same start and fork,
the counts stand and only the manifest is read again for the id, cwd,
name and title. Messages rewritten (any size or mtime change), or a
start or fork that moved, read them whole again as before. A messages
document can't be read on from where it was: it is rewritten, not
appended to.
Measured (CPU, getrusage; 50 MB messages file, the manifest rewritten
between reads; machine loaded):
before: ~205-290 ms per read after a manifest change
after: 0.1 ms per read after a manifest change; first read ~290 ms
Test: TestClineReadsMessagesOnlyWhenTheyChange counts reads of the
messages file (clineHook) and checks each read against a whole one: a
manifest touched or titled reads none of it, and the title from the
first prompt stays; a message changed, the same size at a later time, a
fork added and the start moved each read it again.
Broken by hand: no resume -> red ("manifest touched: messages read
again"); the start and fork not compared -> red (read on differs from
whole, after the fork); the carried prompt dropped -> red (read on
differs from whole).
Run: go test ./internal/sessions -run Cline -count=1 ok, and the whole
package green at the previous commit; gofmt -l and go vet
./internal/sessions clean. The full-suite record is in the last commit
of this series.
|
||
|
|
b3642e7277 |
sessions: a dsh session read before is read on from where it was left, not whole
dsh only appends to a session file, a line at a time or, packed
(.zstd), a frame of lines at a time. Every reply still made the
Sessions and Usage pages read, and for a packed file decompress, the
whole file again: a packed file "can't be read on from the middle of a
frame".
It can be read on from the start of one. frames.go walks a file of zstd
frames without decoding them (RFC 8878: the frame header, then blocks
that each give their length, then the checksum), decodes one frame at a
time, and says where to go on from: the frame the first line not yet
whole starts in, and how far into what it holds. A frame not yet
written whole waits for the next read, and so does a line a frame ends
inside of.
parseDsh keeps a tail (tail.go) and the header it read, and counts each
event as it comes (dshCount) instead of collecting them all first. A
fork's inherited end-seed met in a later read starts the counts over
from the session's start, keeping its title and name, as the whole read
did by cutting at the last one. A file that shrank or was replaced is
read whole again. One change from before: a last line not ended by a
newline now waits for it, like every other appended file's.
Measured (CPU, getrusage; 50 MB of events, a reply appended between
reads; packed: 17 MB of frames; machine loaded):
plain before: ~110-120 ms per read after an append
after: 0.4-2.6 ms per read after an append; first read ~120 ms
packed before: ~190-250 ms per read after an append
after: 0.4-0.5 ms per read after an append; first read ~260 ms
Tests: TestDshReadsOnlyWhatWasAppended runs the shared append, half
line, cut-short and rewritten-in-place cases.
TestDshPackedReadsOnlyWhatWasAppended appends a frame (read alone), half a frame (waits), a
frame ending inside a line and the frame that ends it (read on from the
first of the two, the line counted once), then cuts the file short and
replaces it with a longer one (read whole). TestDshEndSeedAcrossReads
writes a fork's seeded lines, its end-seed and its own, a read apart
each. Every read on is checked equal to a whole read.
Broken by hand: resume off -> red in both ReadsOnly tests ("after a
line appended to 1308 bytes, read from 0", "after a frame appended to
654 bytes, read from 0"); a line split over two frames resumed at the
second frame -> red (read on differs from whole); the end-seed reset
removed -> red in TestDshEndSeedAcrossReads and TestDsh.
Run: go test ./internal/sessions -count=1 -timeout 45m ok; gofmt -l
and go vet ./internal/sessions clean. The full-suite record is in the
last commit of this series.
|
||
|
|
e03d495f83 |
sessions: a Kimi Code session read before is read on from where it was left, not whole
Kimi Code only appends to a session's wire.jsonl, but every message (and
every rewrite of its state.json, whose size and mtime are folded into
the wire's) made the Sessions and Usage pages read the whole wire again,
a fork's twice: once for its last marker, once to count.
parseKimi is now one pass that keeps a tail (tail.go) and what the read
carries on with: the session's start, whether it is a fork, and the
fork's marker time. A forked marker met in a later read starts the
counts over from it, as a whole read does. Title, cwd and name still
come from state.json on every read, so a state.json-only change reads
none of the wire. A forkedFrom set or cleared reads whole again, and so
does a wire that shrank or was replaced; a half line waits.
Measured (CPU, getrusage; 50 MB wire, a message appended between reads;
machine loaded):
before: ~256-278 ms per read after an append (same as the first read)
after: 0.3-0.6 ms per read after an append
Tests: TestKimiReadsOnlyWhatWasAppended runs the shared append, half
line, cut-short and rewritten-in-place cases on a real wire's events,
then a state.json title change (nothing of the wire read) and a
forkedFrom set (read whole). Every read on is checked equal to a whole
read. TestKimiForkMarkerAcrossReads writes a fork's copied lines, then
its marker, then its own usage, a read apart each: only the fork's own
usage counts.
Broken by hand: resume off -> red ("after a line appended to 29089
bytes, read from 0"); the marker's reset removed -> red in
TestKimiForkMarkerAcrossReads and TestKimiCodeSessionFork.
Run: go test ./internal/sessions -count=1 ok; gofmt -l and go vet
./internal/sessions clean. The full-suite record is in the last commit
of this series.
|
||
|
|
b9b4c21c5b |
sessions: a Droid transcript read before is read on from where it was left, not whole
Droid only appends to a session's transcript, but every message (and
every rewrite of its settings.json, whose size and mtime are folded into
the transcript's) made the Sessions and Usage pages parse the whole
transcript again.
parseDroid now keeps a tail (tail.go) and what the read carries on with:
whether the session_start line and a fork's copied lines are behind it,
and what the settings' running total was counted as (date, model,
tokens). The next read takes that total back (dropUse, which leaves no
empty model or day behind, so the summary is the one a whole read makes),
reads on from the tail, and counts the total again on the day of the last
message. A transcript that shrank or was replaced is read whole again; a
half line waits for the next read.
Measured (CPU, getrusage; 50 MB transcript, a message appended between
reads; machine loaded):
before: ~490 ms per read after an append (same as the first read)
after: 0.2-1.8 ms per read after an append; first read ~470 ms
Tests: TestDroidReadsOnlyWhatWasAppended runs the shared append, half
line, cut-short and rewritten-in-place cases, then a message a day later
with a grown total (counted once, moved to the new day), then a
settings-only change (nothing of the transcript read). Every read on is
checked equal to a whole read. TestDroidForkAcrossReads appends a fork's
copied lines one read at a time.
Broken by hand: resume off -> red ("after a line appended to 825 bytes,
read from 0"); the old total not taken back -> red (read on differs from
whole).
Run: go test ./internal/sessions -count=1 ok; gofmt -l and go vet
./internal/sessions clean. The full-suite record is in the last commit
of this series.
|
||
|
|
d9f6b42cbc |
sessions: a Grok Build session read before is read on from where it was left, not whole
Grok Build only appends to a session's updates.jsonl, but every change
to it (and every rewrite of its summary.json, whose size and mtime are
folded into the file's) made the Sessions and Usage pages parse the
whole file again.
parseGrok now keeps a tail (tail.go) with its summary: the offset after
the last whole line, the file's head and a sampled prefix hash. The next
read goes on from that offset when the file has only grown and the
summary still names the same model, created time and parent; the first
prompt still coming in chunks carries over too. A file that shrank, or
whose head or sampled prefix changed, is read whole again, and a half
line at the end waits for the next read.
Measured (CPU, getrusage; 50 MB updates.jsonl, a turn appended between
reads; the machine was loaded, so CPU time, not wall):
before: 46 ms per read after an append (same as the first read)
after: 0.2 ms per read after an append; first read 44 ms
Tests: TestGrokReadsOnlyWhatWasAppended checks where each read starts
(through scanHook) and that every read on from a tail equals a whole
read: a line appended is read alone; half a line waits and is counted
once; the file cut back to its old bytes, or one byte changed in place
in a line it had, is read whole; a summary-only change reads nothing of
the updates; a changed model reads whole. TestGrokPromptAcrossReads
carries a chunked first prompt across reads.
Broken by hand: resume turned off -> red ("after a line appended to
2684 bytes, read from 0"); tail.holds made to trust any grown file ->
red ("rewritten in place, read from 3055").
Run: go test ./internal/sessions -count=1 ok; gofmt -l and go vet
./internal/sessions clean. The full-suite record is in the last commit
of this series.
|
||
|
|
5774c790bd |
plugin: a reply's chunk frame is read by its fixed shape, not through encoding/json
Each chunk of a plugin's streamed reply (up to 64 KB of base64 a frame)
went through json.Unmarshal into message. encoding/json scanned every
byte twice (validating, then decoding the string) and cost far more than
decoding the base64 itself. chunkFrame reads the one shape host.js's
chunkLine writes, {"id":N,"event":"chunk","data":"..."}. Any other line,
or one whose data holds a quote or a backslash, still goes through
json.Unmarshal. push checks the data is base64 of a frame's size either
way, as before.
Measured (64 KB frame, json vs chunkFrame, each followed by the base64
decode push does; -cpu 1, 6 runs, load average ~480, so absolute times
are inflated):
- json.Unmarshal + DecodeString: 7.3-14.0 ms/op, median ~8.7 ms
- chunkFrame + DecodeString: 0.11-2.3 ms/op, median ~0.33 ms
Test: TestChunkFrameReadsWithoutJSON. Frames json.Marshal'd with a \n,
\r\n or no line end must parse and equal what json.Unmarshal makes. It
also refuses 11 other shapes, among them:
- an escape in the data;
- a negative id, or 1e3;
- extra fields or trailing bytes;
- a 20-digit id;
- reordered keys.
Broken by hand (chunkFrame always false), it went red: "a chunk frame as
host.js writes it ... went through encoding/json".
Run (load ~420): go test ./internal/plugin -count=1 -run on the chunk
frame, host, flow, stream, chunk, credit and fetch tests: ok (54.0 s).
The whole package runs with the final checks.
|
||
|
|
ef75a9a2b5 |
plugin: a streamed reply's chunk frame is joined, not stringified, and its bytes viewed, not copied
Every chunk of a plugin's streamed reply went out as
JSON.stringify({id, event: "chunk", data}), and stringify scanned every
byte of the base64 for something to escape. Base64 has nothing JSON
escapes, so chunkLine joins the line from strings instead. The line is
byte-for-byte the one stringify made. A Uint8Array chunk that isn't a
Buffer (what a Response body hands over) was also copied whole by
Buffer.from before it was encoded. It is now viewed: the bytes are
encoded before the next read, so nothing else touches them.
Measured in bun, old and new interleaved in one process, medians (load
average 363-413, so absolute times are inflated). The bench asserts the
lines are equal.
- 2032 B frame: 152.8 us -> 12.8 us (78.9 -> 6.6 ms per MB)
- 16 KB frame: 675.8 us -> 69.4 us (43.3 -> 4.4 ms per MB)
- 64 KB frame (MAX_FRAME): 2135 us -> 292.6 us (34.2 -> 4.7 ms per MB)
Test: TestHostFramesChunksCheaply streams Uint8Array parts (one of 70 KB,
so it splits at MAX_FRAME) through host.js's fetch loop in a vm. It
checks:
- 4 chunk frames;
- the bytes come back equal;
- JSON.stringify never sees a chunk;
- Buffer.from never copies a chunk.
Broken by hand twice, red both times:
- the frame built as an object again: "chunk frames are joined, not
stringified";
- Buffer.from(chunk) again: "chunks are viewed, not copied".
Run (load ~420): go test ./internal/plugin -count=1 -run on the host,
flow, stream, chunk, credit, fetch and auth tests: ok (51.2 s). The whole package runs with the final checks.
|
||
|
|
8f37ed57d2 |
plugin: plugin-auth.json is parsed once per version of the file, not on every request
Every request read and parsed plugin-auth.json in the host two or three
times: accountKey (when no account is named), fresh (is a renewal due),
and the plugin's getAuth from its loader's fetch. Reading and parsing a
20 KB file (12 sign-ins) cost ~0.65-0.97 ms each on this loaded machine.
readAuth now keeps what it parsed while the file has the same mtime,
size and inode, as Go's filememo does. While the file's time is within
2 s of now it also keeps the bytes and compares them, so two same-size
writes inside one tick of a coarse clock (Linux) still read as two. A
file that doesn't parse is never kept, so the .bak recovery path is
unchanged. changeAuth still reads afresh under the lock. The kept
object is shared, so what a plugin is handed (getAuth for loader, usage
and check-in, the models hook's auth, pi.js's readAuth) is a copy of its
own (authCopy).
Measured (load average 360-460, so absolute times are inflated):
- readAuth on a settled 20 KB file, old and new interleaved in one bun
process, 6 rounds of 5000: old median 970 us (min 841) and 1 file read
per call. New median 23 us (min 2.3), a stat, and 0 file reads.
- whole fetch (TestPerfScratch, not committed, {} body, 400 fetches):
host CPU 750-825 us -> 750-775 us per fetch, inside this load's noise.
A control run without the big file read 875 us at the same load. Host
RSS 53 MB -> 42 MB.
Test: TestAuthReadOncePerVersion runs host.js's own auth section in node
with readFileSync counted. It checks:
- 100 reads of a settled file read it once;
- a rewrite is read;
- a same-size rewrite with the same mtime is read;
- authCopy's copies are the caller's own.
Broken by hand twice, red both times:
- readAuth made the old uncached read: "a settled file is read once for
100 reads, read 100 times".
- bytes of a just-written file not kept: "a same-size rewrite in one
tick is read".
Run (-p 4, load ~470): go test ./internal/plugin -count=1 ok with
TestGatewayHookMixedPiPackage skipped. That test passed alone at 545.6 s
(pinned pi install under load); in a full package run it hit its 4-minute
start deadline ("starting plugins: context deadline exceeded").
|
||
|
|
e3c09f4f36 |
plugin: a request is told the provider info built once per account, not built again per fetch
host.js ran info(provider, key) on every fetch, to hand chat.headers
hooks the provider. Each build rebuilt the model list from models.dev and
config, read and parsed plugin-auth.json twice, JSON-cloned the list and
asked the plugin's provider.models hook, which real plugins (cursor, zed
and others) answer by asking the vendor once their own TTL runs out. It ran
even when no plugin had a chat.headers hook.
infoOf(id, key) now keeps the info per account. Any change to the
account's sign-in (setAuth, removeAuth, settle, client.auth.set, renew,
take, reload, all through forgetAccount), new provider options, or a new
models.dev file builds it again, once. providers() seeds the cache with
what it built. The loader, usage and check-in read it too; check's strict
build stays direct. chat.headers gets the shared object, as OpenCode hands
plugins the provider it keeps, and the request asks for it only when a
plugin has a chat.headers hook.
Measured (TestPerfScratch harness, not committed; fake plugin, sandbox
HOME, loaded machine, two runs each):
- {} body, 1-event reply, 400 fetches: models hook asked 400 -> 0 times.
- same, a plugin with 300 config models: 0.995-1.17 ms -> 0.27-0.29 ms
wall per fetch, host CPU 1.23-1.33 ms -> 0.30 ms per fetch, host RSS
87-89 MB -> ~54 MB.
- 246 KB body, 2 MB SSE reply, 40 fetches: host CPU 10.25 -> 8.25 ms per
fetch, models hook asked 40 -> 0 times.
- idle host CPU ~10-20 ms per 10 s before and after.
Tests: TestFetchBuildsInfoOnce counts the fake's models hook (new
FAKE_MODELS_LOG): 20 fetches ask it 0 more times, a new sign-in and new
options each ask it exactly once, and chat.headers and the loader still
see fake-1 and every model. Broken by hand twice, red both times:
returning no cached info ("20 requests asked the models hook 20 more
times, want 0"), and not forgetting it on sign-in ("after a new sign-in
... 0 times, want 1"). host_flow_test's mid-setup case now stubs infoOf
and registers a chat.headers hook for its "info" stage, which red on
this change without it (the stage was never entered).
Run: go test ./internal/plugin -count=1 ok (159.5s);
TestFlowAbortDuringSetup|TestFetchBuildsInfoOnce -count=2 ok.
|
||
|
|
2ceff7370f |
gui: the window back reads the state once, not once for visibility and again for focus
A window shown again hears visibilitychange and focus together, and each called load(true): two reads of /api/state (every agent's config), with loadCLIs, loadInstalls, the providers and the Usage refresh after each. Under focus-follows-mouse every pointer crossing into the window was one more. loadBack now joins a return to the read asked under a second ago; a return while an older read is still out gets one read after it, however many came meanwhile. Numbers (sandbox HOME, 16 agents, 1230 catalog models, dev build): /api/state is 2.28 MB and ~55 ms of CPU per read (20 reads: 1.11 s). Reads per window return: before 2, after 1. The core's scripts were 1,446,845 bytes, 155 under their budget; loadBack adds 523. Every page needs it, so it is the core's own: coreScriptBudget goes to the new total, 1,447,368, plus 1.5% (1,469,000), as the budget's own rule says. Test: internal/gui/tests/window-back-once.test.cjs counts /api/state reads for a return, a later return, and returns during a held read. On the old app.js: 8 of 8 red, "shown again ... actual 2, expected 1". Run at this head (load average ~500, nine sessions' suites at once): node --test window-back-once.test.cjs, Chromium and WebKit, en and zh, window and panel: 8 of 8 ok. TestCoreScriptBudget ok. GUI files that fire focus or visibility (15 files, both engines): 194 of 196 ok. claude-usage-asked webkit en passes 9 of 9 alone. tray-cell-click webkit zh is red alone 3 of 3, on 1a3b92688's own app.js too: #2686, output added there. go test -p 4 ./... -timeout 45m (HOME a sandbox): 59 packages ok, and: - internal/gui: TestCoreScriptBudget red, fixed here (budget above); TestSetAnswersWhileDevinAndProvidersHang red (13.8s sets), ok alone (12.6s) and the whole package ok alone (391s): #1375, output added. - internal/plugin: TestGatewayHookMixedPiPackage red ("starting plugins: context deadline exceeded"), ok alone (110.8s): #2865, output added. - internal/agent, internal/library, internal/gateway: timed out at 45m. agent timed out alone too (2701.5s): #2544, output added. library is #2853 and gateway #2870. Neither was rerun alone, to keep load off the machine. go vet on darwin, linux (nogui) and windows: clean. gofmt -l: clean. |
||
|
|
94919109cb |
gateway: a silent HTTP/2 connection to a vendor is pinged and dropped (#2843)
pinewhite (#2843, v0.1.1279, Linux): for ~30 minutes every request to
group/auto-deepseek-v4-1-flash hung with no first byte. The WorkBuddy
member was resting on a 429, so they all went to ClinePass, and usage
shows only 499s with in=0. A restart answered the same request in 1.6s.
Cause: the gateway's transport (upstreamTransport) speaks HTTP/2 to
any vendor that offers it, so every request to api.cline.bot shares one
connection. It had no HTTP/2 health check. A connection that goes silent
without closing (a local proxy whose own way out died, or a NAT that
forgot the flow) stays in the pool. Every new request is multiplexed
onto it and waits for the 10-minute ResponseHeaderTimeout while the
kernel takes the writes. The agent gives up first, so nothing fails over
and nothing rests the member. Restarting dropped the connection.
Fix: netproxy.HTTP2Health() (SendPingTimeout 20s, PingTimeout 10s) on
upstreamTransport. Go now pings a connection that has had no frame for
20s and closes it when no answer comes within 10s. The requests on it
fail as a 502 ("http2: client connection lost"), so a group moves on,
and the next request dials a new connection. A live vendor answers a
ping whatever its streams are doing, so a long wait for a first byte is
not cut. The same setting goes on http.DefaultTransport in
netproxy.Install, the sibling pool that usage cards, catalogs and
sign-ins use. Not covered: requests a plugin sends from Bun.
Tests (new):
- TestSilentHTTP2ConnectionIsDropped: an HTTP/2 TLS httptest vendor
behind a TCP relay that can go silent on its open connections (it
takes writes, passes nothing). After the relay goes silent, a request
must end well inside 10s, and the next one must succeed on a second
connection.
- TestGroupMovesOnFromSilentHTTP2Connection: the same through the real
Handler, with an ordered group a/m then b/m. Once a's connection is
silent, the request must get b's reply.
- TestInstallChecksHTTP2Connections (netproxy).
What was run (worktree on origin/main
|
||
|
|
47eb42f1a1 |
workbuddy: moved users get plugin 0.1.25, where WorkBuddy AI's "x0.34 credits" rates are read, not unknown (magpie-community/plugins#216)
WorkBuddy AI's /v3/config gives fast-model, balanced-model and
primary-model their credits as "x0.34 credits", "x0.59 credits" and
"x3.31 credits" (read live from the owner's account on 2026-10-19). Plugin
0.1.24 read those as unknown, so the three showed no rate. 0.1.25
(plugins c89cee5, bump ab38da6) strips a trailing "credits" unit only;
empty, negative, non-finite or other trailing text stays unknown. npm view
@magpie-community/opencode-workbuddy-auth version --prefer-online: 0.1.25.
The retired built-in has no wbCredits any more, so there is nothing to
mirror here.
Run on origin/main
|
||
|
|
fc78eb5f6b |
gateway: ClinePass's upstream is read from provider_metadata.gateway.routing.finalProvider (#2847, smart-lty)
ClinePass (api.cline.bot) names the provider that answered only in a
Chat choice's provider_metadata.gateway.routing.finalProvider: under
delta in a stream chunk, and under message in a single body. upstreamOf
read only a top-level provider, message.provider and response.provider,
so the Routing page's 上游 column, the request log and the usage ledger
showed nothing for ClinePass.
upstreamOf now also reads finalProvider at those two places, and nowhere
else. A choice's content belongs to the model. providerAttempts inside
routing lists every provider that was tried, not the one that answered.
The cheap pre-check now passes a chunk that carries only
"finalProvider".
Tests:
- TestUpstreamOfClinePass checks:
- the real chunk gives deepseek;
- the same chunk as one body (message) gives deepseek;
- content, tool_call arguments, providerAttempts alone and an
object-valued finalProvider give "";
- a top-level provider still wins.
- TestClinePassUpstreamRecorded serves the real stream through the
Handler on /v1/chat/completions and on /v1/messages (translated). It
checks that the route, the try, Recent() and the usage ledger all say
deepseek.
The fixture testdata/clinepass_stream.sse is a real ClinePass stream:
api.cline.bot, deepseek/deepseek-v4.1-flash, captured 2026-10-02 in the
MIT-licensed wkeking/clinepass-channel-monitor
(internal/channellog/testdata/plain_success.log). It is not the
reporter's own bytes; #2847 has none.
What was run at
|
||
|
|
3608ed782e |
gui: WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS reaches magpie's WebView2 on Windows again (#2753, LuYquan)
The reporter's Nahimic DLL gets WebView2's renderer killed by code
integrity and the window goes black; the usual workaround,
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--disable-features=RendererCodeIntegrity,
never reached magpie's renderer. The cause is not WebView2 skipping the
variable because magpie passes its own arguments: Wails v3.0.0-beta.24's
loader blanks the variable in its package init
(webviewloader.preventEnvAndRegistryOverrides), before any magpie code
runs. Seen on the Windows box: a debug build's windowsOptions read "".
- internal/webview2env reads the variable at init. It imports only
syscall, so by Go's init order (first ready package by import path)
it is initialized before os, and so before Wails' loader, which needs
os.
- windowsOptions sorts it into Wails' DisabledFeatures, EnabledFeatures
and AdditionalBrowserArgs. Wails writes msSmartScreenProtection plus
the user's features as one --disable-features (Chromium keeps only
the last of two), one --enable-features, and the rest as written.
A list given twice is merged, each feature once.
- Nothing is added by default: RendererCodeIntegrity stays on unless
the user asks.
ProcessFailed: not done. Wails' edge.Chromium has a ProcessFailedCallback,
but setupChromium never sets it, the package is under wails/v3/internal
(not importable) and a window's chromium is unexported; Wails has no
public event for a dead renderer. Reloading on renderer death needs a
change in Wails.
Run:
- gofmt -l: clean. go vet darwin, GOOS=linux -tags nogui, GOOS=windows:
clean. Builds for the three.
- go test ./internal/gui -run 'TestWebView2|TestWindowsOptions' on
macOS, and the windows/amd64 test binary on the Windows box (sandbox
dir, my own process name): TestWebView2ArgsSurviveWailsInit passes
there with os="" (Wails blanked it) and disabled=[RendererCodeIntegrity].
- The real app on the Windows box (portable sandbox, MAGPIE_ADDR :3481,
USERPROFILE/APPDATA/LOCALAPPDATA redirected) started with
"--disable-features=RendererCodeIntegrity --enable-features=msTestFoo
--lang=de": every msedgewebview2.exe of it carries one
--disable-features with both features, --enable-features=msTestFoo
and --lang=de. Before, the same launch showed only
--disable-features=msSmartScreenProtection and --lang=zh-CN.
Broken by hand:
- windowsOptions reading os.Getenv instead of webview2env.Args: on the
Windows box TestWebView2ArgsSurviveWailsInit goes red
(os="" disabled=[]).
- webView2Args ignoring the env (""): TestWebView2ArgsMergeTheUsers red
in "the reporter's" and "twice".
- --disable-features treated as an other argument: red in three cases,
including the one-switch count.
Full suite at origin/main
|
||
|
|
41f5107b91 |
provider: the zed mover's min is 0.1.10, which picks the organization with a plan (plugins#232)
Zed 0.1.10 (plugins 5a83674) no longer always uses the default
organization. It picks the saved org, then the default, then a personal
org, as long as that org has a paid plan and models on, and it moves the
account once when an org answers 402. ReneXiong's default org has no plan
and the personal one has zed_student, so every request got a 402.
Raising the min lets keepMovedCurrent update every moved user.
Run at
|
||
|
|
1a3b926886 |
agent: a [1m] main beside a smaller tier is told its own 1M, the tier held to its own (多喝热水 on Discord)
多喝热水 had Full window on, Claude Code's main on a [1m] DeepSeek 4.1 and a smaller tier beside it. magpie told Claude Code the least tier's window (CLAUDE_CODE_MAX_CONTEXT_TOKENS=246000), so it read 246K as the main model's window and asked why 1M never showed. It is also the window Claude Code falls back to when it stops taking the main for 1M. Now a [1m] main of magpie's beside a tier that isn't takes the layout Desktop already has (desktopPlan): the window told is the main's own (1M), each smaller tier gets modelSettings.<id>.autoCompactWindow at its own window, and the working window goes in the top-level autoCompactWindow in place of the env (none under Full window). A [1m] main alone, a Claude main and the user's own env and settings are as before. Run: - TestClaudeContextWindow's new case (tier beside a [1m] main, with and without Full window, then the tier gone) fails on the old code (window "128000", no tier entry, env compact 272000) and passes now. - Real Claude Code 2.1.302 in a sandbox CLAUDE_CONFIG_DIR on the live gateway, main workbuddy/deepseek-v4.1-flash[1m], haiku workbuddy/hy3: /context shows the main at 272k and hy3 at 192k without Full window, and the main at 1m and hy3 at 192k with it. With the old layout's env of 246000, hy3 showed 246k, past its own 192k. A real request on the main replied "ok". - gofmt -l clean; go vet ./..., GOOS=linux go vet -tags nogui ./... and GOOS=windows go vet ./... clean; go build ./... ok. - go test -timeout 45m -count=1 ./... at |
||
|
|
81029fc63c |
sessions: the overview's stats and their native sessions come of one pass over the files (#2776)
combinedSessionStats, behind /api/sessions/stats and /overview (each
range read again in the background when its memo is over 10 s old, so
on every 15 s poll of the Sessions page), took sessions.StatsFor and then
sessions.List(All) only for the agent|id set that keeps a gateway session
the agent keeps too from counting twice: two passes over every agent's
files, each refreshing them all. sessions.StatsAndNative gives both from
StatsFor's one pass: the same set, a session List would list (one
nothing was said in still left out, as before), but with no 5000 limit,
so a gateway session whose native one is among the oldest of a long
history is no longer counted again.
Test: TestStatsAndNativeOnePass: one pass over the files (filesHook, new),
and the same keys as List(All) on the fixtures. Red with StatsAndNative
written as the old pair of calls: "2 passes over the files".
Measured on the synthetic sandbox HOME (3000 Claude Code, 1500 Codex,
2000 Hermes sessions), combinedSessionStats warm after a restart, CPU
time (load average ~250, wall times noisy), parent 8e2b1dce6 against
this change, 4 rounds each:
days=30 94-99 ms -> 57-62 ms CPU
days=0 107-130 ms -> 68-74 ms CPU
first after a restart (days=30) 558 -> 510 ms CPU
Run at this commit (the series' last; it covers 0179cef63, bbee24810
and 8e2b1dce6 too), on a machine at load average ~250-500:
- go test ./... -timeout 45m: 60 packages ok, sessions (869.8s), usage
ok. Red only under that load, all green when run again:
- internal/agent and internal/gateway timed out at 45m in tests that
don't touch sessions (TestPiOffersItsOwnOpenAICodexModels,
TestVisionSettingPicksTheDescriber). Run again with -timeout 90m:
agent ok (1394.2s), gateway ok (1546.9s).
- internal/gui TestSetAnswersWhileDevinAndProvidersHang: set took
44.6s under load; it is #1375. Alone: ok.
- internal/plugin TestGatewayHookMixedPiPackage: "starting plugins:
context deadline exceeded" after 718s (bun's install cache was slow).
Alone: ok (163.6s). No issue found for it.
- gofmt -l: clean.
- GOOS=windows go vet ./...: ok.
- GOOS=linux go vet -tags nogui ./...: ok. Without the tag, vet stops in
wails v3's own linux files (undefined: pointer, cgo off when vetting
across OSes from macOS); go.mod is untouched here.
- No GUI assets changed, so the GUI suite was not run.
|
||
|
|
38f6bee23e |
sessions: the manage page reads its agents' files once, and only the agents it shows (#2776)
GET /api/sessions/manage went over every agent's session files three
times: sessions.Agents() for the counts, sessions.List(All) only to build
the set that keeps a gateway session its agent keeps too from being
counted twice, and sessions.ListAgent for the list. List(All) also read
every agent's changed files again and put every session together, prices
and titles included, to take its id. So a page showing Claude Code's
sessions parsed Hermes's and Codex's writes too.
sessions.Manage now does it in one pass over the files, under one hold
of the locks: the counts, the ids of the sessions of the agents that have
gateway sessions (nativeIDs: the id from the file's key, or from its
parse for the agents that write it inside the file, idInFile, which are
the only ones read), then the picked agent's list. The handler's pick
runs as a callback so the counts can include the gateway sessions. A
change to an agent not shown and with no gateway sessions waits for a
page that shows it. assemble's id rule moved into sessionID, which both
use.
That set was also wrong in two ways. List leaves out a session nothing
was said in and stops at 5000 (All), while the list beside it keeps
every one, so a gateway session whose agent's file was empty (or among
the oldest of more than 5000) was counted twice and listed once. The
set is now every native session, the same as the list's, and
POST /api/sessions/delete, which tells a listed gateway session from a
native one, uses it too (sessions.NativeIDs).
docs/subsystems/gateway-sessions.md says so.
Tests:
- TestManageReadsOnlyTheAgentsItShows: Codex's files changed, Claude
Code's page parses none of them; asked for Codex's ids it reads them;
the native ids equal the list's, the empty session included. Red with
Manage reading every file as List(All) did ("read 2 of them").
- TestManageCountsAGatewaySessionTheAgentKeepsOnce: a gateway session
whose Claude Code file has nothing said in it is counted once. Red on
the old handler: "one session listed, counted [{claude 2}]".
Measured on the synthetic sandbox HOME (3000 Claude Code, 1500 Codex,
2000 Hermes sessions; no gateway sessions), CPU time of the request
(load average ~250 from other sessions, so wall times are noisy), the
parent bbee24810 against this change, the same run of each:
first manage?agent=claude after a restart 2164 -> 627 ms CPU
(15697 -> 10554 ms wall)
warm manage?agent=claude 173-222 ms -> 64-88 ms CPU
warm manage?agent=hermes 176-243 ms -> 56-70 ms CPU
warm manage?agent=codex 237-269 ms -> 155-162 ms CPU (after its
first, which reads Codex's model/effort)
Run: go test ./internal/sessions -count=1, go test ./internal/gui -count=1;
gofmt -l clean; go vet. Full suite and cross-OS vet are recorded on the
last commit of this series.
|
||
|
|
2b2d5fd8e4 |
sessions: a Hermes store's path is resolved once per listing, not per session (#2776)
hermesFiles built each session's id with hermesID(path, sid), which resolves the store's path (filepath.Abs and EvalSymlinks, a stat per folder) and hashes it, for every session of the store, on every listing. Every Sessions endpoint enumerates every agent, so this ran on each poll. hermesStoreID now resolves and hashes once per store; each session's id is that prefix and its own id, the same string as before. Test: TestHermesStoreResolvedOncePerListing counts resolves for a store of 10 sessions (red on the old code: 12 resolves for 10 sessions) and checks a file's key still equals hermesID's. Measured on the synthetic sandbox HOME (2000 Hermes sessions beside 3000 Claude Code and 1500 Codex), warm index: a CPU profile of 9 warm requests (manage?agent=claude, manage?agent=codex, /api/sessions, three times; 33 enumerations) put 0.96 s CPU in hermesID, ~30 ms per enumeration of 2000 sessions. After, that is one resolve per store. Run: go test ./internal/sessions -run TestHermes -count=1 (ok); gofmt -l clean. Full suite and cross-OS vet are recorded on the last commit of this series. |
||
|
|
9893ae8216 |
sessions: a write to one Hermes session parses only that session again (#2776)
Hermes keeps every session in one state.db, and a session's parse was
reused only while the whole store's revision (state.db and its WAL, size
and mtime) stood. Any write moved it, so every Hermes session's messages
were read, de-duplicated and decoded again: on each Sessions poll while
Hermes ran, and on the first read after a restart if Hermes had run
meanwhile (the reporter's 25-40s Sessions page).
The store's revision still decides whether anything is read. When it
moved, one read transaction now takes a fingerprint of each session
(hermesPrintsFor, fingerprints): its sessions row as metadata() reads it,
and over its messages and usage rows a count, the ids, and sums of every
column parseHermes reads, values or byte lengths (active and compacted,
which a rewind or compaction flips in place, and octet_length of content,
tool calls and display metadata, which Hermes fills in later). They are
kept per store revision. Only sessions whose fingerprint moved are parsed
again. A fingerprint that can't be read is "" and reuses nothing, as
before. A rewrite of a message to text of the very same byte length with
no other column moving is the one change it can miss; said in the code.
Tests: TestHermesWriteParsesOnlyItsSession (one message inserted: 1
session parsed again, 4 on the old check; a message rewritten in place is
read), TestHermesUnreadFingerprintsParseAgain (an unknown fingerprint
reuses nothing; red with the f.rev == "" guard taken out).
Measured on a synthetic sandbox HOME (2000 Hermes sessions, 132k
messages, 465 MB state.db, beside 3000 Claude Code and 1500 Codex
sessions), one message inserted into Hermes before each request, warm
index, load average ~250 from other sessions on the machine (CPU time is
the stable number):
/api/sessions/manage?agent=claude before 2190 ms CPU (11962 ms wall)
after 617 ms CPU ( 4669 ms wall)
/api/sessions/manage?agent=hermes before 2400 ms CPU (14630 ms wall)
after 618 ms CPU ( 6239 ms wall)
/api/sessions before 2102 ms CPU (10229 ms wall)
after 357 ms CPU ( 3136 ms wall)
The fingerprint pass itself over that store: ~0.3 s CPU in sqlite3.
Run: go test ./internal/sessions -count=1 (ok, 241s); gofmt -l clean;
go vet ./internal/sessions. Full suite and cross-OS vet are recorded on
the last commit of this series.
|
||
|
|
a595f1559c |
provider: a request to a routing group builds the groups' entries once, not once per look at every member of every group (colmugx, Yayoi_no_yume on X)
colmugx found magpie hotter with groups, and worse since ~v0.1.1225. Yayoi_no_yume saw CPU jump to 100% as soon as a request entered a group, and stay there under concurrency. Cause: one request to a group asked for the groups' entries (groupEntries) five or six times: Catalog from Resolve and IsDecider, and Served from membersImageInput, outputLimit, windowIn and roomy. A direct provider/model request asked through Resolve too. Nothing held that work. Each build: - went through every member of every group, the found auto-<model> ones included, with a linear pass over the whole catalog per member. It copied each large Entry it passed (groupEntries, resolveIn); - since |
||
|
|
938c31424e |
gateway: a long request body is checked for valid JSON once, not by every decodeJSON
decodeJSON runs jsonValid over its whole input before filling the value,
and a request's body goes through it a dozen times on its way: modelOf,
parseAnthropicRequest, swapImageBlocks, blocksOf, the prompt builder,
conversationID, requestEffort, bodyEffort, streamOf, walkImages... On a
2 MB Anthropic request the repeated checks were ~18% of the CPU of
serving it (pprof).
jsonValid now remembers the last 8 bodies of 32 KB or more that it found
valid, by length and a maphash under a seed of the process's own. Only
valid results are kept, so an invalid body is checked (and refused) every
time. A false hit needs a 64-bit collision under a seed no caller can
see; even then fillJSON still parses the body.
Guard: TestDecodeJSONChecksALongBodyOnce counts the byte-by-byte checks
of one 84 KB body over six decodes. With the lookup turned off by hand:
"a 84087-byte body was checked 6 times over six decodes, want 1".
TestDecodeJSONMemoKeepsRefusing: a body changed by one byte at the same
length, and a truncated one, are still refused after the valid one was
remembered.
Numbers (BenchmarkZZHot, a fake upstream with no network, 2 MB request,
count 3, CPU from rusage since the box sits at load ~350):
big-nostream before 113.4 / 140.1 / 117.1 cpu-ms/op
after 107.6 / 98.7 / 99.2 cpu-ms/op
big-stream-pass before 134.6 / 151.0 / 161.6 cpu-ms/op
after 124.1 / 131.0 / 144.5 cpu-ms/op
B/op and allocs/op are unchanged (65.9 MB, 181k; 81.9 MB, 310k), as
expected: the check allocates nothing.
Run (on
|
||
|
|
24f89cdb14 |
gateway: a streamed reply's text is gathered in a builder, not copied whole on every delta
The collector that every encoder embeds (and conversations, hooks,
relay status, search, the Claude subscription path) added each text or
thinking delta to its part with `p.Text += ev.Text`, copying the whole
reply so far on every delta. Quadratic in the reply: a 4000-delta reply
copied ~57 KB per delta. It shows most on a translated stream (a Chat
upstream served to an Anthropic client), where every chunk is one delta.
Now the last part's text grows in a strings.Builder, written into the
part when another part is touched or at finish().
Guard: TestCollectorTextLinear fails when collecting a reply allocates
more than 16x its size. Before the fix: "collecting a 116014-byte reply
allocated 247395704 bytes (2132x)". TestCollectorKeepsEveryDelta checks
that every part's text, the signature and the tool args are kept whole.
Numbers (a fake upstream, no network, 4000 events, chat -> anthropic
stream, CPU from rusage since the box sits at load ~350):
before: 166.9 cpu-ms/op, 231 MB/op, 391k allocs/op
after: 95.4 cpu-ms/op, 31.3 MB/op, 387k allocs/op
BenchmarkCollectorText (4000 deltas): 667 KB/op, 8048 allocs/op after.
Passthrough cases were unchanged (small-stream-pass 42 ms, chat pass 94 ms).
Run (on
|
||
|
|
db61143fe7 |
usage: the Sessions and Routing caches copy out the strings they keep, so they no longer pin every decoded block
An unpacked block's strings are cut from one allocation (unpackInto). The gateway-sessions projection (gatewayCache) and the vias cache kept a session id, model, agent, provider or effort from nearly every block, and each such substring held the block's whole decoded text: request and response ids and errors included. keptStrings clones each kept value once and interns it, so a cache holds only what it uses. TestSessionCachesHoldNoDecodedBlocks writes 16 blocks x 512 rows with a 1 KB error each, reads GatewaySessions and Vias, drops the snapshot and compares the live heap with and without the caches. Without the fix (both call sites reverted) it is red: "the caches hold 16651 KB for 16 sessions: the decoded text of their blocks (8192 KB)". With it, green -count=3. Measured (macOS, sandbox HOME seeded with 600k gateway calls, the fixed build vs |
||
|
|
cc8e8e3bda |
provider: moved Grok users get plugin 0.1.16, which keeps a sign-in with no email (llllleo9 on X)
llllleo9 couldn't add Grok: grok login --device-auth exited 0, and the
sign-in failed with "grok login finished without an account".
Grok Build 1.0.62 was run in a sandbox against a stand-in auth.x.ai. When
the id_token has no email claim (an account signed in through X), the CLI
writes "email": null, and plugin 0.1.15 refused a sign-in made beside an
already signed-in Grok Build. With GROK_AUTH_PATH set, the CLI kept the
sign-in elsewhere.
Plugin 0.1.16 (magpie-community/plugins 8cdf2d2) fixes both:
- the account is told by its email, else its xAI user id, else the
token's sub;
- GROK_AUTH_PATH is left out of the login;
- a login that leaves nothing says which file it read and what was there.
npm view @magpie-community/opencode-grok-auth@0.1.16 --prefer-online
shows 0.1.16, which is latest, and its integrity matches the publish
run's. This commit raises the mover's min to 0.1.16, so keepMovedCurrent
updates moved users. The built-in's own Grok sign-in (runCLISignIn) has
no caller left, so the built-in is unchanged.
Run at this change, on origin/main
|
||
|
|
95ef45fda4 |
agent: a curl-installed opencode's update passes the version its row promised, so it never asks GitHub's API (#2837, ggbdpq)
What changed: an opencode 1.19.0 that its own installer put at
~/.opencode/bin/opencode (method curl) asks GitHub's API
GET /repos/anomalyco/opencode/releases/latest for the newest release before
installing. That request carries no token, so it spends the 60 an hour GitHub
answers an address without one. Once those are spent the answer is a 403 and
the update stops before its installer runs (ggbdpq: "opencode upgrade: ...
403 GET https://api.github.com/repos/anomalyco/opencode/releases/latest").
cliSpec gains target, for a CLI whose own updater takes the version to
install, and opencode sets it. When opencode's own updater is what runs
(via "self"), UpdateCLI appends the version it already knows, the row's
Latest from npm's opencode-ai, if that is newer than the installed one.
The run is then "opencode upgrade 1.19.3". In opencode's source
(packages/cli/src/commands/handlers/upgrade.ts) a given target skips
latest(), and the curl method passes it to the installer as --version. A
stale npm answer appends nothing (Newer), so an update can never become a
downgrade. When the lookup fails, the command stays "opencode upgrade".
Changed in review: the patch as sent appended the version for every
install method. An opencode installed by npm, bun, pnpm or brew then ran
`npm install -g --prefix P opencode-ai@latest 1.19.3`, which also asks npm
to install a package named "1.19.3", or `brew upgrade opencode 1.19.3`.
The append is now limited to via "self". TestUpdateCLIOpenCodeByNpmTakesNoVersion
(npm prefix install) guards it. The target comment no longer says 1.19.3
asks npm: opencode's current source asks opencode.ai.
Run:
- Breaks: without the via guard (the patch as sent),
TestUpdateCLIOpenCodeByNpmTakesNoVersion fails with "ran [[.../npm install
-g --prefix ... opencode-ai@latest 1.19.3]]". Without the target block,
TestUpdateCLIOpenCodeTakesVersion fails at cliupdate_test.go:411 with
`ran [[".../bin/opencode" "upgrade"]]`. Both pass restored.
- gofmt -l clean; go vet darwin, linux (nogui) and windows ok; go build
for all three ok.
- Full `go test -tags nogui -timeout 45m ./...` on origin/main
|
||
|
|
ec7f474323 |
gateway: Codex on Copilot is relayed with its web_search, and a translated call's arguments stream (echo_ts)
echo_ts (magpie 0.1.1279, macOS): Codex on a GitHub Copilot subscription
through magpie was about 10x slower than Copilot directly. Two causes,
both in the gateway:
- Codex offers web_search on every turn, and magpie counted Copilot as a
provider that can't search, so every Codex turn on Copilot was
translated for magpie's search instead of relayed.
- On that translated path responsesDecoder held a call's argument deltas
until the call was done, so Codex saw nothing while the model wrote a
command or a patch, then all of it at once. A custom tool (apply_patch)
got no custom_tool_call_input deltas at all.
Fixes:
- search.go: searchesItself counts a Copilot account on Responses. Real
check on 2026-10-17 with the owner's account: gpt-5.3-codex,
gpt-5.4-mini, gpt-6-luna, grok-4.7 and mai-code-1.1-flash each answered
a request offering web_search with web_search_call items and cited
pages. searchRank never picks Copilot to search for another provider's
models (its premium requests).
- gateway.go: a Copilot Responses request whose tools mark an argument
"encrypted" (MultiAgentV2's spawn_agent message) is still translated,
marks left out (asksSealing in responses.go). Checked on the real
account: relayed, Copilot seals the message ("UlQC...", no
encrypted_function_args), and the subagent's turn carrying it came back
"Encrypted function output content could not be decrypted or
decoded". This was already broken for a Copilot turn without
web_search; it is fixed for that too. An unsealed agent_message relayed
with web_search answers normally (checked).
- responses.go: responsesDecoder gives argument deltas as they come. It
holds only the deltas that make the arguments whole JSON, until the
done events, so #613's case (deltas that disagree with done) still
ends with the fuller arguments. The encoder sends a custom tool's input
as custom_tool_call_input.delta, read out of the {"input": ...}
arguments as they stream (customStream in custom_tool.go, which waits
for cut escapes, surrogate pairs and UTF-8), and closes it with
custom_tool_call_input.done.
- docs/subsystems/gateway-routing.md says the above.
Not changed: the HTTP/2 connection. Head-of-line blocking from large
uploads on the one connection to Copilot was measured on the real
account with a Go client: a 4MB request and a small one 300ms later,
5 rounds x 2, same connection vs a new one. The small request's first
byte took 0.93-1.68s on the shared connection, 1.26-4.77s on its own
(handshake included), 0.66-1.08s alone. No sign of blocking.
Small requests slower while a long session runs (echo_ts, 42.8s vs
17-29s first text, xhigh): nothing in magpie serializes Copilot requests
by default (lanes need MaxConcurrency, the RPM gate MaxRPM; Go's h2
windows are 1GB per connection, 4MB per stream). Measured: small
requests beside a 412s xhigh stream (16,617 output tokens) were as fast
as idle, via magpie 0.8-1.1s first text, direct 1.3-2.0s, sent_ms
1-10ms. One global lock found: copilotMu is held across the token
refresh's HTTP call, which stalls every Copilot request only around a
refresh, filed as #2762, not changed here. usage.jsonl's own_ms,
queued_ms and sent_ms against ttft_ms tell magpie's time from Copilot's.
Tests:
- TestCallArgsStreamWhenTranslated (function and custom), through the
real handler with an upstream that holds the rest of the call until
the client has the first delta.
- TestResponsesCallArgsStream, TestCustomInputStreams (pieces of 1, 2, 3,
5, 7 bytes and whole).
- TestCopilotRelayedUnlessAskedToSeal; TestCopilotUltraSubagentWithWebSearch
now expects the subagent relayed with the search.
Broken by hand at this tree, each went red:
- decoder holding every delta: TestCallArgsStreamWhenTranslated,
TestResponsesCallArgsStream;
- no custom input delta: TestCallArgsStreamWhenTranslated/custom;
- Copilot out of searchesItself: TestCopilotRelayedUnlessAskedToSeal,
TestCopilotUltraSubagentWithWebSearch;
- the asksSealing check off: the same two.
Real use: a built magpie serve in a sandbox HOME (port 3461) with the
owner's Copilot account, Codex-shaped requests offering exec_command,
apply_patch and web_search to copilot/gpt-5.3-codex:
- unmarked: relayed (Copilot's own response ids), apply_patch gave 93
custom_tool_call_input deltas from 3.55s to 11.69s;
- with a sealed spawn_agent: translated, apply_patch 117 deltas from
1.45s to 11.73s, exec_command 92 function_call_arguments deltas from
1.55s to 8.16s.
Not tried with the Codex binary itself.
Run at
|
||
|
|
11173c8a20 |
gateway: a long Computer Use turn fits each screenshot once, not every turn (fflake33 on Discord)
fflake33 (magpie 0.1.1279, macOS) sent Codex Computer Use turns of
570K-680K tokens with hundreds of screenshots through the Responses
route to codex/gpt-6.1-sol: 26.5s and 52.7s of the 41.7s and 71s to the
first token were magpie's own work, sampled in image resize, JPEG
decode/encode and JSON.
The causes, from a pprof CPU and alloc profile of a synthetic turn (160
distinct 2940x1912 JPEG screenshots, 112 MB body):
- codexImagesFit's cache of fitted images was a map cleared at 64
entries, so past 64 screenshots every image of every turn was decoded,
resized and JPEG-encoded again: ~19s CPU a turn (triangleResize 42 GB
allocated over 3 turns).
- It looked each part up by path from the top of the body
(gjson "input.%d.content.%d"), reading the 112 MB body again for every
image: ~9s CPU a turn.
What changed:
- codexImagesFit walks the body once (ForEach over items and parts, at
their offsets) and splices only the changed image strings; the rest of
the body goes byte for byte as before.
- The cache (fitted) is an LRU keyed by sha256 of the limits and data
URL, bounded at 256 MB of fitted bytes and 8192 entries, letting go of
what goes unsent for an hour. It holds the encoded bytes, not the
base64. A request looks all its images up before keeping any it made,
so a conversation larger than the budget still finds what was kept
since its last turn.
- Images not kept are made side by side, at most min(4, GOMAXPROCS) at
once (each holds ~100 MB for a Retina screenshot); the same image twice
in one request is made once.
- Sibling: the describer's cache (vision.go sights) was FIFO at 256, so a
text-only model sent 300 screenshots described every one again each
turn. It is now LRU at 2048 (a description is a few KB).
Numbers, codex_images_timing_test.go (MAGPIE_TURN_TIMING=1), magpie's
time before the fake upstream had the request, 160-163 screenshots, run
back to back at load ~15-60 on this M-series mac:
- before (
|
||
|
|
ae7dc10ae2 |
docker: the image is Debian 12 slim, so the Cursor and Devin CLIs magpie installs at sign-in run in it (#2834, bborn2)
magpie installs a subscription's CLI at sign-in with its vendor's `curl … | bash` (internal/provider/install.go: Cursor, Devin, Grok Build). The distroless image had no curl and no /usr/bin/env (the installers' shebang), so that install couldn't run there, and only Grok Build had a native fallback. bborn2 reported that a Cursor CLI installed by hand failed with "cannot execute: required file not found". The image is now debian:12-slim with ca-certificates and curl. It keeps the nonroot user at uid/gid 65532, HOME and XDG under /config, the healthcheck, and magpie on PATH. Size: 157MB against 82MB for origin/main's image, both built here on arm64. Running a feature magpie offers is worth the 75MB. Changed in review: dropped the branch's GOPROXY build arg, a separate goal. The comments in install.go and install_test.go that said the image has no curl now say "had". docs/reference.md and the site's Docker page (en, zh, ja) say Debian with bash and curl instead of distroless with busybox. Run, with OrbStack's docker: - docker build of this tree and of d783df46c's Dockerfile: 157MB vs 82MB. - docker run of the new image: health "healthy", user nonroot (id 65532). `curl https://cursor.com/install -fsS | bash` exit 0, then `~/.local/bin/cursor-agent --version` printed 2026.10.16-e3cb207. Devin's install.sh installed devin v3000.11.92 (its trailing `devin setup` said "Login canceled" with no terminal, as on any host). `devin --version` printed 3000.11.92. bash and `magpie version` run. - Old image: `which curl` finds none, and /usr/bin/env doesn't exist. - A volume written by the old image (file owned 65532) was read and written by the new image. - gofmt -l clean; go vet darwin, linux (nogui) and windows clean. - Full `go test -tags nogui -timeout 45m ./...`: every package ok except internal/agent and internal/gateway, which timed out at 45m mid-test (TestConnectSaysHow, TestLargeRequestEndpoints) under a load average of about 200 from parallel suites. This commit changes no code those packages build, only comments in internal/provider, which passed (992s), so they weren't rerun. Not tried: a Grok Build install inside the image, and a full in-magpie Cursor/Devin sign-in with a real account in the container. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
ccb2eea159 |
provider: moved Zed users get plugin 0.1.9, which says why a never-read model list failed (plugins#229)
plugins 779388b published @magpie-community/opencode-zed-auth 0.1.9 at 13:45 (npm view --prefer-online: 0.1.9), but the zed mover's min stayed 0.1.8. keepMovedCurrent installs mv.min, so moved users, ReneXiong among them, kept 0.1.8 and its six pre-sign-in models shown as the account's own. Every other mover's min equals its npm latest (checked all eleven). Run at this tree: go test -timeout 30m ./internal/provider/ ok (1022s, sandbox HOME); gofmt -l clean; GOOS=linux and GOOS=windows go vet ./internal/provider/ clean. Not tried: a real Zed account, as the plugin commit says. |
||
|
|
d783df46cb |
plugin: a plugin's page adds items to a provider's and an agent's row menu (P6)
package.json's magpie.actions: [{id, menu, title, titles}] puts items in
the row menus magpie draws, after its own: a provider row's (right-click)
and an agent row's (its handle, or right-click). Picking one opens the
plugin's page and posts it {event: "action", data: {id, provider|agent:
{id, name}}}, nothing else of the row; the bridge's magpie.onAction(fn)
gets it, and an action picked before fn was given waits for it.
- plugin.Window reads them (page.go): menu one of ActionMenus (provider,
agent; a session's menu is left out, its title is user content), id
^[a-z0-9][a-z0-9-]{0,39}$, an id given twice is the first's, 8 at most,
none for a plugin with no page.
- /api/plugin-pages carries them on the page; a missing title is the
page's, in each language (pluginpage.go).
- pluginpages.js: magpie.actions(menu, context) gives the row menu's
items; openRowMenu draws a plugin's name as written (literal), not
through t().
- The Plugins page says which menus a plugin adds to (actionsLine),
translated in zh, zh-TW, ja and de.
- Docs: plugin-runtime.md's P6 section and verification; the site's
plugin docs (en, zh, ja) gain "Items in magpie's menus".
- The core's budget (TestCoreScriptBudget) is not raised (#2710): with
P6 the core came to 1,447,648 bytes, 648 over. pluginpages.js's header
now says P5's and P6's part in one paragraph and points to
plugin-runtime.md, which says it in full, and plugins.js's panels and
actions lines share whereLine: 1,446,845, 155 under.
Run:
- Full: this series (P5, the Plugins dot, the probe test, P6, and a
built-ins-on commit since dropped for main's own
|
||
|
|
d694d9bf8f |
agent: TestKeptAddressProbeNeverWaitedFor tests that Drift returns, not that it returns within a second
It went red in a full run at load average ~300 ("Drift waited for the
probe") because Drift, which reads the agent's files, took over a second.
The probe it starts is held until the test releases it, so a Drift that
waited for it would never return: the test now waits up to 30s for Drift
and fails only if it hasn't returned.
Run: broken by hand (Drift calls the probe before returning), red at
38.9s with "Drift waited for the probe"; restored, go test -count=3
-run TestKeptAddress ./internal/agent/ ok.
Full run, with the rest of its series:
this series (P5, the Plugins dot, the probe test, P6, and a
built-ins-on commit since dropped for main's own
|
||
|
|
8e44c2f351 |
gui: the dot on Plugins says what it is, and leads to the plugins with an update
The owner, on the sidebar's dot beside Plugins: no one can tell what it means, and once they click it, they should see which plugins need updating. It meant "a plugin update is waiting", said only in a hover title, and Plugins opened on whatever tab was last open. - Sidebar: under Plugins, Installed reads "1 update" / "N updates" in the dot's colour in place of its count, with a title saying where to update. - Opening Plugins while an update waits lands on Installed. - Installed names the plugins with a newer version in a bar above the list, with Update all beside them (moved there from the footer). Each row still shows its own "vX out" and Update. - Strings in zh, zh-TW, ja and de; the docs (en, zh, ja) say the same. Run: - plugin-updates.test.cjs: chromium and webkit, en zh zh-TW ja de, at 1024 (sidebar) and 600 (tab bar), 22 ok. Also ok in both engines: plugin-git, plugin-update-button, plugin-check-updates, plugin-card-update, plugin-prerelease, nav-sub-unroll, sidebar, builtins, i18n-keys. go test ./internal/gui/ -run 'TestCoreScriptBudget' ok. - Broken by hand, each red: no sidebar label (the 1024 cases), no jump to Installed, no bar (every case). - Looked at in WebKit screenshots, zh at 1024 and de at 600. Full run, with the rest of its series: this series (P5, the Plugins dot, the probe test, P6, and a built-ins-on commit since dropped for main's own |
||
|
|
b9f790d37b |
plugins: panels in magpie's pages, a page that replaces a built-in one, titles in the window's language, and a look that matches
P5 of the plugin runtime (docs/subsystems/plugin-runtime.md):
- Panels (magpie.panels): a plugin draws a frame into a slot of a
built-in page (a provider's editor, Settings, Usage); magpie.context
says where it is, and the frame is as tall as what it draws.
- A page can replace a built-in one (magpie.page.replaces); show() opens
it in that page's place, and the sidebar row goes to it.
- page.titles and a panel's titles name it in the window's language
({"zh": …}); a malformed map is dropped, the title kept
(TestWindowTitles).
- main's #2501 already names wails:// in the policy of a page in the
desktop window (through ownWindow), which is why the usage page drew as
bare HTML from v0.1.1259. TestPluginPageLoadsItsFilesInTheWindow loads
a page through ownWindow in a real WKWebView, which Playwright on http
can't; the subsystem page says how.
- The bridge adds magpie's look for what a page leaves unstyled, every
rule in :where() so any rule of the page's wins, and the theme's
colours as --magpie-* variables.
One commit: the panels, the replacing pages and the titles share hunks
in page.go, pluginpage.go, pluginpages.js and the docs, and couldn't be
split cleanly.
Run:
- Full: this series (P5, the Plugins dot, the probe test, P6, and a
built-ins-on commit since dropped for main's own
|
||
|
|
5380114da1 |
LESSONS: 10-17: runs recorded at another tree, "under load" reds left unowned, a body scan on every passing reply
Folds the review of 10-17 04:00 to 10-18 04:00 (77 commits, v0.1.1277 to v0.1.1283) into LESSONS.md, and moves two lessons seen a third day into docs/code-standards.md: - magpie's default never overrides a value the user set (10-05, 10-10, 10-17: 5a2414acd's Essentials to All, #2749), a row under "What a change contains"; - a checkout, worktree or log belongs to the session that made it (10-09, 10-12, 10-17: 7660399a1's worktree checked out by another session, 17557132c's log deleted), under Commits. New lessons, each seen once: - a named sibling left alone gets an issue ( |
||
|
|
7ac20247a9 |
gateway: a large passing reply is not read for why it failed, so a 24MB JSON reply reaches its client again (#2551)
|
||
|
|
b36819d349 |
redact: a long string already scrubbed is not run through the rules again
yetone/magpie-releases#24: ~19% of the profile was gateway
recordConversation -> conversationTurn -> redact.ScrubJSON -> mask. Codex
sends its whole history on every turn, and what is kept of each request
is scrubbed whole, so each turn ran every rule over the whole session
again: O(history) per turn.
Scrub now remembers, for strings of 256 bytes or more, what it made of
them, keyed by SHA-256 of the string and by knownGen. What Scrub returns
depends only on the string and on the values known (rules are static);
known.go bumps knownGen whenever that set changes (a value added or
replaced, a reindex after values are let go), and a result made at
another generation is never used. Nothing is kept but the hash and, when
the string changed, the scrubbed text. Two generations of at most 32,768
entries / 32 MB each. ScrubJSON's fallback for a body that isn't JSON is
unchanged, so a failed parse still scrubs line by line; nothing is
recorded unscrubbed.
Measured (Apple M4 Pro, BenchmarkScrubCodexTurn: turn 301 of a Codex
Responses history, 1.3 MB, each turn's tool output ~4 KB of code naming
tokens, keys and URLs, scrubbed after turn 300 was):
before (memo off): 2.81 s/op
after: 0.10 s/op, 5.4 MB and 21.6k allocs/op
TestScrubRunsTheRulesOnceAString: turn 41 after turn 40 runs the rules
over one long string (its new output); on the old behaviour (memo off)
it fails with "the rules ran over 41 strings for one new turn". It also
checks the output is the same as a fresh scrub.
TestScrubMemoForgetsWhenAValueBecomesKnown: a string remembered as clean
is redacted once a value in it is masked elsewhere (Scrub and ScrubJSON).
TestScrubMemoKeepsTheSecretOut, TestScrubMemoBounded.
Run: go test -tags nogui -count=3 ./internal/redact/ ok; the full suite
as in the sessions commit before this one (same tree). agent and gateway rerun at a lower load: ok; gui rerun: ok. (The first
rerun had TestPluginStreamLargeReplies red on time again, #2551, which
passes alone in 22s, and TestDiffLines at 2.04s against its 2s bound,
filed as #2766.)
gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ./... ok.
Rebased onto
|
||
|
|
3b3bc359da |
sessions: a long Codex session being written is read on from where it was, not from its first line
yetone/magpie-releases#24 (LeiCheng42, v0.1.1280): a 30s profile while Codex ran shows magpie at about a core, ~24% of it in usage.prefetchSources -> sessions.ReadCallSource -> readCalls -> scanAt. The tray's usage loop (watchTrayUsage -> usage.QueryPage(Today)), the usage API and the Sessions page read every source whose size or mtime changed, and an active Codex rollout changes each turn. A Codex continuation's index weighs about six entries a call, so a session past ~1,365 calls was over the shared 8192-entry revision budget: its window was dropped, and every append parsed the whole rollout again from offset 0, for the Requests reader and the summary (List) alike. Now up to two (revisionActiveFiles) recently written Codex sessions keep their window past the shared budget, each up to 16x it (131,072 entries), and only while the file changed in the last revisionIdle (5 min). The full parse built the same index on every append anyway, so this costs no more at its peak; an idle session still loses it. Measured (Apple M4 Pro, BenchmarkLongCodexSessionAppend: a 2,000-call, 10.7 MB rollout, one turn appended, then ReadCallSource + List(0)): before: 0.87-1.09 s/op after: 26-60 ms/op TestLongCodexSessionAppendReadsOnlyTheAppend (via a scanAt hook) checks that each of three appends is read from the previous size by both readers, and that the result DeepEquals a fresh read of the whole file (calls and summary) after the caches are dropped. On the old code it fails: "append 0: read from 0, not where the last read ended (10691427)". TestRevisionEntryBudget covers the two-window cap and the idle/oversize drops. Run: go test -tags nogui ./internal/sessions/ ok; go test -tags nogui -timeout 45m ./... with the redact change on top, under a load average of 440-610 from other sessions' suites: 59 ok, and agent and gateway (45m timeout), gui (TestSetAnswersWhileDevinAndProvidersHang, set took 1m30s), edit (TestTOMLBigFileParsesInLinearTime, 1.0s) and middleware (TestStream, onEvent "took too long") failed on time. edit and middleware rerun alone: ok. agent and gateway rerun at a lower load: ok; gui rerun: ok. (The first rerun had TestPluginStreamLargeReplies red on time again, #2551, which passes alone in 22s, and TestDiffLines at 2.04s against its 2s bound, filed as #2766.) gofmt -l clean; GOOS=linux and GOOS=windows go vet -tags nogui ./... ok. |
||
|
|
b14784c03f |
gateway: a fallback too small for the request is asked once every account with room is out of its allowance (Kai on Discord)
Kai on Discord (0.1.1278): Claude Code to claude/claude-opus-5-5, the
Claude provider's two subscription accounts (Max, Pro) both at their
limit ("resets 5:58am", "resets Oct 18 at 3pm"), its Fallback
codex/gpt-6.1-sol. Routing said the second account's 429 had nobody left
to try, and Claude Code had the 429. The fallback was never in the
route's order.
Cause: roomy (
|
||
|
|
a3b48e0f74 |
gateway tests: TestTranslatedStreamKeepsClientAlive gives a loaded scheduler room (#2169, #2711, #2737)
The test's client hung up after 150ms of hearing nothing counted, while the gateway's keepalive gap is 10ms. Under load (300-600 on the dev box, CI's macOS race shard at |
||
|
|
e44b9aef33 |
middleware: onProvider changes what one provider a request is tried on is sent
A JS gateway middleware can export onProvider(body, ctx). The gateway
calls it on each try, just before the body goes to that provider, with
ctx.provider = {id, name, account, model}: account is the subscription's
kind (claude, antigravity, …), absent for a key. Every try starts again
from the body onRequest left, so a change for one provider never reaches
another in a routing group. null and ctx.reject turn nothing away there.
A hook that throws or runs past 250ms leaves the try's body as it was.
A plugin could act only before routing until now, by the model name the
agent asked for. Claude Desktop asks for opaque aliases, so a plugin
couldn't tell which vendor a request was going to. The first user is
@magpie-community/middleware-antigravity-cloak: it changes only what an
Antigravity account is sent, so that Antigravity stops refusing Claude
Code's system prompt (xzplzpl on X). magpie itself still sends every
prompt as the agent wrote it.
- gwmw.To and gwmw.Tried; middleware.Run.Tried runs the hooks.
- serveAgent puts the runs on the request's context, and serve's
candidate loop calls triedOn before the Antigravity foresight, so it
judges the body that will be sent.
- Docs: gateway-middleware.md, reference.md, integrating.md, and the
hooks table and community list in site docs plugins.html (en, zh, ja).
Run:
- go test ./... -timeout 45m in a sandbox HOME (macOS, at
|
||
|
|
de671719a0 |
provider: a retired built-in's failed move is tried again in 10 minutes, not 6 hours
A failed move waited moveRetry (6h) before KeepRetiringMoved tried it again. That was fine while the built-in carried on serving the accounts. A retired built-in serves nothing, so a move that failed for a moment (npm out of reach, or the plugin listed in plugins.json but not installed yet, which the real-account run on 85b8f6d4d hit with Command Code: the first Move failed, the second worked) left the user's subscription unserved for up to 6 hours unless they pressed Move. - retryWait(id) is retiredRetry (10 minutes) for a retired built-in, and moveRetry otherwise. MoveRetiring and HandOver both use it (retryDue). - KeepRetiringMoved's next run is brought forward to when a retired built-in's failed move is due (nextRetiringRun, at least a minute), instead of always an hour. - docs/subsystems/provider-plugins.md says so. TestMoveCutShort now also checks: - a failed move 11 minutes old waits while the built-in serves it, and the next run is an hour; - once retired, the next run is 10 minutes, it isn't tried at once, and it is moved after retiredRetry. Broken by hand, each red: - retryWait returning moveRetry for a retired built-in: "a retired built-in after retiredRetry: map[]" - nextRetiringRun always an hour: "the next run after a retired built-in's failed move: 1h0m0s, not 10m0s" Run: go test -tags nogui ./internal/provider -run TestMoveCutShort: ok. What was run for the stack, at load ~300 (it was rebased from |
||
|
|
3443d18c31 |
gui tests: keychain-retry waits for the status that comes after the state is read
keychain-retry.test.cjs was red under load, on origin/main
|
||
|
|
0718beb437 |
provider: FetchNew waits on no CLI for who is signed in; none feeds a list it fetches
cliIdentities() still held cursorStatus after Cursor's built-in was retired. Nothing FetchNew fetches waits on `cursor-agent about` any more: the Cursor plugin lists its own accounts (Listed), and cursorIdentity only names its carried-over account. But a page's FetchNewBehind still found the never-asked CLI unsettled and ran behind the page, so FetchingNew stayed up on a poll with nothing due, the same loop Devin's entry caused (TestFetchingNewOnceStarted and TestFetchingNewForgottenWhileListed red from the Cursor commit on). Removed: cliIdentities, awaitIdentities, asking, identitiesUnsettled and identitiesAnswered, and their branches in fetchNewGo and fetchNewHeld, which now list the accounts once. TestFetchingNewForgottenWhileListed (#2390) and the CLI half of TestFetchingNewOnceStarted (#1147, #1789) tested only that wait, and go with it. cursorStatus and devinStatus stay as cliIdentity, asked by the plugin's own-account name and the movers; left_alone_test names them itself. Run in magpie-wt-int (this commit on the retire stack): go test -tags nogui -count=1 -run 'FetchingNew|FetchNew|LeftAlone|Identit|Mover' ./internal/provider: ok go vet -tags nogui ./internal/provider; staticcheck -checks U1000 ./internal/provider: only sameAccount, unused on origin/main too The full suite at the stack's final head is recorded in the last commit's body. |
||
|
|
bd30b068d3 |
docs: every deprecated built-in is retired; AGENTS.md and gateway-routing say so
AGENTS.md: the table's subscriptions are retired, not moving; the plugin does everything, the built-ins' code is gone but for what the movers read; the "fix the built-in too" step is gone; the parity tests hold each plugin to what its built-in did. gateway-routing.md: no bridges to a vendor's own API are left, so the structured-output, tool-image and billing-line lists lose Cursor, Kiro, Qoder, Devin and Command Code; Kiro's image ordering is its plugin's. Run: docs only; the full suite runs at the stack's head. |
||
|
|
e431f71a89 |
gateway, provider: the code only the retired built-ins used is removed
With all eleven built-ins retired, staticcheck U1000 (diffed against |