Commit Graph
2 Commits
Author SHA1 Message Date
yetone 5fadf6aceb gui: Settings' gateway row is titled an address, and says only its port is typed here (Chicring on Discord)
Chicring: Settings showed "网关端口" (gateway port), but the row showed
MAGPIE_ADDR's host:port.

What the field takes, from the code: renderPort posts to
/api/settings/port, and setPort (internal/gui/port.go) accepts only a port
from 1024 to 65535 (settings.CheckPort). The gateway listens on that port,
on 127.0.0.1, or on 0.0.0.0 while shared on the LAN. When MAGPIE_ADDR is
set, it is the whole host:port and comes first. The row then shows its
value and is disabled. So the row is the gateway's address, but only its
port is typed here; it isn't a second way to write MAGPIE_ADDR.

The row is renamed in every language: Gateway address / 网关地址 / 閘道位址 /
ゲートウェイのアドレス / Adresse des Zugangspunkts. The new hint says "Only
the port is set here, 1024 to 65535; MAGPIE_ADDR=host:port sets the whole
address instead. Agents magpie connected move with it. Now {url}". With
MAGPIE_ADDR set, the hint says "MAGPIE_ADDR={addr} sets the gateway's whole
address, host:port: unset it to set the port here". The CLI help (cpu,
healthcheck, heap, quota, statusline) and setPort's comment named
"Settings' Gateway port". They now say "the port in Settings' Gateway
address".

Test: gateway-port.test.cjs pins the new name and hints in en and zh. With
MAGPIE_ADDR set, it now also checks that the field shows 127.0.0.1:3426
and that the row's name and aria-label say the address. gui-zh-tw, gui-ja,
gui-de and i18n-keys cover the other languages. Broken by hand: on the old
app.js it is red, "not ok 1 - en expected: 'Gateway address' actual:
'Gateway port'", and zh red against '网关地址'.

What was run. The whole suites ran at dcf7eeae3, which was these two commits
on origin/main 592899467. They were rebased cleanly onto 5c557c793 and
re-checked there.
- gofmt -l: nothing. go vet ./..., GOOS=linux go vet -tags nogui ./... and
  GOOS=windows go vet ./...: ok, at both heads.
- GOMODCACHE=... go test -timeout 45m ./... in a sandbox HOME: 63 ok.
  internal/agent, internal/gateway and internal/library hit the 45m package
  timeout while other sessions' full suites ran (load ~27-40). Their stacks
  were in short tests (TestDisconnectStaysThroughSync 21s,
  TestSub2APIThinkingOffRefused 0s, TestSkillHow 10s), so nothing hung.
  Each passed when run alone:
  "ok internal/agent 1127.439s", "ok internal/gateway 1044.808s",
  "ok internal/library 1029.999s".
- The whole GUI suite, node --test --test-concurrency=2
  internal/gui/tests/*.test.cjs, with playwright 1.62.0:
  - BROWSER=chromium: "# tests 5862 # pass 5844 # fail 18".
  - BROWSER=webkit: "# tests 5854 # pass 5835 # fail 19".
  Every red file was rerun alone on a freshly fetched origin/main
  (a3ebed202 / 5c557c793) and is red there too:
  - library-row-remove (chromium, 4 of 8 runs on main): filed #3099.
  - quota-count-wrap and quota-name-translated (webkit): #2228.
  - usage-agents-hide (both engines): #2276.
  - usage-fold (chromium): #2163.
  - plugin-card-update (webkit, 2 of 4 runs on 5c557c793): #3079.
  - s3-sync (webkit): #2448.
  - usage-checkin's Qoder tab (webkit): #2549.
  - tray-usages and routing-rule-remove: passed alone on both trees.
  None of these files touch the provider editor or the gateway address row.
- At 5c557c793 + these commits: decide-endpoint-label, gateway-port,
  system-one, remote-magpie, i18n-keys, gui-zh-tw, gui-ja, gui-de and
  lan-docker in both engines: "# tests 54 # pass 54 # fail 0".
  go test ./internal/gui ./internal/cli: ok.
2026-10-21 09:13:30 +08:00
yetone 89521b03d6 cli, gateway: magpie cpu records the running magpie's CPU profile for 30s, for a report of high CPU (@LeiCheng42 on X)
@LeiCheng42 on X reports magpie using the most CPU while Codex runs. As
with magpie heap (e085d6e92), Activity Monitor and `sample` show Go's
frames as ???, so `magpie cpu [<file>] [--seconds N]` asks the magpie
serving the gateway for GET /v1/magpie/cpu?seconds=N: runtime/pprof's CPU
profile over 30s (5..120; else 400), gzipped protobuf, with the pid,
version, uptime, CPU time used over the window (getrusage / GetProcessTimes)
and since start, cores, GOMAXPROCS and goroutines in X-Magpie-CPU-Stats. It
tells the user to use magpie as when busy (run Codex) while it records,
writes <file> else magpie-cpu-<date>-<time>.pb.gz (0600), refuses a file
that is there before recording, and says "is magpie running?" at once when
nothing answers. --help writes nothing; an unknown flag, "-", a second file
or --seconds out of range are refused before anything is asked.

Only the profiling request waits: the gateway serves everything else
meanwhile. pprof keeps one CPU profile at a time, so a second ask gets 409
(cpuRecording), and a caller that hangs up stops the recording. The route
takes heap's guard: heapRefused's checks move into profileRefused, shared
by cpuRefused, so only a loopback, unproxied, browserless call to a
loopback Host gets it, with or without a gateway key or lanGuard.

Run at bad4508c4 + this: gofmt -l (nothing); go vet ./..., GOOS=linux go
vet -tags nogui ./..., GOOS=windows go vet ./... (clean); go test -tags
nogui -timeout 45m ./... under a sandbox HOME: every package ok except
internal/agent (45m timeout, #2544; again alone, in TestPortMovesEveryAgent)
and internal/gateway (TestTranslatedStreamKeepsClientAlive/chat_to_responses,
sibling of #2169/#2711, filed as #2737; alone with -timeout 45m only
/chat_to_anthropic, #2169; the test passes 5/5 alone). TestCPU* -race
-count=3 ok. Broken by hand: cpuRefused returning "" (19 failures in
TestCPUProfileOnlyToThisComputer); no one-at-a-time guard and no hang-up
stop (TestCPUProfileOneAtATime red each); no seconds bounds, no pre-check
of the file, no is-it-running check, no help case (each CLI test red).
Rebased on 2042123f4: go build ./..., gofmt -l, GOOS=windows and
GOOS=linux vet of internal/gateway and internal/cli clean; go test -run
'CPU|Cpu|Heap|Help' ./internal/cli ./internal/gateway ok.

Real use: the built binary's `magpie serve` under a sandbox HOME on
127.0.0.1:3493; `magpie cpu --seconds 5` saved a 0600 profile that go tool
pprof -top reads and printed the numbers; a concurrent second one got the
409 while GET / answered in ms; Origin: null and a rebound Host got 403;
--help wrote nothing; an existing file was refused. Not tried: the GUI
app's process, or the Windows box.
2026-10-17 20:52:13 +08:00