ac4af582301a4e8a29245dbba767eba31334ddf9
10
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
7037cd9801 |
sessions: the reads under a hold share one listing, and a pass's path set is reused (#2278)
A minute of the page's polls over a long history (52G Codex, 13G Claude) allocated ~70 MB copying the held Codex listing for every reader, ~35 MB on pruneCalls' and refresh's path maps, and ~40 MB more on distinctOf's set and the Requests/effort listing made for each ask. Allocation is what drives the collector's ~33% of CPU. - heldFiles and the warm-up's listing hand every reader the same slice, clipped so an append is made elsewhere. Every caller only reads it or copies it (distinctOf, appends into their own); the one that sorted it, traceLineFiles, now concatenates into its own slice. - distinctOf, pruneCalls and refresh take their path sets from a pool and clear them after the pass. - CallSourcesAndCodexIdentities builds its listing in a pooled buffer given back once its sources are taken. TestWarmUpListsRolloutsOnce checked that a caller could write over the kept listing; it now checks the listing is shared and clipped. TestHeldListingShared and TestListingPoolsGiveBackEmpty are new. Run on mote at this tree, rebased onto |
||
|
|
af8f3a9399 |
sessions: a new install reads no agent's session history until the user allows it (RustCats on X)
RustCats on X: a fresh magpie showed every agent's session history on
the Sessions page before anyone agreed to it, and asked for a per-agent
choice instead.
- sessions.Reads(agent) (internal/sessions/access.go) is the one gate,
from settings.SessionReads {Asked, All, Agents}. Every lister asks it,
the aggregators (allFiles, callFilesWith, callSourcesWith,
traceLineFiles, wslFiles, DesktopDataDirs) filter by it again, and
readers of an already-listed session (TranscriptOf, ContentOf,
SearchSession, SubagentTranscript, CarryOver, ReadCallSource) return
ErrNotRead, so a cache from before a switch was turned off goes no
further. The Sessions list, stats, /api/sessions/overview, the call and
trace indexes, Usage's agent-file calls and the Codex/Pi title readers
all pass it.
- SettleReads decides once and saves: an install with sessions.json or
a calls-v* cache read sessions before and keeps all on; a fresh one
reads none, not asked. A saved value is never replaced; save, sync and
restore keep it (KeepOwn); only SetSessionReads writes it. An
unwritable settings.json reads nothing this run.
- GUI: GET/POST /api/sessions/reads. While not asked, the Sessions page
shows a consent card: each agent found (by a stat of its folder only)
with a switch, Allow selected and Allow all. Settings > Privacy >
Agents' session history has "Agents found later" and a row per agent.
Strings in en, zh, zh-TW, ja, de.
- CLI: magpie sessions read [on|off all|<agent>...]; magpie sessions
says on stderr when nothing is allowed yet; the TUI's empty Sessions
page says how.
Read either way, because none of it lists or shows a session: the
gateway's own usage ledger, its projections and the conversations it
recorded (magpie's own records, so usage and cost keep working); the
agents' config and sign-in files; Claude Code's and Codex's
history.jsonl last-used time and a session file's mtime for a quota's
first use; Codex's newest rollout's last line before magpie restarts
Codex (codexTurnOpen).
Tests: TestFreshInstallReadsNoAgentUntilAllowed,
TestSettleReadsKeepsWhatWasThere, TestSessionReadsRoutes,
TestSessionsRead, TestSessionsNotAskedSaysHow, sessions-reads.test.cjs
(26 cases: consent and Settings in 5 languages, Chromium and WebKit,
390 to 900 wide).
Run on mote:
- full Go suite (gofmt -l, go vet ./..., GOOS=linux go vet -tags nogui,
GOOS=windows go vet, go build, go test -timeout 45m ./...) at this
change on
|
||
|
|
bb5930b71b |
sessions: a trace poll reads a long line once, at its own size
TraceReader.Poll, which the OTel exporter runs each tick while session
export is on, read every appended line with bufio.ReadBytes through a
4 KiB reader. Every line was a copy of its own, and a line longer than
4 KiB (a function output, a pasted image in a Codex rollout) was gathered
in 4 KiB clones and then copied whole: about twice the line.
- Lines are read through the pooled line reader every other session
reader uses (scanBuffer's size, 16 KiB to 1 MiB), with ReadSlice. A
line the buffer holds is handed to the cursor in it; the cursor's
parse copies what it keeps (encoding/json copies into RawMessage and
strings), so nothing outlives the read.
- A longer line is gathered into one buffer made at its length, read
ahead with lineLen as scanAt does, and reused for the next long line
of the same poll. It is dropped when the poll returns.
- A line with no newline yet (half-written) is left for the next poll,
as before. When the read ahead finds no end the gathering stops at
once instead of growing the line first. A file rewritten between the
read ahead and the read only grows the buffer again, never cuts a
line.
Measured (TotalAlloc of one cold Poll, a fresh TraceReader over one
Codex rollout in a sandbox CODEX_HOME, 5 runs averaged, 3 runs each,
all equal to within 0.1%):
rollout bodies before after
3 turns, images of 1/3/5 MiB (9.5 MB) off 38.2 MB 28.7 MB
on 57.3 MB 47.6 MB
300 turns, 20 KB images (9.9 MB, 760 spans) off 35.6 MB 20.8 MB
on 60.0 MB 45.1 MB
pprof (memprofilerate 1) puts ReadBytes at 18.7 MB per poll before and
the new read at 9.2 MB after, exactly the long lines read once. The rest
is the cursor's own parse (RawMessage copies of payload and content),
which this change leaves alone.
Tests (internal/sessions/trace_lines_test.go):
- TestNextTraceLineReadsWhatReadBytesRead: lines and end offset equal
ReadBytes' for long lines (1/3/5 MiB, past the 1 MiB buffer), a line
of the buffer's size, empty lines, CRLF, a short and a long unended
last line, no line yet, an empty file; from 0 and from the first
line's end.
- TestNextTraceLineWaitsForALongLineToEnd: a 3 MiB line without its
newline is not read, and is read whole once it has one.
- TestTracePollOfLongLinesIsUnchanged: the spans Poll exports (bodies
off and on) from a rollout with 3 and 2 MiB images, written in three
parts that end inside long lines, are reflect.DeepEqual to those a
cursor fed the whole file's ReadBytes lines exports.
- TestTracePollReadsALongLineOnce: a poll of a 6 MiB reasoning line
allocates at most 2.5 times the line (12.6-13.7 MB over -count=20).
With Poll's ReadBytes loop put back by hand it is red 3 of 3: "a poll
of a 6291589-byte line allocated 19025024 bytes, want at most
15728972".
Run at this commit's tree on origin/main
|
||
|
|
c8ed37e126 |
sessions: each Codex response exported to Langfuse carries only its own reply and tool calls, with the turn's prompt, and a finished turn exports once (#2284, JuckZ)
JuckZ's Codex Desktop trace in Langfuse showed one reply repeated on every
later response of its turn, no prompt or tool linkage, and a completed turn
exported a second time as failed.
- token_usage_record copied t.output (the turn's last AgentMessage, a role-less
text array) into every later response, including tool-call-only ones. Each
generation now takes its bodies from the rollout's response_items: input is
the base instructions (session_meta) as a system message, the turn's
developer/user messages, and the tool results fed back since the previous
response; output is only that response's assistant text and tool calls, in
OpenAI chat shape with call IDs. Turn IDs fall back to the desktop's
internal_chat_message_metadata_passthrough.turn_id, then the current turn
(the CLI records none).
- task_complete/turn_aborted deleted the turn but left it current, so the
following thread_settings_applied recreated it and the next task_started
exported it again as an inferred, failed root under the same ID.
- Extension items (web search, image generation) get a span named by kind with
query/action/prompt in and results/saved_path/failure out; FileChange gets
its diff, ImageView its path. Never the image generation's base64 result.
Not copied from the reference: it rebuilt the whole turn history for every
response. That is quadratic, and the user's real rollouts carry 2-3MB
screenshots in tool outputs and 100-400KB data-URL images in prompts, which
it would repeat on each response. Here inline images in a prompt or fed-back
result are named ("[image image/png, N bytes not exported]"); the tool's own
span keeps the output as recorded. Siblings: Claude, Pi/omp, Gemini and
OpenCode already give each response its own message's content; the reused
output and the recreated root were Codex-only.
Fixture: internal/sessions/testdata/traces/codex-desktop-sanitized.jsonl is
JuckZ's file byte for byte (cmp against d96139c2), described in the README.
Run (worktree on origin/main
|
||
|
|
71d2da1f42 |
catalog, usage, gateway, gui: a price can have a long-context tier and a 1-hour cache write, and the price boxes take decimals (PAMI on Discord)
OpenAI bills gpt-6-astra, gpt-6.1-sol and gpt-6-luna over 272K input at 2× input and cache and 1.5× output, for the whole request. A price now has tiers: `magpie model price <m> 10,50,1,12.5 --tier 272k 20,75,2,25` (--tier can repeat). A tier applies when input + cache reads + cache writes is over its size, so 272,000 is not over and 272,001 is. The built-in prices take tiers only where models.dev lists one (cost.tiers of type "context"), and it does list one for those three. The ledger, each request and OTLP are costed at the tier the call reached. Session and day totals sum many calls, so they stay at the base price.
Anthropic bills a cache write kept for an hour at 2× input and one kept for 5 minutes at 1.25×. Its usage reports which is which in cache_creation.ephemeral_5m/1h_input_tokens. The gateway (API and Claude subscription) and Claude Code's transcripts now keep that split. A price's fifth part is the 1-hour write. When it isn't given, it is 2× input: that is Anthropic's rule, and only Anthropic reports 1-hour writes. Claude list prices carry the 2× too. cache_write_tokens is still the total, and the usage CSV adds cache_write_5m_tokens and cache_write_1h_tokens at the end. The app shows the split on a request's Cache and on the usage tooltips. Old prices and old records, which have no 1-hour part, read as before. The sessions cache (18) and the call cache (calls-v8) are re-read once.
In the GUI, the price boxes were number inputs and dropped what they didn't parse ("0,25"). They are now decimal text boxes that take both "0.25" and "0,25". A model's price row has a 1-hour box (empty means 2× input) and a quiet Long-context price row. That row shows the list's tier greyed in, or sits behind a link when the list has none. A bad size is refused by name. en/zh/ja/de.
Tests:
- New: TestPriceTiers, TestCostSplit, TestPriceJSON, TestModelPriceTiers, TestModelPriceTierCmd, TestAnthropicCacheWriteSplit and TestClaudeCacheWriteSplit. The ledger CSV test expects the new columns.
- model-price-tiers.test.cjs is new; model-price-edit and provider-price-rate are updated. All of them fail against the old assets and pass in WebKit. Chromium couldn't be launched here.
- go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass.
|
||
|
|
cab8a8e450 | fix: refresh first-request discovery and retain late Pi timing (#708) | ||
|
|
ee68b96788 | fix: avoid duplicate Pi interaction and gateway traces (#692) | ||
|
|
2f937f3f39 | fix: defer unfinished session trace roots until completion (#633) | ||
|
|
7d7175cfb1 | fix: preserve Langfuse coverage for first and auxiliary calls (#599) | ||
|
|
38b4a9d984 | feat: export gateway and agent conversation waterfalls to Langfuse (#581) |