ac4af582301a4e8a29245dbba767eba31334ddf9
18
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 |
||
|
|
4534561f6b |
codex: a thread open when magpie quits goes on through a relay, not a 503
idkatbro on X: a Codex session started while magpie was open keeps failing after magpie quits with "unexpected status 503 Service Unavailable: Unknown error, url: http://127.0.0.1:3425/backend-api/codex/responses", until magpie is opened again. Cause: Codex signed in to ChatGPT, with more of its accounts on in magpie, gets openai_base_url = the gateway's /backend-api/codex (failover). At quit EndCodexFailover takes it out of config.toml, but a thread already open, in the Codex app and its app-server above all, keeps the base URL it started with. Every turn after went to a closed port. With a system or env proxy in between, the proxy answers 503 with an empty body, which Codex shows as "Unknown error"; without one Codex says "Connection refused" and reconnects. Reproduced on mote with codex 0.162.1 and a proxy answering 503 for the closed port. Masking plays no part: it runs only in the gateway, is opt-in, and its own 503 carries a readable message. Fix: when quit really ends failover (EndCodexFailover now says so), the gateway is on loopback, and Codex processes run (provider.CodexPIDs), magpie starts a detached `magpie codex-relay` (internal/codexrelay). It waits up to 60s for the gateway's port, then passes /backend-api/codex/* on to the ChatGPT backend with the same transforms the gateway applies to Codex's own turns, signed by the caller's own Authorization; it adds no credential (gateway.CodexRelay). - Refused with a readable 400 (Codex retries a 5xx five times over): a magpie model, a turn naming one of magpie's Codex accounts, and a turn masking would have masked, which is never sent unmasked. - 403 for any Origin (null too) or a non-loopback Host, as corsGuard. - Any other path gets 503 "magpie isn't running", never readable as magpie by ServedBy. - It ends once every Codex process it was left for is gone and nothing is in flight. - The next magpie (GUI or `magpie serve`) calls codexrelay.Leave first: a POST with the token from a 0600 state file. The relay closes its listener at once, so the port is free when Leave returns, and finishes its streams (up to 30 minutes). No running turn is cut. Run (at 6df7dc287 on origin/main |
||
|
|
fcbbb8e479 |
gui: the start's warm-up and read-ahead look at each file once a second (#1665)
The warm-up after a start (sessions, usage, Codex effort) and the usage read-ahead asked for settings.json, logins.json and the rest for each session and row they read: a Windows sandbox's second start stat'ed settings.json 677 times in 25s, 286 of them settings.load and AccountDiscoveryOff under the warm-up. Both now hold what was read (filememo.Hold), as the GUI's requests and a catalog sync's round do. A write still reads the disk (edit.Read, settings' writes, logins.json under loginsMu), so nothing is written from a held read; a file another app changes is seen up to a second late while they run. Measured on xiaomi-gpu (Windows 11), an empty sandbox HOME, magpie web --gateway, second start, 27s, with a build counting each look at the disk (instrumentation not committed): before 1113 looks, settings.json 677 after 483 looks, settings.json 114 The catalog sync's round stays at ~100ms. Run: - TestWarmUpHoldsWhatItReads: red with the warm-up's Hold taken out by hand (the second read saw the other app's change), green with it. - mote: gofmt -l internal/gui clean; GOOS=windows and darwin go vet ./internal/gui and GOOS=linux go vet -tags nogui ./internal/gui clean; go test -count=1 ./internal/gui ./internal/usage: usage ok, gui red only on TestMainWindowCorners (#3949, mote's macOS 27, red on main before this). |
||
|
|
8b0132b3d2 |
codex: the Codex app sends again on every system as soon as magpie takes a used-up ChatGPT account over, and gets it back at the reset
Ethereal499 and Isdavexxx on X, MasterYi on Discord, #540. The Codex app greys Send for every model, magpie's too, while the ChatGPT account it is signed in to is used up. Its composer's gate (ChatGPT.app 26.1013) reads authMethod "chatgpt" plus rate limit allowed=false, and it asks account/read only when its app-server starts. |
||
|
|
1f589e3f4f |
usage: read today's usage ahead at startup
CyberCaius (Discord, Windows): "今天 N 次调用" is slow on the first
panel open after a start. The first usage?period=today parses
usage.jsonl: 0.33s for 2MB, 0.43s for a 40MB sandbox log here, more
on a slower disk. startBackend now runs usage.ReadAhead() in the
background, which works out today's summary into the summary cache,
so the panel's first ask finds it.
Parallel parsing was not done: with the read ahead, a request 1s
after start answers in 1-2ms, so there is nothing left to win there.
Test: TestReadAheadLeavesTodayNothingToRead. After ReadAhead, a
SummarizeTopIn(Today) parses nothing and works nothing out. Red with
ReadAhead's body emptied ("parsed the log 1 more times and was
worked out 1 more").
Run at tree 53ae48f72 (on origin/main
|
||
|
|
ef37b6fb76 |
gateway: an exhausted ChatGPT account no longer greys Codex app's Send while magpie can serve the turn (MasterYi on Discord)
MasterYi (#help, 1563467829687222343): with magpie wired into the Codex
app, a used-up ChatGPT account greys the Send button, so the third-party
models joined in Codex's picker can't be used either.
Cause, as far as the app's bundled code (ChatGPT.app 26.1013.40934,
read-only) shows: Send is gated in the app itself. It needs
authMethod == "chatgpt", the /wham/usage reading (fetched by the app
straight from chatgpt.com, not through magpie) saying not allowed, and
no credits. authMethod is read as the app opens or on account/updated,
which the app-server sends only on login/logout, not on a config change.
So the gate lifts only when model_provider is magpie AND the app has been
opened again. #540 already made magpie the provider while out, but only
when a magpie model was the default; on one of Codex's own models
(joined), nothing changed.
What changed:
- A (agent/codex.go Sync): joined on one of Codex's own models and the
account out (not Always ChatGPT, not magpie API), magpie becomes the
provider on that model as magpie serves it (codex/<model>), the model
kept in codex.out_own. Once the account has room, Codex is put back
joined on that model. A model picked meanwhile stays the user's. With
no ChatGPT account in magpie to serve it, nothing changes. New
Agent.AppOut says magpie is the provider for a used-up sign-in.
- C (provider/codex_app_out.go): a usage_limit_reached rest on the
active Codex account (gateway routing) or an x-codex-* window heard at
100% (NoteCodexLimits) has the account read again at once
(CodexMayBeUsedUp: active account only, at most every 20s, only
while a KeepOnAnAccountWithRoom loop has made its first reading and
still runs), not only on the 5-minute look. A first cut turned this
on for good as the loop started; every gateway test's Serve starts
it, so later gateway tests had accounts read again behind them, and
TestCodexOwnModelMovesToNextAccount and
TestCodexSpentMovesToNextGroupMember went red in the package run
(green alone 3 of 3). Now a counter, up after the first minute's
reading, down as the loop ends; the package run is green with it.
- B (gui/codex_app_out.go): the app open when the account ran out is kept
by its app-server's pid (provider.CodexAppOut; a new pid means it
reopened and read the provider, standing in for "authMethod is still
chatgpt"). On macOS, every 10s, magpie reopens it through the Agents
row's ReopenCodexApp when: AppOut, the account still out, the app is a
copy from before the config change, no turn in flight through the
gateway and none ended in the last 30s. At most once per time the
account runs out, success or not.
Drafts: the app's code keeps composer drafts in a persisted store
(composer-prompt-drafts-v2, 250ms debounce, flushed on quit), and
threads are server-side, so an unsent draft and open threads should
survive the quit. Not watched in a real app.
- D (GUI): Codex's accounts say "The Codex app can't send on {user}'s
used-up account": on macOS that magpie reopens it once no turn runs;
off macOS (no reopen path) or once tried, to quit and reopen it.
en, zh, zh-TW, ja, de.
Tests (each red on the code without its part, broken by hand):
- TestCodexOwnModelGoesThroughMagpieWhileUsedUp: red at "used up" with
the out case off, at "allowance back" with the restore off.
TestCodexOwnModelKeptOnChatGPT: Always ChatGPT stays.
- TestCodexMayBeUsedUpReadsAtOnce: red at "a window full: not read"
with the NoteCodexLimits hook off. TestCodexAppOutEpisode.
- TestCodexUsedUpReplyAsksAtOnce (gateway): red, asked [], with the
routing hook off.
- TestCodexAppOutReopenedOnce (gui, reopen stubbed): red at "a turn in
flight" with the idle check off, and at "again" with the once checks
off.
- codex-app-out.test.cjs: 40 of 40 (chromium, webkit; 900/480; five
languages; both texts); 2 of 2 red with the notice's call site off.
What was run, at this tree:
- gofmt -l: none. go vet ./... (darwin), GOOS=linux go vet -tags nogui
./..., GOOS=windows go vet ./...: exit 0.
- go test -tags nogui -timeout 45m: internal/agent ok (414s, before a
comment-only reorder in Sync); internal/gateway ok (534s),
internal/gui ok (78s), internal/provider ok (137s), after the
live-check fix, at this tree before the previous commit's JS-only
move (then with a budget raise since taken back); internal/gui
again after the move.
- GUI (chromium, webkit), at this tree: codex-app-out, codex-app-stale,
i18n-keys, gui-de, gui-ja, gui-zh-tw and the files reaching the
previous commit's move: 164 of 164. Before the trim, every codex-*
and account-* file: 447 of 448; the red, codex-predictions chromium
ja 420 "picking a model scrolled the page", is #2624 and is red alone
on origin/main
|
||
|
|
a95f0b83ff |
gui: a restart to update hands the gateway to the new version (xuanwo on X)
Before, a restart to update ended the gateway, so it waited until no agent request was in flight (#577). An agent busy for hours held the update back, and Restart now cut its replies off. On a Mac and on Linux the restart now starts the new version beside the old one and hands it the gateway's listening socket. The new version takes every new connection at once. The old one stops accepting, finishes the requests it has (up to 15 minutes, as `make dev` already gave), then quits. Nothing an agent sends is refused or cut short. How (docs/subsystems/gui-shell.md, "A restart to update hands the gateway over"): - internal/handoff, new, darwin and linux. The old magpie opens a unix socket in a 0700 temporary folder and writes handover.json (fresh for 2 minutes) in its config folder. The new one finds it, says Hello, and gets the listening socket by SCM_RIGHTS with the address, its pid and a callbacks socket. Only the same program (same path, same uid) is given it. When TMPDIR is too long for a socket path (sun_path is 104 bytes on a Mac), the folder goes in /tmp (sockDir). - gateway: Inherit/Listen serve on the socket given, and acknowledge once serving. HandOff gives the old one handedOffDrain (15m) instead of the 2s an ordinary end gives. A Claude Code run of the old magpie whose helper calls its tools on the port gets those calls passed back to the old one over the callbacks socket (forwardCallback, mcpCall, ownCallback). The bridge's turns are counted on their own (Busy.Bridge, BridgeLast). - gui: restartInto calls beginHandover (OpenBeside `open -n` on a Mac, StartBeside for the binary on Linux). On the new version's ack, the old one hides its menu bar icon, panel, window and Dock icon (Mac), ends its backend, waits for its requests, and quits. OnShutdown leaves Codex's failover, the thread port and the install to the new one, which serves the gateway they point at. - Never two on screen. Mac: the old one lets go of its instance lock just before giving the socket and takes it back if the handover fails, then hides on the ack. Linux: Wails holds the D-Bus name until exit, so the new one serves the gateway at once but puts its tray up only once the old pid has exited (awaitExit, 16m at most). Until then the old tray stays. - What a handover can't carry: the subscription bridge's Claude Code turns live in the old process, so the restart still waits for those (restartBusy = blocking(Busy, true)), along with turns parked on tools. Every other request is not waited for. The update badge, the Updates page and Settings' "Restart automatically" say so, in every language in i18n.js. - A handover that isn't made restarts as before: socket not opened, new version not started, no hello in 60s, no ack in 90s. Because the restart didn't wait for the requests in flight, it now waits for gatewayBusy to be idle (fallbackWait, 15m at most) before it quits and relaunches, so a failed handover never cuts a request. - The overlap. The instance lock is handled as above. Both processes write: the sticky routing is flushed before the hand (FlushSticks), and files go through the existing locked or atomic writes. Counters (RPM, concurrency) are per process for the overlap (gateway-routing Constraints). OAuth refresh: the previous commit locks Codex's and the ChatGPT API's refreshes across processes. The rest were already locked or don't rotate (providers-accounts Constraints). - Not changed: Windows (no SCM_RIGHTS; it restarts as before and still waits for idle, #577), `magpie web` (re-execs in place), and `make dev` (its own Handover). MAGPIE_NO_HANDOVER=1 turns it off. Found by the sandbox run, fixed here: in run 2 the sandbox's long TMPDIR made the socket bind fail ("bind: invalid argument"). The restart fell back at once, cut the stream at chunk 6 (curl exit 18), and 4 of 381 requests got no answer over ~2s. Two fixes: sockDir (/tmp fallback), and the fallback that waits for idle. Tests (each red when broken by hand or on the old code): - gateway/handover_test.go: TestHandedOverGatewayFinishesItsStream (drainFor without handedOff: "the old one ended with a stream in flight"; takeAck off: "the new one never said it serves"). TestToolCallOfTheMagpieBeforeGoesToIt (mcpCall forward off: 404; ownCallback forwarding off: 401). TestInheritedForAnotherAddressIsLetGo, TestCallbacksSocketServesOnlyToolCalls, TestBridgeTurnsCount, TestSameAddr. - handoff/handoff_test.go: TestHandOverListener, TestNoAckKeepsTheSocket, TestTakeOnlyAFreshOfferForThisProgram, TestCloseRemovesOnlyItsPointer, and TestOpenWithALongTemporaryFolder (red on the old Open: "bind: invalid argument"). - gui/handover_unix_test.go: TestRestartHandsTheGatewayOver, cross- process. The test binary re-execs as the new magpie. A stream through the old one finishes whole, requests during the restart are all answered, the next ones reach the new pid, and the old one quits only after its stream. On the old restart it is red: "quit with a reply streaming". TestHandoverNotMadeRestartsAsBeforeOnceIdle ("never says hello", "doesn't start") is red on the code before the fallback drain: "quit with a reply streaming" / "the restart didn't try to hand over". - gui/handover_test.go: TestRestartWaitsForWhatAHandoverCantCarry, TestHandsOverOnlyWhereItCan. - update/relaunch_open_test.go: TestOpenBeside, TestStartBesideWaitsForNothing. - GUI: update-wait.test.cjs (the handover wording on the badge and page), update-restart.test.cjs (Settings' description). Real run, Mac, sandbox (env -i, HOME and XDG_CONFIG_HOME in a scratch folder, a long TMPDIR, MAGPIE_ADDR 127.0.0.1:63249, MAGPIE_UPDATE_FEED pointed at a fake feed). The app is -tags production, ad-hoc signed, bundle id com.yetone.magpie.sbhandover, built as 0.1.9001 and 0.1.9002. autoRestart is on. A fake upstream streams 100 one-second chunks. The real app found the update, downloaded and staged it, and restarted with the stream in flight (run 3, at this change's tree before the rebase): - 18:31:43, pid 59833 serves. 18:31:51, the new pid 60477 serves; v1 logged "magpie 0.1.9002 (pid 60477) serves the gateway now". - Requests: 375, failed 0. 19 were answered by 59833, then 356 by 60477. - The stream got all 100 chunks, END and [DONE] at 18:33:24, curl exit 0, 92s after the hand. 59833 exited within 3s of the stream's end. Run at the pushed head (7a5bca443's tree, on origin/main |
||
|
|
4896fc3ba1 |
codex: a thread magpie compacted goes on after magpie is quit or disconnected (LukeMa on X)
When magpie answers Codex's compaction itself (a magpie model, Codex's
own models through magpie's accounts, a CC Switch table), the item it
returns carries encrypted_content "magpie1:"+base64(summary). Codex keeps
it in the rollout (a response_item, and the compacted checkpoint's
replacement_history) and replays it with every later turn. Sent to the
ChatGPT backend directly, it is refused: "The encrypted content for item
cmp_magpie_1 could not be verified ... invalid_encrypted_content"
(probed with a real request on gpt-5.6-luna; the same summary as a user
message was answered).
Codex's remote compaction v2 keeps exactly one Compaction item, so magpie
can't answer with a plain message instead. sessions.PortCodexRollouts
writes each of magpie's items in a rollout as the message it stands for
(codexsummary.Message: Codex's summary prefix, a newline and the summary,
as a user message), which is what Codex's own local compaction stores and
what the gateway already sends in its place, so it reads the same through
magpie and goes on without it.
- Only magpie's compaction items change; other lines keep their bytes,
the file its line count, mode and time. An unreadable one is left out
of a list with its replacement_history_metadata entry, as Codex's own
ghost-snapshot strip does.
- Published as Codex publishes a compressed rollout: temp file and
rename, under thread-writer-locks/.coordination.lock and only with the
thread's lock free. A thread a Codex has open is left for a later pass.
A Codex home without thread-writer-locks is left alone.
- .jsonl.zst rollouts are read and written packed.
- Passes: 2 minutes after the GUI or magpie serve starts and every 10
minutes; on Codex Disconnect (3s); as the GUI quits (3s). The first
pass reads rollouts written since 2026-09-24; later ones only what
changed since the last whole pass, plus what was left held
(codex-portable.json in magpie's folder).
Run at this series' head (on origin/main
|
||
|
|
a39e675d2a |
gui: magpie web beside a busy gateway waits for the port instead of failing to bind it (K.Liu)
K.Liu on Discord: `magpie web` next to the systemd `magpie daemon` logged
"gateway: listen tcp 0.0.0.0:3425: bind: address already in use".
Cause: before listening, serveGatewayLocked asks the gateway's address
whether a magpie serves it (ServedBy, one GET with a 700ms timeout). A
magpie that holds the port but doesn't answer in time (busy on a small
server, or still starting) reads as "nobody", so the page's process
listened itself and the bind failed. With the service answering, no
second gateway was started and the page's state matched.
Now, after ServedBy says no, gateway.Taken() dials the address (500ms).
When something accepts, this magpie doesn't listen; it logs once that the
port is taken and leaves it to the 15s watch, which serves the gateway
once the port is free.
Run:
- Sandbox HOME, settings {"port":3461,"lan":true}: `magpie serve`, then
`kill -STOP` it, then `magpie web --no-open --addr 127.0.0.1:3462`. The
old binary printed the exact bind error. The new one logs "is taken but
doesn't answer as magpie yet" and doesn't bind. After SIGCONT,
/v1/models and the page's /api/state show the same 3 models. With the
serve killed, the page's process took 3461 over in about 16s.
- TestGatewayNotServedBesideASlowOne (a listener whose handler blocks):
it goes red with the Taken check reverted by hand.
- gofmt -l; go vet (gui), and go vet -tags nogui for darwin, linux and
windows, on cli, daemon, gui and gateway; go test -tags nogui ./... in a
sandbox HOME.
|
||
|
|
e611fc65d6 |
codex: magpie restarts the codex app-server a change left on the old model list when no codex session is on it, and the Agents page offers Restart when one is (luci on Discord)
luci (Codex CLI 0.162, magpie 0.1.1150): after Codex was wired back to
magpie, codex in a new terminal listed Codex's own models although
config.toml was magpie's.
Cause, reproduced with real codex 0.162.0 in a sandbox CODEX_HOME:
codex sessions attach to a background app-server (the managed daemon)
that is per CODEX_HOME, not per terminal (socket under
$CODEX_HOME/app-server-control). It is detached, has no idle exit and
builds its model list once, at start. A daemon started while Codex was
off magpie keeps the official list for every later session, in this
terminal or a new one, until it restarts. magpie writes only PATH to
shell rc files and doesn't unwire Codex on quit, so nothing
per-terminal is involved. luci's "a new terminal fixed it" isn't
explained by the daemon. Codex's hourly updater restarting it is a
guess, not proven.
What changed:
- provider.KeepCodexDaemonCurrent(ctx, home, changed) compares the
daemon's start time with when magpie last changed what Codex reads at
start. The start time is the mtime of a pid file in that home that
names the running daemon's pid, so another home's daemon (ChatGPT.app,
other sandboxes) is never acted on.
- With no codex session attached, it runs
`codex app-server daemon restart` with CODEX_HOME set to that home.
- Otherwise it reports Behind and how many sessions are attached.
- isCodexClient leaves out apps' and editors' own codex, exec-server,
mcp-server and the daemon's own processes. It reads the whole ps line,
since ps leaves a path's spaces unquoted ("Codex Computer
Use.app/...").
- agent: Codex's Notice after a change runs this check first. It says
either that magpie restarted the daemon, or that the daemon is behind
and how to restart it (Agents page or the command).
- The GUI backend and `magpie serve` re-check every 15s. A session that
was open at the change is usually closed later, and that is when the
daemon can be restarted.
- Agents page: the stale "daemon" copy line has a Restart button that
POSTs /api/codex/daemon/restart (timeout now 2 min, as a running turn
is let finish). It reuses translated strings. On Windows, where
processes aren't listed on each look, the row shows the last check.
- Restarts are serialized by one mutex.
- WSL's Codex is not handled automatically. Its row keeps the advice
text, which names the restart command.
What was run:
- Real codex 0.162.0 in a sandbox CODEX_HOME, with a fake gateway, on
luci's sequence: the daemon started on the official config, then
magpie's config and catalog were written.
- With a TUI open, /model listed GPT-6.x. The check said Behind with
a session attached and did not restart.
- With the TUI quit, the check restarted the daemon. A new codex in
the same terminal listed Magpie Alpha and Beta.
- Earlier in the sandbox: a daemon restart under an idle attached 0.162
TUI reconnects, and /model then shows magpie's models. A running turn
is waited for up to 60s.
- New tests:
- TestKeepCodexDaemonCurrent(Fails), TestIsCodexClient (with the
space-in-path case from the real process list) and
TestCodexNoticeKeepsTheDaemonCurrent. They don't build or fail on
the old code. The space case failed before the ps-line fix.
- The GUI test "the daemon's line restarts it" times out on the old
app.js.
- Results:
- agent-stale-copies.test.cjs: 60/60 in Chromium and WebKit, in en,
zh, zh-TW, ja and de, at widths 980 and 440.
- go test (temp HOME) for ./internal/agent, ./internal/provider,
./internal/gui and the root package: ok.
- gofmt -l: clean.
- GOOS=linux and GOOS=windows go vet -tags nogui: ok.
- The Windows path is checked only by vet and not tried on a Windows
box.
|
||
|
|
745dde65b0 | gui: the gateway watch ends with the backend, and TestGatewayTakenOver no longer leaks it — watchGateway looped forever, so each run of the test left its watch (and the gateway it took up) running after the test: under -count the old watches read gatewayWatch while the next run wrote it (3 DATA RACEs in 20 runs), and once a run's cleanup put HOME and MAGPIE_ADDR back an old watch could serve the gateway on the default address under the real HOME, which set served in the next run before its other magpie was gone ("took the gateway while the other had it", 3 of 20 with -race -count=20 on 8e853a63; the #948 review saw 3 of 10). watchGateway now takes a context and an interval and returns when the context ends; startBackend gives it backendCtx, so it also stops with stopServing instead of starting a gateway after the backend has ended. The test runs the watch on its own context and, at cleanup, stops it and the gateway it took up before its environment is restored. gatewayWatch is a const. TestGatewayTakenOver passes 50 of 50 with -race -count=50; go test -race -tags nogui ./internal/gui/ ./internal/tui/ pass; vet, darwin, linux (nogui) and windows builds pass. | ||
|
|
2c801b6f9a | gui, proc: the Gateway card quits an older magpie serving the gateway and takes it over, or restarts the gateway (leslie_luo on Discord) — the card said an older magpie served the gateway and to quit it, with no way to tell which process that was. With an older magpie on the port it now has "Quit magpie {v} and take over": the process listening on the gateway's port is found (lsof on a Mac, /proc on Linux, Get-NetTCPConnection on Windows), its program path checked to be magpie's (magpie, magpie-*, dial, .exe/.old), asked to quit (SIGTERM, then SIGKILL after 5 s; TerminateProcess on Windows) and this magpie serves the gateway at once instead of within 15 s. Otherwise the card has "Restart gateway" ("Start gateway" when none runs); a magpie of this version or newer gets no button. Anything else on the port is never ended: a program that isn't magpie, one of another user or an administrator, one that won't quit, or a magpie a LaunchAgent/systemd unit/scheduled task starts again is said under the button with its path and pid, in en/zh/ja/de. TestGatewayFixQuitsOnlyAMagpie (copies of the test binary on a port of its own: one named other-server answering as magpie is left running, one named magpie is quit and the gateway is served here, then restarted) and gateway-takeover.test.cjs (WebKit and Chromium, en and zh, no scroll, no left border) fail without the change; TestListeningOn/TestIsMagpie pass on macOS and in a Linux container. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. | ||
|
|
bb5e8a2b61 |
factory: the Gateway page says when an older magpie serves the gateway, and a Factory account can be added by its API key (#506, 黄瑞 and aohun: Factory 403 "Factory refused this account the request; check that droid… sign in to it again" on v0.1.630; aohun: support FACTORY_API_KEY as droid2api does) — the 403's wording quoted in #506 was removed in 5523eb17 (first in v0.1.551; git grep finds it in v0.1.550, not in v0.1.630), so those requests were served by a magpie at v0.1.550 or older still holding :3425 (a magpie serve, a second copy, one that didn't quit): serveGateway leaves the port to any magpie answering GET / and the page said only "running · served by another magpie", so none of the later Factory fixes (droid's opening line on /api/llm/o in v0.1.630 among them) reached their requests. gateway.ServedBy reads the serving magpie's version from its GET / answer (Serving wraps it); the providers state carries it with older when it is below this one's, the Gateway card then says "running · served by magpie <v>, older than this one" with an amber dot and that agents' requests go through it without this version's fixes until it quits, when this one takes over within 15 s (zh too, wrapped, never cut off), and the log says so. A Factory API key (fk-…) is added from the import box (Factory's accounts list "Add an account by API key…", and "Use an API key instead…" on the warning before a sign-in): as droid's om() takes FACTORY_API_KEY, the key is the bearer with droid's headers, never renewed, and sends no X-Factory-Org-Id (droid's active org comes from a sign-in, st() is null for a key); whoami asked with the key says whose it is and its region/host, as droid's yP checks a key ("invalid-api-key" when refused), and a refused key isn't added. factoryFresh hands a key account on as it is (no WorkOS, no whoami for an org) and factoryMendOrg leaves it alone; when Factory has moved to its plugin the key isn't offered, the built-in being what keeps it. No request was made to Factory, no real key or account was tried, and whether Factory serves a key's requests from agents other than droid is not known. TestGatewayServedByAnOlderMagpie (fake magpie answering 0.1.550/0.1.630/0.1.640/no version), TestFactoryAPIKey (fake Factory: import, bearer and headers, no org, no WorkOS, refused key, "exists" again; fails with a 403 without the key handling in factoryFresh) and gateway-older.test.cjs, factory-key.test.cjs (Chromium and WebKit, en and zh) pass; login-import, factory-sub, plugin-moved-signin, gateway-fold pass in WebKit (Chromium's channel launch lacks ICU here). go vet ./internal/..., go build -tags nogui (darwin, GOOS=linux), GOOS=windows go build, go test -tags nogui -count=1 ./... under a temp HOME pass.
|
||
|
|
4f01baa65f |
catalog: fetched again each day magpie stays open, and sooner when a call's model has no price, so a model models.dev lists after magpie started is priced (#224 Koohoko: gpt-6.1-sol shows no cost) — the models.dev catalog, where list prices come from, was fetched only at the app's start (when older than a week), so a magpie left open, or magpie serve, never learned a new model's price. KeepFresh (internal/catalog/fresh.go), run by the app's backend and by magpie serve, looks every hour and fetches when the cache is older than a day; a call whose model has no price asks for a fetch (catalog.Missing, from usage's pricer) when the cache is older than six hours and none was tried in that time, only in a process keeping it fresh, so CLI commands and tests never fetch on their own. Loading and Reset now share a mutex instead of a sync.Once reassigned under a running Do, which a background Sync could hit while a call was being priced. Tested with fresh_test.go against a fake models.dev in a temp XDG_CACHE_HOME: stale after 25h and not before, Missing fetching nothing when not keeping, fetching once when keeping and gpt-6.1-sol then priced, and not again; passes under -race (failed under -race with the Once). go vet, go build -tags nogui (and GOOS=linux, GOOS=windows) and go test -tags nogui ./... pass.
|
||
|
|
3676d2e713 | providers: an account signed in while magpie runs is listed with its vendor's models (#204 uclort: 首次添加 WorkBuddy 模型显示不全,点击刷新后模型全部显示) — a signed-in account's own list was fetched only at start-up, for the accounts there then (and once: a fetch that failed was not tried again). WorkBuddy AI signed in afterwards, in magpie or in WorkBuddy itself, showed magpie's built-in list ("magpie's list · Refresh asks the vendor", 14 models) until Refresh fetched /v3/config's 20-odd. Now provider.FetchNew, which start-up uses in place of its loop, also runs before the providers are listed (providersState, 8s each): each ready account with no fetched list is asked for it, so the first listing after a sign-in is the vendor's. One that fails is asked again after 10 minutes, not on each listing; one fetched is not asked again. Tested with a new TestFetchNewAccount (a fake WorkBuddy /v3/config: nothing asked with no account; a WorkBuddy auth file written while running lists the built-in models, then the vendor's three after FetchNew; not asked again; a 502 asked once over two listings, then again after the retry time). go build -tags nogui (and GOOS=linux, GOOS=windows), go test -tags nogui ./... pass (TestUserPath and three Claude sign-in tests timed out once under load, pass on their own and on a rerun of the package). Not tried in the GUI with a real WorkBuddy account | ||
|
|
e0c6892f56 | dev: a Go change hands the backend over instead of cutting the agents off (为什么老是会reconnecting) — make dev killed the backend, and the dev gateway with it, on every Go save, so Cindy's Pi on :3426 lost its stream and reconnected; now the new backend listens beside the old one (SO_REUSEPORT, dev only), and once it does the old one is sent USR2, stops taking requests, finishes those in flight — a stream as long as it takes — and exits. A backend that builds but never comes up leaves the old one serving. Tested in a sandbox: a 12s stream through the gateway ran to [DONE] across a handover, new requests went to the new backend, and the old one exited when the stream ended | ||
|
|
4e83dc6be8 | web: magpie web knows its version and updates itself as the app does — the badge's restart puts the new version in and runs it in the old one's place with the same arguments and key, so the open page reloads onto it (#111); routing: a gateway served by magpie serve, which has no window, is told apart from another magpie's window, and the routing view says to stop it so this magpie serves the gateway and shows routing live (#110) | ||
|
|
59e4f417b2 | web: magpie web serves the app's window to a browser, with the gateway beside it — for a computer that can't show the app: no desktop, WSL, a server over SSH, or the CLI-only build, which now carries the page too (what of the app needs Wails is left out of nogui builds). Every request needs this run's key, which the printed link carries and trades for a cookie other sites' pages can't send with a POST; --lan serves it on the network too, with a warning, --addr elsewhere, --no-open leaves the browser shut. In the browser the page opens links and sign-ins itself, names a folder instead of opening it, and leaves out the tray, the Dock and open at login. Tested from a nogui build in a sandbox: no key, a wrong key and a cookieless POST are refused; with the link Agents, Providers and Settings load and a setting saves. Issue #102 |