Skip to content

fix(claude): derive context token budget from the Claude model in Claude Code mode#42

Closed
herikwebb wants to merge 1 commit into
mainfrom
fix/claude-context-token-budget
Closed

fix(claude): derive context token budget from the Claude model in Claude Code mode#42
herikwebb wants to merge 1 commit into
mainfrom
fix/claude-context-token-budget

Conversation

@herikwebb

Copy link
Copy Markdown
Owner

Problem

In Claude Code mode, ai_service_manager.chat_model reflects the user's most recent non-Claude provider selection and is None on a Claude-only setup. The attachment token budget in on_message fell through to the legacy 100-token floor (80 tokens after the 0.8 factor), which:

  • silently skipped cell-output attachments (their estimate always exceeds 80 tokens), and
  • dropped every attachment after the first via the remaining_token_budget <= 0 break.

Change

  • New _resolve_context_token_limit helper: in Claude Code mode the budget comes from the configured Claude model via model_info_from_id (200K-window fallback for unknown/default ids); other modes keep the existing behavior.
  • 6 regression tests, including an end-to-end on_message test proving a >80-token output context survives on a Claude-only setup.

Testing

Full Python suite passes (1298 tests).

…ude Code mode

In Claude Code mode ai_service_manager.chat_model reflects the user's most
recent non-Claude provider selection and is None on a Claude-only setup. The
attachment budget fell through to the legacy 100-token floor (80 tokens after
the 0.8 factor), which silently skipped cell-output context and dropped every
attachment after the first via the budget break in on_message.

Resolve the budget from the configured Claude model instead, via
model_info_from_id (200K-window fallback for unknown or default model ids).
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Automated PR Review

Model: gpt-5.5
Verdict: APPROVE

Changed files:

notebook_intelligence/extension.py
tests/test_websocket_handler_integration.py

Review result:

No automated findings were found in the changed code.

Residual risks: this review is based on the provided diff only; behavior still depends on model_info_from_id consistently returning a valid context_window and on nbi_config.claude_settings always being present in real runtime configurations.

@herikwebb herikwebb added the bug Something isn't working label Jul 5, 2026
@herikwebb

Copy link
Copy Markdown
Owner Author

Raised upstream as plmbr#390; closing this fork PR. Review history retained here.

@herikwebb herikwebb closed this Jul 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant