feat(switchyard-protocol): add common utility to hydrate Metadata from headers#92
feat(switchyard-protocol): add common utility to hydrate Metadata from headers#92messiaen wants to merge 3 commits into
Conversation
d3bde40 to
512174f
Compare
…lization Signed-off-by: Greg Clark <grclark@nvidia.com>
Signed-off-by: Greg Clark <grclark@nvidia.com>
Signed-off-by: Greg Clark <grclark@nvidia.com>
512174f to
1ba011b
Compare
WalkthroughThe protocol crate adds a shared public ChangesMetadata protocol integration
Estimated code review effort: 4 (Complex) | ~45 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@crates/libsy-protocol/src/envelope.rs`:
- Line 7: Update the imports in the envelope module to publicly re-export
Metadata, preserving the existing libsy_protocol::envelope::Metadata path while
retaining the existing LlmRequest and LlmResponse imports.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Enterprise
Run ID: 0a0b7e41-3310-4b49-9b1d-2019733eb95f
📒 Files selected for processing (3)
crates/libsy-protocol/src/envelope.rscrates/libsy-protocol/src/lib.rscrates/libsy-protocol/src/metadata.rs
| //! with the original provider payload and correlation [`Metadata`]. | ||
|
|
||
| use crate::{LlmRequest, LlmResponse, WireFormat}; | ||
| use crate::{LlmRequest, LlmResponse, Metadata}; |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Preserve the existing envelope::Metadata public path.
The private import removes libsy_protocol::envelope::Metadata, breaking consumers using the previous public path. Re-export the relocated type here.
Proposed compatibility fix
-use crate::{LlmRequest, LlmResponse, Metadata};
+use crate::{LlmRequest, LlmResponse};
+pub use crate::Metadata;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| use crate::{LlmRequest, LlmResponse, Metadata}; | |
| use crate::{LlmRequest, LlmResponse}; | |
| pub use crate::Metadata; |
🤖 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-protocol/src/envelope.rs` at line 7, Update the imports in the
envelope module to publicly re-export Metadata, preserving the existing
libsy_protocol::envelope::Metadata path while retaining the existing LlmRequest
and LlmResponse imports.
Summary
Extracts the correlation
Metadatatype fromenvelope.rsinto a dedicatedmetadatamodule and gives it aMetadata::from_headersconstructor thatnormalizes the harness-specific HTTP headers emitted by Claude Code, Codex,
NeMo Relay, Dynamo, OpenCode, and OpenAI-style clients into a single neutral
correlation/routing envelope.
Changes
metadatamodule (crates/libsy-protocol/src/metadata.rs): movesMetadataout ofenvelope.rs, re-exported fromlib.rs.envelope.rsnowimports it rather than defining it.
Metadata: adds agent-lineage fields (parent_agent_id,is_subagent,agent_kind,agent_role,task_kind,turn_id,session_final) alongside the existing session/agent/task/correlation fields.Metadata::from_headers: case-insensitive header normalization with adocumented precedence order — explicit
x-switchyard-*overrides win,followed by each harness's native headers. Handles subagent inference from
parent/child lineage headers (with an explicit
x-switchyard-is-subagentoverride), Codex structured turn metadata (JSON), and Claude Code / OpenCode
parent-session inference.
*_HEADERconstants grouped by originating harness.
Tests
12 unit tests covering Codex child/root metadata, Claude Code agent lineage and
parent inference, Relay/Dynamo correlation, OpenCode parent-session scoping,
session_finalparsing, and case-insensitive lookup.Checklist
snake_caseof the primary class.switchyard/__init__.py.__all__if intended for downstream use.--helpupdated if customer-facing surface changed.Signed-off-by: Your Name <email>) per the DCO.Notes for reviewers
Anything reviewers should pay extra attention to — risky paths, follow-up tickets, intentional trade-offs.
Summary by CodeRabbit
New Features
Bug Fixes