ac4af582301a4e8a29245dbba767eba31334ddf9
5
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
90c02326bb |
gui: an app takes the gateway over from its older copy once idle, and says any other version serving it (matrix0487)
matrix0487 on Discord: after an update, pi said 404 'magpie knows no model "kimi/k3.1-pro" ... add a provider in magpie first'. The app had written pi a model its older gateway didn't know, and updating the gateway fixed it. A magpie that finds another one serving the gateway used to log it and wait for that one to quit (watchGateway took the port only once nothing answered). Only the Gateway page said so. Now (otherServes, gateway_older.go): - An older released copy of the app (it says serves app or tray, and a pid) is this app's predecessor. Once its /v1/magpie/concurrency says nothing is in flight (gateway.ServedBusy; unknown is never idle), the app quits it the way the Gateway page's button does (quitMagpieOnPort: a magpie only, by its program) and serves the gateway. A stream through it runs to its end first. watchGateway looks again every 15s while another serves. At most three times a run; a quit that fails is left to the button. - Any other one (magpie serve or the service, magpie web, a TUI, a newer magpie, a build of its own) is left running. /api/state carries it as gatewayOther, and the Agents page says it above the list with what to do, plus the take-over button for an older one (gatewaySkewLine, in plugins/gateway/client.js so app.js stays under its budget). A dev build of this magpie says nothing. New strings in zh, zh-TW, ja and de. How the reporter's older gateway outlived the update isn't known: they never said whether one ran separately. A failed handover leaves the old app serving for up to 15m, and a magpie serve left running is another source. Both are covered now: the first is replaced, and the second is said. Known gap: a request that starts between the idle read and the quit gets the older app's short drain. A socket handover between two running apps (no gap) is not built. Run on mote at 0f8ea30bb (this change on |
||
|
|
d307aa6485 |
gui: /api/state is written one agent at a time, for the page and the kept sum at once
Each poll of the Agents page encoded the whole state (1.3 MB with real accounts) into json's buffer, and the GC between polls empties the pool that buffer comes from, so it grew to the state's size again each poll: 48 MB of what twenty rounds allocated (v0.1.2477 build, real-account sandbox), and 68 MB at v0.1.2463. writeStateJSON encodes the state without its agents twice (as sent, and as keepState keeps it, without the settings), and each agent once, straight to the response and to keepState's sha256, through one encoder. keepState is split so the handler hands it that sum (keepStateSummed). When the splice can't be made (no agents, or a field put before "agents"), it writes and sums the state whole, as before. Measured on this Mac with the real-account sandbox (abr.sh, 20 rounds of drift + state + providers): - v0.1.2477: writeJSON under /api/state 48 MB, 511 MB in all. - this change: writeStateJSON 15 MB, 477 MB in all. The /api/state bytes are identical to v0.1.2477's (cmp). Run on mote (mote-run, Go 1.26.8): - gofmt clean; go vet ok, also GOOS=windows. - TestStateWrittenAsEncoded (same bytes as Encode, same sum as keepState, for a large state, an empty agent list and none) and TestStateWriteGrowsNoBufferItsSize, with TestKeptState* and TestLast*: ok 3 of 3. - Broken by hand (the whole-state path always taken): red, "writing a 1614586-byte state allocated 4207139 bytes, want under half its size". - Not run before this push: the full internal/gui package; it runs next. |
||
|
|
6a23d9d755 |
gui: the kept state and providers are marshaled only when they changed
keepState and keepProviders ran json.Marshal on every /api/state and
/api/providers poll to compare the answer with the one kept on disk.
They now keep a sha256 of what was written and hash the new answer
into it with an Encoder; only a changed answer is marshaled and
written. json.Marshal there was 38.6 MB (keepState 25.9 MB,
keepProviders 12.7 MB) of what twenty window polls allocated with
real accounts (m2463 profile).
Test: TestKeptStateMarshaledOnlyWhenChanged. Twenty identical keeps
marshal nothing, nor does a keep after the file is read again; a
changed state is marshaled once and read back.
Run on mote, at this tree on
|
||
|
|
6a900e0d04 |
gui: a poll of the Agents page no longer drops every cached model list
/api/state keeps the state it built in agents-state.json, written only
when the bytes change. They changed on every poll: a stale copy's start
is now less how long it has run, two clock reads apart, so it moved by
microseconds each time (on a real config, only
/agents[1]/staleCopies[i]/since differed between two polls). The file
was written through edit.WriteAtomic, whose write calls
filememo.Forget(). That bumps provider.StampNow, so every 15s poll threw
away each agent's model list and picker (magpieModels, viaMagpie) and
every provider's kept catalog, and the next look built them anew.
- StaleCopies' since is truncated to the second (the check against
magpie's change still uses the exact time).
- keepState writes through steady.WriteFile (temp, flush, rename), which
leaves filememo alone: nothing a request reads is built from this file.
Not changed: on Linux and WSL the process list gives a run time in whole
seconds (ps etime), so a copy's since can still move by a second between
polls there; macOS reads the exact start from sysctl.
Run on mote at
|
||
|
|
c97b4247a7 |
gui: the Agents page draws the agents magpie read last at once after a start or a light-mode reopen, and the fresh read replaces them (#1519, fatkun)
After a start, or after light mode let the window go, the Agents page
waited for state(): every agent's config read again, and with WSL agents
on each distro's through \\wsl.localhost. Measured on the Windows test box
(realistic config, one running distro with 9 agents):
/api/state, WSL agents on: 456-620 ms per read (WSL rows 20-160 ms each)
/api/state, WSL agents off: 117-253 ms
/api/providers: 83-125 ms, already loaded on its own
(show() at start), not behind the state
Now GET /api/state keeps what it built (memory, and
<cache>/magpie/agents-state.json for the next start, written only when it
changed). GET /api/state?last=1 answers with it at once, marked last, with
the settings as they are now (the kept copy leaves the settings out: they
hold the GitHub token and the LAN key) and only for the version that kept
it. The page's first load asks for both, draws the last-known rows if they
come first, and the fresh read replaces them: an agent leaves the list
only once that read says it is gone. A change made on the early rows
answers with a newer state, which stands over the fresh read asked before
it. With nothing kept the page waits as before.
Windows box, new binary, cold start: /api/state?last=1 7-25 ms (436 KB,
all 20 agents incl. the WSL ones), fresh /api/state 456-550 ms beside it.
Run: TestLastKnownState (fails on the old handler: ?last=1 gave the full
fresh state); agents-last-known.test.cjs in Chromium and WebKit (the
at-once case fails on the old app.js); the 21 GUI tests that count or
stub /api/state; go test ./internal/gui; gofmt; vet darwin, linux,
windows; real page in Chromium against the built binary (second start
drawn from agents-state.json).
Not changed: the ~1.15 s of start-up moves before the window on Windows,
and state()'s own cost.
|