Skip to content

fix(context): avoid noisy metadata fallback errors#1544

Merged
kevincodex1 merged 4 commits into
Gitlawb:mainfrom
chioarub:codex/context-warning-dedupe
Jun 8, 2026
Merged

fix(context): avoid noisy metadata fallback errors#1544
kevincodex1 merged 4 commits into
Gitlawb:mainfrom
chioarub:codex/context-warning-dedupe

Conversation

@chioarub

@chioarub chioarub commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Summary

  • move unknown integration model context-window diagnostics from console.error to debug logging
  • dedupe the fallback warning per route/model
  • keep the existing fallback context window behavior unchanged
  • add regression coverage for warning dedupe and no terminal error output

Impact

  • User-facing: unknown OpenAI-compatible model metadata fallback no longer produces repeated terminal error noise during normal operation.
  • Developer/maintainer: debug logs still capture one warning per route/model so missing integration metadata remains discoverable without polluting stderr.
  • Behavior: context-window fallback remains unchanged at the configured OpenAI-compatible fallback size.

Testing

  • bun test src/utils/context.test.ts
  • env -u CLAUDE_CODE_USE_OPENAI -u OPENAI_BASE_URL -u OPENAI_MODEL -u OPENAI_API_KEY bun test src/integrations/runtimeMetadata.test.ts src/utils/context.test.ts src/services/compact/autoCompact.test.ts

Summary by CodeRabbit

  • Bug Fixes

    • Reduced noisy error output for unknown models by replacing repeated errors with a single deduplicated warning at the warn level, and ensuring the intended fallback context size is returned when model metadata is missing.
  • Tests

    • Added a test confirming the fallback behavior for unknown models, verifying no console errors and exactly one warn-level debug message.

@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Worried about impact? Review this PR in Change Stack to explore blast radius before you approve or request changes.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 9c273af7-c4bb-4f9f-a192-94538cdbe801

📥 Commits

Reviewing files that changed from the base of the PR and between d87acbd and b3369fb.

📒 Files selected for processing (1)
  • src/utils/context.test.ts
📜 Recent review details
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: smoke-and-tests
🧰 Additional context used
📓 Path-based instructions (3)
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/utils/context.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/utils/context.test.ts
**

⚙️ CodeRabbit configuration file

**: # Contributing to OpenClaude

Thanks for contributing.

OpenClaude is a fast-moving open-source coding-agent CLI with support for multiple providers, local backends, MCP, and a terminal-first workflow. The best contributions here are focused, well-tested, and easy to review.

Before You Start

  • Search existing issues and discussions before opening a new thread.
  • Check open pull requests for work that overlaps with your contribution. If a PR already exists that addresses the same change, open an issue or discussion first to align on direction — duplicate PRs may be closed without review.
  • Use issues for confirmed bugs and actionable feature work.
  • Use discussions for setup help, ideas, and general community conversation.
  • For larger changes, open an issue first so the scope is clear before implementation.
  • For security reports, follow SECURITY.md.

Pull Requests

Every PR needs a reason. Your PR description must include:

  • what changed and why
  • the user or developer impact
  • the exact checks you ran
  • a linked issue when one exists, using Fixes fix: skip assertMinVersion for third-party providers #123, `Closes `#123, or another clear link
  • screenshots when the PR touches UI, terminal presentation, or the VS Code extension
  • which provider path was tested when the PR changes provider behavior

The PR author is responsible for ensuring their PR is merge-ready. PRs with merge conflicts will not be reviewed or approved until the conflicts are resolved.

Issues are the recommended starting point for anything non-trivial — opening one first helps avoid wasted effort if the change is out of scope or already being worked on. Small fixes, doc corrections, and obvious improvements can stand on their own without a linked issue, as long as the PR description explains the intent.

What Gets Closed Without Review

PRs may be closed without review...

Files:

  • src/utils/context.test.ts
🔇 Additional comments (2)
src/utils/context.test.ts (2)

1-1: LGTM!


436-468: LGTM!


📝 Walkthrough

Walkthrough

This PR replaces unconditional console.error logging with a deduplicated warning helper that logs one warn-level message per (routeId, model) via logForDebugging; a module Set tracks warned keys. getContextWindowForModel now calls the helper before returning the OPENAI_FALLBACK_CONTEXT_WINDOW. Tests assert the 128_000 fallback is returned without console.error and that a single warn is emitted.

Changes

Deduplicated unknown model warnings

Layer / File(s) Summary
Deduplication infrastructure and warning helper
src/utils/context.ts
Imports logForDebugging, adds module-scoped Set to track warned (routeId, model) pairs, and implements warnUnknownIntegrationRuntimeLimits(model) to emit one warn-level debug log per unique key.
Integration into context window fallback
src/utils/context.ts
Replaces the prior unconditional console.error in getContextWindowForModel with a call to warnUnknownIntegrationRuntimeLimits(model) before returning the OPENAI_FALLBACK_CONTEXT_WINDOW.
Test validation of non-error fallback
src/utils/context.test.ts
Adds mock import from bun:test and a test that mocks the debug logger and console.error, asserts repeated calls return the 128_000 fallback, and verifies exactly one warn-level debug invocation.

🎯 3 (Moderate) | ⏱️ ~22 minutes

🚥 Pre-merge checks | ✅ 6 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (6 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: moving diagnostics from console.error to debug logging to reduce stderr noise for unknown model metadata fallbacks.
Description check ✅ Passed The description covers the key requirements: what changed, why it changed, user/developer impact, and testing performed. All critical sections are present and well-explained.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Risk Surface Disclosed ✅ Passed PR refactors diagnostic logging (console.error → debug) with deduplication only. No sensitive areas touched: auth, routing, permissions, network, CI, or scripts untouched.
No Hidden Policy Change ✅ Passed Only logging changes detected: console.error → debug-level logForDebugging with per-route/model deduplication. No policy, trust-model, routing, telemetry, or permission changes found.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/utils/context.test.ts`:
- Around line 436-451: The test 'unknown openai-compatible model fallback does
not emit console errors' should be extended to assert the dedupe contract by
mocking the debug/warn logger used by the context fallback (replace or spy on
the module's debug logger) and then calling getContextWindowForModel twice with
the same (routeId, model) key, asserting that the warning/debug-warn was invoked
exactly once; restore the original logger after the assertions. Specifically,
locate uses of getContextWindowForModel in the test file and add a mock/spy for
the debug-warn function the module emits (the logger the code uses to emit the
fallback warning), call getContextWindowForModel('another-unknown-3p-model')
twice (same routeId), expect the mocked warn toHaveBeenCalledTimes(1), and
ensure cleanup by restoring the original logger.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a0039d63-6111-4ee1-a096-d61b2d3e21e9

📥 Commits

Reviewing files that changed from the base of the PR and between 1b7e550 and 81eb35c.

📒 Files selected for processing (2)
  • src/utils/context.test.ts
  • src/utils/context.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,js,jsx,py}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Follow the existing code style in the touched files and prefer small, readable changes over broad rewrites

Files:

  • src/utils/context.ts
  • src/utils/context.test.ts
**/*

⚙️ CodeRabbit configuration file

**/*: Apply the OpenClaude maintainer review rubric from AGENTS.md. Review the current diff, not stale discussion context. Separate real blockers from suggestions. Do not request changes for vague style churn. Treat approval as merge-ready from CodeRabbit's side, pending required human review and GitHub Checks. If checks are failing or unavailable, say so clearly instead of implying the PR is fully ready.

Files:

  • src/utils/context.ts
  • src/utils/context.test.ts
**

⚙️ CodeRabbit configuration file

**: # Contributing to OpenClaude

Thanks for contributing.

OpenClaude is a fast-moving open-source coding-agent CLI with support for multiple providers, local backends, MCP, and a terminal-first workflow. The best contributions here are focused, well-tested, and easy to review.

Before You Start

  • Search existing issues and discussions before opening a new thread.
  • Check open pull requests for work that overlaps with your contribution. If a PR already exists that addresses the same change, open an issue or discussion first to align on direction — duplicate PRs may be closed without review.
  • Use issues for confirmed bugs and actionable feature work.
  • Use discussions for setup help, ideas, and general community conversation.
  • For larger changes, open an issue first so the scope is clear before implementation.
  • For security reports, follow SECURITY.md.

Pull Requests

Every PR needs a reason. Your PR description must include:

  • what changed and why
  • the user or developer impact
  • the exact checks you ran
  • a linked issue when one exists, using Fixes #123, `Closes `#123, or another clear link
  • screenshots when the PR touches UI, terminal presentation, or the VS Code extension
  • which provider path was tested when the PR changes provider behavior

The PR author is responsible for ensuring their PR is merge-ready. PRs with merge conflicts will not be reviewed or approved until the conflicts are resolved.

Issues are the recommended starting point for anything non-trivial — opening one first helps avoid wasted effort if the change is out of scope or already being worked on. Small fixes, doc corrections, and obvious improvements can stand on their own without a linked issue, as long as the PR description explains the intent.

What Gets Closed Without Review

PRs may be closed without review...

Files:

  • src/utils/context.ts
  • src/utils/context.test.ts
**/*.test.{ts,js}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Add or update tests when the change affects behavior

Files:

  • src/utils/context.test.ts
{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}

⚙️ CodeRabbit configuration file

{src/**/*.test.ts,src/**/*.test.tsx,tests/**,scripts/**/*.test.ts,vscode-extension/**/*.test.js}: Review tests for meaningful coverage of the changed behavior, isolation of global/env/config state, async cleanup, fake timers, provider profile leaks, and Windows-compatible assumptions. Block when risky runtime changes lack focused regression coverage or tests assert implementation details while missing the user-visible behavior.

Files:

  • src/utils/context.test.ts
🔇 Additional comments (1)
src/utils/context.ts (1)

4-4: LGTM!

Also applies to: 43-43, 83-95, 129-129

Comment thread src/utils/context.test.ts Outdated
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jun 5, 2026
@chioarub chioarub marked this pull request as ready for review June 5, 2026 10:33

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I found one issue that needs to be addressed before this is ready.

Findings

  • [P2] Type the debug logger mock before reading its call arguments
    src/utils/context.test.ts:466
    The new test declares logForDebugging as mock(() => {}), so Bun infers a zero-argument mock. The assertion then reads logForDebugging.mock.calls[0]?.[1], and bun run typecheck now reports TS2493/TS2769 on this added line because that tuple has no second argument. Please type the mock with the same parameters as logForDebugging or otherwise assert the options from a typed call tuple, so this regression test does not add a new touched-path type error.

@chioarub chioarub requested a review from jatmn June 6, 2026 00:18

@jatmn jatmn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@kevincodex1 kevincodex1 merged commit 12cbe92 into Gitlawb:main Jun 8, 2026
3 checks passed
@chioarub chioarub deleted the codex/context-warning-dedupe branch June 8, 2026 23:00
deagwon97 pushed a commit to deagwon97/openclaude that referenced this pull request Jun 11, 2026
* fix(context): avoid noisy metadata fallback errors

* test(context): cover metadata warning dedupe

* docs(context): explain metadata fallback warning

* test(context): type debug warning spy
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.

3 participants