Skip to content

fix(context): resolve context windows per provider/model across status and run accounting#27439

Closed
paul-tian wants to merge 1 commit intoopenclaw:mainfrom
paul-tian:pr/context-window
Closed

fix(context): resolve context windows per provider/model across status and run accounting#27439
paul-tian wants to merge 1 commit intoopenclaw:mainfrom
paul-tian:pr/context-window

Conversation

@paul-tian
Copy link
Copy Markdown

@paul-tian paul-tian commented Feb 26, 2026

Summary

Describe the problem and fix in 2–5 bullets:

  • Problem: Currently the /status is showing context window based on model only
  • Why it matters: same model from different providers may have different ctx window limit
  • What changed: now the ctx window will calculate base on the chosen provider/model
  • What did NOT change (scope boundary): other parts

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

User-visible / Behavior Changes

List user-visible changes (including defaults/config). /status correctly shows the ctx window limit base on chosen model
If none, write None.

Security Impact (required)

  • New permissions/capabilities? (Yes/No) No
  • Secrets/tokens handling changed? (Yes/No) No
  • New/changed network calls? (Yes/No) No
  • Command/tool execution surface changed? (Yes/No) No
  • Data access scope changed? (Yes/No) No
  • If any Yes, explain risk + mitigation:

Repro + Verification

Environment

  • OS: macOS 26.3
  • Runtime/container: direct deployment
  • Model/provider: openai/gpt-5.3-codex and openai-codex/gpt-5.3-codex
  • Integration/channel (if any): Telegram
  • Relevant config (redacted):

Steps

  1. Switch between model openai/gpt-5.3-codex and openai-codex/gpt-5.3-codex
  2. check ctx window using /status

Expected

  • the ctx window update correspondingly

Actual

  • the ctx window update correspondingly

Evidence

Attach at least one:

  • Failing test/log before + passing after
  • Trace/log snippets
  • Screenshot/recording
  • Perf numbers (if relevant)

api
oauth

Human Verification (required)

What you personally verified (not just CI), and how:

  • Verified scenarios: direct deployment, Telegram channel
  • Edge cases checked: N/A
  • What you did not verify: everything else

Compatibility / Migration

  • Backward compatible? (Yes/No) Yes
  • Config/env changes? (Yes/No) No
  • Migration needed? (Yes/No) No
  • If yes, exact upgrade steps:

Failure Recovery (if this breaks)

  • How to disable/revert this change quickly:
  • Files/config to restore:
  • Known bad symptoms reviewers should watch for:

Risks and Mitigations

List only real risks for this PR. Add/remove entries as needed. If none, write None.

  • Risk: None

@openclaw-barnacle openclaw-barnacle bot added gateway Gateway runtime agents Agent runtime and tooling size: M labels Feb 26, 2026
@paul-tian paul-tian marked this pull request as ready for review February 26, 2026 11:18
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Feb 26, 2026

Greptile Summary

This PR correctly implements provider-scoped context window resolution, fixing the issue where /status showed incorrect context windows when the same model was available from different providers with different limits.

  • Core change: Added provider-aware cache keys (provider/model) alongside legacy keys (just model) in src/agents/context.ts
  • Lookup strategy: Prioritizes provider-scoped lookups first, falls back to legacy keys for backward compatibility
  • Fail-safe behavior: When multiple providers expose the same model ID, keeps the smaller window for legacy lookups to prevent token overestimation
  • Comprehensive update: All call sites (agent-runner.ts, directive-handling.persist.ts, followup-runner.ts, status.ts, run.ts, session-utils.ts) now pass provider information to resolveContextTokensForModel()
  • Bonus fix: Corrected followup-runner.ts:241 to persist the actual providerUsed instead of incorrectly passing fallbackProvider
  • Status refresh: The /status command now re-resolves context tokens after parsing transcript metadata, ensuring accurate display when provider/model are updated from logs

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is straightforward and well-structured. All changes maintain backward compatibility through dual-key lookups (scoped and legacy), edge cases are handled properly (empty strings, missing providers), and the test mock is updated. The code includes proper normalization, fail-safe min logic for collisions, and a bonus bug fix. No logical errors or potential runtime issues identified.
  • No files require special attention

Last reviewed commit: 5eb5cd1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant