abc_mine.stages.rank¶
WARNING
This documentation is almost entirely "vibe coded"; while a helpful resource for humans and agents to understand this codebase, it should not be considered a source of ground truth in the way documentation normally is, and the user is responsible for verifying that all instructions given here are safe.
abc_mine.stages.rank
¶
RANK — collapse viable screening summaries into a ranked shortlist.
One decision-making agent reads every viable candidate in a single context and selects the commits genuinely worth building into benchmarks. It may dispatch research subagents to settle a specific uncertainty about a promising candidate, but the selection itself is one judgement made with all candidates visible — which is precisely the comparison the per-commit screening pass cannot make.
The only filtering done here in Python is dropping commits screening marked
disqualified (they failed a rubric gate, and are unusable by construction). No
score threshold is applied: the scores travel along as informational context, and
the agent is explicitly told it may disagree with them.
.. _rank-limitations:
Known limitations — deliberate, not oversights
Single-context only. This stage assumes every candidate fits in one model context. There is no chunk-and-merge, no multi-round tournament, no hierarchical reduction. That is a conscious scoping decision: those designs introduce real complexity (how to compare candidates that never shared a context, how to merge partial orderings fairly, how to keep a merge agent from simply deferring to whichever chunk it saw last) and are not attempted here.
The assumption is therefore checked rather than hoped for. The candidates are
embedded in the prompt itself, not left in a file for the agent to page through
with a read tool (which adds a per-line overhead and a tool round-trip per 50 KB,
and invites skimming). Before any agent runs, the fully composed prompt — the
harness system prompt plus this stage's task prompt — is counted through the
endpoint's own token counter and compared against rank.max_prompt_tokens;
exceeding it is a hard, actionable error. There is no estimate to fall back on:
if the count cannot be obtained, the stage refuses to start. (The count is only
as accurate as the endpoint's counter; a gateway whose counter disagrees with
its models' real tokenizer makes the budget a bound in its units.) Silently overflowing a context and receiving a shortlist quietly drawn
from the first 60% of candidates would be far worse than refusing to start,
because nothing in the output would reveal it had happened.
No mid-stage resume. One agent doing one long task either finishes or does not.
If it dies forty minutes in, rerunning starts over. Per-item checkpointing has no
meaning when there is one item. Bounding the cost of that is what
execution.timeout_seconds is for. A partial-progress design is not possible
without the multi-agent machinery described above.
Both limitations are recorded in the run manifest when this stage runs, so a shortlist is never mistaken for the product of a more sophisticated process than actually produced it.
RankError
¶
TokenCountError
¶
RankPlan
dataclass
¶
What a ranking invocation intends to do.
Source code in abc_mine/stages/rank.py
over_budget
property
¶
True if the measured prompt exceeds the configured token budget.
describe
¶
Render a human-readable plan.
Source code in abc_mine/stages/rank.py
CandidatePool
dataclass
¶
The viable candidates, after disqualification and the max_candidates cap.
Source code in abc_mine/stages/rank.py
GroupResult
dataclass
¶
A validated shortlist from one ranking agent, plus its provenance.
Source code in abc_mine/stages/rank.py
shortlist_path
¶
shortlist_path(cfg: MineConfig) -> Path
rationale_path
¶
rationale_path(cfg: MineConfig) -> Path
attempts_path
¶
attempts_path(cfg: MineConfig) -> Path
build_candidates
¶
Build the compact candidate payload from screening summaries.
Drops disqualified commits, keeps a trimmed projection of the rest, and sorts by score descending purely as a reading order. Pure and side-effect free, so the budget check and the tests can exercise it without a container.
Source code in abc_mine/stages/rank.py
render_candidate
¶
Render one candidate as a compact, self-delimiting text block.
Carries exactly the projected fields of :func:build_candidates, but as
labelled lines rather than indented JSON: the braces, quotes, and
indentation of pretty-printed JSON cost about 15% more tokens for no gain in
legibility, and with a thousand candidates in one context that margin is
the difference between fitting and not.
Source code in abc_mine/stages/rank.py
render_candidates
¶
Render the whole candidate list for embedding in the prompt.
count_tokens
¶
Return the endpoint's input-token count for text.
Uses Anthropic's /v1/messages/count_tokens, which runs no inference.
Transient failures (5xx, connection errors) are retried; anything else is a
:class:TokenCountError. There is deliberately no estimate fallback:
with a hard context limit, a wrong guess surfaces as a failed or truncated
run far from its cause.
Source code in abc_mine/stages/rank.py
harness_prompt_text
¶
Return the text the harness actually sends: its system prompt + the task.
Mirrors the composition in harness/run_benchmark.sh so the size check
measures what the model receives, not just the part this stage wrote.
Source code in abc_mine/stages/rank.py
load_pool
¶
load_pool(cfg: MineConfig) -> CandidatePool
Load summaries and build the candidate pool.
Raises:
| Type | Description |
|---|---|
RankError
|
If there are no summaries. |
Source code in abc_mine/stages/rank.py
plan_group
¶
plan_group(cfg: MineConfig, pack: PromptPack, model: dict[str, str], pool: CandidatePool, candidates: list[dict[str, Any]], *, label: str = '', counter: Any = None) -> RankPlan
Compose the ranking prompt for candidates and measure it.
counter(text) -> int replaces the endpoint call (tests). Candidates are
re-sorted by score as a reading order, whatever order they arrive in.
Raises:
| Type | Description |
|---|---|
TokenCountError
|
If a budget is set but the prompt cannot be counted. |
Source code in abc_mine/stages/rank.py
plan
¶
plan(cfg: MineConfig, pack: PromptPack, model: dict[str, str], *, counter: Any = None) -> RankPlan
Compose the single-context ranking prompt and measure it against the budget.
Raises:
| Type | Description |
|---|---|
RankError
|
If there are no summaries. |
TokenCountError
|
If a budget is set but the prompt cannot be counted. |
Source code in abc_mine/stages/rank.py
rank_group
¶
rank_group(cfg: MineConfig, model: dict[str, str], work_plan: RankPlan, *, logs_dir: Path, item_id: str, dry_run: bool = False) -> GroupResult | None
Run one ranking agent over work_plan and return its validated result.
The unit of work shared by every method: one agent, one context, one prompt
(the one work_plan measured, byte for byte). Returns None under a
dry run.
Raises:
| Type | Description |
|---|---|
RankError
|
If the agent fails or produces no usable shortlist. The attempt is
recorded under |
Source code in abc_mine/stages/rank.py
675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 | |
write_outputs
¶
write_outputs(cfg: MineConfig, shortlist: dict[str, Any], rationale: str) -> Path
Persist the shortlist (atomically, backing up any previous one) and rationale.
Source code in abc_mine/stages/rank.py
run
¶
run(cfg: MineConfig, pack: PromptPack, model: dict[str, str], *, dry_run: bool = False, force: bool = False, progress: bool = True) -> dict[str, Any]
Execute the rank stage with the configured method; return the shortlist.
Raises:
| Type | Description |
|---|---|
RankError
|
If there are no candidates, a prompt exceeds the budget or cannot be measured, or an agent fails to produce a usable shortlist. |
Source code in abc_mine/stages/rank.py
849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 | |
load_shortlist
¶
load_shortlist(cfg: MineConfig) -> dict[str, Any]
Load this run's shortlist.
Raises:
| Type | Description |
|---|---|
RankError
|
If it is missing or unparseable. |