Skip to content

fix(agent): bound structured output generation - #7279

Open
BillLeoutsakosvl346 wants to merge 2 commits into
stagingfrom
investigate/agent-generation-guardrails
Open

fix(agent): bound structured output generation#7279
BillLeoutsakosvl346 wants to merge 2 commits into
stagingfrom
investigate/agent-generation-guardrails

Conversation

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor

Summary

  • default Agent structured-output requests to 4,096 output tokens when Max Output Tokens is blank
  • preserve explicit limits and leave unstructured requests on existing provider/model defaults
  • fail explicitly token-limited structured responses with the non-retryable structured_output_token_limit error
  • propagate Anthropic no-tool stream stop_reason into existing timing segments
  • retain failed-generation content, timing, token, model, and cost diagnostics without exposing a successful downstream output

Incident / root cause

The affected Agent calls had no configured output cap, so Anthropic could continue generating until its provider/model limit. Existing transport deadlines govern connection/body transport rather than intentionally long, continuously progressing generations; there were no Sim retries, restarts, or timeout failures to stop these runs. Malformed structured output then fell through the compatibility fallback as a tiny effective answer.

Validation

  • bun run test -- executor/handlers/agent/agent-handler.test.ts providers/anthropic/utils.test.ts executor/execution/block-executor.test.ts executor/execution/block-retry.test.ts — 158 passed
  • bun run type-check — passed
  • Biome check on the 10 changed files — passed
  • frozen lockfile unchanged; no generated files or environment artifacts changed

Live in-app Browser validation was not run because this environment exposed no iab Browser target (only a Chrome extension target). The requester explicitly waived that gate before PR creation.

Intentionally deferred

This PR adds no universal wall-clock, time-to-first-token, or inter-token idle timeout. Legitimate reasoning and research calls can run for minutes; broader deadline policy should be designed separately.

TEAgent's proposed explicit 1,024-token workflow setting remains a separate workflow configuration change and is not included here.

@vercel

vercel Bot commented Aug 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment 操作 Updated (UTC)
docs Skipped Skipped Aug 29, 2026 7:22pm

Request Review

@greptile-apps

greptile-apps Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR bounds structured Agent output by default, identifies token-limited structured generations as explicit failures, and preserves their provider diagnostics without exposing successful downstream output.

  • Defaults structured responses to 4,096 output tokens while preserving explicit and unstructured behavior.
  • Propagates provider finish reasons through streaming events and timing segments.
  • Retains redacted content, model, token, timing, tool-call, and cost diagnostics for failed generations.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
apps/sim/executor/execution/block-executor.ts Detects token-limited structured streams before downstream completion and safely retains scrubbed provider diagnostics on failure.
apps/sim/executor/handlers/agent/agent-handler.ts Applies the structured-output token default and rejects token-limited non-streaming responses.
apps/sim/executor/handlers/shared/response-format.ts Defines the shared default, finish-reason detection, and non-retryable structured-output limit error.
apps/sim/providers/stream-pump.ts Carries terminal provider finish reasons through the stream-drain result.
apps/sim/providers/anthropic/utils.ts Preserves Anthropic stop reasons when completing no-tool streams.

Sequence Diagram

sequenceDiagram
  participant A as Agent handler
  participant P as Model provider
  participant S as Stream pump
  participant E as Block executor
  participant W as Workflow state

  A->>P: Structured request with explicit/default token limit
  P-->>S: Text deltas and terminal finish reason
  S-->>E: Final text and finish reason
  E->>E: Attach finish reason to provider timing
  alt Token-limited structured output
    E->>E: Build and redact failure diagnostics
    E->>W: Record failed block output
  else Complete structured output
    E->>E: Parse structured response
    E->>W: Record successful block output
  end
Loading

Reviews (2): Last reviewed commit: "fix(agent): harden structured stream gua..." | Re-trigger Greptile

Comment thread apps/sim/executor/execution/block-executor.ts

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 10 files

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

Comment thread apps/sim/executor/execution/block-executor.ts Outdated
Comment thread apps/sim/executor/execution/block-executor.ts
@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Aug 29, 2026

Copy link
Copy Markdown

@cubic-dev-ai review this PR

@BillLeoutsakosvl346 I have started the AI code review. It will take a few minutes to complete.

@BillLeoutsakosvl346

Copy link
Copy Markdown
Contributor Author

@greptileai

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 22 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Re-trigger cubic

注册 for free to join this conversation on GitHub. Already have an account? 登录 to comment

标签

None yet

项目

None yet

Development

Successfully merging this pull request may close these issues.

1 participant