amos 2f32624d3b Batch 18 (20261026-C-hwe-codegen-18): add 100 calibrated HWE code-gen tasks; pause production for rollout
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>
2026-10-27 17:52:13 +08:00

8.4 KiB

Deferred callback engine v1

This specification is normative in full. This is a deterministic software model: no threads, wall clock, devices or kernel facilities are involved. All calls are sequential. C++17 and the standard library suffice.

R1 Interface and domains

deferred.hpp declares namespace deferred, Engine, status constants and plain result records. All declared public methods are required. Engines are independent and start empty. Copying an Engine is not supported. Only the listed candidate files are collected; new files are not collected.

Slots have integer IDs 0..15 inclusive. An uninstalled slot is VACANT (0), an installed slot is LIVE (1), and a killed slot is DEAD (2). Generation starts at 0 and each successful install increments that slot's generation. A run contains at most 4096 method calls, so all counters and signed 64-bit sums fit. No persistence across engine destruction is required.

Statuses are OK=0, BAD_ID=1, BAD_VALUE=2, EXISTS=3, MISSING=4, DEAD_SLOT=5, LIMIT=6, UNBALANCED=7, BUSY=8, NO_EVENT=9. Step kinds are START=10, FINISH=11, IDLE=12. These are numeric API values, not text diagnostics.

R2 Install and validation

install(id, priority, quota, cookie) accepts priority 0..3, quota 1..32, cookie -1000000..1000000 inclusive. Check ID first, then all numeric arguments, then existence: LIVE returns EXISTS. Success resets all per-generation fields, sets LIVE, depth zero, and preserves only the incremented generation. VACANT and DEAD can be installed. Successful install adds one INSTALL event (kind 1) with zero batch fields.

post(id, value) accepts value -1000000..1000000 inclusive. Check ID, value, existence/lifecycle, then quota in that order. A LIVE slot accepts at most quota requests in its pending batch; exceeding it returns LIMIT. An active batch does not consume pending quota. A first pending request receives the next global ticket, starting at 1; subsequent posts merge by adding count and signed sum, retaining that ticket. Posting while disabled or active is permitted. Post does not start a callback or emit an event.

Every mutator error changes only the engine's errors counter, incremented once per rejected call. No other fields, tickets or events change. ID errors take precedence over every other error. For methods without numeric values, test lifecycle after ID: VACANT returns MISSING, DEAD returns DEAD_SLOT. Rejected read-only queries do not increment errors. Success never increments errors.

R3 Gates

disable(id) on a LIVE active slot returns BUSY, even when its depth is already 4. Otherwise it increments depth, unless depth is 4 (LIMIT). disable_nosync(id) increments depth under the same limit, including when active: it neither completes nor interrupts an already started callback. Both are nestable, with depth 0..4.

enable(id) requires a positive depth, otherwise UNBALANCED. Each success subtracts exactly one. Depth 2 to 1 still prevents dispatch. Only depth 1 to 0 permits dispatch on a subsequent explicit step. All pending requests, their sum and ticket survive disable/enable; enabling itself never starts a callback.

R4 Logical worker

At most one callback is active across the whole engine. step() has no arguments. If a callback is active, it completes that exact active batch regardless of current depth and returns an Action of kind FINISH (11). Completion increments that slot's completed_batches and delivered_count/sum/value, increments global finishes, emits a FINISH event (kind 3), and clears only active fields. Any newer pending batch remains intact.

Without an active callback, a step chooses among LIVE slots with depth zero and a nonempty pending batch. The minimum tuple (priority, pending_ticket, id) wins. It moves the entire pending batch into active fields, clears pending fields including its ticket, increments global starts, emits START (kind 2), and returns kind START (10). No other slot changes. If there is no eligible slot, it returns IDLE (12), id -1, and generation/count/sum/value zero, without an event.

Action fields are kind,id,generation,count,sum,value; START and FINISH describe the batch concerned. Its value is sum + cookie * count. Callback completion uses the cookie of that generation. Global starts/finishes are monotonic across reinstall; per-generation counters reset on install. The step Action must directly describe that step, even after other query calls.

R5 Kill and reuse

kill(id) validates ID and lifecycle. On a LIVE slot it synchronously completes that slot's active batch, if any, exactly as an ordinary FINISH (including the FINISH event). It then discards all that slot's pending work, clears depth and active/pending fields, marks DEAD, increments global kills, and emits a KILL event (kind 4, zero batch fields). Other slots and any other active callback are unaffected. A later step cannot deliver canceled requests. Repeated kill on DEAD returns DEAD_SLOT. Reinstall is permitted and does not revive old work. No slot is freed while its active completion is being recorded.

R6 Read-only observations

view(id, out) checks ID then vacancy: VACANT returns MISSING; LIVE and DEAD return OK. On success it fills every View field: life, generation, priority, quota, cookie, depth, pending_count, pending_sum, pending_ticket, active_count, active_sum, active_ticket, completed_batches, delivered_count, delivered_sum, delivered_value. DEAD retains its installed configuration and completion ledger but has zero depth, pending and active fields. On any error out remains byte-for-field unchanged.

summary() returns installs, live, queued, running, starts, finishes, kills, errors, next_ticket, events. live counts LIVE slots; queued counts LIVE slots with pending work (including disabled or active slots); running is 0 or 1. next_ticket starts at 1 and is never reset/reused. events is the number currently retained, not total ever produced. Querying never dispatches or modifies state.

event(index, out) returns retained events oldest first. A ring retains the most recent 16 events, dropping the oldest on overflow. Index 0..15 is syntactically accepted; index outside 0..15 returns BAD_VALUE. An in-domain index at or beyond the retained size returns NO_EVENT. On error out stays unchanged. Event fields are kind,id,generation,count,sum,value,serial; serial starts at 1 and increases for every emitted event. INSTALL/KILL have zero count/sum/value, START/FINISH describe their batch. Queries must expose independent direct API results, not inferred substitutes.

R7 Raw observer and process behavior

observer.cpp is an untrusted-I/O adapter only: it reads commands, calls the corresponding API directly, and prints returned records. It does not generate test cases or judge results. Input is guaranteed well-formed: ASCII decimal tokens fitting signed 64-bit, integers passed as int fitting signed 32-bit, exact arity, one command per line, no unknown commands, at most 4096 commands. Numeric values outside API domains are well-formed and must be validated by the API. Malformed token syntax is outside the contract.

Commands: U instance, I id priority quota cookie, P id value, D id, N id, E id, K id, S, V id marker, G, H index marker. I/P/D/N/E/K print just the numeric status. S prints Action fields. V prints status then all View fields in declaration order; H prints status then all Event fields. V/H initialize every field to marker before calling the API, allowing unchanged-on-error observations. G prints Summary fields in declaration order. Output is decimal fields separated by one space and one newline per command, with no prefixes, banners or extra lines. Stderr must be empty on all well-formed inputs. A complete run exits 0 even when an API call returns an error status. The implementation must not terminate the process or read external files.

The observer constructs two separate Engine objects in the same process, instances 0 and 1, and initially selects instance 0. U instance switches the receiver for subsequent API commands and prints the selected instance number. This adapter command neither calls a mutator nor changes either Engine. Its instance token is guaranteed to be exactly 0 or 1; other selector values are outside the well-formed transport domain. All slots, gates, active and pending work, generations, errors, tickets, counters and event serial/ring state belong to each Engine independently. Selecting an instance never resets or dispatches it. Both objects remain alive until observer exit. The 4096-command limit includes U commands.