Skip to content

fix(coding-agent): handle unusable model budget at startup - #1259

Open
Tinycute00 wants to merge 1 commit into
code-yeongyu:mainfrom
Tinycute00:fix/handle-unusable-model-budget-at-startup
Open

fix(coding-agent): handle unusable model budget at startup#1259
Tinycute00 wants to merge 1 commit into
code-yeongyu:mainfrom
Tinycute00:fix/handle-unusable-model-budget-at-startup

Conversation

@Tinycute00

@Tinycute00 Tinycute00 commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Problem Situation

Resuming a session whose context cannot fit the selected model's usable budget throws ModelUsabilityBudgetError during createAgentSessionRuntime. Because the startup path has no handler around that call, the error reaches the top-level await main() as an uncaught exception. A real 3881-message OmO session reproduced this as a raw stack trace, Node.js v24.18.0 banner, and immediate process exit before the TUI could render a useful error.

Reproduction Logs

Fresh source reproduction: node --import tsx packages/coding-agent/src/cli.ts --session-dir /tmp/senpi-repro/sessions --session 0197f6e4-4cf9-7f44-a2d8-f8f7f49ee9d4 --provider faux-tiny --model tiny-ctx -p continue, using a 16000-token model fixture and an oversized persisted session. Before the fix it emitted ModelUsabilityBudgetError with the full stack through main.ts:1116, sdk.ts:522, and agent-session.ts:4552, followed by Node.js v24.18.0. The same failure was reproduced against the user's real 3881-message session with omo-ai beta.31.

Approach

Import the existing ModelUsabilityBudgetError type and wrap only the createAgentSessionRuntime startup call in main.ts. The handler prints the error's existing actionable message with the established chalk.red Error: prefix and exits with status 1. Other errors are rethrown unchanged. Add the required src/changes.md entry and a real CLI subprocess regression test that asserts the crash signature is absent.

Why I Am Confident

The failing path was reproduced in a fresh clone at the exact source call chain, then the identical command passed after the change with one clean error line, exit 1, no stack trace, and no Node.js crash banner. A mutation proof reverted main.ts to the pre-fix version and made the new test fail on the exact uncaught stack trace; restoring the fix made it pass. Built dist/cli.js was also driven directly and showed the same clean behavior.

Risks

Low. The change only catches the specific typed startup budget error at the existing CLI boundary; unrelated exceptions retain the prior behavior. Models with sufficient context continue through normal startup. The test uses a bounded child-process timeout and cleans its isolated fixture directory.

User-Visible Behavior Changes

When a session is too large for the selected model, senpi now exits orderly with the precise shortfall and the existing compact/revalidate/retry guidance instead of terminating with an uncaught exception and raw Node.js stack trace. Successful sessions and other startup errors are unchanged.

Verification

  • RED mutation proof: with the startup catch removed, the regression test failed because output contained the exact uncaught ModelUsabilityBudgetError stack and Node.js v24.18.0 banner.
  • GREEN focused suite: 4 test files passed, 19/19 tests passed, including the new startup-crash regression and all existing model-usability tests.
  • bun run check components passed: Biome checked 3459 files with no fixes, pinned-deps, TS-import, shrinkwrap, install-lock, Claude SDK platform lock, and tsc --noEmit were clean; browser smoke exited 0.
  • Built CLI manual QA: bun run build succeeded; dist/cli.js with the oversized session exited 1 with one clean Error line and zero Node.js/stack-signature matches; --help exited 0; a roomy model passed session creation and --list-tips exited 0.

This PR was debugged, implemented, and created with LazyCodex.
Tag: lazycodex-generated


Summary by cubic

Fixes a startup crash when resuming a session too large for the selected model's context window. Previously ModelUsabilityBudgetError escaped as an uncaught exception, printing a raw stack trace and Node.js crash banner before exiting; now the CLI prints the error's actionable message and exits with status 1.

  • Catches only ModelUsabilityBudgetError around the createAgentSessionRuntime startup call in main.ts; all other errors are rethrown unchanged.
  • Adds a regression test that spawns the real CLI with an oversized persisted session and a tiny-context model provider, asserting the crash signature does not appear.
  • Adds a changes.md entry describing the fix.

Written for commit a191a56. Summary will update on new commits.

Review in cubic

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review Completed 2026-09-01T12:38:14.726281Z a191a56 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

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.

1 participant