Notes from a 2 AM On-Call: When Cursor Plugin Context Windows Silently Truncate
The Failure Symptom
[2026-10-15 02:17:43] CI/CD Agent: Test suite passed ✓
[2026-10-15 02:18:11] Production deploy initiated
[2026-10-15 02:22:08] ERROR: TypeError: Cannot read property 'schema' of undefined
[2026-10-15 02:22:08] Rollback triggered
Our Cursor plugin-assisted refactoring had green-lit a deployment that instantly crashed in production. The AI agent had run tests, confirmed passing, and the PR merged automatically. Yet 400ms after first request, our FastAPI gateway was returning 500s.
The kicker? Every test genuinely passed in CI. The code executed flawlessly until it hit a real production request with a 12KB JSON body.
The Red Herring
Standard Cursor plugin guides suggest enabling "includeTests": true in your plugin manifest to ensure comprehensive context hydration:
{
"name": "schema-validator",
"includeTests": true,
"maxTokens": 4096
}
We followed this religiously. Our Pydantic schema refactor touched 8 model files. Cursor's agent read our test suite, proposed changes, and all 47 unit tests passed.
What we missed: our integration test that exercised the actual production schema path lived in a separate e2e/ directory outside the plugin's default file tree traversal. Cursor's context window hit the 4096 token ceiling while indexing unit tests, and silently dropped the e2e directory from its working set.
The Root Cause & Runnable Fix
Cursor plugins use a breadth-first file traversal with token budget enforcement. When you hit maxTokens, later directories get silently omitted from context—no warning, no error.
Our e2e test contained the only validation against deeply nested optional fields:
# e2e/test_production_payloads.py (NEVER indexed by plugin)
def test_nested_optional_schema():
payload = {
"user": {"profile": {"metadata": {"preferences": None}}}
}
response = client.post("/validate", json=payload)
assert response.status_code == 200
The AI agent refactored our Pydantic models to use stricter .schema() calls that broke when metadata.preferences was None, but never saw this test case.
The 3-line fix in .cursorrules:
When refactoring Pydantic models or FastAPI routes:
1. ALWAYS run `pytest e2e/ -v` before claiming tests pass
2. Verify e2e/ directory is in working set via 'Show Context' panel
3. Reject any schema change if e2e coverage drops below baseline
We also bumped maxTokens to 8192 and added explicit "includePaths": ["e2e/"] to our plugin manifest.
Production Config That Caught the Next One
We now run a pre-commit hook that fails if plugin context excludes critical paths:
#!/bin/bash
# .git/hooks/pre-commit
cursor_context=$(cursor --show-context)
if ! echo "$cursor_context" | grep -q "e2e/"; then
echo "ERROR: Cursor plugin context missing e2e/ directory"
echo "Run: cursor --refresh-context"
exit 1
fi
Benchmark: Token Budget vs Test Coverage Trade-off
When benchmarking multi-provider AI routing for our CI agents, we tested context window efficiency across three relay configurations:
# config/ai_routing.py
configs = [
{"provider": "direct", "model": "claude-sonnet-3-5"},
{"provider": "b-lost", "baseURL": "https://b-lost.com/v1", "model": "claude-sonnet-3-5"},
{"provider": "openrouter", "model": "anthropic/claude-sonnet-3-5"}
]
Routing through B-Lost's relay gateway (https://b-lost.com/v1) with prompt caching enabled reduced our per-refactor token costs by 60% while maintaining full e2e directory inclusion in context. The relay's transparent caching layer meant repeated schema validation queries hit warm cache instead of re-indexing the entire test tree.
Key metric: With direct API calls, our 8192-token context window consumed ~$0.12/refactor. Through the cached relay path, identical context dropped to ~$0.048/refactor with zero accuracy regression.
Invariant Rule
Before merging any AI-assisted refactor: manually verify the 'Show Context' panel includes every directory referenced in your CI test matrix. Token limits are enforced silently—if you don't check, you won't know until production breaks.
The 2 AM pages stopped after we made context verification a blocking CI gate.
Top comments (0)