[WRONG BRANCH] feat(terminal-guard): opt-in no-tool-call continuation guard for openai-chat providers - #1659
Conversation
…ai-chat providers The no-tool-call terminal continuation guard (lidge-jun#394) is bound to the anthropic adapter only. Self-hosted OpenAI-compatible gateways (GLM/Kimi-family, etc.) routed through openai-chat hit the same premature-completion pattern -- the model announces work but ends the turn without emitting a tool call -- yet never get the bounded re-ask, so they stop mid-work. Extend the guard to openai-chat, gated behind a new per-provider opt-in flag `terminalContinuationGuard`. Default behavior is unchanged: anthropic keeps the guard, and the many registry providers sharing the openai-chat adapter stay off unless a provider explicitly enables it (the suspicious-no-tool-stop heuristic in analyzeTerminalTurn was tuned on Anthropic turns, so opt-in is the conservative default). Fixes lidge-jun#1651
|
✅ Deterministic PR hygiene checks passed. |
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. Its title has been prefixed with |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThe terminal continuation guard now supports opted-in ChangesTerminal guard extension
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to This is a localized, opt-in behavior change with no actionable merge-blocking risk remaining; it is merge-ready after normal checks and review. Sequence Diagram(s)sequenceDiagram
participant Provider
participant CoreResponses
participant TerminalGuard
participant OpenAIChat
Provider->>CoreResponses: Enable terminalContinuationGuard
CoreResponses->>OpenAIChat: Process routed turn
OpenAIChat-->>CoreResponses: Suspicious no-tool-call termination
CoreResponses->>TerminalGuard: Analyze terminal turn
TerminalGuard-->>CoreResponses: Request bounded continuation
CoreResponses-->>Provider: Emit assistant boundary and final done event
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
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. Comment |
|
Reopening against |
What
Extend the no-tool-call terminal continuation guard from the
anthropicadapter toopenai-chatrouted models, gated behind a new per-provider opt-in flagterminalContinuationGuard(default off).Fixes #1651.
Why
The guard added in #394 issues one bounded internal re-ask when a model announces work
(an edit/plan) but ends the turn without emitting a tool call. It is currently wired to
the anthropic adapter only. Self-hosted OpenAI-compatible gateways (GLM / Kimi-family and
similar) routed through
openai-chathit the exact same premature-completion pattern andstop mid-work, because they never reach
analyzeTerminalTurn.Design / why opt-in
analyzeTerminalTurn's suspicious-no-tool-stop heuristic (theACTIONABLE_REQUEST_RE/PLAN_OR_COMPLETION_RE/WAITING_FOR_USER_REregexes) was tuned on Anthropic turns.Its false-continue rate on other model families and non-English output is not yet
characterized. The
openai-chatadapter is shared by many registry providers, so turningthe guard on globally there could inject unexpected continuations for existing users
(xAI, z.ai, etc.).
To keep this strictly do-no-harm, the guard is enabled only when a provider sets
terminalContinuationGuard: true. Anthropic behavior is unchanged; every other provideris unchanged unless it explicitly opts in.
Changes
src/types.ts: add documented optionalterminalContinuationGuard?: booleantoOcxProviderConfig(passthrough config bool, same pattern asparallelToolCalls/promptCacheKey).src/server/responses/core.ts:terminalGuardEnablednow also true foropenai-chatwhenroute.provider.terminalContinuationGuard === true(still excludes combo attempts and routed compaction).src/server/responses/terminal-guard.ts:guardTerminalEventStreamrunsanalyzeTerminalTurnforopenai-chatas well asanthropic; all other adapters still short-circuit topass.tests/terminal-guard.test.ts: add coverage that anopenai-chatstream gets exactly one continuation, and that an unrelated adapter (openai-responses) is never guarded.Not included
No change to
analyzeTerminalTurn's heuristics themselves. If maintainers later gainconfidence in the cross-family false-continue rate, flipping openai-chat to default-on
would be a separate follow-up.
Testing
bun x tsc --noEmitclean.bun testforterminal-guard,terminal-guard-server,anthropic-tail-guard,anthropic-image-guard,bridge-terminal-singleness,responses-terminal-repair,openai-chat-hardening,openai-chat-eof,openai-chat-dangling-toolcalls,openai-chat-parallel-stream,parallel-tool-calls-optin,cl01-openai-chat-review-regressions:185 pass, 0 fail (includes the 2 new cases).
Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
All CI tests are green on my local testing.
I pushed my PR to the latest dev commit.
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.
Summary by CodeRabbit
New Features
Bug Fixes