Skip to content

LCORE-2308: Patched transport layer for server client#2124

Merged
tisnik merged 1 commit into
lightspeed-core:mainfrom
asimurka:fix_providers
Jul 14, 2026
Merged

LCORE-2308: Patched transport layer for server client#2124
tisnik merged 1 commit into
lightspeed-core:mainfrom
asimurka:fix_providers

Conversation

@asimurka

@asimurka asimurka commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Patches transportation layer for server client as well, so that it propagates provider data header correctly, allowing azure entra id correctly working in server mode.

Currently providers e2e tests fail for azure in server mode due to missing provider data headers, see: https://github.com/lightspeed-core/lightspeed-stack/actions/runs/29218394595/job/86718646548

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement
  • Benchmarks improvement

Tools used to create PR

Identify any AI code assistants used in this PR (for transparency and review context)

  • Assisted-by: CUrsor

Related Tickets & Documents

Checklist before requesting a review

  • I have performed a self-review of my code.
  • PR has passed all pre-merge test jobs.
  • If it is a core feature, I have added thorough tests.

Testing

  • Please provide detailed steps to perform tests related to this code change.
  • How were the fix/results from this change verified? Please provide relevant screenshots or results.

Summary by CodeRabbit

  • New Features

    • Llama Stack server requests now automatically include provider metadata when available.
    • Existing per-request provider metadata is preserved without being overwritten.
    • Provider metadata is handled consistently across supported transport modes.
  • Bug Fixes

    • Improved reliability when creating clients from Llama Stack server configurations.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Changes

Llama Stack provider metadata

Layer / File(s) Summary
Provider-data header helpers
src/pydantic_ai_lightspeed/llamastack/_transport.py
Adds shared helpers for decoding headers, injecting provider metadata, copying requests, and wrapping HTTP clients.
Server and library transport integration
src/pydantic_ai_lightspeed/llamastack/_transport.py
Adds LlamaStackServerTransport and reuses shared provider-data injection in library transport handling.
Provider wiring and validation
src/pydantic_ai_lightspeed/llamastack/_provider.py, tests/unit/pydantic_ai_lightspeed/llamastack/*
Extracts provider data from client headers, wraps server-mode clients, simplifies HTTP client initialization, and adds transport coverage.

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

Sequence Diagram(s)

sequenceDiagram
  participant AsyncLlamaStackClient
  participant LlamaStackProvider
  participant LlamaStackServerTransport
  participant LlamaStackServer
  AsyncLlamaStackClient->>LlamaStackProvider: construct from default_headers
  LlamaStackProvider->>LlamaStackServerTransport: wrap HTTP client with provider data
  LlamaStackServerTransport->>LlamaStackServer: send request with provider header
  LlamaStackServer-->>AsyncLlamaStackClient: return response
Loading

Possibly related PRs

Suggested reviewers: jrobertboos, tisnik

🚥 Pre-merge checks | ✅ 7
✅ Passed checks (7 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Performance And Algorithmic Complexity ✅ Passed No blocking perf regressions found: new helpers are per-request O(h) on small header sets, with no added N+1s, nested loops, or unbounded buffers in hot paths.
Security And Secret Handling ✅ Passed No secrets, auth gaps, injection issues, or sensitive-data leaks found in the changed transport/provider code; provider data is only forwarded via headers.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main bug fix: a transport-layer patch for the server client.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
✨ Simplify code
  • Create PR with simplified code

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@asimurka asimurka changed the title LCORE-: Patched transport layer for server client LCORE-2308: Patched transport layer for server client Jul 13, 2026

@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.

Actionable comments posted: 2

🤖 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 `@src/pydantic_ai_lightspeed/llamastack/_transport.py`:
- Around line 31-35: Replace each Args: section with Parameters: in the
docstrings for decode_request_headers, inject_provider_data_into_headers,
request_with_provider_data_headers, wrap_http_client_with_provider_data, and the
LlamaStackServerTransport methods, preserving all existing parameter
descriptions.
- Around line 95-120: Update wrap_http_client_with_provider_data so wrapping
preserves the original httpx.AsyncClient configuration, including headers, auth,
cookies, event_hooks, limits, proxy/mounts, trust_env, and transport ownership.
Prefer modifying or wrapping the existing client in place; otherwise copy every
relevant setting and ensure closing the wrapped client does not unexpectedly
close a transport still owned by the original client.
🪄 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: ASSERTIVE

Plan: Pro

Run ID: fd168876-7497-4f4a-8eda-960be24a9484

📥 Commits

Reviewing files that changed from the base of the PR and between 77ae915 and 5cd7fc4.

📒 Files selected for processing (4)
  • src/pydantic_ai_lightspeed/llamastack/_provider.py
  • src/pydantic_ai_lightspeed/llamastack/_transport.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_provider.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_transport.py
📜 Review details
⏰ Context from checks skipped due to timeout. (15)
  • GitHub Check: spectral
  • GitHub Check: integration_tests (3.13)
  • GitHub Check: integration_tests (3.12)
  • GitHub Check: mypy
  • GitHub Check: build-pr
  • GitHub Check: unit_tests (3.13)
  • GitHub Check: unit_tests (3.12)
  • GitHub Check: Konflux kflux-prd-rh02 / lightspeed-stack-0-7-on-pull-request
  • GitHub Check: E2E: server mode / ci / group 2
  • GitHub Check: E2E: library mode / ci / group 1
  • GitHub Check: E2E: library mode / ci / group 3
  • GitHub Check: E2E: server mode / ci / group 1
  • GitHub Check: E2E: server mode / ci / group 3
  • GitHub Check: E2E: library mode / ci / group 2
  • GitHub Check: E2E Tests for Lightspeed Evaluation job
⚠️ CI failures not shown inline (2)

GitHub Actions: Pyright / 0_Pyright.txt: LCORE-: Patched transport layer for server client

Conclusion: failure

View job details

##[group]Run uv run pyright src
 �[36;1muv run pyright src�[0m
 shell: /usr/bin/bash -e {0}
 env:
   UV_PYTHON: 3.12
   VIRTUAL_ENV: /home/runner/work/lightspeed-stack/lightspeed-stack/.venv
   UV_CACHE_DIR: /home/runner/work/_temp/setup-uv-cache
 ##[endgroup]
 /home/runner/work/lightspeed-stack/lightspeed-stack/src/pydantic_ai_lightspeed/llamastack/_provider.py
   /home/runner/work/lightspeed-stack/lightspeed-stack/src/pydantic_ai_lightspeed/llamastack/_provider.py:80:53 - error: Argument of type "dict[str, str | Omit]" cannot be assigned to parameter "headers" of type "dict[str, str]" in function "parse_request_provider_data"
     "dict[str, str | Omit]" is not assignable to "dict[str, str]"
       Type parameter "_VT@dict" is invariant, but "str | Omit" is not the same as "str"
       Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
 1 error, 0 warnings, 0 informations
 ##[error]Process completed with exit code 1.

GitHub Actions: Pyright / Pyright: LCORE-: Patched transport layer for server client

Conclusion: failure

View job details

##[group]Run uv run pyright src
 �[36;1muv run pyright src�[0m
 shell: /usr/bin/bash -e {0}
 env:
   UV_PYTHON: 3.12
   VIRTUAL_ENV: /home/runner/work/lightspeed-stack/lightspeed-stack/.venv
   UV_CACHE_DIR: /home/runner/work/_temp/setup-uv-cache
 ##[endgroup]
 /home/runner/work/lightspeed-stack/lightspeed-stack/src/pydantic_ai_lightspeed/llamastack/_provider.py
   /home/runner/work/lightspeed-stack/lightspeed-stack/src/pydantic_ai_lightspeed/llamastack/_provider.py:80:53 - error: Argument of type "dict[str, str | Omit]" cannot be assigned to parameter "headers" of type "dict[str, str]" in function "parse_request_provider_data"
     "dict[str, str | Omit]" is not assignable to "dict[str, str]"
       Type parameter "_VT@dict" is invariant, but "str | Omit" is not the same as "str"
       Consider switching from "dict" to "Mapping" which is covariant in the value type (reportArgumentType)
 1 error, 0 warnings, 0 informations
 ##[error]Process completed with exit code 1.
🧰 Additional context used
📓 Path-based instructions (3)
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.py: Use absolute imports for internal modules: from authentication import get_auth_dependency
Llama Stack imports: Use from llama_stack_client import AsyncLlamaStackClient
Check constants.py for shared constants before defining new ones
All modules must start with descriptive docstrings explaining purpose
Use logger = get_logger(__name__) from log.py for module logging
All functions must have complete type annotations for parameters and return types, use modern syntax (str | int), and include descriptive docstrings
Use snake_case with descriptive, action-oriented names for functions (get_, validate_, check_)
Avoid in-place parameter modification anti-patterns; return new data structures instead of modifying function parameters
Use async def for I/O operations and external API calls
Use standard log levels with clear purposes: debug() for diagnostic info, info() for program execution, warning() for unexpected events, error() for serious problems
All classes must have descriptive docstrings explaining purpose and use PascalCase with standard suffixes: Configuration, Error/Exception, Resolver, Interface
Abstract classes must use ABC with @abstractmethod decorators
Follow Google Python docstring conventions with required sections: Parameters, Returns, Raises, and Attributes for classes

Files:

  • src/pydantic_ai_lightspeed/llamastack/_provider.py
  • src/pydantic_ai_lightspeed/llamastack/_transport.py
**/*

📄 CodeRabbit inference engine (Custom checks)

**/*: Flag meaningful O(n^2)+ algorithms on non-trivial inputs, including handlers and Kubernetes list operations.
Flag N+1 patterns that list items and then query once per item, including Kubernetes API and database access.
Flag expensive work inside loops, including API calls, JSON parsing, and regex compilation.
Flag unbounded growth in caches, watchers, or buffers when eviction or limits are missing.
Flag missing pagination or limits on list operations and API endpoints.
Flag secrets or tokens logged in plaintext or hardcoded in source.
Flag API endpoints missing authentication or authorization.
Flag injection vulnerabilities, including SQL injection, command injection, and path traversal.
Flag sensitive data leaked in API responses, WebSocket messages, or logs.
Flag Kubernetes Secrets and Red Hat secrets missing OwnerReferences.

Files:

  • src/pydantic_ai_lightspeed/llamastack/_provider.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_transport.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_provider.py
  • src/pydantic_ai_lightspeed/llamastack/_transport.py
tests/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

tests/**/*.py: Use pytest for all unit and integration tests; do not use unittest
Use pytest.mark.asyncio marker for async tests

Files:

  • tests/unit/pydantic_ai_lightspeed/llamastack/test_transport.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_provider.py
🧠 Learnings (2)
📚 Learning: 2026-06-24T13:45:37.249Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 1971
File: src/utils/markdown_repair.py:31-36
Timestamp: 2026-06-24T13:45:37.249Z
Learning: In the lightspeed-stack repository, docstrings must use the section header name "Parameters:" (not "Args:") for function arguments, even if the project references Google Python docstring conventions. Ensure docstrings follow the project’s established "Parameters:" header format for any documented function parameters.

Applied to files:

  • src/pydantic_ai_lightspeed/llamastack/_provider.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_transport.py
  • tests/unit/pydantic_ai_lightspeed/llamastack/test_provider.py
  • src/pydantic_ai_lightspeed/llamastack/_transport.py
📚 Learning: 2026-07-06T15:26:18.398Z
Learnt from: Jdubrick
Repo: lightspeed-core/lightspeed-stack PR: 2071
File: src/models/config.py:2416-2422
Timestamp: 2026-07-06T15:26:18.398Z
Learning: In this repo’s Python code under src/**, don’t treat differences in string concatenation style as a style inconsistency when Black has effectively forced (or made clearer) use of explicit `+` string concatenation in multi-line logger/string expressions. If adjacent-literal implicit concatenation is avoided/changed specifically to accommodate Black’s formatting in these call sites, accept the `+` usage and don’t recommend converting it solely for consistency with nearby blocks that use implicit concatenation.

Applied to files:

  • src/pydantic_ai_lightspeed/llamastack/_provider.py
  • src/pydantic_ai_lightspeed/llamastack/_transport.py
🪛 ast-grep (0.44.1)
tests/unit/pydantic_ai_lightspeed/llamastack/test_provider.py

[warning] 234-234: Do not make http calls without encryption
Context: "http://my-server:8321/v1"
Note: [CWE-319] Cleartext Transmission of Sensitive Information.

(requests-http)


[warning] 249-249: Do not make http calls without encryption
Context: "http://my-server:8321/v1"
Note: [CWE-319] Cleartext Transmission of Sensitive Information.

(requests-http)

src/pydantic_ai_lightspeed/llamastack/_transport.py

[info] 62-62: use jsonify instead of json.dumps for JSON output
Context: json.dumps(provider_data)
Note: [CWE-116] Improper Encoding or Escaping of Output.

(use-jsonify)

🪛 GitHub Actions: Pyright / 0_Pyright.txt
src/pydantic_ai_lightspeed/llamastack/_provider.py

[error] 80-80: pyright: Argument of type "dict[str, str | Omit]" cannot be assigned to parameter "headers" of type "dict[str, str]" in function "parse_request_provider_data" (reportArgumentType).

🪛 GitHub Actions: Pyright / Pyright
src/pydantic_ai_lightspeed/llamastack/_provider.py

[error] 80-80: pyright: Argument of type "dict[str, str | Omit]" cannot be assigned to parameter "headers" of type "dict[str, str]" in function "parse_request_provider_data". "str | Omit" is not the same as "str". (reportArgumentType).

🔇 Additional comments (5)
src/pydantic_ai_lightspeed/llamastack/_transport.py (1)

141-151: LGTM!

src/pydantic_ai_lightspeed/llamastack/_provider.py (2)

138-142: LGTM!


80-82: 🎯 Functional Correctness

No issue here.

tests/unit/pydantic_ai_lightspeed/llamastack/test_provider.py (1)

164-263: LGTM!

tests/unit/pydantic_ai_lightspeed/llamastack/test_transport.py (1)

77-181: LGTM!

Comment thread src/pydantic_ai_lightspeed/llamastack/_transport.py
Comment thread src/pydantic_ai_lightspeed/llamastack/_transport.py
@asimurka

Copy link
Copy Markdown
Contributor Author

@asimurka asimurka requested a review from tisnik July 14, 2026 08:51

@tisnik tisnik 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.

LGTM

@jrobertboos jrobertboos 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.

LGTM

@tisnik tisnik merged commit 216426e into lightspeed-core:main Jul 14, 2026
33 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.

3 participants