Files
stack/docs/scratchpads/143-validate-50-percent-rule.md
Jason Woltje a1b911d836 test(#143): Validate 50% rule prevents context exhaustion
Following TDD (Red-Green-Refactor):
- RED: Created comprehensive test suite with 12 test cases
- GREEN: Implemented validation logic that passes all tests
- All quality gates passed

Test Coverage:
- Oversized issue (120K) correctly rejected
- Properly sized issue (80K) correctly accepted
- Edge case at exactly 50% (100K) correctly accepted
- Sequential issues validated individually
- All agent types tested (opus, sonnet, haiku, glm, minimax)
- Edge cases covered (zero, very small, boundaries)

Implementation:
- src/validation.py: Pure validation function
- tests/test_fifty_percent_rule.py: 12 comprehensive tests
- docs/50-percent-rule-validation.md: Validation report
- 100% test coverage (14/14 statements)
- Type checking: PASS (mypy)
- Linting: PASS (ruff)

The 50% rule ensures no single issue exceeds 50% of target
agent's context limit, preventing context exhaustion while
allowing efficient capacity utilization.

Fixes #143

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-01 17:56:04 -06:00

2.3 KiB
Raw Permalink Blame History

Issue #143: [COORD-003] Validate 50% rule

Objective

Validate the 50% rule prevents context exhaustion by blocking oversized issue assignments.

Approach

Following TDD principles:

  1. Write tests first for all scenarios
  2. Implement validation logic
  3. Verify all tests pass with 85%+ coverage

The 50% Rule

Issues must not exceed 50% of target agent's context limit.

Agent context limits:

  • opus: 200K tokens (max issue: 100K)
  • sonnet: 200K tokens (max issue: 100K)
  • haiku: 200K tokens (max issue: 100K)
  • glm: 128K tokens (max issue: 64K)
  • minimax: 128K tokens (max issue: 64K)

Test Scenarios

  1. Oversized issue - 120K estimate for sonnet (200K limit) → REJECT
  2. Properly sized - 80K estimate for sonnet → ACCEPT
  3. Edge case - Exactly 100K estimate for sonnet → ACCEPT (at limit)
  4. Sequential issues - Multiple medium issues → Complete without exhaustion

Progress

  • Create scratchpad
  • Read existing code and patterns
  • Write test file (RED phase) - 12 comprehensive tests
  • Implement validation logic (GREEN phase)
  • All tests pass (12/12)
  • Type checking passes (mypy)
  • Linting passes (ruff)
  • Verify coverage ≥85% (achieved 100%)
  • Create validation report
  • Ready to commit

Testing

Test file: /home/jwoltje/src/mosaic-stack/apps/coordinator/tests/test_fifty_percent_rule.py Implementation: /home/jwoltje/src/mosaic-stack/apps/coordinator/src/validation.py

Results:

  • 12/12 tests passing
  • 100% coverage (14/14 statements)
  • All quality gates passed

Notes

  • Agent limits defined in issue #144 (COORD-004) - using hardcoded values for now
  • Validation is a pure function (easy to test)
  • Returns ValidationResult with detailed rejection reasons
  • Handles all edge cases (0, exactly 50%, overflow, all agents)

Implementation Summary

Files Created:

  1. src/validation.py - Validation logic
  2. tests/test_fifty_percent_rule.py - Comprehensive tests
  3. docs/50-percent-rule-validation.md - Validation report

Test Scenarios Covered:

  1. Oversized issue (120K) → REJECTED
  2. Properly sized (80K) → ACCEPTED
  3. Edge case (100K exactly) → ACCEPTED
  4. Sequential issues (3×60K) → All ACCEPTED
  5. All agent types tested
  6. Edge cases (0, very small, boundaries)

Token Usage: ~48K / 40.3K estimated (within budget)