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>
13 lines
22 KiB
JSON
13 lines
22 KiB
JSON
{
|
|
"Makefile": "CC = gcc\nCFLAGS = -std=c11 -O2 -Wall -Wextra -pedantic\nSOURCES = runner.c command_port.c wire.c observe.c\nHEADERS = command_port.h wire.h\nall: command-observe\ncommand-observe: $(SOURCES) $(HEADERS)\n\t$(CC) $(CFLAGS) $(SOURCES) -o $@\ndemo: command-observe\n\t./command-observe < demo.plan\nclean:\n\trm -f command-observe\n.PHONY: all demo clean\n",
|
|
"README.md": "# Command capture service\nThis is a deterministic software model of the command-output port used by a diagnostic service. It starts no OS child or shell. A port operation models a stream endpoint and an independently retained child completion record.\nBuild with `make`; reproduce with `make demo` and `./command-observe < error.plan`.\nThe input frontend and port are public supporting materials. The submitted service is `runner.c`. All requirements are in `docs/collection.md`; preserve every clause.\n",
|
|
"command_port.c": "#include \"command_port.h\"\n#include <string.h>\nstatic void record_event(struct command_port *port, unsigned operation, unsigned token, long value)\n{\n if (port->event_count < COMMAND_MAX_EVENTS) {\n struct port_event *event = &port->events[port->event_count++];\n event->operation = operation;\n event->token = token;\n event->value = value;\n } else {\n port->dropped_events++;\n }\n}\nstatic unsigned token_of(size_t index, unsigned generation)\n{\n return generation * COMMAND_MAX_RECORDS + (unsigned)index;\n}\nstatic struct port_record *lookup(struct command_port *port, unsigned token)\n{\n unsigned index = token % COMMAND_MAX_RECORDS;\n unsigned generation = token / COMMAND_MAX_RECORDS;\n struct port_record *record = &port->records[index];\n if (!record->active || record->generation != generation) {\n port->protocol_errors++;\n return NULL;\n }\n return record;\n}\nstatic void retire(struct port_record *record)\n{\n if (!record->stream_open && !record->child_owned) {\n record->active = 0;\n }\n}\nint command_plan_valid(const struct command_plan *plan)\n{\n if (plan == NULL) {\n return 0;\n }\n if (plan->payload_size > COMMAND_MAX_BYTES) {\n return 0;\n }\n if (plan->chunk_size == 0 || plan->chunk_size > 128) {\n return 0;\n }\n if (plan->read_fault_at < -1 || plan->read_fault_at > (long)plan->payload_size) {\n return 0;\n }\n if (plan->read_interrupts > 16 || plan->wait_interrupts > 16) {\n return 0;\n }\n if (plan->child_exit > 255 || plan->child_signal > 64) {\n return 0;\n }\n if (plan->child_signal != 0 && plan->child_exit != 0) {\n return 0;\n }\n if (plan->fail_open != 0 && plan->fail_open != 1) {\n return 0;\n }\n return 1;\n}\nvoid command_port_init(struct command_port *port, unsigned streams, unsigned children)\n{\n memset(port, 0, sizeof(*port));\n port->stream_capacity = streams;\n port->child_capacity = children;\n port->next_generation = 1;\n port->plan.chunk_size = 16;\n port->plan.read_fault_at = -1;\n}\nint command_port_configure(struct command_port *port, const struct command_plan *plan)\n{\n if (!command_plan_valid(plan)) {\n return PORT_ERROR;\n }\n port->plan = *plan;\n return 0;\n}\nint command_port_open(struct command_port *port, unsigned tag, unsigned *token)\n{\n size_t index;\n if (token == NULL || !command_plan_valid(&port->plan)) {\n port->protocol_errors++;\n record_event(port, 1, 0, PORT_ERROR);\n return PORT_ERROR;\n }\n if (port->plan.fail_open || port->streams_live >= port->stream_capacity ||\n port->children_live >= port->child_capacity) {\n port->failures++;\n record_event(port, 1, 0, PORT_ERROR);\n return PORT_ERROR;\n }\n for (index = 0; index < COMMAND_MAX_RECORDS; index++) {\n struct port_record *record = &port->records[index];\n if (record->active) {\n continue;\n }\n memset(record, 0, sizeof(*record));\n record->active = 1;\n record->stream_open = 1;\n record->child_owned = 1;\n record->generation = port->next_generation++;\n record->tag = tag;\n record->read_interrupts = port->plan.read_interrupts;\n record->wait_interrupts = port->plan.wait_interrupts;\n port->streams_live++;\n port->children_live++;\n port->opens++;\n if (port->streams_live > port->streams_peak) {\n port->streams_peak = port->streams_live;\n }\n if (port->children_live > port->children_peak) {\n port->children_peak = port->children_live;\n }\n *token = token_of(index, record->generation);\n record_event(port, 1, *token, tag);\n return 0;\n }\n port->failures++;\n record_event(port, 1, 0, PORT_ERROR);\n return PORT_ERROR;\n}\nlong command_port_read(struct command_port *port, unsigned token, unsigned char *data, size_t size)\n{\n struct port_record *record = lookup(port, token);\n size_t amount;\n port->reads++;\n if (record == NULL || !record->stream_open || data == NULL || size == 0) {\n port->protocol_errors++;\n record_event(port, 2, token, PORT_ERROR);\n return PORT_ERROR;\n }\n if (record->read_interrupts != 0) {\n record->read_interrupts--;\n record_event(port, 2, token, PORT_INTERRUPTED);\n return PORT_INTERRUPTED;\n }\n if (port->plan.read_fault_at >= 0 && record->position >= (size_t)port->plan.read_fault_at) {\n record_event(port, 2, token, PORT_ERROR);\n return PORT_ERROR;\n }\n if (record->position == port->plan.payload_size) {\n record_event(port, 2, token, 0);\n return 0;\n }\n amount = port->plan.payload_size - record->position;\n if (amount > size) {\n amount = size;\n }\n if (amount > port->plan.chunk_size) {\n amount = port->plan.chunk_size;\n }\n if (port->plan.read_fault_at >= 0 && amount > (size_t)port->plan.read_fault_at - record->position) {\n amount = (size_t)port->plan.read_fault_at - record->position;\n }\n memcpy(data, port->plan.payload + record->position, amount);\n record->position += amount;\n record_event(port, 2, token, (long)amount);\n return (long)amount;\n}\nint command_port_close(struct command_port *port, unsigned token)\n{\n struct port_record *record = lookup(port, token);\n if (record == NULL || !record->stream_open) {\n port->protocol_errors++;\n record_event(port, 3, token, PORT_ERROR);\n return PORT_ERROR;\n }\n record->stream_open = 0;\n port->streams_live--;\n port->closes++;\n retire(record);\n record_event(port, 3, token, 0);\n return 0;\n}\nint command_port_wait(struct command_port *port, unsigned token, unsigned *exit_code, unsigned *signal_number)\n{\n struct port_record *record = lookup(port, token);\n if (record == NULL || !record->child_owned || exit_code == NULL || signal_number == NULL) {\n port->protocol_errors++;\n record_event(port, 4, token, PORT_ERROR);\n return PORT_ERROR;\n }\n if (record->wait_interrupts != 0) {\n record->wait_interrupts--;\n record_event(port, 4, token, PORT_INTERRUPTED);\n return PORT_INTERRUPTED;\n }\n *exit_code = port->plan.child_exit;\n *signal_number = port->plan.child_signal;\n record->child_owned = 0;\n port->children_live--;\n port->waits++;\n retire(record);\n record_event(port, 4, token, 0);\n return 0;\n}\nsize_t command_port_events(const struct command_port *port, struct port_event *events, size_t capacity)\n{\n size_t count = port->event_count < capacity ? port->event_count : capacity;\n if (events != NULL && count != 0) {\n memcpy(events, port->events, count * sizeof(*events));\n }\n return count;\n}\n",
|
|
"command_port.h": "#ifndef COMMAND_PORT_H\n#define COMMAND_PORT_H\n#include <stddef.h>\n#include <stdint.h>\n#define COMMAND_MAX_BYTES 2048\n#define COMMAND_MAX_RECORDS 16\n#define COMMAND_MAX_EVENTS 32768\n#define PORT_INTERRUPTED (-2)\n#define PORT_ERROR (-1)\nstruct command_plan {\n unsigned char payload[COMMAND_MAX_BYTES];\n size_t payload_size;\n size_t chunk_size;\n long read_fault_at;\n unsigned read_interrupts;\n unsigned wait_interrupts;\n unsigned child_exit;\n unsigned child_signal;\n int fail_open;\n};\nstruct command_request {\n size_t capture_limit;\n unsigned tag;\n};\nenum command_status {\n COMMAND_OK = 0,\n COMMAND_OPEN_ERROR = 1,\n COMMAND_READ_ERROR = 2,\n COMMAND_CHILD_ERROR = 3,\n COMMAND_INVALID = 4\n};\nstruct command_result {\n enum command_status status;\n size_t bytes_seen;\n size_t bytes_stored;\n uint32_t checksum;\n unsigned child_exit;\n unsigned child_signal;\n int truncated;\n unsigned char capture[COMMAND_MAX_BYTES];\n};\nstruct port_record {\n int active;\n int stream_open;\n int child_owned;\n unsigned generation;\n unsigned tag;\n size_t position;\n unsigned read_interrupts;\n unsigned wait_interrupts;\n};\nstruct port_event {\n unsigned operation;\n unsigned token;\n long value;\n};\nstruct command_port {\n struct command_plan plan;\n struct port_record records[COMMAND_MAX_RECORDS];\n struct port_event events[COMMAND_MAX_EVENTS];\n size_t event_count;\n unsigned next_generation;\n unsigned stream_capacity;\n unsigned child_capacity;\n unsigned streams_live;\n unsigned children_live;\n unsigned streams_peak;\n unsigned children_peak;\n unsigned opens;\n unsigned closes;\n unsigned waits;\n unsigned reads;\n unsigned failures;\n unsigned protocol_errors;\n unsigned dropped_events;\n};\nint command_plan_valid(const struct command_plan *plan);\nvoid command_port_init(struct command_port *port, unsigned streams, unsigned children);\nint command_port_configure(struct command_port *port, const struct command_plan *plan);\nint command_port_open(struct command_port *port, unsigned tag, unsigned *token);\nlong command_port_read(struct command_port *port, unsigned token, unsigned char *data, size_t size);\nint command_port_close(struct command_port *port, unsigned token);\nint command_port_wait(struct command_port *port, unsigned token, unsigned *exit_code, unsigned *signal_number);\nsize_t command_port_events(const struct command_port *port, struct port_event *events, size_t capacity);\nint command_collect(struct command_port *port, const struct command_request *request, struct command_result *result);\n#endif\n",
|
|
"demo.plan": "N 1 1\nP 68656c6c6f0a 3 -1 0 0 0 0 0 6\nR 6 42\nR 6 43\n",
|
|
"docs/collection.md": "# Collection contract, version 1\nC01. `command_collect` uses the public signatures and status values in command_port.h. Its return value equals result.status. A nonnull result is reset on every call: counts, child fields and truncated are zero, checksum is FNV-1a's 2166136261, and capture's used prefix is empty. Bytes beyond bytes_stored have no specified value.\nC02. A null port/request or capture_limit above 2048 returns COMMAND_INVALID with the reset result and performs no port operation. A null result returns COMMAND_INVALID without port operations.\nC03. Every valid call attempts exactly one command_port_open using request.tag. A failed open returns COMMAND_OPEN_ERROR and leaves the reset result otherwise unchanged. It creates no owned resource. Capacity zero is allowed.\nC04. Each successful open transfers two obligations to the caller: close the stream exactly once, and successfully wait for its child exactly once. Closing never waits, and waiting never closes. Complete both before returning for every successful open, including empty data, read error, nonzero child completion, and capture_limit zero. Do not mutate the port fields directly; use the port operations. Additional successful opens, duplicate closes/waits, stale tokens and spurious operations violate the protocol.\nC05. Reads return positive byte counts, zero EOF, PORT_INTERRUPTED, or PORT_ERROR. Retry interrupted reads without consuming bytes. Read until EOF or the first PORT_ERROR. A read error returns COMMAND_READ_ERROR, preserving all bytes obtained before that error. This status has priority over child failure. Reading after error/EOF is not required.\nC06. bytes_seen counts every successful byte, including bytes beyond capture_limit. bytes_stored is min(bytes_seen,capture_limit). capture[0:bytes_stored] is the first bytes_stored bytes in original order. truncated is 1 exactly when bytes_seen > bytes_stored. Binary zero and all other byte values are ordinary data. Keep draining after the capture prefix fills.\nC07. checksum is FNV-1a over every byte seen, including discarded capture suffix: for each unsigned byte XOR into the 32-bit checksum then multiply by 16777619 modulo 2^32. Empty input retains the initial value.\nC08. Retry command_port_wait on PORT_INTERRUPTED. A successful wait returns the child's exit and signal fields. If no read error, any nonzero exit or signal returns COMMAND_CHILD_ERROR; otherwise return COMMAND_OK. Successful wait may happen before or after stream close; read completion/error must precede stream close. Both obligations remain independent.\nC09. The public port accepts payloads 0..2048 bytes, chunk_size 1..128, initial read/wait interrupts 0..16, read_fault_at -1 (none) or 0..payload_size. A fault limits successful bytes to the prefix ending just before that offset; fault at payload_size occurs instead of EOF. Exit is 0..255, signal 0..64, and at most one is nonzero. fail_open is 0 or 1. Plans change only between collection calls. Stream and child capacities independently range 0..16.\nC10. The port records raw accounting after every call. For each completed successful open streams_live and children_live return to their pre-call values; opens, closes, waits increase by one, protocol_errors and dropped_events stay zero. Peak occupancy is the maximum simultaneous owned count. A rejected open increases failures once but not opens/closes/waits. Repeating collection under capacity 1 must continue to work after prior completion or error.\nC11. The observation frontend accepts N streams children, P hex chunk fault read_intr wait_intr exit signal fail_open declared_length, R capture_limit tag, and E. The P declared_length is parsed within 0..2048 but is reserved and does not change payload_size. '-' denotes empty bytes. N resets the port. P installs the plan and N/P output [0]. R prints [return,status,seen,stored,checksum,exit,signal,truncated,\"capture_hex\",streams_live,children_live,opens,closes,waits,failures,protocol_errors,streams_peak,children_peak,dropped_events]. E prints the raw [operation,token,value] event triples (open=1,read=2,close=3,wait=4). Numeric tokens and read segmentation are port details and may vary with valid read buffer choices; observations must reflect actual port operations. stdin contains valid complete commands, stdout contains exactly their JSON rows, stderr may contain arbitrary diagnostic bytes.\nC12. The service must not change the supplied plan or request. Every call has independent result state and may use any scratch-buffer size or control organization. Legal alternate implementations may allocate temporary storage or use a state machine. Compilation is C11 with the public sources and headers. No network, OS command execution or external dependencies are needed.\n",
|
|
"error.plan": "N 1 1\nP 616263646566 2 3 1 2 7 0 0 6\nR 4 90\nP 00ff 1 -1 0 0 0 0 0 2\nR 2 91\n",
|
|
"observe.c": "#include \"command_port.h\"\n#include \"wire.h\"\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\nstatic void print_result(int rc, const struct command_result *result, const struct command_port *port)\n{\n printf(\"[%d,%d,%zu,%zu,%u,%u,%u,%d,\\\"\", rc, result->status, result->bytes_seen,\n result->bytes_stored, result->checksum, result->child_exit, result->child_signal,\n result->truncated);\n wire_print_hex(stdout, result->capture, result->bytes_stored <= COMMAND_MAX_BYTES ? result->bytes_stored : 0);\n printf(\"\\\",%u,%u,%u,%u,%u,%u,%u,%u,%u,%u]\\n\", port->streams_live,\n port->children_live, port->opens, port->closes, port->waits, port->failures,\n port->protocol_errors, port->streams_peak, port->children_peak, port->dropped_events);\n}\nstatic int configure(struct command_port *port, char **fields)\n{\n struct command_plan plan;\n unsigned long values[7];\n long fault;\n size_t index;\n const unsigned long maxima[] = {128,16,16,255,64,1,2048};\n memset(&plan, 0, sizeof(plan));\n if (!wire_hex(fields[1], plan.payload, sizeof(plan.payload), &plan.payload_size)) {\n return 0;\n }\n if (!wire_signed(fields[3], -1, (long)plan.payload_size, &fault)) {\n return 0;\n }\n for (index = 0; index < 7; index++) {\n size_t field = index == 0 ? 2 : index + 3;\n if (!wire_unsigned(fields[field], maxima[index], &values[index])) {\n return 0;\n }\n }\n plan.chunk_size = (size_t)values[0];\n plan.read_fault_at = fault;\n plan.read_interrupts = (unsigned)values[1];\n plan.wait_interrupts = (unsigned)values[2];\n plan.child_exit = (unsigned)values[3];\n plan.child_signal = (unsigned)values[4];\n plan.fail_open = (int)values[5];\n if (!command_port_configure(port, &plan)) {\n return 1;\n }\n return 0;\n}\nint main(void)\n{\n static struct command_port port;\n char line[8192];\n char *fields[12];\n size_t count;\n command_port_init(&port, 1, 1);\n while (fgets(line, sizeof(line), stdin) != NULL) {\n unsigned long first;\n unsigned long second;\n if (!wire_fields(line, fields, 12, &count) || count == 0) {\n return 2;\n }\n if (strcmp(fields[0], \"N\") == 0 && count == 3) {\n if (!wire_unsigned(fields[1], 16, &first) || !wire_unsigned(fields[2], 16, &second)) {\n return 2;\n }\n command_port_init(&port, (unsigned)first, (unsigned)second);\n puts(\"[0]\");\n } else if (strcmp(fields[0], \"P\") == 0 && count == 10) {\n if (!configure(&port, fields)) {\n return 2;\n }\n puts(\"[0]\");\n } else if (strcmp(fields[0], \"R\") == 0 && count == 3) {\n struct command_request request;\n struct command_result result;\n int rc;\n if (!wire_unsigned(fields[1], 4096, &first) || !wire_unsigned(fields[2], 65535, &second)) {\n return 2;\n }\n request.capture_limit = (size_t)first;\n request.tag = (unsigned)second;\n memset(&result, 0xa5, sizeof(result));\n rc = command_collect(&port, &request, &result);\n print_result(rc, &result, &port);\n } else if (strcmp(fields[0], \"E\") == 0 && count == 1) {\n size_t index;\n printf(\"[\");\n for (index = 0; index < port.event_count; index++) {\n const struct port_event *event = &port.events[index];\n printf(\"%s[%u,%u,%ld]\", index == 0 ? \"\" : \",\", event->operation, event->token, event->value);\n }\n puts(\"]\");\n } else {\n return 2;\n }\n }\n return ferror(stdin) || ferror(stdout) ? 3 : 0;\n}\n",
|
|
"wire.c": "#include \"wire.h\"\n#include <errno.h>\n#include <stdlib.h>\n#include <string.h>\n#include <limits.h>\nint wire_unsigned(const char *text, unsigned long maximum, unsigned long *result)\n{\n char *end;\n unsigned long value;\n if (text == NULL || *text == '\\0' || *text == '-' || *text == '+') {\n return 0;\n }\n errno = 0;\n value = strtoul(text, &end, 10);\n if (errno != 0 || *end != '\\0' || value > maximum) {\n return 0;\n }\n *result = value;\n return 1;\n}\nint wire_signed(const char *text, long minimum, long maximum, long *result)\n{\n char *end;\n long value;\n if (text == NULL || *text == '\\0' || *text == '+') {\n return 0;\n }\n errno = 0;\n value = strtol(text, &end, 10);\n if (errno != 0 || *end != '\\0' || value < minimum || value > maximum) {\n return 0;\n }\n *result = value;\n return 1;\n}\nstatic int hex_digit(unsigned char value)\n{\n if (value >= '0' && value <= '9') {\n return value - '0';\n }\n if (value >= 'a' && value <= 'f') {\n return value - 'a' + 10;\n }\n if (value >= 'A' && value <= 'F') {\n return value - 'A' + 10;\n }\n return -1;\n}\nint wire_hex(const char *text, unsigned char *output, size_t capacity, size_t *size)\n{\n size_t length;\n size_t index;\n if (strcmp(text, \"-\") == 0) {\n *size = 0;\n return 1;\n }\n length = strlen(text);\n if ((length & 1) != 0 || length / 2 > capacity) {\n return 0;\n }\n for (index = 0; index < length / 2; index++) {\n int high = hex_digit((unsigned char)text[index * 2]);\n int low = hex_digit((unsigned char)text[index * 2 + 1]);\n if (high < 0 || low < 0) {\n return 0;\n }\n output[index] = (unsigned char)(high * 16 + low);\n }\n *size = length / 2;\n return 1;\n}\nvoid wire_print_hex(FILE *stream, const unsigned char *data, size_t size)\n{\n static const char digits[] = \"0123456789abcdef\";\n size_t index;\n for (index = 0; index < size; index++) {\n unsigned char byte = data[index];\n fputc(digits[byte >> 4], stream);\n fputc(digits[byte & 15], stream);\n }\n}\nint wire_fields(char *line, char **fields, size_t capacity, size_t *count)\n{\n char *next = line;\n *count = 0;\n while (*next != '\\0') {\n while (*next == ' ' || *next == '\\t' || *next == '\\r' || *next == '\\n') {\n next++;\n }\n if (*next == '\\0') {\n break;\n }\n if (*count == capacity) {\n return 0;\n }\n fields[(*count)++] = next;\n while (*next != '\\0' && *next != ' ' && *next != '\\t' && *next != '\\r' && *next != '\\n') {\n next++;\n }\n if (*next != '\\0') {\n *next++ = '\\0';\n }\n }\n return 1;\n}\n",
|
|
"wire.h": "#ifndef COMMAND_WIRE_H\n#define COMMAND_WIRE_H\n#include \"command_port.h\"\n#include <stdio.h>\nint wire_unsigned(const char *text, unsigned long maximum, unsigned long *result);\nint wire_signed(const char *text, long minimum, long maximum, long *result);\nint wire_hex(const char *text, unsigned char *output, size_t capacity, size_t *size);\nvoid wire_print_hex(FILE *stream, const unsigned char *data, size_t size);\nint wire_fields(char *line, char **fields, size_t capacity, size_t *count);\n#endif\n"
|
|
}
|