Add reverse RPC and hook callback timing traces - #2439
Open
aurokin wants to merge 7 commits into
Open
Conversation
Measure inbound scheduling, hook callback execution, response encoding, writer queue delay, write_all, and flush without exposing callback content or changing RPC behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Capture the forwarding boundary explicitly and key request-derived correlation hashes per client to prevent cross-run linkability or offline session ID guessing. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Make reverse-RPC diagnostics opt-in at the tracing target, preserve reconstructible phase placement, and bound timing delivery without affecting response behavior. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Avoid constructing timing infrastructure when collection is disabled, preserve consumer warning-clean builds, and count saturated terminal records once. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Bind timing to exact forwarded request generations, preserve forwarding order, and restrict trace labels to privacy-safe values. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Copilot review overview
Review tier: Balanced
Findings: 1
新建议题s introduced by this change (3)
| Severity | Finding |
|---|---|
rust/src/jsonrpc.rs — Timing remains active for every outbound JSON-RPC frame even when reverse-RPC tracing was disabled… |
|
rust/src/session.rs — This drain runs before the receiver is closed, while its router sender remains registered until the… |
|
rust/src/jsonrpc.rs — The timing consumer still runs on a Tokio worker, and each debug! call invokes the subscriber… |
What changed in this PR
Adds opt-in reverse JSON-RPC and hook callback timing traces to the Rust SDK.
Changes:
- Correlates inbound requests through routing, dispatch, and response writing.
- Emits bounded timing records for request, hook, encoding, queue, write, flush, and completion phases.
- Adds extensive timing, saturation, cancellation, and redaction tests.
| File | Description |
|---|---|
rust/src/jsonrpc.rs |
Implements timing infrastructure, correlation, emission, and tests. |
rust/src/session.rs |
Propagates traces through session request dispatch. |
rust/src/router.rs |
Routes trace-carrying reverse requests. |
rust/src/lib.rs |
Enables timing-aware client construction and responses. |
rust/src/hooks.rs |
Measures hook callback execution. |
rust/src/github_token.rs |
Preserves traces through token dispatch. |
rust/src/copilot_request_handler.rs |
Preserves traces through inference dispatch. |
rust/Cargo.toml |
Adds timing-test dependencies and features. |
rust/Cargo.lock |
Locks added tracing dependencies. |
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Remove disabled-path clock reads, close request receivers before shutdown draining, and isolate timing subscribers on the opt-in timing thread. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Ensure timing startup fails closed, synchronize terminal ownership through force-close, and let the dedicated timing thread drain and exit even when handlers retain trace senders. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
注册 for free
to join this conversation on GitHub.
Already have an account?
登录 to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
Add opt-in, measurement-only timing for inbound reverse JSON-RPC requests and
SessionHookscallbacks under thegithub_copilot_sdk::reverse_rpc_timingtracing target.The trace separates request forwarding and scheduling, hook callback execution, response encoding, writer queue delay,
write_all, flush, and final completion. Each phase includes a request-relative start offset so consumers can reconstruct the timeline.Safety and behavior
records_droppedrather than delaying RPC work.Validation
cargo +nightly-2026-04-14 fmt --checkcargo clippy --all-features --all-targets -- -D warningscargo test --all-features --libwith 256 tests passingRUSTFLAGS='-D warnings' cargo check --all-featuresIntegration
Consumers must install a tracing subscriber with
github_copilot_sdk::reverse_rpc_timing=debugbefore constructing the SDK client. Enabling the directive later does not add timing infrastructure to an existing client.