feature: export session events for post-processing — content-free per-event projection, NDJSON sink, archive-replayable

オープン
#1,810 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
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 の本文から書いたものです。

説明

enhancement

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
inference field 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.Row already makes this argument: cost is
    derived from the cache-read/write split rather than the total, so a partial set silently
    changes the figure.
  • requestedHost and requestedModel are how a consumer sees that a plugin redirected
    or re-targeted a request. Without them a redirect is invisible.
  • streamedResponse alongside stream — asked-for versus arrived. On this archive 295
    requests asked to stream and did not; that is currently invisible (#1740, item 3).
  • newToolResults / toolResultErrors are #1740, items 1 and 2. Without them, any
    consumer counting ToolResults rows 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 with dial-failed,
    program-refused or os-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 — a Bash command
    line is effectively a secret and belongs in Tier 3.
  • invocations: [{plugin, action, reason}] — per-plugin outcomes. summarizeEvent keeps
    these out of the drop set for good reason: the ACTION column and the plugin:<name>
    filter both read them.
  • identity: {subject, clientId, agentId} — the authenticated identity, as distinct
    from client.

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

  1. Export durationMs; never expect a consumer to subtract timestamps. The fast-tool
    figures above sit near wall-clock resolution, and Seq's own doc notes same-instant
    events are common on a fast local proxy. A consumer pairing by requestId and
    subtracting at gets noise instead of latency.

  2. sessionIncarnation is the one genuinely new field here. A session id is reused: the
    id default recurs 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.

  3. httpPath can 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 was jq and 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/
    ReplaySince excludes 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 wants Page/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分
マージ済み PR(30日)
367

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

rossoctl/cortex のほかの issue

rossoctl/cortex の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。