Skip to content

feat(runtime): invoke_agent_streaming keeps the typed HostedError on the streaming path - #261

Merged
senamakel merged 4 commits into
mainfrom
fix-hosted-stream-typed-failure
Oct 1, 2026
Merged

senamakel merged 4 commits into
mainfrom
fix-hosted-stream-typed-failure

Conversation

@senamakel

@senamakel senamakel commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Adds AgentHarness::invoke_agent_streaming, a public wrapper over the existing crate-private invoke_agent_streaming_with_capabilities. It runs a hosted turn on the streaming model path and returns Result<AgentRun, HostedError>, exactly like invoke_agent, with the closed HostedErrorKind, the fixed per-kind message and the partial run.
  • Adds a regression test: a model whose streaming call never answers, bounded by max_model_call_ms, returns HostedErrorKind::Timeout.

Problem

A host that wants streaming (model deltas and delta middleware) but only the terminal outcome has to drain invoke_agent_stream. That public stream sanitizes its terminal AgentStreamItem::Failed to the single string hosted agent invocation failed for every failure (sanitize_hosted_stream_item). A per-model-call timeout (CallTimeout), a run timeout, a limit and a provider failure are therefore indistinguishable to the host, even though HostedErrorKind exists precisely so a host can tell them apart without reading raw error text. OpenHuman hit this as a wedged model call surfacing as a generic inference error instead of turn_timeout (tinyhumansai/openhuman#6375).

Solution

Expose the typed streaming driver that recursive delegation already uses. No sanitization contract changes: the public stream keeps its fixed string, and HostedError.message is still a fixed string per kind.

Tests

  • cargo test -p tinyagents-harness --lib runtime:: (47 passed, including the new invoke_agent_streaming_preserves_the_timeout_kind_of_a_stalled_model_call)
  • cargo clippy -p tinyagents-harness --all-targets -- -D warnings

Summary by CodeRabbit

  • New Features
    • Added a hosted agent invocation option that uses streaming and returns the completed run.
    • Invocation failures now provide a typed error with the failure category and any partial run, making it easier to handle unsuccessful or timed-out requests.

senamakel and others added 3 commits October 1, 2026 11:21
Add a new `invoke_agent_streaming` method to `AgentHarness` that runs an agent through the streaming model path while returning typed `HostedError` on failure. This preserves the specific error kind from per-model-call timeouts, limits, and provider failures, unlike the public stream's terminal `Failed` item which sanitizes all failures to a single fixed string.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
When the test runtime is not available, the harness now returns a clear error instead of panicking. This improves robustness in environments where the runtime may not be initialized.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Changed the retry policy in the streaming timeout test from `RetryPolicy::none()` to `RetryPolicy::default().with_max_attempts(1)` to ensure the test exercises the same retry logic as production code while still limiting to a single attempt.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
@tinysweeper

tinysweeper Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

⚠️ Review failed for 24984d49bcfd. the review of #261 did not finish within 900s

Last completed report

Tiny Sweeper review

Tiny Sweeper reviewed this change across 6 lane(s) and found 0 active actionable finding(s). Detailed lane evidence and any incomplete work are listed below.

State: Incomplete
Priority: none
Reviewed head: 4583fd645c24
Updated: 1790843444 (Unix time)

Review snapshot

Change surface Files Review signal Count
Production 1 Active findings 0
Tests 1 Noted findings 0
Documentation 0 Resolved findings 0
Configuration 0 Pending checks/questions 4

Completeness: Incomplete
Test assessment: No supported feature-to-test mapping was available; this does not mean tests are absent or passed.

What changed

The review could not produce a supported behavioral summary; inspect the cited changed surface and lane details below.

Features

None identified with supported citations.

Tests

No supported feature-to-test mapping was produced. Test execution is not inferred.

Findings

No active actionable findings.

Could not review: crates/tinyagents-harness/src/runtime/agent.rs, crates/tinyagents-harness/src/runtime/test.rs

Before merge

  • Complete the critique review for crates/tinyagents-harness/src/runtime/agent.rs, crates/tinyagents-harness/src/runtime/test.rs.
  • Complete the security review for crates/tinyagents-harness/src/runtime/agent.rs, crates/tinyagents-harness/src/runtime/test.rs.

How this fits together

flowchart LR
  n0["...call_limit_bounds_initial_host_resolution<br/>changed"]:::changed
  n1["new"]:::impacted
  n2["invoke_agent"]:::impacted
  n3["host"]:::impacted
  n4["...ions_finalize_the_actual_partial_run_once"]:::impacted
  n0 -->|calls| n1
  n0 -->|tests| n1
  n0 -->|calls| n2
  n0 -->|tests| n2
  n0 -->|uses| n3
  n3 -->|calls| n1
  n3 -->|tests| n1
  n4 -->|calls| n1
  n4 -->|tests| n1
  n4 -->|calls| n2
  n4 -->|tests| n2
  classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
  classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
  classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
  classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Loading
Agent review details

critique

  • Conclusion: Neutral
  • Scope reviewed: incomplete; unanswered: crates/tinyagents-harness/src/runtime/agent.rs, crates/tinyagents-harness/src/runtime/test.rs
  • Lane summary: Reviewed 0 files; 0 findings. 2 files could not be reviewed: crates/tinyagents-harness/src/runtime/agent.rs, crates/tinyagents-harness/src/runtime/test.rs.

security

  • Conclusion: Neutral
  • Scope reviewed: incomplete; unanswered: crates/tinyagents-harness/src/runtime/agent.rs, crates/tinyagents-harness/src/runtime/test.rs
  • Lane summary: Reviewed 0 files; 0 findings. 2 files could not be reviewed: crates/tinyagents-harness/src/runtime/agent.rs, crates/tinyagents-harness/src/runtime/test.rs.

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: _The code index is behind this pull request (indexed at `badd268200eb`), so retrieved context may be out of date._ _Memory was unavailable (model: cortex: v1/recall: timed out after 10s), so this review ran without it._

commits

  • Conclusion: Neutral
  • Scope reviewed: all assigned evidence
  • Lane summary: Nothing sensitive found in what this pull request commits.

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: Adds a public `invoke_agent_streaming` method that wraps the crate-private streaming driver, preserving typed `HostedError` on failure, and a regression test verifying that a stalled model call yields `HostedErrorKind::Timeout`. The code is correct and consistent with existing patterns. _The code index is behind this pull request (indexed at `badd268200eb`), so retrieved context may be out of date._ _Memory was unavailable (model: cortex: v1/recall: timed out after 10s), so this review ran without it._

e2e

  • Conclusion: Neutral
  • Scope reviewed: all assigned evidence
  • Lane summary: No end-to-end harness in this repository: no e2e test files and no e2e workflow.
Evidence and run details
  • Models: ladder/vectors, deepseek/deepseek-v4-flash
  • Spend: $0.006224
  • Tokens: 50530 input · 14206 output · 12288 cached · 442 embedding
Head State Pass summary
4583fd645c24 incomplete 0 active finding(s), 0 resolved finding(s) (at 1790843444)

tinysweeper 0.1.0

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-01T09:44:21.569826Z 24984d4 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 9af63e7f-03cc-4d69-bb9d-d6f5fc7fca13

📥 Commits

Reviewing files that changed from the base of the PR and between 4583fd6 and 24984d4.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: f520b8f6-74d2-4d3e-ba96-ee4c26fd51b0

📥 Commits

Reviewing files that changed from the base of the PR and between b88a272 and 4583fd6.

📒 Files selected for processing (2)
  • crates/tinyagents-harness/src/runtime/agent.rs
  • crates/tinyagents-harness/src/runtime/test.rs

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Adds AgentHarness::invoke_agent_streaming, which returns a completed AgentRun or a typed HostedError. Adds a regression test for timeout classification and the sanitized error message.

Changes

Hosted streaming invocation

Layer / File(s) Summary
Streaming invocation and timeout handling
crates/tinyagents-harness/src/runtime/agent.rs, crates/tinyagents-harness/src/runtime/test.rs
Adds the hosted streaming terminal-result API and tests that a stalled model call returns a timeout error with the fixed sanitized message.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature

Suggested reviewers: m3ga-mind

Merge Risk: ⚪ Minimal · up to 4583f

This adds a public method that returns typed hosted errors from the streaming path, with a timeout regression test. No merge-blocking risk was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 4583f

The streaming API shares authorization and sanitized error handling with the other public invocation APIs. No specific security regression was established, but the reviewed baseline and interruption/retry contracts remain partly uncertain.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The visible exposure is an embedding host invocation using its supplied capabilities. Execution can reach configured models, tools, and optional persistence sinks. Actual tenant, credential, service, and data-store scope depends on host configuration not supplied for this review.

Trust Boundaries and Controls

  • observed — The new wrapper does not skip hosted preparation. It uses the same definition resolution, content screening, definition-derived tool restrictions, invocation-local authority binding, and fixed-message error conversion visible in the other hosted APIs.

Resilience and Maintainability Implications

  • observed — Once execution owns the terminal observer, completion and drop consume it once, limiting duplicate finalization. Preparation precedes observer installation. Streaming retries also require consumers to discard earlier deltas via RetryScheduled; host Token progress is documented as a display hint rather than an authoritative reply. No introduced security failure was established from these lifecycle conditions.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding invoke_agent_streaming while preserving typed HostedError handling on the streaming path.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


A rabbit watches tokens stream,
Then waits for runs to reach their end.
A timeout gets its proper name,
Its message stays within its bounds.
The burrow logs one test passed,
And carrots celebrate the change.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4583fd645c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

/// `Failed` item is sanitized to one fixed string for every failure, so a
/// per-model-call timeout, a limit, and a provider failure become
/// indistinguishable. This entry point keeps the kind.
pub async fn invoke_agent_streaming(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Document the typed hosted streaming entry point

Add this method to the hosted-invocation documentation. The canonical crates/tinyagents-harness/src/runtime/README.md still lists only invoke_agent and invoke_agent_stream, while docs/modules/harness/hosting.md demonstrates only the unary API, so users seeking streaming execution with a terminal result are not told that this typed-error alternative exists or why it should replace draining the sanitized stream. This leaves the module guides out of sync with the new public API.

AGENTS.md reference: AGENTS.md:L78-L82

Useful? React with 👍 / 👎.

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tinysweeper found nothing blocking, but could not review everything, so this is not an approval: crates/tinyagents-harness/src/runtime/agent.rs, crates/tinyagents-harness/src/runtime/test.rs.

             $0.0062 · 50,530 in / 14,206 out · 12,288 cached (24%) · ladder/vectors, deepseek/deepseek-v4-flash · 442 embedded
tests:       $0.0045 · 43,176 in / 8,305 out  · 12,288 cached (28%) · deepseek/deepseek-v4-flash
description: $0.0011 · 4,596 in  / 3,872 out  · 0 cached (0%)       · deepseek/deepseek-v4-flash

Co-authored-by: Medulla <medulla@tinyhumans.ai>
@senamakel
senamakel merged commit 3cc14c2 into main Oct 1, 2026
10 of 11 checks passed
@senamakel
senamakel deleted the fix-hosted-stream-typed-failure branch October 2, 2026 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant