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.2 KiB
6.2 KiB
Retained sample contract v1
- Build this C11 project with
make; run./retained-demo < demo.txt. The library is declared ininclude/retained.h. All public functions remain usable. Use only the allocator callbacks for retained objects.RsSamplermay own at most oneRsSaved, allocated as exactlysizeof(RsSaved); no other callback allocation remains live when any API returns. Each allocated object must be released once through the same callback. No invalid release is permitted. Internal temporary stack data and extra temporary allocations are allowed. - Initialize once with a valid allocator and policy.
rs_initzeros counters, sets ready, opens the sampler and starts without a retained result. Invalid arguments return RS_INVALID. The public driver always initializes successfully. Default policy: channels=255, minimum=-10000, maximum=10000, max_age=10000, forbidden=1, value_weight=1, age_weight=1, all channel_bias=0. - Valid policies have channels in 0..255, -10000 <= minimum <= maximum <= 10000, max_age 0..10000, forbidden 0..3, weights -100..100 and each bias -1000..1000. Configure copies a valid policy and retains the previous result and counters. Invalid configuration increments invalid once and changes nothing else. Configuration after close returns RS_CLOSED and changes nothing.
- A valid record has id 0..1000000, channel 0..7, value -10000..10000, age 0..10000, flags 0..3 and length 0..32. Exactly length payload bytes are meaningful. Unused payload bytes, struct padding and output data beyond defined length are unspecified. Record validity does not depend on policy.
- A record matches if its channel bit is enabled, minimum <= value <= maximum, age <= max_age, and (flags & forbidden)==0. Invalid record or policy never matches. Score is signed 64 bit valuevalue_weight - ageage_weight + channel_bias[channel]; invalid record or policy scores zero. Preferred order is larger score, then smaller age, then smaller id, then earliest position.
rs_preferred(NULL,anything)is false; any non-NULL left beats NULL right. - Batch size is 0..64. A nonzero count requires a non-NULL array. Validate the complete batch before modifying state or allocating. Invalid batch increments invalid once, returns RS_INVALID and leaves retained result, all other counters, policy and ownership unchanged. Input records and payloads must not be modified. The caller may overwrite or discard them immediately after return: the retained result is an independent owned copy.
- Every successful batch increments batches once, records by count, matches/rejected by the matching classification, value_sum by all values, and per-channel totals for all records. These totals include rejected records. Select the preferred matching record from this batch only, store its score and the new cumulative batch number, replace the previous retained result, and increment changes once. A batch with no match, including an empty batch, retains the previous result unchanged and does not increment changes. Continuous batches are supported without clear; replacement must fully release the prior ownership. The current retained result may predate the current policy.
- Allocation failure returns RS_NOMEM, leaves previous retained result and all counters unchanged, and releases all temporary allocations from that call. Allocators may return NULL; allocation strategy and total allocation/free call counts are not prescribed. The public driver does not inject allocation failures.
- Clear releases retained ownership, leaves an empty result and increments clears on every call, including repeated clears. Other counters and policy remain. Close releases retained ownership and marks closed; it is idempotent and does not increment clears. Batch/configure/clear after close return RS_CLOSED without any mutation or allocation. Views, payload copying and counters remain readable after close.
rs_viewreports the retained record, score, originating batch and payload digest. For an empty result all view fields are zero.rs_payload_digestis 32-bit FNV-1a (offset 2166136261, prime 16777619, wrap modulo 2^32) over exactly length bytes. It returns zero for NULL data with positive length. Copy payload reports required length; insufficient capacity or NULL output with nonzero required length returns RS_INVALID without copying; otherwise returns RS_OK and copies exactly the required bytes. Zero-length copy succeeds even with NULL output.rs_counterscopies all counters.rs_channel_totalreturns one channel count for 0..7, otherwise RS_INVALID.rs_meanreturns exact (value_sum, records), including (0,0), without division. View equality compares present and all meaningful fields; two absent views are equal; NULL view pointers are unequal. Null required output pointers or an uninitialized/NULL sampler return RS_INVALID.rs_batch_infovalidates its policy, input array, count and output pointer and does not partially write on failure. On success report count, matches, rejected, minimum/maximum over all values (both zero for empty), signed sum, OR of channel bits, and digest. Its digest starts at 2166136261 and for each record in input order applies (digest XOR payload_digest)*16777619 modulo 2^32. It does not mutate sampler or inputs.- The driver protocol is whitespace-delimited. P is followed by channels/minimum/maximum/max_age/forbidden/value_weight/age_weight then eight biases. B count is followed by count records: id/channel/value/age/flags/length/hex-payload (
-for zero length). C clears; X closes. The normal driver accepts count up to 65 to expose invalid-size handling. At EOF it closes and emits a final snapshot. Tests use parseable commands only. The driver prints raw observations: INIT status sizeof(RsSaved); I batch-info result and defined fields; N validity/matches/score per record; INPUT mutation flag; R step/status/closed; V view result and fields; K counters result and fields; L live-blocks/live-bytes/invalid-releases/retained-pointer-known; D full-copy result/length/hex then NULL-small-copy result/length; M mean result/numerator/denominator, self/changed-id equality, and channel results/counts 0..8. Only successful result fields are defined. Output to stderr may contain arbitrary diagnostic bytes of arbitrary size; it has no semantic role. Stdout uses this exact line protocol.