Skip to content

fix(core): preserve incomplete no-tool foreground outcomes - #420

Merged
Phantivia merged 2 commits into
Pal-AI-Lab:mainfrom
jcs130:fix/foreground-incomplete-terminal-20261118
Nov 19, 2026
Merged

Phantivia merged 2 commits into
Pal-AI-Lab:mainfrom
jcs130:fix/foreground-incomplete-terminal-20261118

Conversation

@jcs130

@jcs130 jcs130 commented Nov 18, 2026

Copy link
Copy Markdown

When a foreground provider explicitly returns an incomplete response with no function calls, the main loop persists the output items, then records the round as completed. A Persona observing onTurnEnded gets identical information for a normal silent reply and a truncated reply.

Reproduction

An in-process provider returns a partial message with response.status=incomplete, incomplete_details.reason=max_output_tokens and zero function calls. On v0.2.16 the round trace says completed and the end hook receives no details. An entirely empty output reproduces the same outcome.

Change

The no-tool incomplete branch records an incomplete round and passes an optional context to the existing Persona and visible World hooks. It includes the original response ID and the exact provider reason, with null for an omitted reason. Native output records retain this reason alongside their existing response status. The batch ends once. Tool results and usage retain their original ownership. Existing zero-argument hooks remain valid.

Validation

The tests drive the foreground loop with partial text, empty incomplete output with no reason, a complete empty response, and an incomplete response that includes one complete tool call. They check the round log, both hooks, absence of an extra request, native evidence and single execution of the tool. Full v0.2.16 suite: 5,225 passed, 4 skipped. TypeScript checking passed.

Codex and others added 2 commits November 18, 2026 13:25
The foreground loop used the absence of a function call to report completion even when the provider explicitly returned an incomplete response. Notify hooks with the original response ID and reason and retain the reason on native output records. Existing calls keep their normal pairing and execution. Exercise silence, absent reasons, partial text and mixed tool output.
- IncompleteTurnContext 的判别字段按仓里的命名规则叫 kind;类型、字段和记录字段的注释改成中文,写参数何时出现。
- incomplete 只看 Response 的状态,带不带参数由 calls.length === 0 那一支决定:被丢弃的仿造保留帧调用不再让截断
  的一轮记成 completed。
- docs/personas.md、docs/worlds.md、docs/world-compatibility.md 补一句:一轮因回复截断而结束时,onTurnEnded 带一个
  说明原因的参数;src/core/README.md 那段挪到主循环一节的轮次规则之后,用仓里的词(工具调用、模型服务)。
- 测试:不是 incomplete 的轮断言钩子不带参数。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Phantivia
Phantivia merged commit 9609ddc into Pal-AI-Lab:main Nov 19, 2026
3 checks passed
@Phantivia

Copy link
Copy Markdown
Member

Thanks @jcs130, merged. Before merging we pushed one commit to your branch:

  • The discriminant of IncompleteTurnContext is kind instead of reason, following the naming rules in AGENTS.md. incompleteReason keeps its name.
  • The context is set whenever the response is incomplete, and passed when the round has no call left to execute, so the check matches the calls.length === 0 branch it feeds.
  • docs/personas.md, docs/worlds.md and docs/world-compatibility.md now say that onTurnEnded() gets a parameter describing the reason when a round ends because the reply was cut off. The paragraph in src/core/README.md moved after the round rules in the main-loop section.
  • In the tests, the rounds that are not incomplete assert that the hooks receive no argument.

We have seen the same case on a local model served by llama.cpp: one call spent the whole 8,192-token output limit on reasoning, the round ended with no tool call and no text, and the next wake had no way to tell the round had been cut off.

It ships with the next release.

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