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

10 lines
15 KiB
JSON

{
"Makefile": "CC = gcc\nCFLAGS = -std=c11 -O2 -Wall -Wextra -pedantic\n.PHONY: all demo clean\nall: format-observe\nformat-observe: buffer.c buffer.h ledger.c ledger.h observe.c\n\t$(CC) $(CFLAGS) buffer.c ledger.c observe.c -o $@\ndemo: format-observe\n\tprintf 'O 128\\nK label 67726f7761626c652d627566\\nQ\\nC\\n' | ./format-observe\nclean:\n\trm -f format-observe\n",
"ledger.h": "#ifndef FORMAT_LEDGER_H\n#define FORMAT_LEDGER_H\n#include \"buffer.h\"\ntypedef struct {\n void *address;\n size_t bytes;\n} ledger_block;\ntypedef struct {\n ledger_block blocks[128];\n size_t live;\n size_t bytes;\n size_t resize_calls;\n size_t release_calls;\n size_t failures;\n size_t errors;\n int fail_next;\n} allocation_ledger;\nvoid ledger_init(allocation_ledger *ledger);\nfb_allocator ledger_allocator(allocation_ledger *ledger);\nvoid ledger_arm(allocation_ledger *ledger);\nvoid ledger_dispose(allocation_ledger *ledger);\n#endif\n",
"observe.c": "#include \"buffer.h\"\n#include \"ledger.h\"\n#include <inttypes.h>\n#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n\nstatic unsigned char payload[65536];\nstatic unsigned char copied[65537];\nstatic char line[262300];\n\nstatic int digit(char c)\n{\n if (c >= '0' && c <= '9')\n return c - '0';\n if (c >= 'a' && c <= 'f')\n return c - 'a' + 10;\n if (c >= 'A' && c <= 'F')\n return c - 'A' + 10;\n return -1;\n}\n\nstatic int decode(const char *text, size_t *length)\n{\n size_t count;\n if (text == NULL)\n return 0;\n if (strcmp(text, \"-\") == 0) {\n *length = 0;\n return 1;\n }\n count = strlen(text);\n if (count % 2 != 0 || count / 2 > sizeof payload)\n return 0;\n for (size_t i = 0; i < count; i += 2) {\n int high = digit(text[i]);\n int low = digit(text[i + 1]);\n if (high < 0 || low < 0)\n return 0;\n payload[i / 2] = (unsigned char)(high * 16 + low);\n }\n *length = count / 2;\n return 1;\n}\n\nstatic void print_hex(const unsigned char *data, size_t length)\n{\n if (length == 0) {\n putchar('-');\n return;\n }\n if (data == NULL) {\n fputs(\"NULL\", stdout);\n return;\n }\n for (size_t i = 0; i < length; ++i)\n printf(\"%02x\", data[i]);\n}\n\nstatic void observe(int result, allocation_ledger *ledger, size_t copy_size)\n{\n fb_snapshot view = fb_view();\n printf(\"%d %d %zu %zu %zu %zu %zu %zu %zu %d \", result, view.active,\n view.length, view.capacity, view.limit, view.fields,\n ledger->live, ledger->bytes, ledger->errors, ledger->fail_next);\n if (view.length <= 65535)\n print_hex(view.data, view.length);\n else\n fputs(\"OVERSIZE\", stdout);\n printf(\" %d %zu \", view.data == NULL ? 1 :\n view.length < view.capacity ? view.data[view.length] == 0 : 0, copy_size);\n if (copy_size <= sizeof copied)\n print_hex(copied, copy_size);\n else\n fputs(\"OVERSIZE\", stdout);\n putchar('\\n');\n}\n\nstatic int execute(char *command, allocation_ledger *ledger, size_t *copy_size)\n{\n char *kind = strtok(command, \" \\t\\r\\n\");\n char *a = strtok(NULL, \" \\t\\r\\n\");\n char *b = strtok(NULL, \" \\t\\r\\n\");\n size_t length = 0;\n if (kind == NULL)\n return FB_INVALID;\n if (strcmp(kind, \"O\") == 0 && a != NULL)\n return fb_open((size_t)strtoull(a, NULL, 10), ledger_allocator(ledger));\n if (strcmp(kind, \"R\") == 0 && a != NULL)\n return fb_reserve((size_t)strtoull(a, NULL, 10));\n if (strcmp(kind, \"A\") == 0 && decode(a, &length))\n return fb_append(payload, length);\n if (strcmp(kind, \"E\") == 0 && decode(a, &length))\n return fb_escaped(payload, length);\n if (strcmp(kind, \"K\") == 0 && decode(b, &length))\n return fb_field(strcmp(a, \"-\") == 0 ? \"\" : a, payload, length);\n if (strcmp(kind, \"I\") == 0 && a != NULL && b != NULL)\n return fb_integer(strcmp(a, \"-\") == 0 ? \"\" : a, (int64_t)strtoll(b, NULL, 10));\n if (strcmp(kind, \"X\") == 0)\n return fb_reset();\n if (strcmp(kind, \"C\") == 0)\n return fb_close();\n if (strcmp(kind, \"F\") == 0) {\n ledger_arm(ledger);\n return FB_OK;\n }\n if (strcmp(kind, \"Q\") == 0)\n return FB_OK;\n if (strcmp(kind, \"N\") == 0 && a != NULL)\n return fb_append(NULL, (size_t)strtoull(a, NULL, 10));\n if (strcmp(kind, \"Y\") == 0 && a != NULL) {\n size_t capacity = (size_t)strtoull(a, NULL, 10);\n *copy_size = 7;\n memset(copied, 0xA7, sizeof copied);\n return fb_copy(copied, capacity, copy_size);\n }\n return FB_INVALID;\n}\n\nint main(void)\n{\n allocation_ledger ledger;\n ledger_init(&ledger);\n while (fgets(line, sizeof line, stdin) != NULL) {\n size_t copy_size = 0;\n int result = execute(line, &ledger, &copy_size);\n observe(result, &ledger, copy_size);\n }\n ledger_dispose(&ledger);\n return 0;\n}\n",
"buffer.h": "#ifndef RESOURCE_FORMAT_BUFFER_H\n#define RESOURCE_FORMAT_BUFFER_H\n#include <stddef.h>\n#include <stdint.h>\ntypedef void *(*fb_resize_fn)(void *, size_t, size_t, void *);\ntypedef void (*fb_release_fn)(void *, size_t, void *);\ntypedef struct {\n fb_resize_fn resize;\n fb_release_fn release;\n void *context;\n} fb_allocator;\ntypedef struct {\n const unsigned char *data;\n size_t length;\n size_t capacity;\n size_t limit;\n size_t fields;\n int active;\n} fb_snapshot;\nenum { FB_OK = 0, FB_INVALID = 1, FB_STATE = 2, FB_LIMIT = 3, FB_MEMORY = 4 };\nint fb_open(size_t limit, fb_allocator allocator);\nint fb_reserve(size_t logical);\nint fb_append(const unsigned char *data, size_t length);\nint fb_escaped(const unsigned char *data, size_t length);\nint fb_field(const char *key, const unsigned char *data, size_t length);\nint fb_integer(const char *key, int64_t value);\nint fb_reset(void);\nint fb_close(void);\nfb_snapshot fb_view(void);\nint fb_copy(unsigned char *destination, size_t capacity, size_t *written);\n#endif\n",
"ledger.c": "#include \"ledger.h\"\n#include <stdlib.h>\n#include <string.h>\n\nstatic size_t locate(allocation_ledger *ledger, void *address)\n{\n for (size_t i = 0; i < 128; ++i) {\n if (ledger->blocks[i].address == address)\n return i;\n }\n return 128;\n}\n\nstatic void remove_block(allocation_ledger *ledger, size_t index)\n{\n ledger->bytes -= ledger->blocks[index].bytes;\n ledger->live--;\n ledger->blocks[index].address = NULL;\n ledger->blocks[index].bytes = 0;\n}\n\nstatic void *ledger_resize(void *address, size_t old_size, size_t new_size, void *context)\n{\n allocation_ledger *ledger = context;\n size_t index;\n size_t vacant;\n void *replacement;\n ledger->resize_calls++;\n if (new_size == 0 || new_size > 65536) {\n ledger->errors++;\n return NULL;\n }\n index = address == NULL ? 128 : locate(ledger, address);\n if ((address == NULL && old_size != 0) ||\n (address != NULL && (index == 128 || ledger->blocks[index].bytes != old_size))) {\n ledger->errors++;\n return NULL;\n }\n if (ledger->fail_next) {\n ledger->fail_next = 0;\n ledger->failures++;\n return NULL;\n }\n vacant = index;\n if (vacant == 128) {\n for (size_t i = 0; i < 128; ++i) {\n if (ledger->blocks[i].address == NULL) {\n vacant = i;\n break;\n }\n }\n }\n if (vacant == 128) {\n ledger->errors++;\n return NULL;\n }\n replacement = malloc(new_size);\n if (replacement == NULL) {\n ledger->failures++;\n return NULL;\n }\n memset(replacement, 0xD3, new_size);\n if (address != NULL) {\n size_t preserved = old_size < new_size ? old_size : new_size;\n memcpy(replacement, address, preserved);\n free(address);\n remove_block(ledger, index);\n }\n ledger->blocks[vacant].address = replacement;\n ledger->blocks[vacant].bytes = new_size;\n ledger->live++;\n ledger->bytes += new_size;\n return replacement;\n}\n\nstatic void ledger_release(void *address, size_t bytes, void *context)\n{\n allocation_ledger *ledger = context;\n size_t index;\n ledger->release_calls++;\n index = address == NULL ? 128 : locate(ledger, address);\n if (index == 128 || ledger->blocks[index].bytes != bytes) {\n ledger->errors++;\n return;\n }\n free(address);\n remove_block(ledger, index);\n}\n\nvoid ledger_init(allocation_ledger *ledger)\n{\n memset(ledger, 0, sizeof *ledger);\n}\n\nfb_allocator ledger_allocator(allocation_ledger *ledger)\n{\n fb_allocator allocator;\n allocator.resize = ledger_resize;\n allocator.release = ledger_release;\n allocator.context = ledger;\n return allocator;\n}\n\nvoid ledger_arm(allocation_ledger *ledger)\n{\n ledger->fail_next = 1;\n}\n\nvoid ledger_dispose(allocation_ledger *ledger)\n{\n for (size_t i = 0; i < 128; ++i) {\n if (ledger->blocks[i].address != NULL) {\n free(ledger->blocks[i].address);\n ledger->blocks[i].address = NULL;\n }\n }\n}\n",
"README.md": "# Persistent telemetry format buffer\n\nBuild with `make`; `make demo` runs the default report. `format-observe` reads the public command protocol in docs/format-buffer.md and prints raw observations. The library implements a process-wide text assembly session. This is a deterministic software exercise; it does not require a board, Valgrind, networking or installation.\n\nEdit and submit buffer.c. Follow every clause of docs/format-buffer.md. The allocator ledger and observer are public support files and are rebuilt during assessment. They contain no pass/fail assertions.\n",
"docs/format-buffer.md": "# Format buffer contract\n\nC01 Lifecycle: fb_open(limit, allocator) opens the single closed session, with empty content and no allocation. Limit is 0..65535 inclusive; both callbacks are required. Invalid open returns FB_INVALID and preserves closed state. Open while active returns FB_STATE and preserves everything. Closed view is data NULL, length/capacity/limit/fields/active zero. Mutators and copy on closed return FB_STATE, except close which is idempotent and returns FB_OK. F/Q observer commands do not call a mutator.\n\nC02 Ownership: all dynamic storage used by the library goes through the supplied allocator. resize(p, old_bytes, new_bytes, context) preserves min(old,new) bytes on success, releases the old block, and returns a block of exactly new_bytes; NULL with old_bytes=0 is an allocation. On NULL result the old block is untouched. release accepts a live non-NULL block with its exact allocation size. No zero-size allocation and no double/invalid release are allowed. At each API boundary exactly one live block of capacity bytes exists if capacity>0, otherwise none. fb_close releases the final block, clears session state and permits reopening. The ledger is cumulative across sessions and never clears evidence on close.\n\nC03 Capacity: length counts logical bytes including embedded NULs, capacity includes room for a trailing NUL. If allocated, 1<=capacity<=limit+1 and capacity>=length+1. Allocation is lazy: open, append of zero bytes into an empty unallocated session, reset and reserve(0) do not allocate. Reserve(n) requires capacity>=n+1 for nonzero n without changing content/fields; n>limit returns FB_LIMIT. Existing adequate capacity is reused without any allocator call. Growth amount is otherwise unrestricted. No shrink occurs except close. Bytes after data[length] are unspecified and are never compared.\n\nC04 Content: append concatenates exactly the supplied bytes, including NUL and bytes 128..255. NULL is valid only with length=0. Snapshot data[0:length] is the logical content, and data[length] is NUL whenever allocated. View returns current length, capacity, limit, number of fields and active=1. Append/escaped do not increment fields. Input buffers do not alias the session allocation and remain unchanged.\n\nC05 Escaping: fb_escaped appends each input byte 32..126 literally except backslash, equal sign and semicolon; all other bytes and those three delimiters become four ASCII bytes backslash, lowercase x, and two uppercase hexadecimal digits. Empty input is valid. No Unicode interpretation is performed.\n\nC06 Fields: fb_field appends key, '=', escaped value, ';', then increments fields once. Key is 1..24 ASCII letters, digits or underscores. Empty/NULL/invalid key returns FB_INVALID. Values follow C04/C05. fb_integer uses the same field representation with the signed decimal value, including INT64_MIN, zero and INT64_MAX, no plus sign or leading zeroes. Signed decimal has no bytes needing escape.\n\nC07 Atomicity and errors: after closed-state and invalid-pointer/key validation, a raw length or escaped/field encoded result exceeding limit returns FB_LIMIT. On limit/invalid/state errors content, capacity, fields and allocator state are unchanged. Growth callback failure returns FB_MEMORY and preserves the old pointer, content, capacity and fields. Only that failed callback consumes the ledger failure arm. Successful operations may grow only when needed; no mutation commits before a required allocation succeeds. Input lengths 0..65536 are supported for boundary checks. No operation is allowed to overflow arithmetic.\n\nC08 Reset: fb_reset preserves allocation/capacity and the active session limit/allocator, sets length/fields=0, writes a terminator if allocated, and allows reuse. Close after reset still releases that retained block.\n\nC09 Copy: fb_copy(destination, capacity, written) copies logical bytes and one terminator if capacity>=length+1, writes length to *written and returns FB_OK. NULL destination/written returns FB_INVALID. Insufficient capacity returns FB_LIMIT and leaves destination and *written unchanged. It never allocates or changes session state. Destinations do not alias session data.\n\nC10 Observer input: one command per line. O limit opens with ledger callbacks; R n reserves logical n; A hex appends; E hex appends escaped bytes; K key hex appends a field; I key signed_decimal appends an integer field; X resets; C closes; Q observes; F arms the next nonzero resize request to fail (an arm remains across close/open); N n calls append(NULL,n); Y capacity calls copy with destination filled with A7 and written initialized to 7. Hex '-' means empty and key '-' means empty. Command numeric tokens are unsigned decimal except I's signed value; inputs are well formed within the API's documented ranges. Ordinary clients may also call the header API directly.\n\nC11 Observer output: each command prints space-separated result, active, length, capacity, limit, fields, ledger live block count, ledger live bytes, ledger error count, failure arm, logical content hex (or '-' empty), terminator-ok, copy-written, copy bytes hex (or '-' empty). Copy bytes are the first copy-written bytes, even on error. Non-Y commands use copy-written=0. Empty unallocated view has terminator-ok=1. Output is raw observation, no assertions. The ledger releases leftovers only after the last observation, so leaks remain visible. stdout must follow this protocol; stderr may contain arbitrary diagnostics and is ignored for business comparison. All commands must finish normally within the supplied execution deadline.\n"
}