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.0 KiB
Message notification runtime contract v1
This C++17 component is a deterministic Linux userspace software model. The rules below are the complete custom contract, inspired by one-shot queue notifications. They do not claim full POSIX mq_notify semantics. No signal, thread, process queue, clock, network, or hardware is involved. Implement every rule in this document. Only runtime.hpp, state.hpp, runtime.cpp, storage.cpp, notify.cpp are submitted and collected; extra files are not collected. Public types and methods in runtime.hpp must remain source compatible; internal representation may change.
State and domains
Each constructed Runtime owns four independent initially absent FIFO queues, its pending event collection, and nine initially zero counters. Two Runtime objects in one process share no state. No copy or assignment is required. Destruction releases that object's resources without output. A fresh instance starts event serials and queue epochs at zero.
All integer arguments are C++ int, including cookies. Queue domain is 0..3, capacity 1..8, owner 1..65535, message id -32768..32767, message value -1000000..1000000, drain limit 0..8, and at index 0..7. Cookie accepts the complete signed 32-bit range, including -2147483648 and 2147483647. IDs need not be unique; FIFO means successful send order, with no priority or sorting by ID/value/owner.
Return codes are Code::ok=0, invalid=-1, missing=-2, busy=-3, full=-4, empty=-5, denied=-6. Validate every supplied argument's domain first, before existence or state checks; any invalid argument gives invalid, even when other state errors also apply. Then an absent queue gives missing. Every failure is atomic: no messages, registrations, events, epochs, or counters change. Every Result error has a value-initialized payload (zero fields, or an empty vector). Code-returning operations have no payload. Successful observations never change state.
A live queue contains capacity, messages, a registration (owner,cookie) or no registration, and an epoch. create(q,cap) returns busy if already live; otherwise it creates an empty unarmed queue, increments that slot's epoch by one and created by one. close(q) removes a live queue, drops its remaining messages into discarded, and increments closed. It clears its registration without incrementing canceled. Epoch survives close internally and increments on the next create. Pending events survive close and recreation. An absent queue has no observable snapshot: snapshot returns missing with a zero payload.
Notification lifecycle
arm(q,owner,cookie) succeeds only when live and unarmed. Any occupied registration gives busy, including the same owner/cookie; a busy arm cannot replace either field. Successful arm stores the supplied owner/cookie and increments armed.
Arming an already nonempty queue never creates an event and never consumes the registration. It remains armed through receives, partial drains, zero drains, failed sends, queries and further sends to a nonempty queue. After the queue eventually becomes empty, a future successful send from size 0 to size 1 creates its event. The arm operation itself is never an empty-to-nonempty transition.
A successful send to an empty armed queue appends exactly one pending Event {serial,queue,owner,cookie}, using the stored registration and the queue slot number. It increments notified, whose new value is the event serial (starting at 1 per Runtime). It consumes the registration completely before returning, so snapshot owner/cookie become 0/0. Later sends cannot notify until another successful arm, even after the queue has drained empty. A new arm may succeed while an earlier event remains unclaimed. Events cannot be silently coalesced.
cancel(q,owner) succeeds with no change if unarmed. If armed by another owner it returns denied. If armed by the same owner it clears both owner and cookie and increments canceled. cancel never erases an event that was already created. Closing a queue also never erases events. Each pending event records its original cookie; rearming, cancellation, close and recreation cannot rewrite it.
Message and observation APIs
send(q,id,value) appends a Message on success and increments sent. A queue at capacity gives full; it never drops/replaces an existing message or consumes an arm on failure. Messages preserve both integer fields exactly.
receive(q) removes and returns the first FIFO message and increments received, or gives empty with zero message if no message is available. Removing the final message does not alter a registration or create an event.
drain(q,limit) removes up to limit FIFO messages and returns them in order, incrementing received by the number removed. Empty drains and limit 0 are successful with an empty vector. Draining never alters registration or pending events. The final removal only enables a future send to be a 0-to-1 transition.
front(q) returns the first FIFO Message or empty with zero message. at(q,index) returns the indexed FIFO Message, or empty with zero message if index is valid but >= current size. Neither removes a message. snapshot(q) returns QueueView {epoch,capacity,size,owner,cookie}; an unarmed queue has owner=cookie=0. All three are const observations and must agree with receive/drain.
inspect(owner) returns that owner's oldest pending Event (lowest serial), or empty with a zero event. claim(owner) returns and removes that same event, incrementing claimed on success; no event gives empty with zero event. Events for other owners are untouched, including earlier ones. pending(owner) returns the count of that owner's events, including zero with ok. All three validate owner even when no events exist. inspect and pending are const observations.
stats() is a const observation returning {created,closed,sent,received,discarded,armed,canceled,notified,claimed}. Counts are successful actions only: canceled counts explicit removal of an occupied registration, received counts messages removed by receive/drain, discarded counts messages removed by close, notified counts generated events, and claimed counts successful claim calls. Failed calls, empty/zero drains, unarmed cancel and every observation change none. Counters use uint64_t; test histories stay below 100000 operations per object and never overflow.
Raw observer and byte protocol
The provided observer.cpp is a transport adapter, not an oracle. Build with c++ -std=c++17 -O2 runtime.cpp storage.cpp notify.cpp observer.cpp -o message-observer or make. Run ./message-observer < smoke.in. Well-formed input only is required: each line has an instance (0 or 1), one command, and its exact count of decimal int arguments, and a final LF; integers fit int. Malformed syntax, unknown commands, invalid instance numbers and integer lexical overflow are outside the input contract. Domain-invalid int arguments in otherwise well-formed commands are required to work as specified above.
Commands and directly called APIs: C q cap -> create; X q -> close; A q owner cookie -> arm; K q owner -> cancel; S q id value -> send; R q -> receive; D q limit -> drain; F q -> front; M q index -> at; V q -> snapshot; E owner -> claim; I owner -> inspect; N owner -> pending; G -> stats. Both instances live for the complete input. The observer calls exactly the named API and prints one line per command, with no automatic snapshot or hidden API calls.
Each output starts instance command. Code-only commands append code. R/F/M append code id value. D appends code count followed by each id value. V appends code epoch capacity size owner cookie. E/I append code serial queue owner cookie. N appends code count. G appends the nine counters in the stats order above with no code. Decimal fields are separated by one ASCII space. Every line ends in exactly one LF; there are no CR bytes, leading/trailing spaces, banners or extra lines. Normal complete input exits 0 and stderr must be empty. Candidate code must not print diagnostics. Official checks capture bytes and compare the complete stdout with this encoding and require stderr == empty; they do not normalize whitespace or line endings.