Skip to content

fix(agent): continue truncated model turns - #185

Merged
iamjr15 merged 1 commit into
mainfrom
fix/model-length-continuation
Aug 8, 2026
Merged

fix(agent): continue truncated model turns#185
iamjr15 merged 1 commit into
mainfrom
fix/model-length-continuation

Conversation

@iamjr15

@iamjr15 iamjr15 commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Treat provider length finish reasons as nonterminal model turns.
  • Checkpoint the partial response and continue durably with an internal instruction to split interrupted operations into smaller complete tool calls.
  • Validate the SDK finish-reason contract at the agent boundary and accept only stop as tool-free semantic completion.
  • Fail blocked, provider-error, and invalid terminal reasons explicitly instead of publishing incomplete work as successful.

Root cause

The production Pomodoro retry recovered its Daytona runtime correctly, but Claude reached its per-response output limit while forming the next operation. The Workflow used only the absence of parsed tool calls as its completion condition, so it finalized that truncated turn and exposed the sandbox readiness page.

Architecture

The Mastra adapter validates the six AI SDK finish reasons. Cloudflare Workflow owns the policy: tool calls execute durably; length appends a non-visible continuation message and starts another checkpointed model turn; only stop completes a tool-free run. This keeps semantic completion in charge without adding a step, token, duration, or cost ceiling.

Decisions

Decision Choice Reason
Handle truncation in Workflow Durable continuation It preserves replay safety and applies to every provider and run type.
Preserve partial response history Append an internal user continuation message The next turn sees the exact work already attempted and avoids repeating completed actions.
Keep provider output settings unchanged No fixed output-token override A larger fixed cap only postpones truncation and does not establish correct completion semantics.
Reject non-stop terminal reasons Explicit upstream failure Content filtering and provider errors are not successful outcomes.

Production evidence

Verification

  • pnpm lint
  • pnpm typecheck
  • pnpm turbo build --force
  • pnpm deadcode
  • pnpm architecture:check
  • pnpm turbo skills:build
  • production flow will be repeated after merge and exact-SHA Cloudflare deployment

How to review

  1. Review the finish-reason schema in packages/agent-core/src/mastra/durable-agent-step.ts.
  2. Review the durable loop policy in apps/agent-worker/src/durable-objects/agent-run-workflow.ts.
  3. Confirm the shared schema is enforced by agent-run-workflow-runtime.ts and the README contract matches the implementation.

Treat provider output-length termination as nonterminal durable state.
Validate finish reasons at the agent boundary and complete only after a semantic stop.
@vercel

vercel Bot commented Aug 8, 2026

Copy link
Copy Markdown

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

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
cheatcode Skipped Skipped Aug 8, 2026 2:19pm

@iamjr15
iamjr15 merged commit c730ec0 into main Aug 8, 2026
6 checks passed
@iamjr15
iamjr15 deleted the fix/model-length-continuation branch August 8, 2026 14:21
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.

1 participant