Skip to content

feat(libsy): warn when affinity cannot derive a key - #308

Merged
ayushag-nv merged 1 commit into
NVIDIA-NeMo:mainfrom
joelagnel:aow/affinity-session-fixes
Aug 11, 2026
Merged

ayushag-nv merged 1 commit into
NVIDIA-NeMo:mainfrom
joelagnel:aow/affinity-session-fixes

Conversation

@joelagnel

@joelagnel joelagnel commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

What

  • Emit a one-time warning when session affinity cannot derive a usable request identity.
  • Keep intentional subagents_only root abstention silent.
  • Preserve existing message-hash fallback and child-identity behavior.

Why

session_affinity = true can be silently inert when a request supplies no supported session metadata and message_hash_fallback is disabled. Every turn is then classified again even though affinity is configured.

Benchmark clients without session metadata can enable message_hash_fallback as a best-effort task key. Production clients should send a generic supported session header such as x-switchyard-session-id.

Addresses the warning portion of #301.

How tested

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo test -p switchyard-libsy
  • uv run ruff check .
  • uv run pytest tests/

Scope

This PR does not recognize benchmark-private proxy headers, change server request-log formatting, or change configuration/public APIs.

@joelagnel
joelagnel requested a review from a team as a code owner August 5, 2026 18:20
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

Session handling

Layer / File(s) Summary
Harbor session header resolution
crates/protocol/src/metadata.rs
Session lookup now includes proxy_x_session_id between OpenCode and the generic session-id header. Tests cover extraction and precedence.
Affinity keying and warning behavior
crates/libsy/src/algorithms/util/affinity.rs
Empty session IDs no longer create shared affinity keys. Unkeyable requests emit a warning once, while intentional root abstention remains silent. Tests cover these cases.
Session ID request logging
crates/switchyard-server/src/lib.rs
Missing session IDs now log as -; explicitly empty session IDs remain empty.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Poem

A rabbit checks the session trail,
Empty keys no longer prevail.
One warning hops, then rests from sight,
Harbor headers choose the right.
Missing logs wear a dash so neat.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR addresses all three requirements in [#301]: empty IDs are ignored, missing keys warn once, and absent IDs log as "-".
Out of Scope Changes check ✅ Passed Harbor header normalization directly supports session affinity identity handling and does not introduce unrelated behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary affinity warning change, although it does not mention the related session identity and Harbor metadata fixes.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
crates/libsy/src/algorithms/util/affinity.rs (1)

121-167: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Warn when a child request has no usable affinity identity.

If metadata.is_subagent is true and agent_id is absent, lines 121-125 return None. If its session ID is absent or empty, lines 138-141 also return None. Neither path reaches the one-time warning at line 154.

Return early only for intentional subagents_only root abstention. Preserve child message-hash fallback abstention, but let child requests without a usable {session_id, agent_id} pair consume the warning. Add regressions for both paths.

As per PR objectives, affinity must warn once when it cannot derive a key.

Also applies to: 515-577

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/libsy/src/algorithms/util/affinity.rs` around lines 121 - 167, Update
the affinity key derivation flow so child requests lacking a usable agent_id or
session identity reach the one-time unkeyed warning via should_warn_unkeyed.
Keep the intentional subagents_only root-request abstention and child
message-hash fallback abstention behavior, but ensure both missing-identity
paths warn once before returning None. Add regressions covering a subagent
without agent_id and a subagent with an absent or empty session ID.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@crates/libsy/src/algorithms/util/affinity.rs`:
- Around line 121-167: Update the affinity key derivation flow so child requests
lacking a usable agent_id or session identity reach the one-time unkeyed warning
via should_warn_unkeyed. Keep the intentional subagents_only root-request
abstention and child message-hash fallback abstention behavior, but ensure both
missing-identity paths warn once before returning None. Add regressions covering
a subagent without agent_id and a subagent with an absent or empty session ID.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: e6a1aa02-41be-4822-a300-e3afe2b3eca8

📥 Commits

Reviewing files that changed from the base of the PR and between 54d4b66 and 0e2fda8.

📒 Files selected for processing (3)
  • crates/libsy/src/algorithms/util/affinity.rs
  • crates/protocol/src/metadata.rs
  • crates/switchyard-server/src/lib.rs

Comment thread crates/protocol/src/metadata.rs Resolved
@joelagnel
joelagnel force-pushed the aow/affinity-session-fixes branch from 9918c90 to c48f442 Compare August 11, 2026 18:31
@joelagnel joelagnel changed the title fix: harden session affinity identity handling feat(libsy): warn when affinity cannot derive a key Aug 11, 2026
@joelagnel
joelagnel force-pushed the aow/affinity-session-fixes branch from c48f442 to 82c1b21 Compare August 11, 2026 18:46
@joelagnel
joelagnel force-pushed the aow/affinity-session-fixes branch 3 times, most recently from d2318ac to a144ddc Compare August 11, 2026 19:25
@joelagnel
joelagnel force-pushed the aow/affinity-session-fixes branch from a144ddc to 1dbbc01 Compare August 11, 2026 19:26
@ayushag-nv
ayushag-nv enabled auto-merge (squash) August 11, 2026 19:27
@ayushag-nv
ayushag-nv merged commit ad8478b into NVIDIA-NeMo:main Aug 11, 2026
19 checks passed
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.

2 participants