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>
14 lines
17 KiB
JSON
14 lines
17 KiB
JSON
{
|
|
"seed": 240621,
|
|
"context": {
|
|
"memory.cpp": "#include \"packet.hpp\"\n#include <cstdlib>\n#include <new>\nnamespace packet {\nMemory::Memory() : countdown_(0) {\n}\nMemory::~Memory() {\n for (const Allocation& allocation : live_) {\n std::free(allocation.address);\n }\n}\nvoid* Memory::acquire(Kind kind, std::size_t bytes) {\n counters_.attempts += 1;\n if (countdown_ != 0) {\n countdown_ -= 1;\n if (countdown_ == 0) {\n counters_.failures += 1;\n return nullptr;\n }\n }\n void* address = std::malloc(bytes);\n if (address == nullptr) {\n counters_.failures += 1;\n return nullptr;\n }\n try {\n live_.push_back(Allocation{address, bytes, kind});\n } catch (...) {\n std::free(address);\n throw;\n }\n counters_.allocated += 1;\n counters_.bytes += bytes;\n if (kind == Kind::Node) {\n counters_.nodes += 1;\n } else {\n counters_.payloads += 1;\n }\n return address;\n}\nvoid Memory::release(void* address) {\n if (address == nullptr) {\n return;\n }\n for (auto iterator = live_.begin(); iterator != live_.end(); ++iterator) {\n if (iterator->address != address) {\n continue;\n }\n counters_.released += 1;\n counters_.bytes -= iterator->bytes;\n if (iterator->kind == Kind::Node) {\n counters_.nodes -= 1;\n } else {\n counters_.payloads -= 1;\n }\n std::free(iterator->address);\n live_.erase(iterator);\n return;\n }\n counters_.invalid += 1;\n}\nvoid Memory::fail_after(std::uint64_t count) {\n countdown_ = count;\n}\nMemoryView Memory::view() const {\n return counters_;\n}\n}\n",
|
|
"Makefile": "CXX ?= g++\nCXXFLAGS ?= -std=c++17 -O2 -Wall -Wextra -pedantic\nSOURCES = queue.cpp memory.cpp codec.cpp service.cpp\nHEADERS = packet.hpp\nall: packet-demo\npacket-demo: $(SOURCES) $(HEADERS)\n\t$(CXX) $(CXXFLAGS) $(SOURCES) -o $@\nclean:\n\trm -f packet-demo\n.PHONY: all clean\n",
|
|
"codec.cpp": "#include \"packet.hpp\"\n#include <sstream>\nnamespace packet {\nbool number(const std::string& token, std::uint32_t maximum, std::uint32_t& value) {\n if (token.empty()) {\n return false;\n }\n std::uint32_t current = 0;\n for (char character : token) {\n if (character < '0' || character > '9') {\n return false;\n }\n unsigned digit = static_cast<unsigned>(character - '0');\n if (current > maximum / 10) {\n return false;\n }\n if (current == maximum / 10 && digit > maximum % 10) {\n return false;\n }\n current = current * 10 + digit;\n }\n value = current;\n return true;\n}\nstatic int nibble(char character) {\n if (character >= '0' && character <= '9') {\n return character - '0';\n }\n if (character >= 'a' && character <= 'f') {\n return character - 'a' + 10;\n }\n if (character >= 'A' && character <= 'F') {\n return character - 'A' + 10;\n }\n return -1;\n}\nbool decode(const std::string& token, std::string& bytes) {\n bytes.clear();\n if (token == \"-\") {\n return true;\n }\n if (token.empty() || token.size() > 128 || token.size() % 2 != 0) {\n return false;\n }\n std::string result;\n result.reserve(token.size() / 2);\n for (std::size_t index = 0; index < token.size(); index += 2) {\n int high = nibble(token[index]);\n int low = nibble(token[index + 1]);\n if (high < 0 || low < 0) {\n return false;\n }\n result.push_back(static_cast<char>(high * 16 + low));\n }\n bytes.swap(result);\n return true;\n}\nstd::string encode(const std::string& bytes) {\n if (bytes.empty()) {\n return \"-\";\n }\n const char* alphabet = \"0123456789abcdef\";\n std::string result;\n result.reserve(bytes.size() * 2);\n for (unsigned char byte : bytes) {\n result.push_back(alphabet[byte >> 4]);\n result.push_back(alphabet[byte & 15]);\n }\n return result;\n}\nstd::uint32_t checksum(const Packet& packet) {\n std::uint32_t result = 2166136261u;\n auto feed = [&result](unsigned byte) {\n result ^= byte;\n result *= 16777619u;\n };\n for (unsigned shift = 0; shift != 32; shift += 8) {\n feed((packet.id >> shift) & 255);\n }\n feed(packet.priority);\n for (unsigned shift = 0; shift != 32; shift += 8) {\n feed((packet.deadline >> shift) & 255);\n }\n for (unsigned char byte : packet.data) {\n feed(byte);\n }\n return result;\n}\nstd::vector<std::string> words(const std::string& line) {\n std::istringstream input(line);\n std::vector<std::string> tokens;\n std::string token;\n while (input >> token) {\n tokens.push_back(token);\n }\n return tokens;\n}\n}\n",
|
|
"demo.txt": "P 0 11 1 0 010203\nP 0 12 0 0 ff\nO 0\nK 0\n",
|
|
"packet.hpp": "#ifndef PACKET_HPP\n#define PACKET_HPP\n#include <array>\n#include <cstddef>\n#include <cstdint>\n#include <string>\n#include <vector>\nnamespace packet {\nenum class Kind { Node, Payload };\nstruct Allocation {\n void* address;\n std::size_t bytes;\n Kind kind;\n};\nstruct MemoryView {\n std::uint64_t attempts = 0;\n std::uint64_t allocated = 0;\n std::uint64_t released = 0;\n std::uint64_t failures = 0;\n std::uint64_t invalid = 0;\n std::uint64_t nodes = 0;\n std::uint64_t payloads = 0;\n std::uint64_t bytes = 0;\n};\nclass Memory {\npublic:\n Memory();\n ~Memory();\n Memory(const Memory&) = delete;\n Memory& operator=(const Memory&) = delete;\n void* acquire(Kind kind, std::size_t bytes);\n void release(void* address);\n void fail_after(std::uint64_t count);\n MemoryView view() const;\nprivate:\n std::vector<Allocation> live_;\n MemoryView counters_;\n std::uint64_t countdown_;\n};\nstruct Packet {\n std::uint32_t id = 0;\n unsigned priority = 0;\n std::uint32_t deadline = 0;\n std::string data;\n};\nstruct LaneView {\n std::size_t count = 0;\n std::size_t bytes = 0;\n std::uint32_t head = 0;\n std::uint32_t tail = 0;\n std::uint32_t checksum = 0;\n unsigned capacity = 8;\n};\nstruct Stats {\n std::uint64_t accepted = 0;\n std::uint64_t popped = 0;\n std::uint64_t expired = 0;\n std::uint64_t cleared = 0;\n std::uint64_t moved = 0;\n std::uint64_t refused = 0;\n std::uint64_t oom = 0;\n};\nclass Queue {\npublic:\n explicit Queue(Memory& memory);\n ~Queue();\n Queue(const Queue&) = delete;\n Queue& operator=(const Queue&) = delete;\n int push(unsigned lane, const Packet& packet);\n int pop(unsigned lane, Packet& packet);\n int peek(unsigned lane, Packet& packet) const;\n int expire(unsigned lane, std::uint32_t now);\n int clear(unsigned lane);\n int move(unsigned from, unsigned to, unsigned maximum);\n int limit(unsigned lane, unsigned capacity);\n LaneView lane(unsigned index) const;\n Stats stats() const;\n void shutdown();\nprivate:\n struct State;\n State* state_;\n};\nbool number(const std::string& token, std::uint32_t maximum, std::uint32_t& value);\nbool decode(const std::string& token, std::string& bytes);\nstd::string encode(const std::string& bytes);\nstd::uint32_t checksum(const Packet& packet);\nstd::vector<std::string> words(const std::string& line);\n}\n#endif\n",
|
|
"service.cpp": "#include \"packet.hpp\"\n#include <iostream>\nnamespace {\nusing namespace packet;\nvoid print_memory(const Memory& memory) {\n MemoryView view = memory.view();\n std::cout << ' ' << view.attempts;\n std::cout << ' ' << view.allocated;\n std::cout << ' ' << view.released;\n std::cout << ' ' << view.failures;\n std::cout << ' ' << view.invalid;\n std::cout << ' ' << view.nodes;\n std::cout << ' ' << view.payloads;\n std::cout << ' ' << view.bytes;\n}\nvoid snapshot(unsigned step, const Queue& queue, const Memory& memory) {\n Stats stats = queue.stats();\n std::cout << \"S \" << step;\n std::cout << ' ' << stats.accepted;\n std::cout << ' ' << stats.popped;\n std::cout << ' ' << stats.expired;\n std::cout << ' ' << stats.cleared;\n std::cout << ' ' << stats.moved;\n std::cout << ' ' << stats.refused;\n std::cout << ' ' << stats.oom;\n for (unsigned index = 0; index != 3; ++index) {\n LaneView lane = queue.lane(index);\n std::cout << ' ' << lane.count;\n std::cout << ' ' << lane.bytes;\n std::cout << ' ' << lane.head;\n std::cout << ' ' << lane.tail;\n std::cout << ' ' << lane.checksum;\n std::cout << ' ' << lane.capacity;\n }\n print_memory(memory);\n std::cout << '\\n';\n}\nint execute(const std::vector<std::string>& tokens, Queue& queue, Memory& memory, Packet& result) {\n std::uint32_t first = 0;\n std::uint32_t second = 0;\n std::uint32_t third = 0;\n if (tokens.empty()) {\n return -1;\n }\n const std::string& command = tokens[0];\n if (command == \"P\" && tokens.size() == 6) {\n Packet packet;\n if (!number(tokens[1], 2, first)) {\n return -1;\n }\n if (!number(tokens[2], 999999, packet.id)) {\n return -1;\n }\n if (!number(tokens[3], 3, second)) {\n return -1;\n }\n if (!number(tokens[4], 1000000, packet.deadline)) {\n return -1;\n }\n if (!decode(tokens[5], packet.data)) {\n return -1;\n }\n packet.priority = second;\n return queue.push(first, packet);\n }\n if ((command == \"O\" || command == \"K\" || command == \"C\") && tokens.size() == 2) {\n if (!number(tokens[1], 2, first)) {\n return -1;\n }\n if (command == \"O\") {\n return queue.pop(first, result);\n }\n if (command == \"K\") {\n return queue.peek(first, result);\n }\n return queue.clear(first);\n }\n if (command == \"E\" && tokens.size() == 3) {\n if (!number(tokens[1], 2, first) || !number(tokens[2], 1000000, second)) {\n return -1;\n }\n return queue.expire(first, second);\n }\n if (command == \"M\" && tokens.size() == 4) {\n if (!number(tokens[1], 2, first) || !number(tokens[2], 2, second)) {\n return -1;\n }\n if (!number(tokens[3], 32, third)) {\n return -1;\n }\n return queue.move(first, second, third);\n }\n if (command == \"L\" && tokens.size() == 3) {\n if (!number(tokens[1], 2, first) || !number(tokens[2], 32, second)) {\n return -1;\n }\n return queue.limit(first, second);\n }\n if (command == \"F\" && tokens.size() == 2) {\n if (!number(tokens[1], 1000, first)) {\n return -1;\n }\n memory.fail_after(first);\n return 0;\n }\n if (command == \"X\" && tokens.size() == 1) {\n queue.shutdown();\n return 0;\n }\n return -1;\n}\n}\nint main() {\n packet::Memory memory;\n {\n packet::Queue queue(memory);\n std::string line;\n unsigned step = 0;\n while (std::getline(std::cin, line)) {\n std::vector<std::string> tokens = packet::words(line);\n if (tokens.empty()) {\n continue;\n }\n ++step;\n packet::Packet result;\n int code = execute(tokens, queue, memory, result);\n std::cout << \"R \" << step << ' ' << code;\n if (code == 0 && (tokens[0] == \"O\" || tokens[0] == \"K\")) {\n std::cout << ' ' << result.id << ' ' << result.priority;\n std::cout << ' ' << result.deadline << ' ' << packet::encode(result.data);\n }\n std::cout << '\\n';\n snapshot(step, queue, memory);\n }\n }\n std::cout << \"Z\";\n print_memory(memory);\n std::cout << '\\n';\n return 0;\n}\n",
|
|
"README.md": "# Packet spool service\nBuild with `make`, replay with `./packet-demo < demo.txt`. The command stream can be supplied from any text file or stdin. The public service prints raw queue and Memory observations; consult docs/queue.md for the complete contract. Only queue.cpp is submitted. The other files define the fixed public adapter and console.\n",
|
|
"docs/queue.md": "# Packet queue contract\n1. There are three FIFO lanes numbered 0..2. Initial capacity is 8 per lane. No board, network, wall clock or threads are required. Priority is metadata; it does not reorder FIFO.\n2. P lane id priority deadline hex submits a packet. id is 0..999999, priority 0..3, deadline 0..1000000; hex is 1..64 bytes encoded as pairs (case insensitive), or - for zero bytes. Duplicate IDs are allowed. A successful push appends a copy, increments accepted, and returns 0.\n3. Each queued packet owns exactly one Memory Node allocation of 64 bytes followed by one Payload allocation of data length+1 bytes, including empty data. The last payload byte is a zero terminator. Resources must be returned via Memory.release when a packet leaves ownership. Internal organization is otherwise unrestricted; no access to Memory private state is allowed.\n4. Full lanes refuse P with -2 and increment refused without allocation. Otherwise P attempts node then payload; a failure returns -3, increments oom, releases any allocation acquired for that attempt, and leaves lane content unchanged. Memory counts every acquire attempt; successful allocations and releases, failure and invalid-release counts, live nodes/payloads and sum of live allocated bytes are observable. A null release has no effect. Invalid releases are forbidden.\n5. O lane removes and returns its oldest packet, increments popped and returns 0; empty lane returns -2 with no other effect. K lane returns the same oldest packet without mutation, or -2 on empty. After emptying, a lane can accept a new packet normally.\n6. E lane now removes every packet with nonzero deadline <= now, preserving the order of survivors. It returns the number removed and increments expired by that count. Each removed packet must release both owned allocations. now ranges 0..1000000; deadline 0 never expires.\n7. C lane removes every packet, returns the count, increments cleared by that count and releases both allocations of each. Empty C has no effect. X clears all lanes by C in lane order and returns 0. EOF destroys the queue with the same releases; repeated shutdown and destruction of an empty queue have no further effects. Capacity is preserved by C and X.\n8. M from to maximum transfers the oldest prefix, bounded by maximum (0..32), source count and free destination capacity. It appends to the destination in source order; same lane returns 0. It returns the number transferred and adds it to moved. Ownership transfers without acquire/release calls, accepted/popped/expired/cleared do not change.\n9. L lane capacity changes the limit to 1..32, returns 0; a limit below current count returns -2 with no effect. F n sets a one-shot allocation-failure countdown, 0 disables. Each subsequent Memory.acquire decrements a positive countdown; the acquire reaching zero fails. n ranges 0..1000; full/rejected operations do not advance it.\n10. All numbers are unsigned ASCII decimal, leading zeros allowed; signs, overflow, missing/extra tokens, unknown command, invalid hex or out-of-range argument return -1 without queue, statistics, Memory or F mutation. Blank lines are ignored. Input is whitespace separated, one command per line.\n11. After each nonblank line, R step rc is printed; a successful O/K appends id priority deadline lowercase_hex (or -). Then S step prints accepted popped expired cleared moved refused oom, six fields per lane (count payload_bytes head_id tail_id checksum capacity), then Memory fields attempts allocated released failures invalid live_nodes live_payloads live_bytes. An empty lane has head/tail/checksum zero. No extra stdout is permitted; arbitrary diagnostic stderr bytes are permitted.\n12. Packet checksum is 32-bit FNV-1a starting at 2166136261, feeding id as four little-endian bytes, priority as one byte, deadline as four little-endian bytes, then the data bytes; xor each byte then multiply by 16777619 modulo 2^32. Lane checksum starts zero and folds FIFO packet checksums as h=(h*33+packet_checksum) modulo 2^32. IDs of zero are ordinary IDs, not sentinels.\n13. After EOF destruction, Z plus the eight Memory fields is printed. All live resources must be zero and invalid release count zero; the Memory destructor may finally reclaim leftovers to keep diagnostics safe, but that occurs after Z and cannot satisfy queue ownership. Exit status is 0 on normal EOF. Limits describe supported inputs, not permission to omit documented paths.\n"
|
|
}
|
|
}
|