Skip to content

Cap /reflect effective-token totals at configured maxEffectiveTokens#3208

Merged
lpcox merged 3 commits into
mainfrom
copilot/fix-max-effective-tokens
May 15, 2026
Merged

Cap /reflect effective-token totals at configured maxEffectiveTokens#3208
lpcox merged 3 commits into
mainfrom
copilot/fix-max-effective-tokens

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 15, 2026

Bug Fix

/reflect could report effective_tokens.total_effective_tokens above the configured budget (e.g., ~46M with a 25M max), which made the reported budget state look inconsistent. The issue was in reflect-state presentation, not in request-blocking enforcement.

  • Reflect-state clamping

    • Updated effective-token reflect output to cap displayed totals at max_effective_tokens.
    • remaining_effective_tokens and percent_used are now derived from the clamped value, so reported usage cannot exceed 100%.
  • Enforcement behavior preserved

    • Kept internal over-budget tracking unchanged for guard/block decisions.
    • Limit enforcement still uses the true accumulated total.
  • Focused boundary coverage

    • Added guard-level tests for:
      • below-max behavior (no clamp),
      • exact-max behavior (100%),
      • above-max behavior (reflected values clamp to max).
const reflectedTotal = Math.min(state.totalEffectiveTokens, config.max);
return {
  max_effective_tokens: config.max,
  total_effective_tokens: reflectedTotal,
  remaining_effective_tokens: Math.max(0, config.max - reflectedTotal),
  percent_used: Math.round((reflectedTotal / config.max) * 10000) / 100,
};

Copilot AI linked an issue May 15, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix max-effective-tokens value to default 25M Cap /reflect effective-token totals at configured maxEffectiveTokens May 15, 2026
Copilot AI requested a review from lpcox May 15, 2026 13:46
Copilot finished work on behalf of lpcox May 15, 2026 13:46
@lpcox lpcox marked this pull request as ready for review May 15, 2026 13:53
@lpcox lpcox requested a review from Mossaka as a code owner May 15, 2026 13:53
Copilot AI review requested due to automatic review settings May 15, 2026 13:53
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the API proxy effective-token guard so /reflect reports budget usage capped at the configured maximum while preserving the true internal total for enforcement.

Changes:

  • Clamps reflected total_effective_tokens to max_effective_tokens.
  • Derives reflected remaining budget and percent used from the clamped value.
  • Adds focused guard tests for below, exact, and over-budget reflect behavior.
Show a summary per file
File Description
containers/api-proxy/guards/effective-token-guard.js Caps effective-token values returned for reflect-state presentation.
containers/api-proxy/guards/effective-token-guard.test.js Adds tests covering reflected budget clamping boundaries.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

Test Result
GitHub API ❌ FAIL
Playwright ✅ PASS
File verify ✅ PASS

Overall: PARTIAL (2/3 tests)

Notes:

  • GitHub API failed due to gh CLI authentication not being configured (expected per safe-outputs limitations)
  • Playwright successfully navigated to https://github.com and verified title contains 'GitHub'
  • Smoke test marker file exists with expected content

💥 [THE END] — Illustrated by Smoke Claude

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Offline) Mode

Test Result
1. GitHub MCP connectivity ❌ (401 Bad credentials)
2. GitHub.com HTTP ✅ HTTP 200
3. File write/read ❌ (pre-step outputs not substituted)
4. BYOK inference (this response)

Running in BYOK offline mode (COPILOT_OFFLINE=true) via api-proxy → api.githubcopilot.com.

Overall: FAIL — GitHub MCP auth and pre-step smoke data unavailable.

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions
Copy link
Copy Markdown
Contributor

refactor: [Export Audit] Remove test-only re-exports from barrel modules
feat: auto-forward OTEL_* env vars with one-shot token protection for headers
GitHub PR review: ✅
safeinputs-gh: ❌
Playwright: ✅
Tavily: ❌
File/Bash: ✅ | Discussion: ✅ | Build: ✅
Overall status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions
Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

Test Status
GitHub MCP connectivity ❌ (401 Bad credentials)
GitHub.com HTTP connectivity ❌ (template vars not expanded)
File write/read ❌ (template vars not expanded)

Overall: FAIL

The workflow template variables (${{ steps.smoke-data.outputs.* }}) were not expanded before reaching the agent, indicating a workflow configuration issue rather than an engine failure.

📰 BREAKING: Report filed by Smoke Copilot

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

  • GitHub MCP Testing: ❌ (Tools not found)
  • GitHub.com Connectivity: ❌ (Status 000/SSL error)
  • File Writing: ✅
  • Bash Tool Testing: ✅

Overall Status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@github-actions
Copy link
Copy Markdown
Contributor

Chroot Smoke Test Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.15.0 v20.20.2
Go go1.22.12 go1.22.12

Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot.

Tested by Smoke Chroot

@github-actions
Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color passed ✅ PASS
Go env passed ✅ PASS
Go uuid passed ✅ PASS
Java gson N/A ❌ FAIL
Java caffeine N/A ❌ FAIL
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 0 tests ✅ PASS
Rust zoxide 0 tests ✅ PASS

Overall: 7/8 ecosystems passed — ❌ FAIL


❌ Failure Details

Java (gson, caffeine) — Both projects failed with:

[ERROR] Could not create local repository at /home/runner/.m2/repository

The /home/runner/.m2 directory is owned by root in this environment, preventing Maven from creating the local repository subdirectory (permission denied). This is an environment-level permission issue, not a code issue with the test projects themselves.

Generated by Build Test Suite for issue #3208 · ● 3.8M ·

@github-actions
Copy link
Copy Markdown
Contributor

Smoke Test Results

  • Redis PING: ❌ (no response / timeout)
  • PostgreSQL pg_isready: ❌ (no response)
  • PostgreSQL SELECT 1: ❌ (no response / timeout)

Overall: FAILhost.docker.internal is unreachable from this runner environment. Service containers are not accessible.

🔌 Service connectivity validated by Smoke Services

@lpcox
Copy link
Copy Markdown
Collaborator

lpcox commented May 15, 2026

@copilot address review feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 15, 2026

@copilot address review feedback

I don’t see any actionable reviewer comments on this PR to address yet. Please point me to the specific feedback (comment link or details), and I’ll apply the requested changes right away.

Copilot finished work on behalf of lpcox May 15, 2026 14:35
@lpcox lpcox merged commit ff0e5ef into main May 15, 2026
66 of 78 checks passed
@lpcox lpcox deleted the copilot/fix-max-effective-tokens branch May 15, 2026 14:49
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.

Max-effective-tokens seems to be off

3 participants