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

12 lines
19 KiB
JSON

{
"Makefile": "CC = gcc\nCFLAGS = -std=c11 -O2 -Wall -Wextra -Wpedantic\nall: vector-demo\nvector-demo: main.c observer.c pool.c vector.c vector.h\n\t$(CC) $(CFLAGS) main.c observer.c pool.c vector.c -o $@\nclean:\n\trm -f vector-demo\n.PHONY: all clean\n",
"observer.c": "#include \"vector.h\"\n#include <inttypes.h>\n#include <stdio.h>\n#include <string.h>\n\nstatic uint64_t hash_byte(uint64_t value, unsigned char byte)\n{\n return (value ^ byte) * UINT64_C(1099511628211);\n}\nuint64_t observe_hash(struct strvec *v, int *readable)\n{\n uint64_t value = UINT64_C(14695981039346656037);\n size_t index;\n *readable = 1;\n if (v->count > SV_LIMIT) {\n *readable = 0;\n return 0;\n }\n if (v->count && !pool_live(v->pool, v->items, POOL_ARRAY,\n v->count * sizeof(*v->items))) {\n *readable = 0;\n return 0;\n }\n for (index = 0; index < v->count; index++) {\n const char *entry = sv_at(v, index);\n size_t length = 0;\n if (!pool_live(v->pool, entry, POOL_STRING, 1)) {\n *readable = 0;\n return 0;\n }\n while (length <= SV_WORD_LIMIT) {\n if (!pool_live(v->pool, entry, POOL_STRING, length + 1)) {\n *readable = 0;\n return 0;\n }\n if (entry[length] == '\\0') {\n break;\n }\n value = hash_byte(value, (unsigned char)entry[length]);\n length++;\n }\n if (length > SV_WORD_LIMIT) {\n *readable = 0;\n return 0;\n }\n value = hash_byte(value, 255);\n }\n return value;\n}\nvoid observe_line(struct strvec *v, int rc)\n{\n int readable;\n uint64_t hash = observe_hash(v, &readable);\n struct pool_stats stats = pool_observe(v->pool);\n printf(\"%d %zu %zu %zu %zu %zu %d %\" PRIu64 \"\\n\", rc,\n v->count, stats.arrays, stats.strings, stats.string_bytes,\n stats.invalid, readable, hash);\n}\nstatic int decimal(const char *text, size_t *result)\n{\n size_t value = 0;\n const unsigned char *cursor = (const unsigned char *)text;\n if (*cursor == '+') {\n cursor++;\n }\n if (*cursor == '\\0') {\n return 0;\n }\n while (*cursor) {\n unsigned digit;\n if (*cursor < '0' || *cursor > '9') {\n return 0;\n }\n digit = *cursor - '0';\n if (value > (1000000U - digit) / 10U) {\n return 0;\n }\n value = value * 10U + digit;\n cursor++;\n }\n *result = value;\n return 1;\n}\nstatic int nibble(unsigned char c)\n{\n if (c >= '0' && c <= '9') {\n return c - '0';\n }\n if (c >= 'a' && c <= 'f') {\n return c - 'a' + 10;\n }\n if (c >= 'A' && c <= 'F') {\n return c - 'A' + 10;\n }\n return -1;\n}\nstatic int decode_word(const char *token, char *word)\n{\n size_t length;\n size_t index;\n if (!strcmp(token, \"-\")) {\n word[0] = '\\0';\n return 1;\n }\n length = strlen(token);\n if (length % 2 || length > 2 * (SV_WORD_LIMIT + 1)) {\n return 0;\n }\n for (index = 0; index < length / 2; index++) {\n int high = nibble((unsigned char)token[2 * index]);\n int low = nibble((unsigned char)token[2 * index + 1]);\n int byte;\n if (high < 0 || low < 0) {\n return 0;\n }\n byte = high * 16 + low;\n if (byte == 0) {\n return 0;\n }\n word[index] = (char)byte;\n }\n word[length / 2] = '\\0';\n return 1;\n}\nstatic size_t tokenize(char *line, char **tokens, size_t maximum)\n{\n size_t count = 0;\n char *cursor = line;\n while (*cursor) {\n while (*cursor == ' ' || *cursor == '\\t' || *cursor == '\\r') {\n cursor++;\n }\n if (!*cursor) {\n break;\n }\n if (count == maximum) {\n return maximum + 1;\n }\n tokens[count++] = cursor;\n while (*cursor && *cursor != ' ' && *cursor != '\\t' && *cursor != '\\r') {\n cursor++;\n }\n if (*cursor) {\n *cursor++ = '\\0';\n }\n }\n return count;\n}\nstatic int read_line(char *line, size_t size, int *malformed)\n{\n size_t used = 0;\n int byte;\n int seen = 0;\n *malformed = 0;\n while ((byte = fgetc(stdin)) != EOF) {\n seen = 1;\n if (byte == '\\n') {\n break;\n }\n if (byte == 0) {\n *malformed = 1;\n }\n if (used + 1 < size) {\n line[used++] = (char)byte;\n } else {\n *malformed = 1;\n }\n }\n line[used] = '\\0';\n return seen;\n}\nint run_stream(void)\n{\n static struct pool storage;\n struct strvec vector;\n char line[70000];\n char *tokens[SV_LIMIT + 5];\n char words[SV_LIMIT][SV_WORD_LIMIT + 2];\n const char *batch[SV_LIMIT];\n size_t quantum = 4;\n int initialized = 0;\n int malformed;\n pool_init(&storage);\n sv_init(&vector, &storage, quantum);\n while (read_line(line, sizeof(line), &malformed)) {\n size_t count;\n size_t a = 0;\n size_t b = 0;\n size_t index;\n int rc = -2;\n if (malformed) {\n observe_line(&vector, -2);\n continue;\n }\n count = tokenize(line, tokens, SV_LIMIT + 5);\n if (!count || count > SV_LIMIT + 5) {\n observe_line(&vector, -2);\n continue;\n }\n if (!strcmp(tokens[0], \"N\") && count == 2 &&\n decimal(tokens[1], &a) && (a == 1 || a == 2 || a == 4 || a == 8)) {\n sv_drop(&vector);\n quantum = a;\n sv_init(&vector, &storage, quantum);\n initialized = 1;\n rc = 0;\n } else if (!initialized) {\n rc = -2;\n } else if (!strcmp(tokens[0], \"F\") && count == 3 &&\n decimal(tokens[1], &a) && decimal(tokens[2], &b) &&\n a <= 2 && b <= SV_LIMIT) {\n pool_arm(&storage, (int)a, (int)b);\n rc = 0;\n } else if (!strcmp(tokens[0], \"P\") && count == 2 &&\n decode_word(tokens[1], words[0])) {\n rc = sv_push(&vector, words[0]);\n pool_disarm(&storage);\n } else if (!strcmp(tokens[0], \"B\") && count >= 2 &&\n decimal(tokens[1], &a) && a <= SV_LIMIT && count == a + 2) {\n int valid = 1;\n for (index = 0; index < a; index++) {\n if (!decode_word(tokens[index + 2], words[index])) {\n valid = 0;\n break;\n }\n batch[index] = words[index];\n }\n if (valid) {\n rc = sv_batch(&vector, batch, a);\n pool_disarm(&storage);\n }\n } else if (!strcmp(tokens[0], \"R\") && count == 3 &&\n decimal(tokens[1], &a) && decode_word(tokens[2], words[0])) {\n rc = sv_replace(&vector, a, words[0]);\n pool_disarm(&storage);\n } else if (!strcmp(tokens[0], \"E\") && count == 3 &&\n decimal(tokens[1], &a) && decimal(tokens[2], &b)) {\n rc = sv_erase(&vector, a, b);\n } else if (!strcmp(tokens[0], \"C\") && count == 1) {\n sv_clear(&vector);\n rc = 0;\n } else if (!strcmp(tokens[0], \"D\") && count == 1) {\n sv_drop(&vector);\n rc = 0;\n } else if (!strcmp(tokens[0], \"A\") && count == 1) {\n rc = 0;\n }\n observe_line(&vector, rc);\n }\n sv_drop(&vector);\n pool_destroy(&storage);\n return ferror(stdin) ? 3 : 0;\n}\n",
"pool.c": "#include \"vector.h\"\n#include <stdlib.h>\n#include <string.h>\n\nvoid pool_init(struct pool *p)\n{\n memset(p, 0, sizeof(*p));\n p->fail_after = -1;\n}\nvoid pool_arm(struct pool *p, int kind, int after)\n{\n p->fail_kind = kind;\n p->fail_after = after;\n}\nvoid pool_disarm(struct pool *p)\n{\n p->fail_kind = 0;\n p->fail_after = -1;\n}\nstatic int injected(struct pool *p, int kind)\n{\n if (p->fail_kind != kind || p->fail_after < 0) {\n return 0;\n }\n if (p->fail_after == 0) {\n pool_disarm(p);\n return 1;\n }\n p->fail_after--;\n return 0;\n}\nstatic struct pool_block *lookup(struct pool *p, const void *address)\n{\n size_t index;\n for (index = p->used; index > 0; index--) {\n struct pool_block *b = &p->blocks[index - 1];\n if (b->address == address && b->live) {\n return b;\n }\n }\n return NULL;\n}\nvoid *pool_allocate(struct pool *p, size_t bytes, int kind)\n{\n void *address;\n struct pool_block *b;\n if (bytes == 0 || (kind != POOL_ARRAY && kind != POOL_STRING)) {\n p->invalid++;\n return NULL;\n }\n if (injected(p, kind)) {\n return NULL;\n }\n if (p->used == POOL_BLOCKS) {\n return NULL;\n }\n address = calloc(1, bytes);\n if (address == NULL) {\n return NULL;\n }\n b = &p->blocks[p->used++];\n b->address = address;\n b->bytes = bytes;\n b->kind = kind;\n b->live = 1;\n return address;\n}\nvoid *pool_resize(struct pool *p, void *old, size_t bytes, int kind)\n{\n struct pool_block *b = NULL;\n void *replacement;\n size_t old_bytes = 0;\n if (old != NULL) {\n b = lookup(p, old);\n if (b == NULL || b->kind != kind) {\n p->invalid++;\n return NULL;\n }\n old_bytes = b->bytes;\n }\n replacement = pool_allocate(p, bytes, kind);\n if (replacement == NULL) {\n return NULL;\n }\n if (old != NULL) {\n size_t copied = old_bytes < bytes ? old_bytes : bytes;\n memcpy(replacement, old, copied);\n b->live = 0;\n }\n return replacement;\n}\nvoid pool_release(struct pool *p, void *address)\n{\n struct pool_block *b;\n if (address == NULL) {\n return;\n }\n b = lookup(p, address);\n if (b == NULL) {\n p->invalid++;\n return;\n }\n b->live = 0;\n}\nint pool_live(struct pool *p, const void *address, int kind, size_t needed)\n{\n struct pool_block *b;\n if (address == NULL) {\n return 0;\n }\n b = lookup(p, address);\n if (b == NULL) {\n return 0;\n }\n if (b->kind != kind || b->bytes < needed) {\n return 0;\n }\n return 1;\n}\nstruct pool_stats pool_observe(const struct pool *p)\n{\n struct pool_stats result = {0, 0, 0, 0};\n size_t index;\n result.invalid = p->invalid;\n for (index = 0; index < p->used; index++) {\n const struct pool_block *b = &p->blocks[index];\n if (!b->live) {\n continue;\n }\n if (b->kind == POOL_ARRAY) {\n result.arrays++;\n }\n if (b->kind == POOL_STRING) {\n result.strings++;\n result.string_bytes += b->bytes;\n }\n }\n return result;\n}\nvoid pool_destroy(struct pool *p)\n{\n size_t index;\n for (index = 0; index < p->used; index++) {\n free(p->blocks[index].address);\n p->blocks[index].address = NULL;\n p->blocks[index].live = 0;\n }\n p->used = 0;\n pool_disarm(p);\n}\n",
"main.c": "#include \"vector.h\"\nint main(void)\n{\n return run_stream();\n}\n",
"vector.h": "#ifndef VECTOR_H\n#define VECTOR_H\n#include <stddef.h>\n#include <stdint.h>\n#define SV_LIMIT 128\n#define SV_WORD_LIMIT 256\n#define POOL_BLOCKS 8192\n#define POOL_ARRAY 1\n#define POOL_STRING 2\nstruct pool_block {\n void *address;\n size_t bytes;\n int kind;\n int live;\n};\nstruct pool {\n struct pool_block blocks[POOL_BLOCKS];\n size_t used;\n size_t invalid;\n int fail_kind;\n int fail_after;\n};\nstruct pool_stats {\n size_t arrays;\n size_t strings;\n size_t string_bytes;\n size_t invalid;\n};\nstruct strvec {\n struct pool *pool;\n char **items;\n size_t count;\n size_t capacity;\n size_t quantum;\n};\nvoid pool_init(struct pool *p);\nvoid pool_arm(struct pool *p, int kind, int after);\nvoid pool_disarm(struct pool *p);\nvoid *pool_allocate(struct pool *p, size_t bytes, int kind);\nvoid *pool_resize(struct pool *p, void *old, size_t bytes, int kind);\nvoid pool_release(struct pool *p, void *address);\nint pool_live(struct pool *p, const void *address, int kind, size_t needed);\nstruct pool_stats pool_observe(const struct pool *p);\nvoid pool_destroy(struct pool *p);\nvoid sv_init(struct strvec *v, struct pool *p, size_t quantum);\nint sv_push(struct strvec *v, const char *word);\nint sv_batch(struct strvec *v, const char *const *words, size_t count);\nint sv_replace(struct strvec *v, size_t index, const char *word);\nint sv_erase(struct strvec *v, size_t index, size_t count);\nvoid sv_clear(struct strvec *v);\nvoid sv_drop(struct strvec *v);\nconst char *sv_at(const struct strvec *v, size_t index);\nuint64_t observe_hash(struct strvec *v, int *readable);\nvoid observe_line(struct strvec *v, int rc);\nint run_stream(void);\n#endif\n",
"README.md": "# String table maintenance bench\nBuild with `make`; run `./vector-demo < examples/default.txt` or `./vector-demo < examples/batch.txt`.\nThe C11 API and observer contract are in docs/contract.md. Submit vector.c.\nThe pool records logical release while retaining memory until final destruction, so raw observations stay safe and reproducible.\n",
"examples/batch.txt": "N 2\nP 6f6c64\nF 2 1\nB 3 6e6577 6d6f7265 6c617374\nA\nD\n",
"examples/default.txt": "N 4\nP 616c706861\nP 62657461\nP 67616d6d61\nP 64656c7461\nF 1 0\nP 657073696c6f6e\nA\nD\n",
"docs/contract.md": "# String table contract\n\n1. Build with the provided Makefile using gcc C11; no external dependencies are needed. Only vector.c is submitted. vector.h, pool.c, observer.c and main.c define the public ABI and observation protocol.\n2. A strvec owns an ordered sequence of at most 128 NUL-terminated byte strings. Each string has 0..256 nonzero bytes. Duplicates and bytes 1..255 are valid. Initialization takes a growth quantum 1, 2, 4 or 8 and allocates nothing.\n3. Storage uses pool_allocate/pool_resize/pool_release only. Every owned string has exactly one live POOL_STRING block of strlen+1 bytes. At most one live POOL_ARRAY block belongs to the vector. Every removed/replaced/discarded string is released once. The array holds count pointers and capacity slots. Only items[0..count) is defined; unused slots are unconstrained.\n4. Growth occurs once before copying any requested strings when count+incoming exceeds capacity. New capacity starts at quantum if capacity is zero, then doubles until enough, capped at 128. pool_resize(NULL,...) is allowed. On failure it preserves the old allocation. On success it copies the old bytes and logically releases the old array. Capacity may stay enlarged if subsequent string copying fails. No shrinking or extra array allocation is performed by other operations.\n5. sv_push validates the string and count first, grows as needed, allocates one string copy and appends it. Return 0 on success, -1 on allocation failure and -2 on invalid argument. Failure preserves the entire previous ordered sequence and all its ownership.\n6. sv_batch validates all inputs and total length before any allocation. A zero-size batch returns 0 and performs no allocation. Otherwise it grows once as in clause 4, then requests one POOL_STRING allocation for each input in order. It returns 0 with all copies appended, or -1 with the previous sequence and its ownership completely preserved. All copies made by a failed batch must be released. Invalid input returns -2 without allocation.\n7. sv_replace validates index<count and the word before allocation, requests one string copy, then replaces and releases the old string. Failure returns -1 preserving the previous sequence; invalid input returns -2 unchanged. sv_erase requires index<=count and incoming<=count-index, releases that range and shifts the following strings; zero-length erase is valid. It returns 0 or -2 without allocating.\n8. sv_clear releases all strings and sets count=0, retaining the array and capacity. sv_drop releases strings and the array and resets capacity=0; repeated drop is valid. sv_at returns the indexed string or NULL when index>=count. Both clear and drop preserve quantum and pool identity so subsequent appends work.\n9. The public pool stores real allocations and a logical ownership ledger. pool_release and successful pool_resize mark old blocks inactive but defer real free until pool_destroy. This intentionally avoids dereferencing actually freed memory in diagnostics. Invalid release or resize increments invalid. Only live exact base pointers satisfy pool_live. A failed allocation does not create a live block. This is controlled failure injection, not real OOM.\n10. Observer input is one command per LF-delimited line, with tokens separated only by space, TAB or CR. An unsigned number is an optional '+' followed by one or more ASCII decimal digits, numeric value <=1000000; arbitrary leading zeros are valid within the input line bound 69998 bytes. Strings use an even number of ASCII hexadecimal digits (case-insensitive), or '-' for an empty string, without encoded zero; up to 257 decoded bytes can be supplied so a 257-byte word tests API rejection. A malformed line returns -2 and preserves state. Lines fit 69998 bytes plus LF. The stream starts uninitialized; only a valid N initializes it.\n11. Commands: N quantum drops prior contents and initializes; F kind after arms one allocation failure (kind 1=array, 2=string, 0=disabled; after 0..128 matching successes before failure); P hex pushes; B count hex... appends a batch of 0..128 strings; R index hex replaces; E index count erases; C clears; D drops; A audits. F/N/C/D/A/E return 0 when syntactically valid and semantically valid, except E returns -2 for invalid range. A does not change state. Failure injection is disarmed after a syntactically recognized P/B/R, including API validation failure, and otherwise stays armed until it fires or is replaced by F. N, C and D do not consume or reset it. Unknown/malformed commands have no effect.\n12. Every input line emits one raw record with eight decimal integers: rc, count, live_arrays, live_strings, live_string_bytes, invalid_operations, readable, content_hash. rc is the function return; other fields are the actual vector/pool observations. readable=1 means active data could be read, otherwise hash=0 and readable=0. Hash starts at 14695981039346656037 and for each byte of each ordered string applies (hash XOR byte)*1099511628211 modulo 2^64, then applies the same step with byte 255 after each string. Empty sequence uses the initial hash. After D all live block counts and bytes must be zero. For other records the array count follows clauses 3/4/8; string counts and bytes follow ownership exactly. stdout permits optional '+' or '-' on decimal integers, arbitrary leading zeros, horizontal space/TAB/CR between tokens and around records, and an optional final LF. stderr may contain arbitrary diagnostic bytes of any length. Exit 0 after complete input, with no extra stdout records.\n"
}