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>
16 lines
19 KiB
JSON
16 lines
19 KiB
JSON
{
|
|
"seed": 72419031,
|
|
"context": {
|
|
"service.h": "#ifndef TELEMETRY_SERVICE_H\n#define TELEMETRY_SERVICE_H\n\n#include \"queue.h\"\n#include \"monitor.h\"\n#include <stdint.h>\n\n#define SERVICE_WORKERS 6\n#define SERVICE_OBSERVATIONS 83\n\nenum service_phase {\n SERVICE_OPEN = 0,\n SERVICE_DRAIN = 1,\n SERVICE_DISCARD = 2\n};\n\nenum worker_state {\n WORKER_READY = 0,\n WORKER_WAITING = 1,\n WORKER_EXITED = 2,\n WORKER_UNUSED = 3\n};\n\nenum service_result {\n SERVICE_OK = 0,\n SERVICE_INVALID = -1,\n SERVICE_CLOSED = -2,\n SERVICE_FULL = -3,\n SERVICE_DUPLICATE = -4,\n SERVICE_MISSING = -5\n};\n\ntypedef struct {\n unsigned state;\n uint64_t completed;\n int64_t total;\n uint32_t hash;\n} service_worker;\n\ntypedef struct {\n work_queue pending;\n queue_monitor monitor;\n service_worker workers[SERVICE_WORKERS];\n unsigned worker_count;\n unsigned phase;\n uint64_t accepted;\n uint64_t completed;\n uint64_t cancelled;\n uint64_t rejected;\n int64_t total;\n uint32_t hash;\n} queue_service;\n\nint service_init(queue_service *service, int workers, int capacity);\nint service_submit(queue_service *service, int id, int value, int lane);\nint service_turn(queue_service *service, int worker);\nint service_advance(queue_service *service, int rounds);\nint service_cancel(queue_service *service, int id);\nint service_close(queue_service *service, int mode);\nint service_spurious(queue_service *service, int worker);\nint service_reject(queue_service *service);\nvoid service_snapshot(const queue_service *service, int rc,\n int64_t output[SERVICE_OBSERVATIONS]);\n\n#endif\n",
|
|
"Makefile": "CC = cc\nCFLAGS = -std=c11 -O2 -Wall -Wextra -Wpedantic\n\nqueue-demo: queue.c service.c cli.c monitor.c queue.h service.h monitor.h\n\t$(CC) $(CFLAGS) queue.c service.c monitor.c cli.c -o queue-demo\n\nclean:\n\trm -f queue-demo\n\n.PHONY: clean\n",
|
|
"monitor.c": "#include \"monitor.h\"\n\nstatic unsigned worker_bit(unsigned worker)\n{\n return 1u << worker;\n}\n\nvoid monitor_init(queue_monitor *monitor, unsigned workers)\n{\n monitor->locked = 0;\n monitor->waiting = 0;\n monitor->workers = workers;\n monitor->faults = 0;\n}\n\nvoid monitor_lock(queue_monitor *monitor)\n{\n if (monitor->locked) {\n monitor->faults += 1;\n }\n monitor->locked = 1;\n}\n\nvoid monitor_unlock(queue_monitor *monitor)\n{\n if (!monitor->locked) {\n monitor->faults += 1;\n }\n monitor->locked = 0;\n}\n\nvoid monitor_wait(queue_monitor *monitor, unsigned worker)\n{\n if (!monitor->locked) {\n monitor->faults += 1;\n return;\n }\n if (worker >= monitor->workers) {\n monitor->faults += 1;\n return;\n }\n unsigned bit = worker_bit(worker);\n if (monitor->waiting & bit) {\n monitor->faults += 1;\n return;\n }\n monitor->waiting |= bit;\n}\n\nunsigned monitor_notify_one(queue_monitor *monitor)\n{\n if (!monitor->locked) {\n monitor->faults += 1;\n return 0;\n }\n for (unsigned worker = 0; worker < monitor->workers; ++worker) {\n unsigned bit = worker_bit(worker);\n if (monitor->waiting & bit) {\n monitor->waiting &= ~bit;\n return bit;\n }\n }\n return 0;\n}\n\nunsigned monitor_notify_all(queue_monitor *monitor)\n{\n if (!monitor->locked) {\n monitor->faults += 1;\n return 0;\n }\n unsigned wake = monitor->waiting;\n monitor->waiting = 0;\n return wake;\n}\n\nunsigned monitor_spurious(queue_monitor *monitor, unsigned worker)\n{\n if (worker >= monitor->workers) {\n monitor->faults += 1;\n return 0;\n }\n unsigned bit = worker_bit(worker);\n unsigned wake = monitor->waiting & bit;\n monitor->waiting &= ~bit;\n return wake;\n}\n",
|
|
"monitor.h": "#ifndef TELEMETRY_MONITOR_H\n#define TELEMETRY_MONITOR_H\n\n#include <stdint.h>\n\n#define MONITOR_WORKERS 6\n\ntypedef struct {\n unsigned locked;\n unsigned waiting;\n unsigned workers;\n uint64_t faults;\n} queue_monitor;\n\nvoid monitor_init(queue_monitor *monitor, unsigned workers);\nvoid monitor_lock(queue_monitor *monitor);\nvoid monitor_unlock(queue_monitor *monitor);\nvoid monitor_wait(queue_monitor *monitor, unsigned worker);\nunsigned monitor_notify_one(queue_monitor *monitor);\nunsigned monitor_notify_all(queue_monitor *monitor);\nunsigned monitor_spurious(queue_monitor *monitor, unsigned worker);\n\n#endif\n",
|
|
"queue.h": "#ifndef TELEMETRY_QUEUE_H\n#define TELEMETRY_QUEUE_H\n\n#include <stddef.h>\n\n#define QUEUE_LIMIT 16\n\ntypedef struct {\n unsigned id;\n int value;\n unsigned lane;\n} queue_job;\n\ntypedef struct {\n queue_job slots[QUEUE_LIMIT];\n unsigned head;\n unsigned count;\n unsigned capacity;\n} work_queue;\n\nint queue_init(work_queue *queue, unsigned capacity);\nint queue_valid(const work_queue *queue);\nunsigned queue_count(const work_queue *queue);\nunsigned queue_capacity(const work_queue *queue);\nint queue_empty(const work_queue *queue);\nint queue_full(const work_queue *queue);\nint queue_contains(const work_queue *queue, unsigned id);\nint queue_push(work_queue *queue, const queue_job *job);\nint queue_front(const work_queue *queue, queue_job *job);\nint queue_pop(work_queue *queue, queue_job *job);\nint queue_at(const work_queue *queue, unsigned offset, queue_job *job);\nint queue_remove(work_queue *queue, unsigned id, queue_job *job);\nunsigned queue_clear(work_queue *queue);\n\n#endif\n",
|
|
"cli.c": "#include \"service.h\"\n#include <ctype.h>\n#include <errno.h>\n#include <inttypes.h>\n#include <limits.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nstatic void observe(const queue_service *service, int rc)\n{\n int64_t values[SERVICE_OBSERVATIONS];\n service_snapshot(service, rc, values);\n for (unsigned index = 0; index < SERVICE_OBSERVATIONS; ++index) {\n if (index != 0) {\n putchar(' ');\n }\n printf(\"%\" PRId64, values[index]);\n }\n putchar('\\n');\n}\n\nstatic int parse_integer(const char *text, int *result)\n{\n if (text == NULL || *text == '\\0') {\n return 0;\n }\n const char *cursor = text;\n if (*cursor == '+' || *cursor == '-') {\n cursor += 1;\n }\n if (*cursor == '\\0') {\n return 0;\n }\n while (*cursor != '\\0') {\n if (!isdigit((unsigned char)*cursor)) {\n return 0;\n }\n cursor += 1;\n }\n errno = 0;\n char *end = NULL;\n long long value = strtoll(text, &end, 10);\n if (errno == ERANGE || *end != '\\0' || value < INT_MIN || value > INT_MAX) {\n return 0;\n }\n *result = (int)value;\n return 1;\n}\n\nstatic int dispatch(queue_service *service, char *line)\n{\n char *words[6];\n unsigned count = 0;\n char *word = strtok(line, \" \\t\\r\\n\");\n while (word != NULL && count < 6) {\n words[count++] = word;\n word = strtok(NULL, \" \\t\\r\\n\");\n }\n if (count == 0) {\n return SERVICE_OK;\n }\n if (word != NULL || strlen(words[0]) != 1) {\n return service_reject(service);\n }\n int values[5];\n for (unsigned index = 1; index < count; ++index) {\n if (!parse_integer(words[index], &values[index - 1])) {\n return service_reject(service);\n }\n }\n char command = words[0][0];\n if (command == 'I' && count == 3) {\n return service_init(service, values[0], values[1]);\n }\n if (command == 'S' && count == 4) {\n return service_submit(service, values[0], values[1], values[2]);\n }\n if (command == 'T' && count == 2) {\n return service_turn(service, values[0]);\n }\n if (command == 'A' && count == 2) {\n return service_advance(service, values[0]);\n }\n if (command == 'C' && count == 2) {\n return service_cancel(service, values[0]);\n }\n if (command == 'X' && count == 2) {\n return service_close(service, values[0]);\n }\n if (command == 'N' && count == 2) {\n return service_spurious(service, values[0]);\n }\n if (command == 'Q' && count == 1) {\n return SERVICE_OK;\n }\n return service_reject(service);\n}\n\nint main(void)\n{\n queue_service service = {0};\n service_init(&service, 1, 4);\n char line[512];\n while (fgets(line, sizeof(line), stdin) != NULL) {\n int nonblank = 0;\n for (size_t index = 0; line[index] != '\\0'; ++index) {\n if (!isspace((unsigned char)line[index])) {\n nonblank = 1;\n }\n }\n if (!nonblank) {\n continue;\n }\n int rc = dispatch(&service, line);\n observe(&service, rc);\n }\n return ferror(stdin) ? 1 : 0;\n}\n",
|
|
"README.md": "# Telemetry queue replay\n\nBuild: `make`\n\nReplay: `./queue-demo < examples/restart.txt`\n\nThe complete behavior and public C interface contract is in `docs/service.md`.\n`queue.c` and `service.c` are the submitted files. Headers, `monitor.c`,\n`cli.c`, examples and the Makefile are fixed support materials.\nThis is an offline software model; no external packages or board are needed.\n",
|
|
"examples/restart.txt": "I 1 4\nA 1\nS 11 70 2\nA 1\nQ\nX 0\nA 4\nQ\nI 4 2\nA 1\nX 1\nA 2\nQ\n",
|
|
"docs/service.md": "# Queue service contract, revision 1\n\n## 1. Scope and execution\n\nThis is a deterministic model of an embedded telemetry uploader's monitor, FIFO and worker pool. It performs no real I/O, threading, waiting, sleeping or clock reads. Each input command is one atomic controller action. A worker runs only when a T or A command explicitly gives it a turn. All integers are decimal. Build with `make`, then run `./queue-demo < examples/restart.txt`. The program handles a stream until EOF, emits one observation per nonblank input line, and exits 0. Blank lines emit nothing. No other stdout is permitted. Diagnostics may use stderr.\n\nThe service starts as if `I 1 4` had run. `I workers capacity` resets the complete instance, metrics, monitor and workers; workers is 1..6 and capacity is 1..16. Invalid initialization leaves the previous instance intact and records a rejection. No process-global state survives a successful I.\n\n## 2. State and jobs\n\nPhases are OPEN=0, DRAIN=1, DISCARD=2. Worker states are READY=0, WAITING=1, EXITED=2; unused worker observation slots use 3 and zero metrics. Initialization makes all configured workers READY. A job has id 1..65535, signed value -100000..100000, and lane 0..3. The bounded pending FIFO preserves submission order, including across cancellation and wraparound. Duplicate ids are forbidden only among pending jobs; an id can be reused once consumed or cancelled. Failed operations must not alter pending jobs, worker states or successful-work metrics.\n\nReturn codes are OK=0, INVALID=-1, CLOSED=-2, FULL=-3, DUPLICATE=-4, MISSING=-5. Every nonzero return increments `rejected` exactly once, including syntax errors. All counts, totals and hashes reset at successful I. Supported traces have at most 20000 commands; signed totals fit int64 and unsigned counters fit uint64.\n\n## 3. Controller commands\n\n`S id value lane`: validate all three fields, then check phase, duplicate id, and capacity in that order. Reject a submission outside OPEN with CLOSED; reject duplicate pending id before checking FULL. Accept by appending the job, increasing accepted by one, and making the lowest-index WAITING worker READY if one exists. Exactly one waiter becomes eligible per accepted job. No job runs during S. This publication and handoff are a single monitor action. With no waiting worker, no worker state changes.\n\n`T worker`: worker index is 0..workers-1. A WAITING or EXITED worker does nothing. A READY worker acquires the monitor, then consumes exactly one oldest pending job if available. It remains READY after consumption, including during DRAIN. If no job is pending, a READY worker enters WAITING in OPEN, or EXITED in either closing phase. Reading the predicate and registering the wait are one monitor action. A worker never consumes or completes a nonexistent job.\n\n`A rounds`: rounds is 0..128. Perform exactly that many sweeps; each sweep gives T to every configured worker once in ascending index order. A does not alter rejected for internally executed valid worker turns. A 0 is a successful no-op. Scheduling order is part of this software model, independent of CPU timing.\n\n`C id`: id is 1..65535. Remove that pending job, preserving relative order of all others, and increase cancelled by one. If it is absent return MISSING. Cancellation remains available during DRAIN. No worker runs or changes eligibility during C.\n\n`X mode`: mode 0 requests DRAIN, mode 1 requests DISCARD. On the first X, change OPEN to the requested phase and make every WAITING worker READY in the same monitor action. DRAIN retains all pending jobs for worker turns. DISCARD removes every pending job and increases cancelled by that count. Once closing, further valid X commands return OK without changing phase, jobs, eligibility or counters. READY workers still need a T/A turn to consume or exit. After enough turns every worker must EXIT, including pools larger than one. Successful submissions are never silently lost: accepted = pending + completed + cancelled.\n\n`N worker`: inject a spurious notification for a configured worker. WAITING becomes READY; other states do not change. This does not create a job or increment work metrics. A subsequent turn must recheck the normal predicate and may wait again.\n\n`Q`: return OK and observe without changing state. Unknown commands, missing/extra arguments, noninteger tokens and out-of-range fields return INVALID. Each command occupies a line of at most 511 bytes. The provided parser is part of the fixed frontend. Command letters are case sensitive.\n\n## 4. Completion accounting\n\nOn consumption of (id,value,lane), `result = value * (lane + 1) + id`. Add result to the service total and that worker's total; increment completed globally and for that worker. Both service and worker hashes begin at zero and update on each completion as `h = (h * 33 + id * 17 + (value modulo 2^32) + lane) modulo 2^32`. The service hash follows actual consumption order; worker hashes follow their own completions. A rejected operation, wait, wake, cancellation or exit does not update these metrics.\n\n## 5. Monitor and public C interfaces\n\n`queue.h`, `service.h`, and `monitor.h` declare the public structures and functions. The monitor is an instrumented software replacement for mutex/condition operations, supplied by `monitor.c`. Only a held monitor may wait, signal or broadcast. Nested locking, unlocking an unlocked monitor, invalid wait registrations or notify outside the lock increase `faults`; correct service traces always have faults=0 and return with the monitor unlocked. The caller applies returned wake masks to worker eligibility. `monitor_notify_one` returns the lowest waiting bit; `monitor_notify_all` returns all waiting bits, clearing returned bits. `monitor_spurious` removes only its specified waiting bit and does not require the monitor lock. No busy polling or implicit worker scheduling occurs. The FIFO can use any internal arrangement that honors its public interface and capacity; its head field is internal.\n\nFunctions in queue.c implement bounded FIFO initialization, validation, insertion, front/pop, indexed copying, stable removal and clearing. The mutating/result-copying functions queue_init, queue_push, queue_front, queue_pop, queue_at and queue_remove return 0 on success or -1 on invalid/unavailable operations, leave output jobs untouched on failure, and do not alter a queue on failure. queue_count and queue_capacity return their named values; queue_empty, queue_full, queue_contains and queue_valid return boolean 0 or 1. `queue_clear` returns its previous count. `queue_valid` recognizes initialized queues with capacity 1..16, head within capacity, count at most capacity, valid job fields and unique pending ids. The other queue functions receive initialized queues. `service_init` returns INVALID for invalid bounds; other service functions return the codes in section 2. `service_reject` records one INVALID. `service_snapshot` is observational and must not alter the service. No submitted code may read files or obtain answers from external state; the entire job stream is its input.\n\n## 6. Observation format\n\nEvery command emits a flat line of 83 decimal integers in this order: return code, phase, accepted, completed, cancelled, rejected, pending count, configured workers, monitor faults, service signed total, service unsigned hash; then six worker records `(state, completed, signed total, unsigned hash)`; then sixteen FIFO records `(id,value,lane)` in consumption order, padding absent entries with `(0,0,0)`. All observation fields come from the public `service_snapshot` interface. A correct response to Q is byte-for-byte stable. There is one space between integers, no trailing spaces, and a newline. Counts are exact; no numeric tolerance applies.\n\n## 7. Delivery and evaluation boundary\n\nSubmit only `queue.c` and `service.c`. All fixed headers, monitor, frontend, examples and Makefile are restored from this distribution for evaluation. The evaluator builds fresh C11 code against those interfaces, drives command streams including different pool/capacity sizes, and compares raw observations with this contract. It may also use the public FIFO API directly. Tests cover normal processing, restart, partial sweeps, no-op scheduling, spurious notifications, capacity and id boundaries, cancellation, both close policies and malformed commands. No board, real pthread timing, GDB invocation, performance threshold or wall-clock latency is evaluated.\n",
|
|
"fifo_probe.c": "#include \"queue.h\"\n#include <stdio.h>\n\nint main(void)\n{\n work_queue queue;\n queue_init(&queue, 4);\n char line[256];\n while (fgets(line, sizeof(line), stdin) != NULL) {\n char command = 0;\n int a = 0, b = 0, c = 0;\n sscanf(line, \" %c %d %d %d\", &command, &a, &b, &c);\n queue_job output = {77, -777, 7};\n queue_job input = {(unsigned)a, b, (unsigned)c};\n int rc = 0;\n switch (command) {\n case 'J': rc = queue_init(&queue, (unsigned)a); break;\n case 'P': rc = queue_push(&queue, &input); break;\n case 'O': rc = queue_pop(&queue, &output); break;\n case 'F': rc = queue_front(&queue, &output); break;\n case 'D': rc = queue_remove(&queue, (unsigned)a, &output); break;\n case 'K': rc = queue_at(&queue, (unsigned)a, &output); break;\n case 'V': rc = queue_contains(&queue, (unsigned)a); break;\n case 'E': rc = (int)queue_clear(&queue); break;\n }\n printf(\"%d %u %d %u %u %u %d %d %d\", rc, output.id, output.value,\n output.lane, queue_count(&queue), queue_capacity(&queue),\n queue_empty(&queue), queue_full(&queue), queue_valid(&queue));\n for (unsigned index = 0; index < QUEUE_LIMIT; ++index) {\n queue_job job = {0};\n queue_at(&queue, index, &job);\n printf(\" %u %d %u\", job.id, job.value, job.lane);\n }\n putchar('\\n');\n }\n return 0;\n}\n"
|
|
}
|
|
}
|