Skip to content

feat(agent): continue bounded turns from provider stop reasons - #75

Merged
austinchennn merged 1 commit into
EmergentExit:mainfrom
wangyeyu1129:codex/stop-reason-continuations
Oct 23, 2026
Merged

austinchennn merged 1 commit into
EmergentExit:mainfrom
wangyeyu1129:codex/stop-reason-continuations

Conversation

@wangyeyu1129

Copy link
Copy Markdown
Contributor

Description:

A response could end successfully at the transport layer while generation was truncated. AgentSession previously continued only after tool calls, so a no-tool token limit or provider pause ended the user turn early. Carry a provider-neutral stop reason and continue within a bounded per-turn budget.

Fixes:

No linked issue. Implements the requested stop-reason continuation contract; the paired vdoc-server integration pins local SDK packages until an upstream release is available.

Behaviours Completed:

  • Add optional stopReason and rawStopReason to response endings and cascade text finishes; export StopReason from core while preserving existing response statuses.
  • Normalize OpenAI-compatible completion, tool calls, output limits, filtering, cancellation, failure and unknown outcomes. Keep raw reasons to short enum tokens; cancellation/failure status takes precedence.
  • Continue max_tokens and pause even without tools. Wait for every issued tool result before deciding; preserve the existing validation, authorization, serial execution and interruption gates.
  • Stop and report refusal, content filtering, failure, unknown reasons or tool_calls without actual calls. Providers that omit reasons retain the previous inference behavior.
  • Default to 16 continuations per user turn, validate maxContinuations, reset the budget on new input, and report continuation_limit when exhausted.
  • Ignore repeated response endings and stale epochs; discard unfinished tool argument streams without executing them. Publish one final turn hook with the standardized stop reason and continuation count.

Files Changed:

  • packages/core/src/{events,agent,index,session}.ts: public contract, metrics, bounded scheduling and lifecycle guards.
  • packages/openai-compatible/src/index.ts: provider mapping and short raw-reason preservation.
  • packages/cascade/src/index.ts: finish propagation after synthesized audio completes; preserve conversation history for continuations.
  • Core, Boson and cascade tests: retryable and terminal reasons, tool settlement, duplicate endings, budgets, interruption, history and audio ordering.

Brief Explanation:

Transport status remains independent of generation stop reason. The runtime makes one decision only after the response has ended and its issued calls have settled; subsequent generations stay in the same turn. Only real tool feedback uses autoReplyAfterResult. No fabricated user messages, write replay, provider network retries or browser wire-protocol changes are introduced. This branch is based on current upstream main, including bounded cascade history.

Testing:

  • npm run typecheck: passed. npm test: 591 tests across 34 files passed on current upstream main.
  • npm run pack, npm run check:budgets, npm run check:spec and git diff --check: passed.
  • Regression coverage exercises max_tokens → pause → completed, terminal outcomes with and without tools, budget reset/default/zero, late interrupted responses, duplicate usage and preserved assistant/tool history.

Unsure About:

  • Real Boson/Claude API behavior and speech continuity require a separate credentialed integration run; simulated tests do not claim those are verified.
  • completed means generation ended, not that a business task or document write succeeded. Tool results and application verification retain that responsibility.
  • Providers that omit stop reasons keep legacy behavior and cannot identify native truncation. Existing provider auto-reply capability contracts and timeout behavior remain in force.

@austinchennn
austinchennn merged commit 855c765 into EmergentExit:main Oct 23, 2026
5 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.

2 participants