One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6.8 KiB
Cache service contract v1
C01 Scope and build
This is a single-threaded C++17 resource service. Build with make; the executable is cache_probe. No external libraries, network, timing, memory-pressure measurement, or board are involved. Only cache.hpp, payload.cpp, registry.cpp and commands.cpp are submitted. main.cpp is an observer: it prints the returned integer vector as a JSON array for every input line. All commands below are public and valid in arbitrary order and combinations. stderr may contain arbitrary diagnostic bytes and is not part of the result. Successful input processing exits 0.
C02 Input and result protocol
Each stdin line is one command; tokens are separated by ASCII space, TAB or CR. Names and command words are case-sensitive. Numeric tokens are ASCII decimal, with optional + or - and any number of leading zeros. A value outside its stated range, an unknown command, wrong arity, or invalid name returns [1]. Empty or whitespace-only lines also return [1]. There is no trailing argument. An unavailable owner or cache key returns [2]. Errors preserve all state. Every result is an array of JSON integers, in the exact field order below; ordinary JSON whitespace is allowed. Every input line produces exactly one result. EOF ends processing without an additional row.
C03 Resources and identity
There are 32 external owner slots numbered 0..31, initially empty. Cache keys are ordered pairs (tenant, name), each component 1..32 ASCII letters, digits, underscore, dot or hyphen. Distinct pairs never alias. Each newly created resource gets a monotonically increasing serial starting at 1, never reused, even after deletion or cache clearing. A resource contains 0..4096 bytes. Its initial byte at index i is (seed + 17i + (ii mod 251)) mod 256, with seed 0..255. Its checksum is sum((i+1)*byte[i]) mod 1000000007. Length zero has checksum zero.
C04 Lifetime and registry
Only occupied external slots own resources. The registry observes resources without extending their lifetime. Destruction occurs immediately after the last external slot releases or replaces that resource. A destruction appends its serial to the destruction journal and subtracts its current byte length from the live-byte ledger. Expired registry entries may remain until SWEEP, replacement, ERASE, RETIRE or CLEAR. They are not owners and cannot be looked up. Cache inspection must not change lifetime. Acquiring an expired key replaces its entry and creates a fresh serial. Acquiring a live key returns that same resource and ignores the supplied length/seed. A new ACQUIRE or successful LOOKUP obtains the target resource before replacing the destination slot; if old and new are the same object nothing is destroyed.
C05 Owner commands
ACQUIRE slot tenant name length seed returns [0,serial,checksum]. LOOKUP slot tenant name returns [0,serial,checksum] or [2]; a miss preserves the previous slot. COPY source destination returns [0,serial] and shares the source resource; empty source returns [2]. MOVE source destination returns [0,serial] and transfers source ownership; empty source returns [2]. For COPY/MOVE with the same source/destination, the resource is preserved. SWAP left right exchanges the two slots, including empty slots, without releasing any resource, and returns [0,left_serial_or_0,right_serial_or_0] for the resulting slots. DROP slot returns [0], including an empty slot. DROP_ALL releases slots in ascending slot order and returns [0,number_of_previously_occupied_slots]. Replacement of an occupied slot releases its former ownership immediately. VIEW slot returns [0,serial,length,checksum] or [2]. OWNERS slot returns [0,serial,number_of_slots_sharing_that_resource] or [2].
C06 Shared mutable payload
WRITE slot offset byte updates one byte and returns [0,checksum]. Offset must be less than resource length and byte 0..255. FILL slot offset count byte fills [offset,offset+count) and returns [0,checksum]; offset/count must be nonnegative and offset+count<=length. A zero count is valid at offset==length. RESIZE slot length seed preserves the common prefix, truncates excess bytes, and initializes newly appended byte i using the C03 formula with the supplied seed. It returns [0,checksum]. All aliases observe the same changes. Missing slot returns [2] after syntactic/range validation; an invalid payload interval returns [1]. The live-byte ledger always uses the current lengths of living resources, never cumulative allocation.
COMPARE left right returns [0,same_identity,same_bytes], with the last two fields integer 0 or 1, or [2] if either slot is empty; byte equality includes length and every byte. READ slot offset count returns [0,count,byte_0,...,byte_(count-1)] for the requested window. COPY_RANGE source source_offset destination destination_offset count copies a snapshot of the source window to the destination window and returns [0,destination_checksum]; overlap, including aliases of the same object, behaves as if source bytes were copied first to temporary storage. Either missing resource returns [2]. An invalid window returns [1] without changing bytes. All offset/count operands in WRITE/FILL/READ/COPY_RANGE are integers 0..4096; each window must fit its resource, and a zero-length window is valid at its end.
C07 Registry maintenance
ERASE tenant name removes the exact registry entry and returns [0,0_or_1_removed], without releasing slots. A removed key can be reacquired as a distinct new resource even while former owners remain. RETIRE tenant removes all entries of that tenant and returns [0,removed_count]. CLEAR removes all registry entries and returns [0,removed_count]. Neither destroys any resource with external owners. SWEEP removes all and only expired registry entries and returns [0,removed_count]. Live identity and payload survive maintenance. CACHE returns [0,total_entries,live_entries,expired_entries], with total==live+expired.
C08 Ledger and journal
STATS returns [0,created,destroyed,live_resources,live_bytes,occupied_slots,registry_entries]. Created counts successful new resources; destroyed counts journal entries; live_resources==created-destroyed. DEATHS returns [0,count,serial_1,...,serial_count], in actual destruction order. Inspection commands do not create, release or mutate resources. Counters start at zero and accumulate for the entire process; CLEAR, RETIRE and SWEEP never reset them. Tests use at most 10000 commands, 10000 created resources and 32*4096 live payload bytes.
C09 Public exercise
Run ./cache_probe < examples/default.txt and ./cache_probe < examples/tenants.txt. The examples are input scripts, not the full acceptance set. The service must satisfy C01..C08 for every allowed command sequence, including reuse after final owner destruction, overlapping aliases, cache invalidation while owners remain, zero-length resources and invalid commands followed by valid commands.