Skip to content

Rust SDK: PR #1367 review follow-ups#1382

Merged
SteveSandersonMS merged 3 commits into
mainfrom
stevesandersonms/rust-sdk-1367-followups
May 22, 2026
Merged

Rust SDK: PR #1367 review follow-ups#1382
SteveSandersonMS merged 3 commits into
mainfrom
stevesandersonms/rust-sdk-1367-followups

Conversation

@SteveSandersonMS
Copy link
Copy Markdown
Contributor

Local review of #1367 (Rust SDK API cleanup) flagged 9 follow-ups: 3 fix-before-done items (broken doc build, an ordering hazard, and a silent-handler-drop footgun) plus 6 nice-to-haves. This PR addresses all 9 in a single pass so the API is in shape before the next round of dependents pin against it.

Fix-before-done

  • cargo doc --no-deps is no longer broken on default features. tool.rs ToolHandler doc was using [Tool] and [define_tool] intra-doc links that fail rustdoc's broken-link lint when derive is off. Switched to fully-qualified paths for Tool and plain backticks for define_tool / schema_for. Same sweep applied to the README and a couple of types.rs items that linked to pub(crate) symbols.

  • SessionConfig::to_wire / ResumeSessionConfig::to_wire are now consuming into_wire(self) -> Result<(Wire, SessionConfigRuntime), Error>. The new SessionConfigRuntime struct holds the trait-object handlers, tool-handler map, session-fs provider, and slash commands drained out of the config. This eliminates the deep Vec<Tool> / HashMap<String, Value> clone the old &self-based shape required, and makes the .take()-after-to_wire ordering hazard a compile-time impossibility. The duplicate-tool-handler check moved into into_wire as part of the drain.

  • Serialize / Deserialize dropped from SessionConfig and ResumeSessionConfig. Every handler field had #[serde(skip)], so serde round-tripping silently dropped all runtime behavior. The wire payload is now produced exclusively via into_wire on the wire::Session{Create,Resume}Wire structs. Also dropped the now-redundant env_value_mode field on the configs (the wire struct hard-codes "direct"). Two *_serializes_bucket_b_fields integration tests moved into the in-crate unit-test module since the wire types are pub(crate).

Nice-to-haves

  • Session rustdoc: get_messages -> get_events (the Phase A canonical name).
  • Simplified the Client::start connection-token resolution block - dropped the shadow block, let _ = &mut options;, and the redundant retyped let.
  • Tool::with_parameters now panics on non-object input via the existing tool_parameters helper instead of silently producing an empty parameter map. Matches the loud-on-misuse pattern of the rest of the tool module; in-tree call sites using json!({...}) are unaffected.
  • README typo: second ToolHandler replaced with SystemMessageTransform in the handler-trait list.
  • Trimmed the unreachable tool_name.is_empty() branch in the ExternalToolRequested dispatch path (the outer guard already short-circuits when the tools map lookup fails).
  • Tool::handler moved from pub to pub(crate) and a Tool::handler() read-only accessor added. External callers can no longer overwrite an already-attached handler via direct field assignment; mutation goes through Tool::with_handler.

Public API impact

Three breaking changes worth calling out (all latent-bug or encapsulation fixes; SDK is pre-1.0):

  • SessionConfig / ResumeSessionConfig lose Serialize + Deserialize (the path was always broken).
  • Tool::with_parameters panics on non-object instead of silently dropping (real callers use json!({...}) and are unaffected).
  • Tool::handler field becomes pub(crate); new Tool::handler() accessor is the read replacement.

Everything else is implementation-detail-only (to_wire was pub(crate), doc/typo fixes, dead-branch removal).

Validation

  • cargo check --tests --all-features
  • cargo doc --no-deps (default features) - confirms the fix-before-done #1 fix
  • cargo doc --no-deps --all-features
  • cargo test --lib --features test-support (128 passed)
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo fmt --check

Fixes: #1380

SteveSandersonMS and others added 3 commits May 22, 2026 18:20
Three fix-before-done items:

* Repair broken intra-doc links in tool.rs ToolHandler doc and related
  sites so cargo doc --no-deps works on default features (without
  --all-features). Tool and define_tool were both feature-gated under
  derive, causing rustdoc::broken_intra_doc_links to fail. Switched
  to fully-qualified paths (Tool) and plain backticks (define_tool,
  schema_for).

* Convert SessionConfig::to_wire and ResumeSessionConfig::to_wire into
  consuming into_wire(self) -> (Wire, SessionConfigRuntime). The new
  SessionConfigRuntime bundle holds the trait-object handlers, tool
  handlers map, session-fs provider, and slash commands drained out of
  the config. Eliminates the deep Vec<Tool> / HashMap<String, Value>
  clone the old &self-based shape required, and makes the
  .take()-after-to_wire ordering hazard a compile-time impossibility.
  The duplicate-tool-handler check moves into into_wire as part of the
  drain.

* Drop Serialize and Deserialize derives from SessionConfig and
  ResumeSessionConfig. Since every handler field had #[serde(skip)],
  serde round-tripping silently dropped all runtime behavior -- a
  footgun. The wire payload is now produced exclusively via into_wire
  on the dedicated wire::Session{Create,Resume}Wire structs. Also
  dropped the now-redundant env_value_mode field (the wire struct
  hard-codes "direct"). Two bucket_b coverage tests moved into the
  in-crate unit-test module since the wire types are pub(crate).

Nice-to-haves:

* Session struct rustdoc: get_messages -> get_events (the canonical
  Phase A name).

* Simplify the Client::start connection-token resolution block (drop
  the shadowing inner block + redundant retyped let).

* Tighten Tool::with_parameters to panic on non-object input via the
  existing tool_parameters helper, matching the loud-on-misuse
  semantics of the rest of the tool module instead of silently
  producing an empty parameter map.

* Fix README typo: SystemMessageTransform replaces the duplicate
  ToolHandler in the handler-trait list.

* Trim the unreachable tool_name.is_empty() branch in the
  ExternalToolRequested dispatch path (the outer guard already
  short-circuits when the tools map lookup fails).

* Move Tool::handler from pub to pub(crate) and add a Tool::handler()
  accessor so external callers can no longer overwrite an
  already-attached handler by direct field assignment.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SteveSandersonMS SteveSandersonMS marked this pull request as ready for review May 22, 2026 17:48
@SteveSandersonMS SteveSandersonMS requested a review from a team as a code owner May 22, 2026 17:48
Copilot AI review requested due to automatic review settings May 22, 2026 17:48
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR applies the follow-ups from Rust SDK API cleanup (#1367) to harden the Rust SDK’s public surface and wire serialization path, while fixing rustdoc breakages on default features and removing a few remaining footguns.

Changes:

  • Reworked session config wire-building to into_wire(self) -> Result<(Wire, SessionConfigRuntime), Error>, eliminating ordering hazards and deep cloning while centralizing duplicate tool-handler validation.
  • Removed Serialize/Deserialize from SessionConfig and ResumeSessionConfig to prevent silent dropping of runtime handler fields; shifted wire-shape assertions into in-crate unit tests.
  • Tightened tool API ergonomics and docs: Tool::with_parameters now panics on non-object schema input, Tool::handler is no longer publicly settable, and rustdoc/README links were fixed for default-feature builds.
Show a summary per file
File Description
rust/tests/session_test.rs Drops integration-test assertions that relied on serde wire-shape for configs; keeps token-redaction Debug coverage.
rust/src/types.rs Implements into_wire + SessionConfigRuntime, removes serde derives from configs, enforces tool handler encapsulation, and updates tests accordingly.
rust/src/tool.rs Fixes rustdoc links for default features and routes parameter-schema normalization through tool_parameters (panic-on-misuse).
rust/src/session.rs Adopts into_wire runtime bundle, removes now-unreachable tool-name empty branch, and keeps handler extraction correct.
rust/src/lib.rs Simplifies connection-token resolution logic in Client::start.
rust/README.md Fixes handler-trait list typo and removes feature-gated rustdoc link to define_tool.

Copilot's findings

  • Files reviewed: 6/6 changed files
  • Comments generated: 0

@SteveSandersonMS SteveSandersonMS merged commit 578782e into main May 22, 2026
36 checks passed
@SteveSandersonMS SteveSandersonMS deleted the stevesandersonms/rust-sdk-1367-followups branch May 22, 2026 17:57
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.

Rust SDK: follow-ups from #1367 API review

2 participants