abc_mine.stages.build¶
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.build
¶
BUILD — turn each shortlisted commit into a complete ABC Runner task.
One construction agent per shortlisted commit, in parallel. Each agent authors three artifacts:
prompt.md— the task statement, the solver's only instruction,build_env.sh— environment setup run before the solver,verification/verify_solution.sh— the hidden deterministic check.
The fourth component, workspace/ (the starting state), is not authored by
any agent. The pipeline builds it deterministically by git bundle-cutoff at the
parent commit (see :func:abc_mine.repo.build_cutoff_workspace). An agent
asked to "remove the change" would introduce exactly the kind of subtle,
unauditable variation a benchmark cannot tolerate — and could accidentally leave
the answer in the tree.
Two independent polarity layers
A verifier that does not actually discriminate between the fixed and unfixed trees is worthless, and worse than worthless if it passes vacuously: it would certify solvers that did nothing. So polarity is enforced twice, by different parties:
Layer 1 (the agent, in its sandbox). The construction agent is required to check its own verifier against the post-change and pre-change trees before finishing, and to iterate until it discriminates.
Layer 2 (this stage, deterministically). After the agent finishes, the pipeline
re-checks polarity on the shipped artifact, in an environment that mirrors the
real grader: the code tree bind-mounted at the grading path, the verifier staged
outside it, and none of the conveniences that existed during authoring. A task
reaches ok only when the verifier FAILs on the shipped starting state and PASSes
on a clean checkout of the change commit.
Layer 2 is not redundant. It catches the most common way a plausible-looking verifier is actually broken: depending on a path that existed while the agent was working but does not exist at grading time. Layer 1 cannot catch that by construction, because Layer 1 runs in the environment that has those paths.
Build order
Commits are built in rank order. When the rank stage produced a full ranking
(rank.output: full) there is no shortlist to exhaust: the stage simply works
down the order, skipping commits already built or out of attempts, until either
the list runs out or the per-invocation limit (--limit N) is reached. That
limit is a property of one job, not of the run — resubmitting continues from
where the previous job stopped. Under parallel backends the limit is a count
of commits started, taken from the top of the remaining order.
Checkpoint and resume
The durable record is an append-only manifest.jsonl, written the instant each
task finishes. On resume, tasks whose latest entry is ok are skipped; any
planned-but-incomplete task directory (from a killed job) is removed and rebuilt.
Nothing partial is ever left for a later stage to trust.
BuildPlan
dataclass
¶
What a build invocation intends to do.
Source code in abc_mine/stages/build.py
describe
¶
Render a human-readable plan.
Source code in abc_mine/stages/build.py
manifest_path
¶
manifest_path(cfg: MineConfig) -> Path
attempts_path
¶
attempts_path(cfg: MineConfig) -> Path
group_dir
¶
group_dir(cfg: MineConfig) -> Path
task_id
¶
Build a stable, filesystem-safe task id from a description and SHA.
The SHA suffix guarantees uniqueness even when two commits carry identical descriptions, which is common in histories with templated commit subjects.
Source code in abc_mine/stages/build.py
read_manifest
¶
Read every manifest entry, skipping malformed lines.
Source code in abc_mine/stages/build.py
append_manifest
¶
Append one entry atomically.
O_APPEND makes a single small write atomic on POSIX, so parallel workers on
a shared filesystem never interleave partial lines — which is what allows the
manifest to be the source of truth without a lock.
Source code in abc_mine/stages/build.py
record_usage_fields
¶
record_usage_fields(build_dir: Path, tid: str, included: Sequence[Segment], discarded: Sequence[Segment], prior_records: Sequence[dict[str, Any]]) -> dict[str, Any]
Return the usage fields of one manifest record for tid.
usage sums the segments this outcome builds on. usage_discarded sums
the spend whose work was thrown away: discarded segments plus any
telemetry directory for the task that no earlier record accounts for (an
agent whose save was abandoned, say). A label counts as accounted for once a
finished (ok/failed) record included it or any record discarded it,
so each discarded run is charged exactly once.
Source code in abc_mine/stages/build.py
latest_status
¶
Return each task's latest manifest status (latest-entry-wins).
Source code in abc_mine/stages/build.py
completed_tasks
¶
Return task ids whose latest manifest entry is ok.
Latest-entry-wins: a task that failed and was later rebuilt successfully counts
as done, and one that was ok but failed on a later forced rebuild does not.
An unfinished or awaiting_check task is NOT complete: it must be
resumed, so it is excluded here exactly as a plain failure would be.
Source code in abc_mine/stages/build.py
saved_tasks
¶
Return task ids whose latest status is a resumable saved state.
Maps task_id -> status where status is unfinished or
awaiting_check. These are the tasks a resume must pick up (and which do
NOT count as attempts).
The saved state itself must still be on disk: a resume consumes it, so a record whose state is gone (resumed, then killed before a new save) is an unsaved leftover and is rebuilt from scratch.
Source code in abc_mine/stages/build.py
cumulative_budget_exhausted
¶
Return True iff the cumulative agent time has reached the hard limit.
hard_limit (execution.timeout_seconds) is a cap on agent wall time
summed across every interrupted-and-resumed segment — queue, save, and check
time never count. A None limit means uncapped. When the accumulated agent
time meets or exceeds the limit, the task is a hard failed (and consumes
an attempt) rather than being saved for yet another resume: a commit that has
already spent its whole budget without finishing will not finish on a retry.
Source code in abc_mine/stages/build.py
remaining_agent_budget
¶
Return the agent time left before the hard limit, or None if uncapped.
Always at least 1 second so a resume is never launched with a zero/negative
timeout; the start-of-segment :func:cumulative_budget_exhausted check is
what refuses to launch at all once the budget is spent.
Source code in abc_mine/stages/build.py
decide_verifier_result
¶
Decide PASS/FAIL from verifier output, matching abc-runner exactly.
The last line whose stripped content is exactly PASS or FAIL wins,
and PASS additionally requires a zero exit status. Both halves matter: a
script that prints PASS then dies in cleanup has not passed, and a bare
successful exit with no status line is not a pass either.
This mirrors abc-runner's own logic deliberately. If the two disagreed, a task could satisfy this stage's polarity check and then be graded differently in production — the exact failure this check exists to prevent.
Source code in abc_mine/stages/build.py
validate_task_dir
¶
Return the missing components of an emitted task directory.
Source code in abc_mine/stages/build.py
run_verifier_against_tree
¶
run_verifier_against_tree(cfg: MineConfig, *, sandbox: Any, verifier: Path, tree: Path, log_file: Path, scratch: Path) -> str
Run verifier against tree the way the real grader will.
Reproduces the grading environment faithfully, which is the entire point:
- the code tree is bind-mounted at :data:
GRADING_WORKSPACEand is$ABC_RUNNER_WORKSPACE; - the verifier is staged outside that mount, as the grader does;
- nothing that existed for the agent's convenience during authoring is present.
A verifier that quietly depends on an authoring-time path therefore fails here, where it is cheap to discover, rather than in production.
The tree is hard-linked rather than copied where the filesystem permits: source trees are large, this runs twice per task, and a verifier that mutates its input still must not disturb the original.
Source code in abc_mine/stages/build.py
write_group_yaml
¶
write_group_yaml(cfg: MineConfig) -> Path
Write the abc-runner group.yaml for the emitted task group.
Source code in abc_mine/stages/build.py
plan
¶
plan(cfg: MineConfig, *, only: Sequence[str] = (), force: bool = False, sweep: bool = False, limit: int | None = None) -> BuildPlan
Compute the work list, in rank order.
Read-only unless sweep is set, so every MPI rank derives an identical plan.
Only rank 0 should pass sweep=True, since removing directories concurrently
with workers reading them would be a race.
limit caps how many commits this invocation starts, taken from the top of
the order after skipping those already built or out of attempts.
Source code in abc_mine/stages/build.py
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
make_worker
¶
make_worker(cfg: MineConfig, pack: PromptPack, model: dict[str, str], *, dry_run: bool = False) -> Callable[[dict[str, Any]], ItemResult]
Build the per-commit construction worker.
Source code in abc_mine/stages/build.py
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 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 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 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 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 | |
run
¶
run(cfg: MineConfig, pack: PromptPack, model: dict[str, str], *, dry_run: bool = False, only: Sequence[str] = (), force: bool = False, progress: bool = True, limit: int | None = None) -> BatchOutcome
Execute the build stage, building commits in rank order.
limit caps how many commits this invocation starts (see :func:plan).
Source code in abc_mine/stages/build.py
1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 | |
summarize
¶
summarize(cfg: MineConfig) -> dict[str, Any]
Return aggregate statistics over emitted tasks, from the manifest.