Skip to content

fix(context): score every snapshot entry before applying the candidate cap - #31

Merged
GQAdonis merged 1 commit into
mainfrom
fix/context-score-all-entries
Oct 4, 2026
Merged

GQAdonis merged 1 commit into
mainfrom
fix/context-score-all-entries

Conversation

@GQAdonis

@GQAdonis GQAdonis commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Summary

pk context used to cut each scope to ceil(max_candidates / scopes) entries in snapshot order before scoring them. A large KB was therefore mostly invisible to recall:

  • with 200 entries and default flags, only 128 were scored, and a match that sorted late was never returned;
  • a scope that failed kept its share of the budget, so the other scopes could not use it.

Change (pk-cli/src/main.rs::run_context):

  • Every entry of every readable scope is now scored.
  • --max-candidates caps the merged, ranked list after de-duplication.
  • The ranking is deterministic: score descending, then scope priority, then id.
  • The JSON output gains scored_count. candidate_count now means "ranked candidates kept after the cap".

The existing test candidate_budget_is_shared_across_requested_scopes asserted the old count of inspected entries. It now asserts scored_count = 5 and candidate_count = 1.

This is part of the team-aware learning work, plan PR A1 (skill-pack docs/plans/team-aware-learning-memory-implementation.md).

Test plan

  • cargo test -p pk-cli --test context_scoring passes. It covers a 200-entry scope with the last-by-id match recalled, a failed scope that does not reserve budget, and byte-identical output across runs with the stated ordering.
  • cargo test -p pk-cli --test context passes.
  • Negative control: the original code, run on the same 200-entry fixture, returns results=[] with candidate_count=128.

🤖 Generated with Claude Code

…e cap

run_context took ceil(max_candidates/scopes) entries per scope in snapshot
order before scoring, so most entries in a large scope were never
considered (200 entries, default flags: only 128 scored, a late-sorting
match was never returned) and a failed scope's share of the budget was
lost. Every entry is now scored; --max-candidates caps the merged,
ranked list. Output adds scored_count; candidate_count now counts the
ranked candidates kept after the cap.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@GQAdonis
GQAdonis merged commit 173373a into main Oct 4, 2026
2 of 3 checks passed
@GQAdonis
GQAdonis deleted the fix/context-score-all-entries branch October 4, 2026 10:41
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