Skip to content

[codex-analytics] add tool item event schemas#17089

Draft
rhan-oai wants to merge 3 commits intorhan/app-server-item-timingfrom
pr17089
Draft

[codex-analytics] add tool item event schemas#17089
rhan-oai wants to merge 3 commits intorhan/app-server-item-timingfrom
pr17089

Conversation

@rhan-oai
Copy link
Copy Markdown
Collaborator

@rhan-oai rhan-oai commented Apr 8, 2026

Why

Tool analytics need stable, typed payloads before the later lifecycle reducer starts emitting them. Keeping the event schema definitions isolated in their own PR makes the emitted surface reviewable separately from the reducer logic that produces those events.

What changed

  • Adds the common tool-item analytics event base plus event payload types for command execution, file changes, MCP calls, dynamic tools, collaboration tools, web search, and image generation.
  • Extends TrackEventRequest with the corresponding tool-item variants.
  • Adds serialization coverage for the command-execution event shape.

Verification

  • cargo test -p codex-analytics

Stack created with Sapling. Best reviewed with ReviewStack.

@rhan-oai rhan-oai force-pushed the pr17089 branch 9 times, most recently from 68d22f3 to fa81361 Compare April 14, 2026 06:13
@rhan-oai rhan-oai changed the title [codex-analytics] add tool call event schema [codex-analytics] add tool item event schemas Apr 14, 2026
@rhan-oai rhan-oai force-pushed the pr17089 branch 7 times, most recently from 888f26a to ecd06cb Compare April 20, 2026 20:37
@rhan-oai rhan-oai force-pushed the pr17089 branch 3 times, most recently from 90ea95d to a65b88c Compare April 22, 2026 07:02
@rhan-oai rhan-oai force-pushed the pr17089 branch 2 times, most recently from 06888b6 to 7dbe287 Compare April 28, 2026 21:57
@rhan-oai rhan-oai changed the base branch from main to pr17088 April 28, 2026 22:22
@rhan-oai rhan-oai changed the base branch from pr20239 to codex/thread-analytics-state April 29, 2026 18:30
@rhan-oai rhan-oai force-pushed the codex/thread-analytics-state branch from ff2f306 to 54756f4 Compare April 29, 2026 18:58
@rhan-oai rhan-oai force-pushed the codex/thread-analytics-state branch from 54756f4 to 4340ce1 Compare April 29, 2026 19:05
rhan-oai added a commit that referenced this pull request Apr 29, 2026
## Why

Codex analytics needs a typed seam for app-server-originated
request/response traffic so future tool-approval analytics can consume
those facts without adding bespoke callsite tracking each time. Server
responses arrive as JSON-RPC `id + result` payloads, so analytics has to
reconstruct the matching typed response from the original typed request
while that request context still exists in app-server.

This also puts analytics on the app-server outbound path, which needs to
avoid keeping the runtime alive during shutdown. The final ownership fix
keeps the normal strong auth-manager retention in analytics and makes
the external-auth refresh bridge hold a weak back-reference to
`OutgoingMessageSender`, breaking the runtime cycle at the bridge
boundary instead of exposing retention policy through the analytics
client API.

## What changed

- Adds typed `ServerRequest` and `ServerResponse` analytics facts, plus
`AnalyticsEventsClient::track_server_request` and
`track_server_response`.
- Renames the existing client-side facts to `ClientRequest` and
`ClientResponse` so reducers can distinguish client-to-server traffic
from server-to-client traffic.
- Adds `ServerRequest::response_from_result`, allowing a stored typed
request to decode the matching typed server response from a raw JSON-RPC
result payload.
- Threads `AnalyticsEventsClient` through `OutgoingMessageSender` and
records targeted server requests, replayed targeted requests, and
matching targeted responses with the responding connection id needed for
correlation.
- Intentionally leaves broadcast server requests/responses out of
analytics for now because the current model is per connection, while
broadcasts fan one logical request out across multiple connections.
- Breaks the app-server shutdown cycle by storing
`Weak<OutgoingMessageSender>` in `ExternalAuthRefreshBridge` and
upgrading it only when an external-auth refresh is actually requested.
- Keeps reducer ingestion of the new server-side facts as no-ops for
now; this PR is plumbing for later tool-approval analytics work.

## Verification

- `cargo test -p codex-analytics`
- `cargo test -p codex-app-server outgoing_message::tests::`
- Covers typed-response reconstruction plus the targeted, replayed,
broadcast-exclusion, and response-attribution analytics paths.

## Follow-up

This PR intentionally stops at ingestion plumbing, so `ServerRequest`
and `ServerResponse` facts are still reducer no-ops. Once a follow-up PR
adds real downstream analytics output for those facts:

- replace the temporary pre-reducer observation seam with reducer tests
for the emitted event shape;
- add end-to-end coverage in `app-server/tests/suite/v2/analytics.rs`
for the real app-server workflow and captured analytics payload;
- remove the temporary sender-level observer tests added here in favor
of the real-output coverage above.

---

[//]: # (BEGIN SAPLING FOOTER)
Stack created with [Sapling](https://sapling-scm.com). Best reviewed
with [ReviewStack](https://reviewstack.dev/openai/codex/pull/17088).
* #18748
* #18747
* #17090
* #17089
* #20241
* #20239
* __->__ #17088
@rhan-oai rhan-oai force-pushed the codex/thread-analytics-state branch 2 times, most recently from b39f92b to 4340ce1 Compare April 29, 2026 21:14
@rhan-oai rhan-oai force-pushed the codex/thread-analytics-state branch from 4340ce1 to f1478ed Compare April 29, 2026 21:18
@rhan-oai rhan-oai force-pushed the codex/thread-analytics-state branch from f1478ed to 9412dae Compare April 29, 2026 22:37
@rhan-oai rhan-oai force-pushed the codex/thread-analytics-state branch from 9412dae to 96f46a2 Compare April 29, 2026 22:54
@rhan-oai rhan-oai force-pushed the codex/thread-analytics-state branch 3 times, most recently from c2e3246 to ffbe9fe Compare April 30, 2026 01:24
Base automatically changed from codex/thread-analytics-state to pr20239 April 30, 2026 01:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant