fix(coding-agent): handle unusable model budget at startup - #1259
Open
Tinycute00 wants to merge 1 commit into
Open
fix(coding-agent): handle unusable model budget at startup#1259Tinycute00 wants to merge 1 commit into
Tinycute00 wants to merge 1 commit into
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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
ModelUsabilityBudgetErrorescaped 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.ModelUsabilityBudgetErroraround thecreateAgentSessionRuntimestartup call inmain.ts; all other errors are rethrown unchanged.changes.mdentry describing the fix.Written for commit a191a56. Summary will update on new commits.