Skip to content

feat(health-score): raise context thresholds and update critical coaching [LCO-44] - #42

Merged
DevanshuNEU merged 3 commits into
OpenCodeIntel:mainfrom
DevanshuNEU:feat/lco-44-context-threshold-warnings
Apr 19, 2026
Merged

feat(health-score): raise context thresholds and update critical coaching [LCO-44]#42
DevanshuNEU merged 3 commits into
OpenCodeIntel:mainfrom
DevanshuNEU:feat/lco-44-context-threshold-warnings

Conversation

@DevanshuNEU

@DevanshuNEU DevanshuNEU commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

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 feature

What Was Changed

  • lib/health-score.ts: HEALTHY_CEIL 50 -> 70, DEGRADING_CEIL 80 -> 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

  1. bun run compile — should exit clean
  2. bun run test — 1452 tests, all pass
  3. Load the unpacked extension on claude.ai
  4. Open a conversation that has filled past 70% of the context window — overlay should show "Degrading"
  5. Fill past 90% — overlay should show "Critical" with coaching text "Context nearly full. Start a new chat, or use Claude Projects for ongoing work."
  6. Confirm conversations below 70% show "Healthy"

Checklist

  • Tests pass locally (bun run test)
  • TypeScript compiles clean (bun run compile)
  • Extension builds without errors (bun run build)
  • No secrets, hardcoded URLs, or sensitive tokens exposed
  • Comments are professional and clear — no emojis, no AI-generated filler
  • Commit messages follow conventional commits (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

    • Raised health-score thresholds for context usage (healthy and degrading boundaries increased) and adjusted the critical-condition logic.
    • Revised the coaching message when context nears capacity to recommend starting a new chat or using Projects.
  • Tests

    • Updated and added tests to reflect the new threshold boundaries and to cover healthy, degrading, and critical scenarios.

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

coderabbitai Bot commented Apr 19, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c7034246-0a57-44b7-964b-343239b17f13

📥 Commits

Reviewing files that changed from the base of the PR and between 1418ed2 and df3e87b.

📒 Files selected for processing (4)
  • lib/health-score.ts
  • tests/audit/health-score-audit.test.ts
  • tests/integration/agent-pipeline.test.ts
  • tests/unit/health-score.test.ts
✅ Files skipped from review due to trivial changes (1)
  • tests/integration/agent-pipeline.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/unit/health-score.test.ts
  • tests/audit/health-score-audit.test.ts

📝 Walkthrough

Walkthrough

Updated health-score context utilization thresholds: HEALTHY_CEIL increased from 50 to 70, and DEGRADING_CEIL increased from 80 to 90. Critical coaching message text was modified. Corresponding test cases across audit, integration, and unit suites were updated to reflect the new boundary values.

Changes

Cohort / File(s) Summary
Core Threshold Constants
lib/health-score.ts
Increased HEALTHY_CEIL from 50 → 70 and DEGRADING_CEIL from 80 → 90. Updated the critical “context nearly full” coaching message wording.
Audit Tests
tests/audit/health-score-audit.test.ts
Adjusted audit rule boundaries to assert critical/degrading/healthy at the new context thresholds (70 and 90) and updated test descriptions.
Integration Tests
tests/integration/agent-pipeline.test.ts
Updated expectations for mid-conversation health classification; added a “degrading mid-conversation” suite asserting 75% context is degrading and verifying coaching/label payloads.
Unit Tests
tests/unit/health-score.test.ts
Updated unit test inputs and assertions to reflect raised contextPct boundaries (e.g., 55→75, 79→80) and preserved priority/coach message expectations where applicable.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I nudged the numbers, hopped with glee,
Context ceilings climbed from low to high,
Tests adjusted, tidy as can be,
A gentle twitch, a cheerful cry,
New thresholds bloom beneath my sky 🌱

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main changes: raising context thresholds in health-score and updating critical coaching text, with issue reference.
Description check ✅ Passed The PR description covers all required template sections with concrete details about what changed, how to test, and includes completed checklist items.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

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

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.

❤️ Share

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

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 | 🟡 Minor

Stale inline comment: DEGRADING_CEIL is 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_CEIL and 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 | 🟡 Minor

Stale 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:

  • h at 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 only if (h2.level === 'degrading'), so the test can pass without asserting anything.

Consider replacing with an input that deterministically produces ~1 message under Rule 4 and asserting unconditionally (e.g. contextPct: 89, growthRate: 11remaining = 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ba13bc and 1418ed2.

📒 Files selected for processing (4)
  • lib/health-score.ts
  • tests/audit/health-score-audit.test.ts
  • tests/integration/agent-pipeline.test.ts
  • tests/unit/health-score.test.ts

Comment thread tests/audit/health-score-audit.test.ts Outdated
@DevanshuNEU
DevanshuNEU merged commit 4d803aa into OpenCodeIntel:main Apr 19, 2026
5 checks passed
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.

1 participant