Skip to content

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

Open
herikwebb wants to merge 1 commit into
plmbr:mainfrom
herikwebb:fix/claude-context-token-budget
Open

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

Conversation

@herikwebb

Copy link
Copy Markdown
Contributor

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. Manually verified in JupyterLab on a Claude-only setup: attaching a 34-line cell output (well over the old 80-token budget) via "Ask about this output" and asking the agent to echo a sentinel marker + a derived value returned the correct SENTINEL-7F3A / col_sum_A=1198 — i.e. the full output reached the model. On main the same attachment comes back NO CONTEXT.

…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).
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