Skip to content

feat(server): record the turn ID in the routing log - #971

Merged
elyasmnvidian merged 1 commit into
mainfrom
emehtabuddin/routing-log-turn-id
Oct 15, 2026
Merged

elyasmnvidian merged 1 commit into
mainfrom
emehtabuddin/routing-log-turn-id

Conversation

@elyasmnvidian

@elyasmnvidian elyasmnvidian commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

The routing log records a session ID for each model call but leaves out the turn ID, even though the server already reads one from the request. A turn is one user message plus every model call the agent makes to answer it. Without the turn ID, a reader of routing.jsonl cannot group the calls of one turn, so the desktop app's usage table (#976) cannot link to the calls for a turn.

Each routing log record now has a turn_id field between session_id and model. The server takes it from the x-switchyard-turn-id header or from the turn_id in Codex's x-codex-turn-metadata header. These are the sources it already uses for request metadata. When a request carries neither, the field is null. Records still contain only IDs, model names, and token counts, not prompts or responses.

The server tests send requests through the real server and read the log file it writes:

  • routing_log_prefers_canonical_and_preserves_legacy_fallback: the record has the turn from x-switchyard-turn-id, and a request without one gets null.
  • routing_log_keeps_the_canonical_session_id_until_a_stream_drains: a streamed response keeps its turn ID until the stream ends.
  • The observer test in lib.rs: a judge call's record has the session and turn IDs from the routed request.

Summary by CodeRabbit

  • Improvements
    • Routing log entries now include a turn identifier when one is available, alongside the session identifier. This makes it easier to distinguish separate turns in the same session. Entries without a turn identifier continue to record it as null, preserving clarity for requests that do not provide one.

Signed-off-by: Elyas Mehtabuddin <emehtabuddin@nvidia.com>
@elyasmnvidian
elyasmnvidian force-pushed the emehtabuddin/routing-log-turn-id branch from b6bd9ef to c9af42a Compare October 15, 2026 16:35
@elyasmnvidian
elyasmnvidian marked this pull request as ready for review October 15, 2026 16:35
@elyasmnvidian
elyasmnvidian requested a review from a team as a code owner October 15, 2026 16:35
@coderabbitai

coderabbitai Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: NVIDIA-NeMo/Switchyard/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Enterprise
  • Run ID: beff961a-03a1-47e5-9348-f0c2badc351e
📥 Commits

Reviewing files that changed from the base of the PR and between 38a71ed and c9af42a.

📒 Files selected for processing: 3
  • crates/switchyard-server/src/lib.rs
  • crates/switchyard-server/src/routing_log.rs
  • crates/switchyard-server/tests/server.rs

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 10 remain after this review.

Walkthrough

Routing log records now include an optional turn ID from request metadata. Tests check turn IDs in judge-call, buffered, and streaming routing logs. Records without a turn ID remain supported.

Changes

Routing log turn IDs

Layer / File(s) Summary
Capture and read turn IDs
crates/switchyard-server/src/routing_log.rs
RoutingLogContext stores the optional turn ID from metadata. Appended records include it, and deserialization accepts records without the field.
Verify turn IDs in routing logs
crates/switchyard-server/src/lib.rs, crates/switchyard-server/tests/server.rs
Tests provide turn IDs in judge-call, buffered, and streaming requests. They check the IDs in the corresponding records, including a null value when a buffered request has no turn ID.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c9af4

Routing records can now be grouped by turn, while requests without a turn ID and older records remain supported. No concrete merge blocker is identified.

Pre-merge checks: Passed 5
Passed Passed checks: 5 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: recording the turn ID in the server routing log.
Docstring Coverage Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit checks the log at night
Each turn ID is tucked in right
A buffered turn, a streaming trail
Older records still prevail
I hop along, the fields in sight

Comment @coderabbitai help to get the list of available commands.

@elyasmnvidian
elyasmnvidian merged commit 7f0602d into main Oct 15, 2026
17 checks passed
@elyasmnvidian
elyasmnvidian deleted the emehtabuddin/routing-log-turn-id branch October 15, 2026 17:10
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.

3 participants