Commit Graph
2 Commits
Author SHA1 Message Date
yetone 47ca891b1b gateway: a request's capture for Recent calls is copied once, not twice
captureRequestBody wrote the body's first 256 KiB into a bytes.Buffer
and then copied the buffer into a string: 512 KiB allocated for every
request of 256 KiB or more. It is now one string conversion of the same
bytes, and the same truncated flag.

BenchmarkLargeRequest, ~2 MB conversation, B/op before → after:
  anthropic        45.84 → 45.58 MB
  anthropic-group  57.30 → 57.03 MB
  chat             36.61 → 36.35 MB
  responses        46.04 → 45.78 MB
In the 60-min soak before (dee5c9d75), Buffer.String was 1.08 GB
allocated.

TestCaptureRequestBodyLimit now also checks exact sizes (0, 5 and
callBodyLimit bytes are not truncated), that a capture allocates at most
1.25× callBodyLimit, and that the capture is a copy, not the body's
memory. Broken by hand (the buffer put back): red, "capturing 262144
bytes allocated 524288".

Run (darwin arm64, go1.26.8, sandbox HOME, load 40 to 90 from other
sessions' suites):
- go test ./... -count=1 -timeout 45m on the series' final tree at
  ba319a758: exit 0, all 68 packages ok (gateway 1498s, agent 1633s).
- After the rebase onto b855cfee9 (two redact commits): go test
  ./internal/redact ./internal/gateway -count=1 -timeout 45m, both ok
  (gateway 917s).
- go test -race -count=3 on the Held, ReadersOfAHeldBody, RecentRing,
  RequestBody, CaptureRequest, folder, WorkPlace, WorkDir and Turn
  tests: ok, after
  TestReadersOfAHeldBodyParseItOnce's byte bound was skipped under
  -race (the third commit says why); that test and
  TestHeldFactsGoWithTheirBody then passed -count=30 with and without
  -race.
- Each commit alone: go vet ./internal/gateway and gofmt -l clean.
- Final tree: gofmt -l clean; go vet ./... for darwin, GOOS=windows and
  GOOS=linux -tags nogui, all exit 0.
Not tried: a second 60-minute soak after the series (the one before is
the "before" here; the "after" numbers are the benchmark's), the GUI
suite (nothing in it changed), Windows and Linux test runs (vet only).
2026-10-21 19:17:09 +08:00
yetone 702477525a Claude subscription as a provider; model lists fetched, never compiled in
A signed-in Claude Code is now offered as a provider (claude/…) like Codex
and Copilot. Anthropic classifies another agent's system prompt as
third-party traffic even over Claude Code's OAuth, so magpie drives the
real local claude binary for every generation: the caller's tools are
bridged in over MCP (magpie claude-mcp-helper), and tool results resume
the same Claude Code turn. Token counting is estimated locally so the
OAuth token takes no side path.

No model list is compiled in any more. The built-in catalog, preset
defaults and Claude Code's alias list are gone; the picker shows the
models.dev catalog (refreshed in the background when stale) layered with
each vendor's own /models answer, and signed-in accounts fetch theirs at
start-up. Whether a model rejects temperature/top_p now comes from
models.dev rather than a name prefix.

The gateway retries a Chat request on the Responses endpoint when the
model is Responses-only, and remembers that. Recent calls keep the first
256 KB of request and response bodies, viewable in the call list. The
Usage tab shows subscription allowances (Claude, Codex, Copilot) as the
vendors report them.
2026-09-24 00:20:59 +08:00