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

9.1 KiB

Ordered workqueue model contract

This is a deterministic C++17 user-space model of a dedicated max_active=1 workqueue. No kernel, threads, clock, device, privilege or network is involved. Implement every clause in this document. Only engine.hpp and engine.cpp are collected for grading; extra files are ignored. Keep the public API of namespace ordered in engine.hpp compatible, including enum numeric values, result fields and method signatures. Internal representation and algorithms may change.

Identity, bounds and errors

An Engine initially has no queues and an empty lifetime journal. Each Engine is independent. Number is signed 64-bit. A trace contains at most 10000 API calls. Queue IDs are 1..8, job IDs 1..1000000000, capacity 1..64, job units 1..1000000, payload value -1000000000..1000000000, work budget 0..1000000, event cursor 0..INT64_MAX, and event limit 0..256. API values outside these ranges are BadValue. No overflow is possible within these bounds and trace limit.

Code values: Ok=0, BadValue=1, MissingQueue=2, Exists=3, Closed=4, Full=5, MissingJob=6, Busy=7, BadState=8. Each call validates all its numeric ranges first, then queue existence, then the operation-specific checks in the order listed below. All errors leave all state, counters, tickets and journal unchanged. Query result errors have empty lists or default scalar fields: JobView id/total/remaining/value/ticket=0 and state=Waiting; Stats all fields=0; Work spent/finished=0. code is the actual error. Empty successful lists and zero-work operations are valid.

State values: Waiting=1, Running=2, Complete=3, Cancelled=4. Kind values: Accept=1, Start=2, Finish=3, Cancel=4, Release=5, Close=6. Terminal means Complete or Cancelled.

Creation and admission

create(queue, capacity) checks bounds then Exists if the queue has ever been created. Success installs an open empty queue with the given capacity, ticket counter starting at 1 and all statistics zero. Creation generates no journal event. A destroyed queue remains addressable and cannot be recreated.

submit(queue, job, units, value) checks bounds, MissingQueue, Closed, existing retained job ID (Exists), then capacity and retained-record limits (Full). Capacity counts Waiting plus Running jobs only; Complete and Cancelled records do not consume capacity. At most 256 retained records exist per queue, including terminal ones. A rejected submit consumes no ticket. Success retains a distinct Waiting job, stores total=remaining=units and value, assigns the next monotonically increasing queue-local ticket, increments accepted and waiting, and emits Accept. IDs may be reused only after their terminal record has been released; reused IDs receive a fresh ticket. Different queues may use the same job ID.

Dedicated execution

work(queue, budget) checks bounds, MissingQueue, then Closed. A zero budget is a successful no-op, even with queued work; it does not start a job. Positive budget spends at most that many work units, and reports the actual spent and the number of jobs newly completed by this call. Excess budget on an empty queue is unused. A queue progresses only through work on that queue or destroy on that queue.

When no job is Running, choose the Waiting job with the smallest accepted ticket, change it to Running, decrement waiting, increment started and emit Start before consuming its first unit. At most one job is Running per queue. A Running job always resumes before any later Waiting job, including jobs submitted after a partial work call. Consume min(remaining, available budget) units, subtract from remaining and add to queue ticks. A partially processed job remains Running with positive remaining. If the budget ends exactly at a job boundary, do not start the next job.

When remaining reaches zero, set Complete, increment completed, add that job's value exactly once to total_value, and emit Finish at the resulting tick. The running slot becomes empty. If budget remains, continue with the next oldest Waiting job. Job IDs and payload values do not affect ordering. Cancelled jobs are skipped. Completion retains the record until release.

Cancellation, release and destruction

cancel(queue, job) checks bounds, MissingQueue, MissingJob, Running (Busy), then terminal state (BadState). A Waiting job becomes Cancelled, is removed from pending execution, decrements waiting, increments cancelled and emits Cancel. Its remaining equals its original total because Waiting jobs never consume work. Cancelling does not consume ticks or add to total_value. Repeated cancellation is BadState. Cancel does not separately check Closed; a valid closed queue has no Waiting or Running records.

release(queue, job) checks bounds, MissingQueue, MissingJob, then nonterminal state (Busy). Success emits Release containing the still-retained terminal record, then deletes only that record and increments released. It leaves cumulative accepted/started/completed/cancelled/ticks/total_value unchanged. Release is permitted on a closed queue. Releasing again is MissingJob. Released IDs may be submitted again while open.

destroy(queue) checks bounds then MissingQueue. If already closed, success reports spent=finished=0 and generates no event. Otherwise finish every remaining Running and Waiting job, preserving the same ordering and accounting as work with unlimited sufficient budget. Its spent is the total remaining work, which can exceed 1000000; finished counts completions during this destroy. Cancelled and previously completed jobs are unaffected. After draining, set closed=1 and emit exactly one Close. Close has job=ticket=remaining=value=0 and ticks equal to the queue's final tick. No accepted job may be lost or converted to Cancelled by destroy. Destroy retains all terminal records and statistics. Later submit/work return Closed; queries/release remain available.

Observation and ownership

job(queue, job) checks bounds, MissingQueue, MissingJob and otherwise returns code=Ok plus id,state,total,remaining,value,ticket. jobs(queue) checks bounds then MissingQueue and returns all retained JobViews in ascending ticket order, including Running and terminal jobs. Neither call mutates state. No representation layout or container choice is required.

stats(queue) checks bounds then MissingQueue and returns capacity, closed (0/1), accepted, started, completed, cancelled, released, waiting, running (0/1), retained, ticks and total_value. All counters are cumulative except waiting/running/retained, which describe current records. accepted = retained + released; accepted = waiting + running + completed + cancelled. total_value sums only completed job values, including those whose records were released. Reads do not emit events or advance work.

events(after, limit) validates cursor and limit and returns up to limit lifetime events with serial strictly greater than after, in serial order. A cursor beyond the last serial or limit zero returns an empty list. Events from all queues share one Engine-local serial sequence starting at 1 with no gaps. No event is removed by release/destroy. Each Event contains serial, queue, job, kind, ticket, remaining, ticks, value. For job events capture that job's state fields at the event: Accept/Start have pre-work remaining, Finish has remaining=0, Cancel has original remaining, Release has terminal remaining; ticks is the queue tick at emission. Failed calls produce no events. No events are produced solely for partial progress, create, queries, zero work or repeated destroy. Independent Engine instances start serial numbering afresh. Retained records and journal must remain valid after subsequent operations; results are value snapshots, not aliases.

Raw observer protocol and build

Build: g++ -std=c++17 -O2 -Wall -Wextra engine.cpp runner.cpp -o queue-demo. The grading observer uses the same API and prints raw return values; it supplies no cases, expected values or assertions to candidate code. stdin has one command per line. Arguments are signed 64-bit decimal tokens (optional minus, no plus); arity must be exact. Blank lines, unknown commands, partial numbers, overflow/underflow or extra/missing tokens print INPUT and call no API; subsequent lines continue normally. Valid lexical numbers outside API bounds go through the API and return BadValue. Normal EOF exits 0. No diagnostics or additional stdout are allowed.

Commands and outputs (bracketed groups repeat n times, not literal brackets):

  • C q cap -> R code; S q job units value -> R code.
  • X q job -> R code from cancel; F q job -> R code from release.
  • W q budget or D q -> W code spent finished.
  • J q job -> J code id state total remaining value ticket.
  • Q q -> Q code capacity closed accepted started completed cancelled released waiting running retained ticks total_value.
  • L q -> L code n [id state total remaining value ticket].
  • E after limit -> E code n [serial queue job kind ticket remaining ticks value].

No command may read files or infer expected output. All execution state belongs to the Engine. The observer is a convenience client; replacing it does not affect grading. Formal grading compiles only the declared candidate files with an independent raw API observer, then compares observations with a Python model outside the candidate process.