pi-mono/packages/coding-agent/test
David Brailovsky 32850ef7c5
fix(coding-agent): resume after context-limited length stops (#7540)
* fix(coding-agent): resume after context-limited length stops

Treat length stops as context overflow when prompt usage is within 1% of
Pi's configured context window. Include cache-write tokens in that usage
and allow non-zero output because OpenAI may emit reasoning tokens before
returning an incomplete response.

After compaction, remove any retryable error or truncated-length assistant
message restored from persisted session history so the interrupted agent
turn can continue.

This is specifically for handling this case for openai models:
https://developers.openai.com/api/docs/guides/reasoning

> If the generated tokens reach the context window limit or the max_output_tokens value you’ve set, you’ll receive a response with a status of incomplete and incomplete_details with reason set to max_output_tokens. This might occur before any visible output tokens are produced, meaning you could incur costs for input and reasoning tokens without receiving a visible response.

This detection currently assumes the reported prompt usage is within 1% of
the context window configured in Pi. Its reliability therefore depends on
Pi's model contextWindow metadata matching the provider's effective limit.

Maybe we should consider treating OpenAI incomplete responses as requiring compaction
regardless of the local context-window estimate?

fixes #7020

* fix(coding-agent): recover truncated responses after compaction

Classify length stops by comparing provider-reported output usage with the model's intended output limit. Compact and retry once when generation ends below that limit, avoiding unreliable context-window estimates while preserving genuine max-output stops.

Normalize OpenAI Responses incomplete reasons so only max_output_tokens is treated as a length stop. Preserve qualified provider reasons for diagnostics, surface other reasons as errors, and use neutral truncation wording in the TUI.
2026-08-03 18:07:53 +02:00
..
client fix: make session authentication transport-specific (#7551) 2026-08-03 16:40:00 +03:00
fixtures fix(coding-agent): speed up external editor launch (#6903) 2026-07-22 15:49:01 +02:00
session-manager fix: complete extension usage accounting 2026-07-20 17:06:22 +02:00
suite fix(coding-agent): resume after context-limited length stops (#7540) 2026-08-03 18:07:53 +02:00
agent-session-auto-compaction-queue.test.ts fix(agent): restore streamFn extension compatibility 2026-07-21 18:37:07 +02:00
agent-session-branching.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
agent-session-compaction.test.ts fix(agent): restore streamFn extension compatibility 2026-07-21 18:37:07 +02:00
agent-session-concurrent.test.ts fix(agent): restore streamFn extension compatibility 2026-07-21 18:37:07 +02:00
agent-session-dynamic-provider.test.ts fix(agent): decouple agent streams from compat 2026-07-20 17:54:36 +02:00
agent-session-dynamic-tools.test.ts feat(coding-agent): expose session metadata to bash tools (#6967) 2026-07-22 20:15:02 +02:00
agent-session-retry.test.ts fix(agent): restore streamFn extension compatibility 2026-07-21 18:37:07 +02:00
agent-session-runtime-events.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
agent-session-stats.test.ts fix(agent): restore streamFn extension compatibility 2026-07-21 18:37:07 +02:00
agent-session-tree-navigation.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
ansi-utils.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
args.test.ts feat(coding-agent): add ui mode setting 2026-07-31 15:33:52 +02:00
assistant-message.test.ts fix(coding-agent): resume after context-limited length stops (#7540) 2026-08-03 18:07:53 +02:00
auth-storage.test.ts fix(coding-agent): avoid auth read lock contention 2026-07-31 13:23:08 +02:00
bash-close-hang-windows.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
bash-execution-width.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
block-images.test.ts fix(coding-agent): process BMP images from disk 2026-06-25 12:52:21 +02:00
branch-summary-extensions.test.ts add usage info to branch summary, compaction and tool result entries (#6671) 2026-07-20 16:41:43 +02:00
cache-stats.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
changelog.test.ts fix(coding-agent): fix changelog links 2026-06-08 20:31:20 +02:00
clipboard-image-bmp-conversion.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
clipboard-image.test.ts Fix native clipboard in bun release (#6418) 2026-07-08 11:20:24 +02:00
clipboard-native.test.ts fix(coding-agent): fall back to text clipboard paste 2026-07-10 21:46:15 +02:00
clipboard.test.ts fix(coding-agent): read clipboard text on Wayland 2026-07-31 18:10:28 +03:00
compaction-extensions-example.test.ts fix: custom-compaction through provider via new model runtime complete (#7325) 2026-07-31 10:54:26 +02:00
compaction-extensions.test.ts fix(agent): restore streamFn extension compatibility 2026-07-21 18:37:07 +02:00
compaction-serialization.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
compaction-summary-reasoning.test.ts fix(coding-agent): isolate summarization requests 2026-07-22 23:54:57 +02:00
compaction.test.ts fix(coding-agent): count custom messages in compaction budget 2026-07-09 12:46:03 +02:00
config-value-migration.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
config.test.ts fix(coding-agent): install checked pi update version 2026-06-21 14:46:07 +02:00
credential-print.test.ts feat: auth print (#7168) 2026-07-27 16:13:06 +02:00
custom-message.test.ts feat(coding-agent): expose output padding to custom renderers (#7045) 2026-07-25 08:29:34 +02:00
edit-tool-legacy-input.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
edit-tool-no-full-redraw.test.ts feat(tui): add alternate-screen renderer 2026-07-30 12:59:48 +02:00
experimental-cli-command.test.ts feat(coding-agent): compose experimental CLI commands 2026-08-02 11:50:56 +03:00
experimental-cli-resolution.test.ts feat(coding-agent): compose experimental CLI commands 2026-08-02 11:50:56 +03:00
experimental.test.ts feat(coding-agent): add experimental feature guard (#5547) 2026-06-09 13:23:07 +02:00
export-html-skill-block.test.ts fix(coding-agent): strip skill wrapper XML from HTML export user messages (#4234) 2026-05-06 18:06:37 +02:00
export-html-whitespace.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
export-html-xss.test.ts Fix HTML export URL sanitization 2026-06-02 16:32:18 +02:00
extensions-discovery.test.ts Markdown api (#7231) 2026-07-30 22:39:04 +02:00
extensions-input-event.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
extensions-runner.test.ts Markdown api (#7231) 2026-07-30 22:39:04 +02:00
external-editor.test.ts fix(coding-agent): speed up external editor launch (#6903) 2026-07-22 15:49:01 +02:00
file-mutation-queue.test.ts fix(coding-agent): use async operations in tools 2026-05-23 09:50:03 +02:00
first-time-setup-fork.test.ts fix(coding-agent): skip first-time setup for forks (#5627) 2026-06-11 21:36:26 +02:00
first-time-setup.test.ts feat(coding-agent): add experimental first-time setup flow (#5587) 2026-06-10 12:11:49 +02:00
footer-data-provider.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
footer-width.test.ts add usage info to branch summary, compaction and tool result entries (#6671) 2026-07-20 16:41:43 +02:00
format-resume-command.test.ts feat(coding-agent): print resume hint on interactive exit 2026-05-29 15:56:42 +08:00
frontmatter.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
git-merge-and-resolve-extension.test.ts fix(coding-agent): drain follow-ups queued during agent_end 2026-05-28 18:27:39 +10:00
git-ssh-url.test.ts fix(coding-agent): harden git package install paths 2026-06-02 18:20:35 +02:00
git-update.test.ts fix(coding-agent): run coding-agent tests offline by default (#7031) 2026-07-27 11:27:43 +02:00
http-dispatcher.test.ts fix(coding-agent): increase connection attempt timeout (#7435) 2026-08-02 09:26:23 +02:00
image-process.test.ts fix(coding-agent): process BMP images from disk 2026-06-25 12:52:21 +02:00
image-processing.test.ts fix(coding-agent): use async operations in tools 2026-05-23 09:50:03 +02:00
image-resize-callers.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
initial-message.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
input-transform-streaming-example.test.ts feat(coding-agent): expose streamingBehavior on InputEvent 2026-05-28 15:52:38 +10:00
interactive-mode-anthropic-warning.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
interactive-mode-clone-command.test.ts fix(coding-agent): preserve startup extension UI 2026-06-21 23:19:34 +02:00
interactive-mode-compaction.test.ts fix(coding-agent): preserve compaction queue behavior (#6730) 2026-07-17 09:09:01 +02:00
interactive-mode-import-command.test.ts fix(coding-agent): stabilize interactive status indicators 2026-06-29 16:53:39 +02:00
interactive-mode-startup-input.test.ts fix(coding-agent): buffer early input before prompt loop 2026-05-29 23:03:03 +08:00
interactive-mode-status.test.ts fix(tui): normalize source filenames 2026-08-01 14:38:13 +02:00
interactive-mode-suspend.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
interactive-tui.test.ts feat(coding-agent): switch UI modes at runtime (#7555) 2026-08-03 17:32:48 +02:00
keybindings-migration.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
llama-extension.test.ts fix(coding-agent): cache llama.cpp model catalog (#7072) 2026-07-25 08:27:05 +02:00
max-thinking.test.ts feat(ai): add max thinking level 2026-07-09 22:30:53 +02:00
model-registry.test.ts feat(ai): add Baseten provider 2026-08-03 14:33:21 +02:00
model-resolver.test.ts fix: --model collects authed providers (#7366) 2026-08-03 13:59:55 +02:00
model-runtime-auth-options.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
model-runtime-cloudflare-compat.test.ts fix(coding-agent): preserve auth header deletion markers (#7539) 2026-08-03 14:28:26 +02:00
model-runtime-modify-models-compat.test.ts feat(coding-agent): accept native extension providers 2026-07-17 10:58:48 +02:00
model-runtime-test-utils.ts fix(coding-agent): refresh model catalogs in picker 2026-07-15 12:35:29 +02:00
model-selector.test.ts fix(coding-agent): identify failed model catalogs 2026-08-03 08:43:30 +02:00
models-store.test.ts feat(coding-agent): expose dynamic provider refresh 2026-07-15 12:56:50 +02:00
oauth-selector.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
package-command-paths.test.ts fix(coding-agent): run coding-agent tests offline by default (#7031) 2026-07-27 11:27:43 +02:00
package-manager-ssh.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
package-manager.test.ts fix(coding-agent): clean up failed git installs (#7210) 2026-07-28 14:43:22 +02:00
path-utils.test.ts fix(coding-agent): Clean up Path Handling (#4873) 2026-05-22 11:25:15 +02:00
paths.test.ts fix(coding-agent): Clean up Path Handling (#4873) 2026-05-22 11:25:15 +02:00
pi-user-agent.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
plan-mode-extension.test.ts fix(coding-agent): fix plan-mode example 2026-06-21 22:10:17 +02:00
plan-mode-utils.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
print-mode.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
prompt-templates.test.ts fix(coding-agent): support all-argument prompt defaults closes #6695 2026-07-17 13:52:32 +02:00
radius.test.ts fix(coding-agent): run coding-agent tests offline by default (#7031) 2026-07-27 11:27:43 +02:00
remote-catalog-provider.test.ts feat(coding-agent): revalidate remote model catalogs with ETag 2026-07-25 12:26:19 +02:00
resolve-config-value.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
resource-loader.test.ts fix(coding-agent): show system prompt files in startup context (#7266) 2026-07-29 17:05:22 +02:00
restore-sandbox-env.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
rpc-client-clone.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
rpc-client-process-exit.test.ts fix(rpc): reject pending requests on child process exit 2026-05-25 00:40:07 +02:00
rpc-example.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
rpc-jsonl.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
rpc-prompt-response-semantics.test.ts fix(agent): restore streamFn extension compatibility 2026-07-21 18:37:07 +02:00
rpc.test.ts feat: get_available_thinking_levels rpc (#6865) 2026-07-20 16:29:10 +02:00
runtime-credentials.test.ts feat(coding-agent): replace model registry with model runtime 2026-07-14 17:48:45 +02:00
scrollbar-theme.test.ts feat(coding-agent): add scrollbar thumb theme color 2026-07-31 17:41:40 +02:00
sdk-codex-cache-probe-tool-loop.ts fix(coding-agent): show system prompt files in startup context (#7266) 2026-07-29 17:05:22 +02:00
sdk-openrouter-attribution.test.ts fix(agent): decouple agent streams from compat 2026-07-20 17:54:36 +02:00
sdk-session-manager.test.ts feat(coding-agent): expose session metadata to bash tools (#6967) 2026-07-22 20:15:02 +02:00
sdk-skills.test.ts fix(coding-agent): show system prompt files in startup context (#7266) 2026-07-29 17:05:22 +02:00
sdk-stream-options.test.ts fix(ai): make provider retries abortable (#6980) 2026-07-23 12:25:37 +02:00
session-cwd.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
session-file-invalid.test.ts fix(coding-agent): shorten invalid session error 2026-06-25 15:20:08 +02:00
session-id-readonly.test.ts fix(coding-agent): warn when session-id creates a session 2026-07-09 11:37:07 +02:00
session-info-modified-timestamp.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
session-selector-path-delete.test.ts fix(coding-agent): sort threaded sessions by latest activity in the subtree 2026-06-16 00:39:30 +04:00
session-selector-rename.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
session-selector-search.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
settings-manager-bug.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
settings-manager.test.ts feat(tui): add configurable fullscreen scrollbars 2026-07-31 17:17:02 +02:00
settings-selector.test.ts feat(tui): add configurable fullscreen scrollbars 2026-07-31 17:17:02 +02:00
skills.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
startup-session-name.test.ts Add startup session name flag 2026-05-29 11:40:58 +02:00
status-indicator.test.ts fix(coding-agent): stabilize interactive status indicators 2026-06-29 16:53:39 +02:00
stdout-cleanliness.test.ts fix(coding-agent): run coding-agent tests offline by default (#7031) 2026-07-27 11:27:43 +02:00
streaming-render-debug.ts feat(tui): add alternate-screen renderer 2026-07-30 12:59:48 +02:00
syntax-highlight.test.ts fix(coding-agent): restore diff code block highlighting 2026-05-28 00:49:27 +02:00
system-prompt.test.ts feat(coding-agent): expose session metadata to bash tools (#6967) 2026-07-22 20:15:02 +02:00
test-harness.test.ts feat(ai): expose pending stop reason while streaming (#7151) 2026-07-27 11:56:15 +02:00
test-harness.ts feat(ai): expose pending stop reason while streaming (#7151) 2026-07-27 11:56:15 +02:00
test-network-env.ts fix(coding-agent): run coding-agent tests offline by default (#7031) 2026-07-27 11:27:43 +02:00
test-theme-colors.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
theme-detection.test.ts feat(coding-agent): add automatic theme mode (#5874) 2026-06-18 17:13:47 +02:00
theme-export.test.ts chore: pin dependencies and use native TypeScript 2026-05-20 12:46:17 +02:00
theme-picker.test.ts fix(coding-agent): list themes by content name 2026-05-21 00:10:50 +04:00
tool-execution-component.test.ts feat(coding-agent): expose session metadata to bash tools (#6967) 2026-07-22 20:15:02 +02:00
tool-result-images.test.ts fix(coding-agent): resize images returned by tools (#7330) 2026-08-03 14:02:03 +02:00
tools.test.ts fix(coding-agent): process BMP images from disk 2026-06-25 12:52:21 +02:00
tree-selector.test.ts feat(coding-agent): add message copy shortcut 2026-07-10 21:35:53 +02:00
trigger-compact-extension.test.ts Revert "fix(coding-agent): build-check-test (#7206)" 2026-07-28 15:09:46 +02:00
truncate-to-width.test.ts chore: migrate pi packages to earendil works scope 2026-05-07 15:59:42 +02:00
trust-manager.test.ts fix(coding-agent): avoid project trust prompt for update (#5674) 2026-06-12 23:37:16 +02:00
trust-selector.test.ts feat(ui): Improved project approval settings 2026-06-09 13:25:54 +02:00
user-message.test.ts Markdown api (#7231) 2026-07-30 22:39:04 +02:00
utilities.ts fix(coding-agent): show system prompt files in startup context (#7266) 2026-07-29 17:05:22 +02:00
version-check.test.ts fix(coding-agent): run coding-agent tests offline by default (#7031) 2026-07-27 11:27:43 +02:00