feat(health-score): raise context thresholds and update critical coaching [LCO-44] - #42
Conversation
…hing [LCO-44] HEALTHY_CEIL 50->70, DEGRADING_CEIL 80->90. Critical coaching now reads "Context nearly full. Start a new chat, or use Claude Projects for ongoing work." Update all hardcoded threshold values in audit, unit, and integration tests to match new constants.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughWalkthroughUpdated health-score context utilization thresholds: Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
tests/integration/agent-pipeline.test.ts (1)
203-206:⚠️ Potential issue | 🟡 MinorStale inline comment:
DEGRADING_CEILis 90, not 80.At
contextPct: 85, turnCount: 25, Rule 1 does not fire (85 < 90); the fixture is actually critical via Rule 2 (context ≥HEALTHY_CEILand turns >TURN_DEGRADING_CEIL). The assertion still passes, but the justification comment is wrong.Proposed fix
it('health agent returns critical', () => { - // contextPct(85) >= DEGRADING_CEIL(80) + // contextPct(85) >= HEALTHY_CEIL(70) && turnCount(25) > TURN_DEGRADING_CEIL(20) -> Rule 2 critical expect(health.level).toBe('critical'); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/integration/agent-pipeline.test.ts` around lines 203 - 206, The inline comment in the test "health agent returns critical" is incorrect: DEGRADING_CEIL is 90 not 80, so the current fixture (contextPct: 85, turnCount: 25) triggers Rule 2 rather than Rule 1. Update the comment to reflect the correct logic by stating that contextPct (85) < DEGRADING_CEIL (90) and the agent is critical because contextPct >= HEALTHY_CEIL and turnCount > TURN_DEGRADING_CEIL; reference the test identifier ('health agent returns critical') and the constants DEGRADING_CEIL, HEALTHY_CEIL, and TURN_DEGRADING_CEIL when making the clarification.lib/health-score.ts (1)
50-73:⚠️ Potential issue | 🟡 MinorStale threshold references in doc comments.
Two comments still reference the old thresholds, which will confuse future readers now that the constants have moved:
- Line 54: "Critical from context alone (>80%)" — should be 90%.
- Line 72: "past 20 turns with >50% context" — Rule 2 now fires at
HEALTHY_CEIL = 70, not 50.Proposed fix
- * A conversation can be Critical from context alone (>80%) or from - * a combination of moderate context + high turn count (the "attention - * valley" effect from context rot research). + * A conversation can be Critical from context alone (>=90%) or from + * a combination of moderate context + high turn count (the "attention + * valley" effect from context rot research). @@ // Rule 2: High context + many turns = Critical. - // The "attention valley": past 20 turns with >50% context, Claude's attention - // to mid-conversation details degrades measurably. + // The "attention valley": past 20 turns with >=70% context, Claude's attention + // to mid-conversation details degrades measurably.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/health-score.ts` around lines 50 - 73, Update the stale inline doc comments in computeHealthScore to match the current threshold constants: replace "Critical from context alone (>80%)" with the correct DEGRADING_CEIL value (90%) and update the "past 20 turns with >50% context" reference to reflect HEALTHY_CEIL (70%)/the current Rule 2 threshold; ensure the comments mention the DEGRADING_CEIL and HEALTHY_CEIL symbols so future readers link the prose to the actual constants used by the function.
🧹 Nitpick comments (1)
tests/unit/health-score.test.ts (1)
97-113: Test body does not match its description and contains a dead computation.This block was touched by the threshold update, so worth cleaning up while here:
hat line 98 is assigned but never asserted — it's Rule 1 critical and unused.- The test is titled "uses singular 'message' when only 1 message remaining" but the only assertion matches the plural
~0 messages, and even that runs onlyif (h2.level === 'degrading'), so the test can pass without asserting anything.Consider replacing with an input that deterministically produces
~1 messageunder Rule 4 and asserting unconditionally (e.g.contextPct: 89, growthRate: 11→remaining = round(11/11) = 1).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/health-score.test.ts` around lines 97 - 113, The test assigns an unused variable h and its body contradicts the title: it purports to check singular "message" but asserts "~0 messages" conditionally. Replace the setup to deterministically hit Rule 4 (remaining ≈ 1) by removing the unused h, call computeHealthScore with an input that yields remaining = 1 (e.g. contextPct and growthRate adjusted so (100 - contextPct)/growthRate rounds to 1), and then unconditionally assert that computeHealthScore(...).coaching matches the singular "message" form; update references to the input helper and computeHealthScore (and remove the conditional if (h2.level === 'degrading')) so the test always verifies the singular wording.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/audit/health-score-audit.test.ts`:
- Around line 17-19: Update the stale section header and describe label that
reference an 80% threshold to reflect the current 90% threshold: change the
comment line ("computeHealthScore: Rule 1 (context >= 80% = critical)") and the
describe title string ("computeHealthScore: Rule 1 (high context = critical)")
in tests/audit/health-score-audit.test.ts to mention 90% so they match the
updated assertions and avoid misleading docs.
---
Outside diff comments:
In `@lib/health-score.ts`:
- Around line 50-73: Update the stale inline doc comments in computeHealthScore
to match the current threshold constants: replace "Critical from context alone
(>80%)" with the correct DEGRADING_CEIL value (90%) and update the "past 20
turns with >50% context" reference to reflect HEALTHY_CEIL (70%)/the current
Rule 2 threshold; ensure the comments mention the DEGRADING_CEIL and
HEALTHY_CEIL symbols so future readers link the prose to the actual constants
used by the function.
In `@tests/integration/agent-pipeline.test.ts`:
- Around line 203-206: The inline comment in the test "health agent returns
critical" is incorrect: DEGRADING_CEIL is 90 not 80, so the current fixture
(contextPct: 85, turnCount: 25) triggers Rule 2 rather than Rule 1. Update the
comment to reflect the correct logic by stating that contextPct (85) <
DEGRADING_CEIL (90) and the agent is critical because contextPct >= HEALTHY_CEIL
and turnCount > TURN_DEGRADING_CEIL; reference the test identifier ('health
agent returns critical') and the constants DEGRADING_CEIL, HEALTHY_CEIL, and
TURN_DEGRADING_CEIL when making the clarification.
---
Nitpick comments:
In `@tests/unit/health-score.test.ts`:
- Around line 97-113: The test assigns an unused variable h and its body
contradicts the title: it purports to check singular "message" but asserts "~0
messages" conditionally. Replace the setup to deterministically hit Rule 4
(remaining ≈ 1) by removing the unused h, call computeHealthScore with an input
that yields remaining = 1 (e.g. contextPct and growthRate adjusted so (100 -
contextPct)/growthRate rounds to 1), and then unconditionally assert that
computeHealthScore(...).coaching matches the singular "message" form; update
references to the input helper and computeHealthScore (and remove the
conditional if (h2.level === 'degrading')) so the test always verifies the
singular wording.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: fbd63ccf-f884-4bed-b959-5e7ec850a134
📒 Files selected for processing (4)
lib/health-score.tstests/audit/health-score-audit.test.tstests/integration/agent-pipeline.test.tstests/unit/health-score.test.ts
…essage test [LCO-44]
Summary
Raises the health-score thresholds to better reflect real model degradation curves: degrading now starts at 70% context fill (was 50%) and critical at 90% (was 80%). Updates the critical coaching message to mention Claude Projects as an option alongside starting a new chat.
Type of Change
feat— New featureWhat Was Changed
lib/health-score.ts:HEALTHY_CEIL50 -> 70,DEGRADING_CEIL80 -> 90. Critical Rule 1 coaching updated to "Context nearly full. Start a new chat, or use Claude Projects for ongoing work."tests/unit/health-score.test.ts: Updated two hardcoded values that referenced old thresholds (contextPct: 55 -> 75 in rule-priority test; stale comment 80 -> 90).tests/audit/health-score-audit.test.ts: Updated all hardcoded threshold values and describe/test names to match new constants (80->90, 79.9->89.9, 50->70 in Rule 2/3 boundary tests).tests/integration/agent-pipeline.test.ts: Updated expectation for 55%-context fixture from degrading -> healthy (correct at new HEALTHY_CEIL=70). Added new degrading-boundary describe block at 75% context.How to Test
bun run compile— should exit cleanbun run test— 1452 tests, all passChecklist
bun run test)bun run compile)bun run build)feat:,fix:,refactor:,test:,chore:)Related Issues
Closes LCO-44
Notes for Reviewer
The old thresholds (50/80) were overly conservative and flagged healthy conversations as degrading. The new thresholds (70/90) match observed model attention degradation patterns more accurately. All tests that previously used hardcoded values were updated; tests that imported exported constants auto-adjusted.
Summary by CodeRabbit
Updates
Tests