100 tasks from the HWE arm-linux code-gen pool (outside the lk/man/pth range given to batch 22), each with at least one independent contract-edge defect and plain public docs. Claude reviewed 100/100 USABLE against current digests; no ID or source overlap with main or batch 22. Difficulty is unmeasured. progress.md records the wrap-up: all Codex sessions and Qwen schedulers stopped for the user's rollout, Qwen results so far (57 HARD of 373), and what is left on each batch branch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
8.3 KiB
Reference ledger contract
Scope and numeric domain
R1. This is a deterministic Linux userspace C++17 model. There is no actual allocation, kernel reference, CPU affinity, clock or thread. Each Ledger is independent. The default has four CPUs. reset(cpus) accepts 1..8 and clears objects, release events and the creation/event sequences to zero; invalid reset is atomic and returns -22.
R2. IDs are integers 1..1000000; invalid IDs return -22. There are at most eight resident objects, including released tombstones. CPU indices are 0..cpu_count-1. Amounts are signed int64 values in 1..1000000000000 inclusive. Global live balances cannot exceed 1000000000000. Histories contain at most 20000 commands; all resulting signed CPU counters and sequence numbers fit int64.
R3. Return codes are 0 success, -22 invalid ID/CPU, -34 invalid amount or balance overflow/underflow, -2 absent ID, -17 duplicate ID, -28 full table, -108 killed/released object forbids acquisition, -16 wrong lifecycle state. Methods are silent: no stdout or stderr. Only the supplied console prints observations. Output references are unchanged on errors. All errors leave the ledger unchanged, including audit sequences and events.
Objects and accounting
R4. create(id,payload) creates one active resident object with exactly one owner reference, base=1, and all CPU local and folded counters zero. Payload is any signed int64; it is returned unchanged. Each successful creation assigns an incarnation one greater than the previous successful creation, initially 1, including reuse after erase. Error priority is invalid ID, duplicate ID, full table.
R5. Every CPU has a signed cumulative local and signed folded watermark, initially zero. Its pending contribution is local-folded. Object total is base + sum(pending). get(id,cpu,n) adds n to that CPU's local counter; put(id,cpu,n) subtracts n. Local and pending contributions may be negative: a CPU with zero local references may return globally available borrowed references acquired on another CPU. Never reject or truncate such a valid put merely because its local value is zero or negative.
R6. An active object's owner reference cannot be returned by put: active total after put must be at least 1. A killed object has no owner and put may reduce total to 0. get requires active state. put on a released tombstone returns -108. get/put priority is invalid ID, absent ID, invalid CPU, invalid amount, forbidden lifecycle, then balance overflow/underflow. Both amounts 1 and 1000000000000 are valid amounts even when their requested transition is rejected by the balance constraint.
R7. fold_cpu(id,cpu) adds that CPU's pending contribution to base and sets its folded watermark to local. fold_all(id) folds CPUs in ascending order. Both preserve total, local counters, lifecycle and events; repeated folding is idempotent. Folding a released tombstone is allowed and harmless. Priority is invalid ID, absent ID, then invalid CPU. Neither operation releases an active object.
R8. kill(id) changes active to killed, drops exactly the owner reference from base, and folds every CPU. It returns -16 on killed or released objects and performs no additional drop. ID validation and existence precede lifecycle validation. Existing borrowed references remain returnable on any CPU after kill; acquisition is forbidden. If the resulting total is 0 the object immediately becomes released.
R9. Any successful kill or put that first makes a killed object's total 0 folds all CPU contributions, sets state released, and appends exactly one release event. Events carry monotonically increasing sequence (first 1), ID, incarnation and payload. This event order is the order of final release operations across objects. Released objects remain queryable and consume capacity. erase(id) succeeds only on released objects, then removes the tombstone without changing events; it returns -16 for active/killed objects, with invalid ID/existence checked first.
Observations and transactions
R10. query(id,View&) returns id, payload, incarnation, state (0 active, 1 killed, 2 released), base, total and CPU count. query_cpu(id,cpu,CpuView&) returns local, folded, pending. total(id,int64&) independently returns exact total. Validation is invalid ID, absent ID, then CPU for query_cpu. Each observation returns 0 or an error, does not fold or otherwise mutate, and preserves its supplied output on error.
R11. resident_count(), cpu_count() and events() return resident count, configured CPU count and the complete ordered release-event vector by value. Repeated reads preserve state. An empty ledger has no objects/events. Neither create/erase nor observation clears earlier events. Reset is the only event-clearing operation.
R12. batch(vector<Op>,vector<int64>& totals) atomically executes up to 64 operations in order. Each Op has kind, id, cpu, amount. Kinds 1=get, 2=put, 3=fold_cpu, 4=fold_all, 5=kill, 6=erase; unused cpu/amount fields are ignored. Kind outside 1..6 returns -22 at that position. More than 64 operations returns -22 before any execution. Empty batch succeeds and replaces totals by empty. For success, totals becomes each target object's total immediately after that operation (0 after erase). On first failure, return its error, preserve the entire ledger and caller's totals. Committed batch release events follow operation order; aborted events/incarnation/sequence changes are discarded.
R16. contains(id) returns -22 for invalid ID, 0 for absent ID, 1 for any resident state; console I id prints I rc. stats() returns active/killed/released resident counts, the sum of all resident totals, the signed sum of all pending contributions, and number of historical release events, in that order. event(index,Release&) reads zero-based event index and returns -34 with unchanged output for negative/past-end indices. select(ids,vector<View>&) returns query results in requested order, preserving duplicates. It accepts 0..8 IDs; size above 8 returns -22 first, otherwise the first failed query determines the error and preserves the caller vector. Empty select succeeds with empty vector. These observations never mutate. Console S prints S and six stats fields. H index nonce initializes four release fields to nonce and prints H rc sequence id incarnation payload. V count nonce ids... accepts count 0..9, starts with a one-element View vector with all fields nonce, and prints V rc count followed by seven fields for each resulting View.
Public console and delivery
R13. Build with make; stdin is well formed ASCII, whitespace-separated records with signed int64 values in range and exact documented arities. No malformed tokens, unknown console commands, out-of-range integers or empty records are supplied. Semantic invalid IDs, CPUs, amounts, batch kinds and sizes are supplied as specified above. On valid protocol input the console exits 0; its stdout is exactly one observation record per command, with no extra bytes, and stderr is empty. Candidate methods must not print diagnostics to either stream.
R14. Commands: Z cpus reset; C id payload create; G id cpu n get; P id cpu n put; F id cpu fold_cpu; A id fold_all; K id kill; E id erase. These print R rc. Q id nonce initializes all seven View fields to nonce and prints Q rc id payload incarnation state base total cpus. D id cpu nonce initializes all three CpuView fields to nonce and prints D rc local folded pending. T id nonce prints T rc value. N prints N resident_count cpu_count. L prints L count followed by each event's sequence id incarnation payload. For B, nonce is at most 9223372036854775806 so nonce+1 is representable; all other nonce values may span signed int64. B count nonce followed by count groups kind id cpu amount in the same line initializes totals to [nonce,nonce+1] and prints B rc count values.... Negative batch count is not supplied; count 0..65 is supplied. U index selects ledger 0 or 1 and prints U index. Both ledgers start independently at four CPUs.
R15. Only reference_ledger.hpp, reference_ledger.cpp and reference_batch.cpp are collected and scored. The console, Makefile, documentation and smoke input are public support files. Implementations may change representation and algorithms while preserving every contract clause. No hidden files, environment variables, grader access, process inspection or hardcoded public transcript may be required.