amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

1 line
15 KiB
JSON

{"include/fd_batch.h":"#ifndef FD_BATCH_H\n#define FD_BATCH_H\n\n#include <stddef.h>\n\nenum batch_status {\n BATCH_OK = 0,\n BATCH_OPEN_ERROR = 2,\n BATCH_READ_ERROR = 3,\n BATCH_CLOSE_ERROR = 4,\n BATCH_BAD_PLAN = 5\n};\n\nstruct batch_plan {\n unsigned count;\n unsigned window;\n unsigned skip_every;\n};\n\nstruct batch_port {\n void *context;\n int (*open_one)(void *context, unsigned item);\n int (*read_one)(void *context, unsigned item, int handle);\n int (*close_one)(void *context, unsigned item, int handle);\n};\n\nstruct batch_slot {\n unsigned item;\n int handle;\n int acquired;\n int read_done;\n int released;\n};\n\nstruct batch_window {\n struct batch_slot slots[8];\n unsigned used;\n unsigned acquired;\n unsigned reads;\n unsigned releases;\n};\n\nint batch_execute(const struct batch_plan *plan, const struct batch_port *port);\nvoid batch_window_reset(struct batch_window *window);\nint batch_window_push(struct batch_window *window, unsigned item, int handle);\nint batch_window_read(struct batch_window *window, const struct batch_port *port);\nint batch_window_release(struct batch_window *window, const struct batch_port *port);\nunsigned batch_window_live(const struct batch_window *window);\n\n#endif\n","include/sim_port.h":"#ifndef SIM_PORT_H\n#define SIM_PORT_H\n\n#include \"fd_batch.h\"\n#include <stddef.h>\n\nenum sim_event_kind { SIM_OPEN = 1, SIM_READ = 2, SIM_CLOSE = 3 };\n\nstruct sim_event {\n enum sim_event_kind kind;\n unsigned item;\n int handle;\n int outcome;\n};\n\nstruct sim_port {\n unsigned open_fail_at;\n unsigned read_fail_at;\n unsigned close_fail_at;\n unsigned open_calls;\n unsigned read_calls;\n unsigned close_calls;\n unsigned active_count;\n unsigned peak_live;\n unsigned active_items[64];\n int active_handles[64];\n struct sim_event events[256];\n unsigned event_count;\n};\n\nvoid sim_port_init(struct sim_port *sim, unsigned open_fail_at,\n unsigned read_fail_at, unsigned close_fail_at);\nvoid sim_port_bind(struct sim_port *sim, struct batch_port *port);\nvoid sim_port_print(const struct sim_port *sim, int status);\nvoid sim_trace_print(const struct sim_port *sim);\n\n#endif\n","src/main.c":"#include \"fd_batch.h\"\n#include \"sim_port.h\"\n#include <ctype.h>\n#include <errno.h>\n#include <limits.h>\n#include <stdint.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nstruct scenario {\n struct batch_plan plan;\n unsigned open_fail_at;\n unsigned read_fail_at;\n unsigned close_fail_at;\n};\n\nstatic int horizontal(unsigned char ch)\n{\n return ch == ' ' || ch == '\\t' || ch == '\\r';\n}\n\nstatic int parse_uint(const char **cursor, unsigned maximum, unsigned *value)\n{\n const unsigned char *text = (const unsigned char *)*cursor;\n unsigned number = 0;\n int saw_digit = 0;\n while (horizontal(*text)) {\n ++text;\n }\n if (*text == '+') {\n ++text;\n }\n while (*text >= '0' && *text <= '9') {\n unsigned digit = (unsigned)(*text - '0');\n saw_digit = 1;\n if (digit > maximum || number > (maximum - digit) / 10) {\n return -1;\n }\n number = number * 10 + digit;\n ++text;\n }\n if (!saw_digit || (!horizontal(*text) && *text != '\\n' && *text != 0)) {\n return -1;\n }\n *value = number;\n *cursor = (const char *)text;\n return 0;\n}\n\nstatic int parse_scenario(const char *line, struct scenario *scenario)\n{\n const char *cursor = line;\n unsigned values[6];\n unsigned limits[6] = {32, 8, 8, 64, 64, 64};\n unsigned i;\n for (i = 0; i < 6; ++i) {\n if (parse_uint(&cursor, limits[i], &values[i]) != 0) {\n return -1;\n }\n }\n while (horizontal((unsigned char)*cursor)) {\n ++cursor;\n }\n if (*cursor == '\\n') {\n ++cursor;\n }\n if (*cursor != 0 || values[1] == 0) {\n return -1;\n }\n scenario->plan.count = values[0];\n scenario->plan.window = values[1];\n scenario->plan.skip_every = values[2];\n scenario->open_fail_at = values[3];\n scenario->read_fail_at = values[4];\n scenario->close_fail_at = values[5];\n return 0;\n}\n\nstatic char *read_line(void)\n{\n size_t used = 0;\n size_t capacity = 128;\n char *buffer = malloc(capacity);\n int ch;\n if (buffer == NULL) {\n return NULL;\n }\n while ((ch = getchar()) != EOF) {\n if (used + 1 >= capacity) {\n size_t next_capacity;\n char *replacement;\n if (capacity > SIZE_MAX / 2) {\n free(buffer);\n return NULL;\n }\n next_capacity = capacity * 2;\n replacement = realloc(buffer, next_capacity);\n if (replacement == NULL) {\n free(buffer);\n return NULL;\n }\n buffer = replacement;\n capacity = next_capacity;\n }\n buffer[used++] = (char)ch;\n if (ch == '\\n') {\n break;\n }\n }\n if (used == 0 || memchr(buffer, 0, used) != NULL) {\n free(buffer);\n return NULL;\n }\n buffer[used] = 0;\n return buffer;\n}\n\nstatic int only_trailing_space(void)\n{\n int ch;\n while ((ch = getchar()) != EOF) {\n if (ch != ' ' && ch != '\\t' && ch != '\\r' && ch != '\\n') {\n return 0;\n }\n }\n return 1;\n}\n\nint main(void)\n{\n char *line;\n struct scenario scenario;\n struct sim_port sim;\n struct batch_port port;\n int status;\n line = read_line();\n if (line == NULL || parse_scenario(line, &scenario) != 0 ||\n !only_trailing_space()) {\n free(line);\n fputs(\"invalid scenario\\n\", stderr);\n return 64;\n }\n free(line);\n sim_port_init(&sim, scenario.open_fail_at, scenario.read_fail_at,\n scenario.close_fail_at);\n sim_port_bind(&sim, &port);\n status = batch_execute(&scenario.plan, &port);\n sim_port_print(&sim, status);\n return 0;\n}\n","src/port.c":"#include \"sim_port.h\"\n#include <stdio.h>\n#include <string.h>\n\nstatic void append_event(struct sim_port *sim, enum sim_event_kind kind,\n unsigned item, int handle, int outcome)\n{\n struct sim_event *event;\n if (sim->event_count >= sizeof sim->events / sizeof sim->events[0]) {\n return;\n }\n event = &sim->events[sim->event_count++];\n event->kind = kind;\n event->item = item;\n event->handle = handle;\n event->outcome = outcome;\n}\n\nstatic int make_handle(unsigned call)\n{\n if (call == 1) {\n return 0;\n }\n return (int)(call * 7 + 3);\n}\n\nstatic int find_handle(const struct sim_port *sim, int handle)\n{\n unsigned i;\n for (i = 0; i < sim->active_count; ++i) {\n if (sim->active_handles[i] == handle) {\n return (int)i;\n }\n }\n return -1;\n}\n\nstatic int sim_open(void *context, unsigned item)\n{\n struct sim_port *sim = context;\n int handle;\n sim->open_calls++;\n if (sim->open_fail_at == sim->open_calls || sim->active_count == 8) {\n append_event(sim, SIM_OPEN, item, -1, -1);\n return -1;\n }\n handle = make_handle(sim->open_calls);\n sim->active_items[sim->active_count] = item;\n sim->active_handles[sim->active_count] = handle;\n sim->active_count++;\n if (sim->active_count > sim->peak_live) {\n sim->peak_live = sim->active_count;\n }\n append_event(sim, SIM_OPEN, item, handle, 0);\n return handle;\n}\n\nstatic int sim_read(void *context, unsigned item, int handle)\n{\n struct sim_port *sim = context;\n int index;\n sim->read_calls++;\n index = find_handle(sim, handle);\n if (index < 0 || sim->active_items[index] != item ||\n sim->read_fail_at == sim->read_calls) {\n append_event(sim, SIM_READ, item, handle, -1);\n return -1;\n }\n append_event(sim, SIM_READ, item, handle, 0);\n return 0;\n}\n\nstatic int sim_close(void *context, unsigned item, int handle)\n{\n struct sim_port *sim = context;\n int index;\n int outcome;\n unsigned cursor;\n sim->close_calls++;\n index = find_handle(sim, handle);\n if (index < 0 || sim->active_items[index] != item) {\n append_event(sim, SIM_CLOSE, item, handle, -1);\n return -1;\n }\n outcome = sim->close_fail_at == sim->close_calls ? -1 : 0;\n for (cursor = (unsigned)index + 1; cursor < sim->active_count; ++cursor) {\n sim->active_items[cursor - 1] = sim->active_items[cursor];\n sim->active_handles[cursor - 1] = sim->active_handles[cursor];\n }\n sim->active_count--;\n append_event(sim, SIM_CLOSE, item, handle, outcome);\n return outcome;\n}\n\nvoid sim_port_init(struct sim_port *sim, unsigned open_fail_at,\n unsigned read_fail_at, unsigned close_fail_at)\n{\n memset(sim, 0, sizeof *sim);\n sim->open_fail_at = open_fail_at;\n sim->read_fail_at = read_fail_at;\n sim->close_fail_at = close_fail_at;\n}\n\nvoid sim_port_bind(struct sim_port *sim, struct batch_port *port)\n{\n port->context = sim;\n port->open_one = sim_open;\n port->read_one = sim_read;\n port->close_one = sim_close;\n}\n\nstatic char event_letter(enum sim_event_kind kind)\n{\n if (kind == SIM_OPEN) {\n return 'O';\n }\n if (kind == SIM_READ) {\n return 'R';\n }\n return 'C';\n}\n\nvoid sim_port_print(const struct sim_port *sim, int status)\n{\n unsigned i;\n for (i = 0; i < sim->event_count; ++i) {\n const struct sim_event *event = &sim->events[i];\n printf(\"%c %u %d %d\\n\", event_letter(event->kind), event->item,\n event->handle, event->outcome);\n }\n sim_trace_print(sim);\n printf(\"Z %d %u %u %u %u\\n\", status, sim->active_count,\n sim->open_calls, sim->read_calls, sim->close_calls);\n}\n","src/trace.c":"#include \"sim_port.h\"\n#include <stdio.h>\n#include <string.h>\n\nstruct operation_counts {\n unsigned open_ok;\n unsigned open_fail;\n unsigned read_ok;\n unsigned read_fail;\n unsigned close_ok;\n unsigned close_fail;\n};\n\nstatic void count_one(struct operation_counts *counts,\n const struct sim_event *event)\n{\n if (event->kind == SIM_OPEN) {\n if (event->outcome == 0) {\n counts->open_ok++;\n } else {\n counts->open_fail++;\n }\n return;\n }\n if (event->kind == SIM_READ) {\n if (event->outcome == 0) {\n counts->read_ok++;\n } else {\n counts->read_fail++;\n }\n return;\n }\n if (event->kind == SIM_CLOSE) {\n if (event->outcome == 0) {\n counts->close_ok++;\n } else {\n counts->close_fail++;\n }\n }\n}\n\nstatic void count_all(const struct sim_port *sim,\n struct operation_counts *counts)\n{\n unsigned index;\n memset(counts, 0, sizeof *counts);\n for (index = 0; index < sim->event_count; ++index) {\n count_one(counts, &sim->events[index]);\n }\n}\n\nstatic int has_calls(const struct operation_counts *counts)\n{\n return counts->open_ok != 0 || counts->open_fail != 0 ||\n counts->read_ok != 0 || counts->read_fail != 0 ||\n counts->close_ok != 0 || counts->close_fail != 0;\n}\n\nstatic void print_counts(char prefix, unsigned item,\n const struct operation_counts *counts)\n{\n if (prefix == 'A') {\n printf(\"A %u %u %u %u %u %u\\n\",\n counts->open_ok, counts->open_fail,\n counts->read_ok, counts->read_fail,\n counts->close_ok, counts->close_fail);\n } else {\n printf(\"I %u %u %u %u %u %u %u\\n\", item,\n counts->open_ok, counts->open_fail,\n counts->read_ok, counts->read_fail,\n counts->close_ok, counts->close_fail);\n }\n}\n\nstatic void print_active(const struct sim_port *sim)\n{\n unsigned index;\n for (index = 0; index < sim->active_count; ++index) {\n printf(\"L %u %d\\n\", sim->active_items[index],\n sim->active_handles[index]);\n }\n}\n\nstatic void print_items(const struct sim_port *sim)\n{\n unsigned item;\n for (item = 0; item < 32; ++item) {\n struct operation_counts counts = {0, 0, 0, 0, 0, 0};\n unsigned index;\n for (index = 0; index < sim->event_count; ++index) {\n const struct sim_event *event = &sim->events[index];\n if (event->item == item) {\n count_one(&counts, event);\n }\n }\n if (has_calls(&counts)) {\n print_counts('I', item, &counts);\n }\n }\n}\n\nstatic void print_coverage(const struct sim_port *sim)\n{\n unsigned seen[32] = {0};\n unsigned touched = 0;\n int first = -1;\n int last = -1;\n unsigned index;\n for (index = 0; index < sim->event_count; ++index) {\n unsigned item = sim->events[index].item;\n if (item >= 32 || seen[item]) {\n continue;\n }\n seen[item] = 1;\n touched++;\n if (first < 0 || (int)item < first) {\n first = (int)item;\n }\n if (last < 0 || (int)item > last) {\n last = (int)item;\n }\n }\n printf(\"U %u %d %d\\n\", touched, first, last);\n}\n\nstatic void print_lifetimes(const struct sim_port *sim)\n{\n unsigned opened_at;\n for (opened_at = 0; opened_at < sim->event_count; ++opened_at) {\n const struct sim_event *opened = &sim->events[opened_at];\n int read_at = -1;\n int released_at = -1;\n unsigned later;\n if (opened->kind != SIM_OPEN || opened->outcome != 0) {\n continue;\n }\n for (later = opened_at + 1; later < sim->event_count; ++later) {\n const struct sim_event *event = &sim->events[later];\n if (event->item != opened->item ||\n event->handle != opened->handle) {\n continue;\n }\n if (event->kind == SIM_READ && read_at < 0) {\n read_at = (int)later;\n }\n if (event->kind == SIM_CLOSE && released_at < 0) {\n released_at = (int)later;\n }\n }\n printf(\"H %u %d %u %d %d\\n\", opened->item, opened->handle,\n opened_at, read_at, released_at);\n }\n}\n\nvoid sim_trace_print(const struct sim_port *sim)\n{\n struct operation_counts totals;\n count_all(sim, &totals);\n print_counts('A', 0, &totals);\n printf(\"P %u %u\\n\", sim->peak_live, sim->event_count);\n print_coverage(sim);\n print_active(sim);\n print_lifetimes(sim);\n print_items(sim);\n}\n"}