Skip to content

[WRONG BRANCH] feat(terminal-guard): opt-in no-tool-call continuation guard for openai-chat providers - #1659

Closed
TooSpace wants to merge 1 commit into
lidge-jun:mainfrom
TooSpace:feat/openai-chat-terminal-continuation-guard
Closed

[WRONG BRANCH] feat(terminal-guard): opt-in no-tool-call continuation guard for openai-chat providers#1659
TooSpace wants to merge 1 commit into
lidge-jun:mainfrom
TooSpace:feat/openai-chat-terminal-continuation-guard

Conversation

@TooSpace

@TooSpace TooSpace commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

What

Extend the no-tool-call terminal continuation guard from the anthropic adapter to
openai-chat routed models, gated behind a new per-provider opt-in flag
terminalContinuationGuard (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-chat hit the exact same premature-completion pattern and
stop mid-work, because they never reach analyzeTerminalTurn.

Design / why opt-in

analyzeTerminalTurn's suspicious-no-tool-stop heuristic (the ACTIONABLE_REQUEST_RE /
PLAN_OR_COMPLETION_RE / WAITING_FOR_USER_RE regexes) was tuned on Anthropic turns.
Its false-continue rate on other model families and non-English output is not yet
characterized. The openai-chat adapter is shared by many registry providers, so turning
the 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 provider
is unchanged unless it explicitly opts in.

Changes

  • src/types.ts: add documented optional terminalContinuationGuard?: boolean to OcxProviderConfig (passthrough config bool, same pattern as parallelToolCalls / promptCacheKey).
  • src/server/responses/core.ts: terminalGuardEnabled now also true for openai-chat when route.provider.terminalContinuationGuard === true (still excludes combo attempts and routed compaction).
  • src/server/responses/terminal-guard.ts: guardTerminalEventStream runs analyzeTerminalTurn for openai-chat as well as anthropic; all other adapters still short-circuit to pass.
  • tests/terminal-guard.test.ts: add coverage that an openai-chat stream 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 gain
confidence in the cross-family false-continue rate, flipping openai-chat to default-on
would be a separate follow-up.

Testing

  • bun x tsc --noEmit clean.
  • bun test for terminal-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

    • Added an optional terminal continuation guard for supported chat providers.
    • The guard can limit repeated no-tool-call continuations and ensure clean completion events.
    • Anthropic-based responses now receive terminal guard analysis automatically.
    • OpenAI chat responses support the guard when explicitly enabled.
  • Bug Fixes

    • Improved handling of assistant response boundaries and final completion signals.
    • Other response modes remain unaffected unless specifically supported or enabled.

…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
@github-actions

Copy link
Copy Markdown
Contributor

Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the enhancement New feature or request label Aug 14, 2026
@github-actions github-actions Bot changed the title feat(terminal-guard): opt-in no-tool-call continuation guard for openai-chat providers [WRONG BRANCH] feat(terminal-guard): opt-in no-tool-call continuation guard for openai-chat providers Aug 14, 2026
@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

⏳ DRAFT

  • wrong target branch (main); retarget to dev.

What to do

  • Retarget this PR to dev — all contributions go to dev.
  • Tick all four boxes in the PR description once you're done (currently 0/4).

Review readiness checklist

  • ⬜ 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.

0/4 boxes ticked.

Its title has been prefixed with [WRONG BRANCH].
This pull request was already a draft. Its draft status will be preserved after every issue above is resolved.
@TooSpace Tick the boxes once your local CI is green, your branch is on the latest dev commit, and every correct Codex and CodeRabbit finding is resolved.

@github-actions
github-actions Bot marked this pull request as draft August 14, 2026 03:09
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: ddb1e566-e01b-4686-a35b-502f245d29df

📥 Commits

Reviewing files that changed from the base of the PR and between 1a937d8 and 64c1121.

📒 Files selected for processing (4)
  • src/server/responses/core.ts
  • src/server/responses/terminal-guard.ts
  • src/types.ts
  • tests/terminal-guard.test.ts

📝 Walkthrough

Walkthrough

The terminal continuation guard now supports opted-in openai-chat routes. Anthropic behavior remains enabled, while combo attempts, routed compaction, and openai-responses remain excluded.

Changes

Terminal guard extension

Layer / File(s) Summary
Guard configuration and eligibility
src/types.ts, src/server/responses/core.ts, src/server/responses/terminal-guard.ts
Adds the optional terminalContinuationGuard provider flag. Enables terminal analysis and bounded continuation for configured openai-chat routes while retaining existing exclusions.
Guard behavior validation
tests/terminal-guard.test.ts
Verifies one openai-chat continuation, assistant-boundary emission, and one final done event. Confirms openai-responses remains unguarded.

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

Merge Risk: ⚪ Minimal · up to 64c11

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
Loading

Possibly related PRs

Suggested labels: review-ready

Suggested reviewers: ingwannu, lidge-jun, wibias

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the opt-in continuation guard for openai-chat providers, which is the primary change.
Linked Issues check ✅ Passed The PR addresses issue #1651 by adding provider opt-in support and applying the existing bounded guard to openai-chat streams.
Out of Scope Changes check ✅ Passed The changes are limited to guard configuration, adapter eligibility, terminal analysis, and focused tests related to issue #1651.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

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

@TooSpace

Copy link
Copy Markdown
Contributor Author

Reopening against dev per enforce-pr-target (this repo takes all contributions on dev, not main). Superseded by a dev-targeted PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: extend the no-tool-call terminal continuation guard beyond the anthropic adapter (openai-chat routed models stop early)

1 participant