feature: export session events for post-processing — content-free per-event projection, NDJSON sink, archive-replayable
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- go
调研方向
Start by reading core/sessionapi/summary.go and its TestSummarizeEvent_KeepsEverythingTheFilterSearches test, then inspect the archive APIs Page and Earlier referenced in the issue. The issue calls for a content-free per-event projection, an NDJSON sink and archive replay; review must settle the handling of httpPath secrets and the relationship to #898. Done means Tier 1 fields have a documented drop rule pinned by a test and archived events can be exported.
由索引模型根据 Issue 内容生成。
描述
Summary
Cortex already holds the richest record of what a coding agent did — 30 days of events on
disk, with timings, token counts, hosts and failures that exist nowhere else. Today the only
ways to read it are the session API (one session at a time, for a TUI) and a bespoke Go
program against archive.Page/Earlier. There is no supported way to get a month of events
out of the archive and into a data store for analysis.
This proposes a content-free per-event export: a projection of SessionEvent to a flat
record, an NDJSON sink, and the ability to replay it out of the archive so the existing 30
days can be backfilled rather than only tapped live.
Why a projection is the feature, not an optimisation
core/sessionapi/summary.go already solved a near-identical problem and measured it:
a single inference request carries the whole conversation... 99.5% of that is the
inferencefield alone. Measured on real traffic, dropping the payloads is a 203x
reduction.
The same ratio governs an export. An analysis of a local 30-day archive (66 sessions,
29,606 events) kept ~30 scalars per event and produced a 29,606-row NDJSON file; the same
corpus at full fidelity is multi-gigabyte (BytesUp alone totals 6.08 GB). Exporting raw
events would be unshippable and would carry every prompt off-box. The projection is what
makes this safe and affordable at once.
summarizeEvent also documents the trap worth copying: its drop rule fails silently —
"a search for completion text simply stops matching." An export schema needs the same
discipline: an explicit rule for what may be dropped, and a test that pins the contract so
it cannot drift.
Tier 1 — the core record, always exported, content-free by construction
Roughly 30 scalars per event. This is the set that an offline analysis of this archive
actually used; each group is here because something could not be answered without it.
| Group | Fields |
|---|---|
| Identity | sessionId, sessionIncarnation, seq, requestId, at |
| Routing | host, requestedHost, httpMethod, httpPath |
| Outcome | phase, statusCode, errorKind, errorCode |
| Timing | durationMs (and ttfbMs once #951 lands) |
| Size | bytesUp, bytesDown |
| Attribution | client, agentRole |
| Inference | model, requestedModel, stream, streamedResponse, finishReason |
| Tokens | promptTokens, completionTokens, cacheReadTokens, cacheWriteTokens |
| Counts | messageCount, toolCount, toolCallCount, newToolResults, toolResultErrors |
| Tunnel | tunnel, tunnelReason |
Notes on the non-obvious ones:
- All four token counts separately.
ledger.Rowalready makes this argument: cost is
derived from the cache-read/write split rather than the total, so a partial set silently
changes the figure. requestedHostandrequestedModelare how a consumer sees that a plugin redirected
or re-targeted a request. Without them a redirect is invisible.streamedResponsealongsidestream— asked-for versus arrived. On this archive 295
requests asked to stream and did not; that is currently invisible (#1740, item 3).newToolResults/toolResultErrorsare #1740, items 1 and 2. Without them, any
consumer countingToolResultsrows overcounts by ~272x on this corpus, because every
request re-sends the whole conversation. This is the single easiest metric in the export
to get wrong.tunnel/tunnelReason— 287 tunnels on this archive failed withdial-failed,
program-refusedoros-trust-only, i.e. traffic every plugin was blind to. Nothing
aggregates it today.
No message content, no completion, no tool arguments, no tool results, no MCP params.
That is what makes a Tier 1 record shippable to an external collector without a per-
destination privacy review.
Tier 2 — opt-in structured detail
toolCallNames: []string— the tool names a response asked for. This is what enables
per-tool latency (below). Names are low-risk; arguments are not — aBashcommand
line is effectively a secret and belongs in Tier 3.invocations: [{plugin, action, reason}]— per-plugin outcomes.summarizeEventkeeps
these out of the drop set for good reason: the ACTION column and theplugin:<name>
filter both read them.identity: {subject, clientId, agentId}— the authenticated identity, as distinct
fromclient.
Tier 3 — content, off by default
Messages, completions, tool results, MCP params. Proposed position: an export path should
refuse this by default rather than offer it as a flag someone flips under time pressure.
The replay use case for full fidelity is already specified in #1494; this issue is not that.
What this unlocks: tool time vs human time, from Cortex alone
The motivating question was "where did the agent's wall-clock go", with no agent-harness
access. Tier 1 answers it. Classifying each response -> next request gap by whether
proxied traffic landed inside it:
| n | p50 | total | share of gap time | |
|---|---|---|---|---|
Proxied tool (measured from durationMs) |
1,910 | 1,045 ms | 11.6 h | 18.8% |
| Local tool (inferred — no proxied traffic) | 5,653 | 158 ms | 5.3 h | 8.6% |
| User wait (0 tool calls) | 1,442 | 32,358 ms | 44.8 h | 72.6% |
With toolCallNames (Tier 2), single-tool-call turns yield per-tool latency directly:
Bash p50 201 ms (n=3,754), Edit 89 ms (n=814), Read 82 ms (n=338), and AskUserQuestion
62,602 ms (n=68) — the last being useful validation, since the classifier never saw the
tool's name yet separated the one human-blocking tool from the machine ones by three orders
of magnitude.
Honest limits: the user-wait total is very sensitive to the gap ceiling (24.8 h at 300s,
44.8 h at 1800s, 56.8 h at 3600s, 539 h uncapped), so any consumer publishing it must
publish the cap too.
Three schema decisions worth settling in review
-
Export
durationMs; never expect a consumer to subtract timestamps. The fast-tool
figures above sit near wall-clock resolution, andSeq's own doc notes same-instant
events are common on a fast local proxy. A consumer pairing byrequestIdand
subtractingatgets noise instead of latency. -
sessionIncarnationis the one genuinely new field here. A session id is reused: the
iddefaultrecurs across the entire 2026-10-15 -> 2026-11-06 range of this archive, in
one directory, spanning many unrelated working periods. Without an incarnation key, every
per-session aggregate downstream silently averages unrelated work. The archive can derive
it from segment boundaries (one of these sessions has 34 segments across three weeks).
Raised independently on #1739, where it also affects per-directory cost totals. -
httpPathcan carry secrets and needs a decision before it ships off-box. Per its
own documentation: "A secret embedded in a path SEGMENT does survive, because nothing can
tell it from a resource id — a bot token or a webhook path lands here verbatim." Query
strings are already stripped; path segments are not. Either redact, or make this field
opt-out, but do not ship it off-box silently.
Same caveat applies to client, which is derived from a request header: a cost-attribution
and display key, never an authorization subject. Worth restating in the export docs,
since an external collector is exactly where someone will be tempted to treat it as identity.
Format and transport
- NDJSON, to a file or an HTTP endpoint. This is what post-processing wants: the
analysis behind this issue wasjqand Python over NDJSON, and a full 30-day pass took
~10s single-threaded. - Archive-replayable, not only a live tap. The archive already holds 30 days;
backfill is most of the value. Note for whoever implements it:ReplaySources/
ReplaySinceexcludes tunnel rows by design (correct for cost replay — no tokens),
which is 10,493 of 29,606 events here and includes every non-LLM latency figure.
An export walk wantsPage/Earlier, which do not filter. - A documented drop rule plus a test pinning the Tier 1 contract, in the spirit of
TestSummarizeEvent_KeepsEverythingTheFilterSearches.
OTLP deliberately left as a follow-up. The metrics subset maps cleanly onto the GenAI
semantic conventions (gen_ai.* already standardises model, token counts and finish reason)
and belongs with #505, which is about emitting spans for Cortex's own pipeline. Bundling
both into one issue makes it unreviewable.
Relationship to existing issues
- #898 (report statistics to a central collector) wants aggregates — token count by
hour — shipped to a remote endpoint. This issue is the per-event layer those aggregates
could be derived from. Worth deciding whether #898 becomes a consumer of this or stays
separate, rather than building two exporters. - #505 (first-class OpenTelemetry) instruments Cortex itself. Different axis: that is
the proxy's own behaviour, this is the traffic it observed. - #1740 adds three of the Tier 1 count fields. This export is the main consumer for them.
- #1494 (lossless capture and replay) is the Tier 3 / full-fidelity case, already specified.
- #1466 wants a long-term performance view; it notes the archive's raw material exists
but is never aggregated beyond six hours. An export is one way to get that aggregation
outside the proxy.
Scope of the measurements above
One developer's laptop archive, heavily Claude Code (18,785 of 29,606 events carry
claude-code/2.1.270). The field list generalises — it follows the event schema, not
this traffic. The ratios do not: #1494 measured 59% of replies batching tool calls under
explicit prompting against 7.3% here unprompted, so those numbers move with working style
and prompting.
Assisted-By: Claude (Anthropic AI) [email protected]
- 主要语言
- Go
- 星标
- 31
- 派生
- 49
- 平均合并
- 9 小时 43 分钟
- 30 天内合并 PR
- 367
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rossoctl/cortex 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
bug laptop
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 55/100
维护者通常 1 天内回复
相似的 Issue
-
taskmanager: a failed v1alpha1 backup leaves the partial backup behind可能已有人在做 @arshil42 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 80/100
ether/etherpad-go#571 ·
维护者通常 1 天内回复
-
labeler: read a limit above math.MaxInt as math.MaxInt in nonNegative (CodeQL alerts #20 and #21)未关闭cost:approved factory:queued factory:tracking priority:p2 rank:12 ready-for-doing task:approved tokens:50k
难度 2/5 1-3 小时 新手友好度 88/100
sisaku-security/sisakulint#860 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 78/100