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
14 KiB
JSON

{
"Makefile": "CXX ?= g++\nCXXFLAGS ?= -std=c++17 -O2 -Wall -Wextra -pedantic\nCPPFLAGS ?= -Iinclude\nSOURCES = src/observe.cpp src/lifecycle.cpp src/device.cpp\nHEADERS = include/service.hpp\n.PHONY: all clean demo\nall: device-demo\ndevice-demo: $(SOURCES) $(HEADERS)\n\t$(CXX) $(CPPFLAGS) $(CXXFLAGS) $(SOURCES) -o $@\ndemo: device-demo\n\t./device-demo < examples/demo.txt\nclean:\n\trm -f device-demo\n",
"README.md": "Device service repair workspace. Read docs/service.md for all API and protocol requirements. Build with make and run examples/demo.txt or examples/callbacks.txt.\n",
"docs/service.md": "# Device service contract\n\n1. This is a deterministic C++17 software device service. `make` builds `device-demo` using g++. `./device-demo < examples/demo.txt` is the default demo; `./device-demo < examples/callbacks.txt` exercises callback rejection. No downloads, ROS2, hardware, clock or network are involved. Only src/lifecycle.cpp and src/device.cpp are submitted. Header and observer are fixed public support.\n2. Each of eight slots owns an independent Device. Initially all have requested capacity 4; N replaces a slot with a fresh Device having requested capacity 1..64. A new device is state U=0, epoch=1, requested capacity as specified, actual capacity=0, empty queue, next ticket=1, zero counters, zero callback trace and empty journal. States I=1, A=2, F=3 denote inactive, active, finalized.\n3. Legal edges are configure(0): U->I; activate(1): I->A; deactivate(2): A->I; cleanup(3): I->U; shutdown(4): U/I/A->F. No edge leaves F. Any other event/state pair returns -10, does not invoke a callback and changes no service data except the attempt journal. In particular activate in U is rejected.\n4. A legal edge invokes exactly its callback once. The supplied outcome is 0=success, 1=failure, 2=error. Out-of-range outcome on a legal edge returns -11 without invoking a callback or changing service data except journal; legality is checked first. Each invocation increments its per-event count and trace = (trace*131 + event*17 + old_state*5 + outcome + 1) modulo 1000000007.\n5. Outcome 0 returns 0 and commits the legal target. Configure increments epoch and allocates actual capacity equal to requested capacity. Activate preserves resources. Deactivate discards all pending work, adding its count to dropped, but keeps capacity and epoch. Cleanup and shutdown discard all pending work, set actual capacity 0, and increment epoch. Counter/ticket/history values survive these transitions.\n6. Outcome 1 returns 1 and leaves state, epoch, capacity, requested capacity, queue, tickets and work counters unchanged. Callback counts, callback trace and attempt journal still record the invocation. Outcome 2 returns 2, sets state U, discards pending work, clears actual capacity and increments epoch; requested capacity and all cumulative work counters/ticket values are retained. This recovery also applies to a failed shutdown callback.\n7. C requests a capacity. In state U and range 1..64 it updates requested capacity and returns 0; invalid range returns -5, otherwise a non-U request returns -1 (state takes precedence). C never changes actual capacity. Configuration is per device.\n8. P submits an int32 payload. Outside A return -1; when full return -2, with state taking precedence. Otherwise append (next_ticket, current_epoch, payload), advance next_ticket, increment submitted and return that positive ticket. Tickets are uint64, and tested workloads do not overflow any counter, epoch or ticket.\n9. K completes a (ticket, epoch). Outside A return -1. In A a different epoch returns -3 before searching; no matching ticket returns -4. Success removes that one queue entry while preserving order, increments completed, stores last_completed=payload and returns 0. Failed P/K operations leave all service data unchanged. An empty queue has digest 0; otherwise fold entries in order, starting 0: h=(h*257 + ticket%M*7 + epoch%M*11 + (payload%M+M)%M) % M, M=1000000007.\n10. Every T, C, P, K operation appends a journal record (kind,event_or_argument,rc,before_state,after_state), including rejections. K's argument is ticket modulo M; P's is its signed payload; T's is event; C's is capacity. kind is 1,2,3,4 for T,C,P,K. Journal retains the newest 16 records in original order. Its digest folds each record: h=(h*263 + kind*13 + norm(argument)*17 + norm(rc)*19 + before*23 + after*29)%M, with norm(x)=(x%M+M)%M. Journal does not influence transitions or queue decisions.\n11. Snapshot has 21 integer fields: state, epoch, requested_capacity, actual_capacity, pending, next_ticket, submitted, completed, dropped, last_completed, callback_count[0..4], callback_trace, queue_digest, journal_size, journal_digest, oldest_pending_ticket (0 if empty), newest_pending_ticket (0 if empty). Returned snapshots are values; modifying a snapshot must not alter the Device. `snapshot()` never changes history or counters.\n12. Input is a sequence of LF-delimited ASCII lines. Tokens are separated by one or more SPACE/TAB/CR. Commands: `N slot capacity`, `T slot event outcome`, `C slot capacity`, `P slot payload`, `K slot ticket epoch`, `Q slot`, `V slot`. Slots 0..7; capacity/event/outcome/C/P fit signed int32; K values are uint64. All commands are well-formed and all N capacities are 1..64. Decimal tokens permit leading + and arbitrarily many leading zeros; negative zero is allowed for signed tokens. V obtains a snapshot, changes its local state/epoch/first callback count, then obtains the actual snapshot again. It emits the same observation as Q, proving snapshot value semantics. Input can contain blank lines. This protocol is an observer interface, not a lifecycle command language that may add extra transitions.\n13. Every nonblank command emits one JSON array `[rc, ...21_snapshot_fields]` followed by LF, in input order, and exits 0 after EOF. N/Q/V use rc=0. JSON fields are integer numbers, never strings/bools/floats; whitespace and alternate valid JSON integer formatting are immaterial. No extra stdout is permitted. Arbitrary stderr bytes are allowed diagnostics. The public observer prints only raw API return values and snapshot fields, without expected values or assertions. Only public input ranges and effective fields above are checked.\n",
"examples/callbacks.txt": "N 0 3\nT 0 0 1\nQ 0\nT 0 0 0\nT 0 1 0\nP 0 12\nT 0 2 1\nQ 0\n",
"examples/demo.txt": "T 0 1 0\nT 0 0 0\nT 0 1 0\nP 0 42\nQ 0\n",
"include/service.hpp": "#ifndef DEVICE_SERVICE_HPP\n#define DEVICE_SERVICE_HPP\n#include <array>\n#include <cstddef>\n#include <cstdint>\n#include <deque>\n#include <vector>\nnamespace service {\nconstexpr std::uint64_t modulus = 1000000007ULL;\nenum class State : int { U = 0, I = 1, A = 2, F = 3 };\nstruct Work {\n std::uint64_t ticket;\n std::uint64_t epoch;\n std::int32_t payload;\n};\nstruct JournalEntry {\n int kind;\n std::int64_t argument;\n std::int64_t result;\n State before;\n State after;\n};\nstruct Snapshot {\n int state;\n std::uint64_t epoch;\n int requested_capacity;\n int actual_capacity;\n std::size_t pending;\n std::uint64_t next_ticket;\n std::uint64_t submitted;\n std::uint64_t completed;\n std::uint64_t dropped;\n std::int32_t last_completed;\n std::array<std::uint64_t, 5> callbacks;\n std::uint64_t callback_trace;\n std::uint64_t queue_digest;\n std::size_t journal_size;\n std::uint64_t journal_digest;\n std::uint64_t oldest_ticket;\n std::uint64_t newest_ticket;\n};\nclass Device {\npublic:\n explicit Device(int requested = 4);\n int transition(int event, int outcome);\n int request_capacity(int capacity);\n std::int64_t publish(std::int32_t payload);\n int complete(std::uint64_t ticket, std::uint64_t epoch);\n Snapshot snapshot() const;\nprivate:\n State state_;\n std::uint64_t epoch_;\n int requested_capacity_;\n int actual_capacity_;\n std::uint64_t next_ticket_;\n std::uint64_t submitted_;\n std::uint64_t completed_;\n std::uint64_t dropped_;\n std::int32_t last_completed_;\n std::array<std::uint64_t, 5> callbacks_;\n std::uint64_t callback_trace_;\n std::deque<Work> work_;\n std::deque<JournalEntry> journal_;\n bool target_for(int event, State& target) const;\n void invoke(int event, int outcome);\n void commit(int event, State target);\n void recover();\n void discard_pending();\n void record(int kind, std::int64_t arg, std::int64_t result, State before);\n std::uint64_t work_digest() const;\n std::uint64_t history_digest() const;\n static std::uint64_t normalize(std::int64_t value);\n};\n}\n#endif\n",
"src/observe.cpp": "#include \"service.hpp\"\n#include <array>\n#include <cstdint>\n#include <iostream>\n#include <limits>\n#include <memory>\n#include <string>\n#include <vector>\nnamespace {\nbool separator(char value) {\n return value == ' ' || value == '\\t' || value == '\\r';\n}\nstd::vector<std::string> split(const std::string& line) {\n std::vector<std::string> tokens;\n std::size_t offset = 0;\n while (offset < line.size()) {\n while (offset < line.size() && separator(line[offset])) {\n ++offset;\n }\n if (offset == line.size()) {\n break;\n }\n const auto start = offset;\n while (offset < line.size() && !separator(line[offset])) {\n ++offset;\n }\n tokens.push_back(line.substr(start, offset - start));\n }\n return tokens;\n}\nbool magnitude(const std::string& token, bool& negative, std::uint64_t& value) {\n if (token.empty()) {\n return false;\n }\n std::size_t offset = 0;\n negative = false;\n if (token[offset] == '+' || token[offset] == '-') {\n negative = token[offset] == '-';\n ++offset;\n }\n if (offset == token.size()) {\n return false;\n }\n value = 0;\n for (; offset < token.size(); ++offset) {\n const char byte = token[offset];\n if (byte < '0' || byte > '9') {\n return false;\n }\n const auto digit = static_cast<std::uint64_t>(byte - '0');\n if (value > (std::numeric_limits<std::uint64_t>::max() - digit) / 10) {\n return false;\n }\n value = value * 10 + digit;\n }\n return true;\n}\nbool signed_value(const std::string& token, std::int32_t& result) {\n bool negative;\n std::uint64_t value;\n if (!magnitude(token, negative, value)) {\n return false;\n }\n const std::uint64_t limit = negative ? 2147483648ULL : 2147483647ULL;\n if (value > limit) {\n return false;\n }\n if (negative) {\n result = static_cast<std::int32_t>(-static_cast<std::int64_t>(value));\n } else {\n result = static_cast<std::int32_t>(value);\n }\n return true;\n}\nbool unsigned_value(const std::string& token, std::uint64_t& result) {\n bool negative;\n if (!magnitude(token, negative, result)) {\n return false;\n }\n return !negative;\n}\nvoid print_snapshot(std::int64_t result, const service::Snapshot& value) {\n std::cout << '[' << result;\n std::cout << ',' << value.state;\n std::cout << ',' << value.epoch;\n std::cout << ',' << value.requested_capacity;\n std::cout << ',' << value.actual_capacity;\n std::cout << ',' << value.pending;\n std::cout << ',' << value.next_ticket;\n std::cout << ',' << value.submitted;\n std::cout << ',' << value.completed;\n std::cout << ',' << value.dropped;\n std::cout << ',' << value.last_completed;\n for (auto count : value.callbacks) {\n std::cout << ',' << count;\n }\n std::cout << ',' << value.callback_trace;\n std::cout << ',' << value.queue_digest;\n std::cout << ',' << value.journal_size;\n std::cout << ',' << value.journal_digest;\n std::cout << ',' << value.oldest_ticket;\n std::cout << ',' << value.newest_ticket;\n std::cout << \"]\\n\";\n}\nbool count_is(const std::vector<std::string>& words, std::size_t count) {\n return words.size() == count;\n}\n}\nint main() {\n std::array<std::unique_ptr<service::Device>, 8> devices;\n for (auto& device : devices) {\n device = std::make_unique<service::Device>();\n }\n std::string line;\n while (std::getline(std::cin, line)) {\n const auto words = split(line);\n if (words.empty()) {\n continue;\n }\n std::int32_t slot;\n if (words.size() < 2 || !signed_value(words[1], slot) || slot < 0 || slot >= 8) {\n return 2;\n }\n auto& selected = devices[static_cast<std::size_t>(slot)];\n std::int64_t result = 0;\n const auto& operation = words[0];\n if (operation == \"N\") {\n std::int32_t capacity;\n if (!count_is(words, 3) || !signed_value(words[2], capacity) || capacity < 1 || capacity > 64) {\n return 2;\n }\n selected = std::make_unique<service::Device>(capacity);\n } else if (operation == \"T\") {\n std::int32_t event;\n std::int32_t outcome;\n if (!count_is(words, 4) || !signed_value(words[2], event) || !signed_value(words[3], outcome)) {\n return 2;\n }\n result = selected->transition(event, outcome);\n } else if (operation == \"C\") {\n std::int32_t capacity;\n if (!count_is(words, 3) || !signed_value(words[2], capacity)) {\n return 2;\n }\n result = selected->request_capacity(capacity);\n } else if (operation == \"P\") {\n std::int32_t payload;\n if (!count_is(words, 3) || !signed_value(words[2], payload)) {\n return 2;\n }\n result = selected->publish(payload);\n } else if (operation == \"K\") {\n std::uint64_t ticket;\n std::uint64_t epoch;\n if (!count_is(words, 4) || !unsigned_value(words[2], ticket) || !unsigned_value(words[3], epoch)) {\n return 2;\n }\n result = selected->complete(ticket, epoch);\n } else if (operation == \"Q\") {\n if (!count_is(words, 2)) {\n return 2;\n }\n } else if (operation == \"V\") {\n if (!count_is(words, 2)) {\n return 2;\n }\n auto copy = selected->snapshot();\n copy.state = 99;\n copy.epoch = 0;\n copy.callbacks[0] = 777;\n } else {\n return 2;\n }\n print_snapshot(result, selected->snapshot());\n }\n return 0;\n}\n"
}