fix: harden session affinity identity handling - #308
Conversation
Signed-off-by: Joel Fernandes <joel@joelfernandes.org>
WalkthroughChangesSession handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
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 winWarn when a child request has no usable affinity identity.
If
metadata.is_subagentis true andagent_idis absent, lines 121-125 returnNone. If its session ID is absent or empty, lines 138-141 also returnNone. Neither path reaches the one-time warning at line 154.Return early only for intentional
subagents_onlyroot 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
📒 Files selected for processing (3)
crates/libsy/src/algorithms/util/affinity.rscrates/protocol/src/metadata.rscrates/switchyard-server/src/lib.rs
0e2fda8 to
a20a712
Compare
Affinity without recognized session metadata and with message_hash_fallback disabled cannot derive a key, so every turn is classified again despite session_affinity being enabled. Emit this warning once. This was observed with Harbor running Hermes: Hermes supplied no native session header, and the Harbor proxy ID was not yet normalized for affinity. Configurations with message_hash_fallback enabled already retain best-effort affinity. Signed-off-by: Joel Fernandes <joel@joelfernandes.org>
…quest logs Signed-off-by: Joel Fernandes <joel@joelfernandes.org>
Harbor's proxy generates a stable UUID per trial attempt and sends it as proxy_x_session_id. Hermes does not supply a native session header in this path. Normalize the proxy header into request metadata so affinity uses the exact Harbor attempt identity. This fixes Harbor/Hermes configurations with message_hash_fallback disabled; configurations with it enabled already had best-effort message-hash affinity and now prefer the exact ID. Signed-off-by: Joel Fernandes <joel@joelfernandes.org>
a20a712 to
5f80d1d
Compare
Scope clarification
The repeatedly reclassified TB-Lite run was specifically Harbor running Hermes with
session_affinity = trueandmessage_hash_fallbackomitted/false. Hermes supplied no native session header, while Harbor's proxy-generatedproxy_x_session_idwas previously used only for routing statistics.With
message_hash_fallback = true, classifier affinity already worked on a best-effort basis by hashing the first user message. Recognizing Harbor's proxy ID is therefore the exact-identity fix for Harbor/Hermes when the fallback is disabled, and an upgrade from heuristic to exact identity when it is enabled. The empty-ID hardening and diagnostics in this PR remain general.What
proxy_x_session_idinto request metadata so Harbor-proxied agents such as Hermes receive exact session affinity.Why
Session affinity could silently classify every turn again when a harness supplied no recognized session identity, or collapse unrelated requests onto one assignment when a caller supplied an empty identity. Harbor already generates a unique session ID per trial attempt, but Switchyard previously used it only for routing statistics rather than affinity.
Closes #301
How tested
cargo fmt --all -- --checkcargo clippy --workspace --all-targets -- -D warningscargo test --workspaceChecklist
session-id.Notes for reviewers
Harbor's proxy generates and overwrites
proxy_x_session_idonce per trial attempt. Hermes itself does not currently send a Switchyard-recognized live session header. Normalizing the proxy header therefore gives Harbor-proxied Hermes runs an exact affinity key while preservingmessage_hash_fallbackfor clients that genuinely lack an identity.Summary by CodeRabbit
-when no session ID is provided.