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>
11 lines
23 KiB
JSON
11 lines
23 KiB
JSON
{
|
|
"Makefile": "CXX ?= g++\nCXXFLAGS ?= -std=c++17 -O2 -Wall -Wextra -pedantic\nSOURCES = observe.cpp fifo.cpp peer.cpp wire.cpp pump.cpp\nall: duplex-observe\nduplex-observe: $(SOURCES) duplex.hpp\n\t$(CXX) $(CXXFLAGS) $(SOURCES) -o $@\ndemo: duplex-observe\n\tprintf 'RUN 8 8 3 3 3 3 0 1 1 1000 2000000 0 - - 68656c6c6f\\n' | ./duplex-observe\nclean:\n\trm -f duplex-observe\n.PHONY: all demo clean\n",
|
|
"README.md": "# Duplex capture service\n\nBuild with `make`, run `make demo`. The public executable `duplex-observe` reads one RUN request per line. All service/API, byte stream, scheduling, completion and observation requirements are in [docs/contract.md](docs/contract.md). Only `pump.cpp` is submitted. Other public files define the endpoint and observer used during clean grading.\n",
|
|
"docs/contract.md": "# Duplex service contract\n\nC01. Implement `duplex::pump(Port&, const Bytes&, const Settings&)` in C++17, with the signature and structures in duplex.hpp. Each call is a fresh independent conversation. Input is arbitrary bytes, length 0..1048576. The caller owns input; do not mutate it.\n\nC02. Port is a finite independent request FIFO and response FIFO. `write`/`read` return `Data` with 1..requested bytes, `Again` with zero (temporarily unavailable), `End` with zero (only read, permanent EOF), or `Error` with zero. A short transfer consumes only its returned count. Port methods take nonzero requested lengths. Never treat Again as End. Write has no End on a valid ScriptPort.\n\nC03. Send every input byte once in order. Drain response while input is still pending, because either independent FIFO may fill, including while the peer emits its prefix before consuming any request. Finite capacity does not imply a fixed operating-system pipe capacity. The controlled endpoint advances only through `advance`; one advance starts a new tick. At most one read and one write is accepted per tick; otherwise Again. `advance` returning true means internal progress, not completion.\n\nC04. Exactly once, after all request bytes are accepted, call close_write(). That is a half-close. The peer consumes queued bytes, then observes request EOF. It may still emit output. Continue advancing and reading until actual End, including temporary empty intervals. Successful Outcome has status `ok`, sent=input length, write_closed=true, output_end=true, and output exactly C05. Error status is `error`, genuine no-progress is `stalled`; never claim ok before actual End.\n\nC05. Response bytes are prefix + each input byte XOR key + suffix, in that order, byte-for-byte. Prefix may precede request consumption. Suffix is emitted after input EOF and quiet_ticks additional service ticks. Prefix/suffix may be empty, include NUL or any byte, and each is at most 65536 bytes. Key is 0..255.\n\nC06. Valid Settings: each FIFO capacity and each of peer_read_quantum, peer_write_quantum, write_quantum, read_quantum is 1..65536; quiet_ticks 0..100; tx_period and rx_period 1..100. A write/read is eligible only when the current tick is divisible by its period. idle_limit 1000..100000, tick_limit 1000..10000000. Terminate by these limits if necessary. Acceptance success cases provide tick_limit sufficient for all streams and idle_limit above scheduling gaps. Do not depend on exact number/order of successful read/write calls, iterations or peak occupancies.\n\nC07. The observer prints raw actual endpoint facts, not success assertions. An ok completed conversation leaves no request, response or peer pending bytes, actual request written/read=input length, actual response written/read=expected output length, close_calls=1, actual input_end/output_closed/output_end_observed=true. These independently observable facts are required along with returned bytes.\n\nC08. Input protocol: ASCII lines separated by LF; tokens separated only by space, TAB or CR. Exactly 16 tokens: RUN request_capacity response_capacity peer_read_quantum peer_write_quantum write_quantum read_quantum quiet_ticks tx_period rx_period idle_limit tick_limit key prefix_hex suffix_hex input_hex. Numeric tokens are complete ASCII decimal, may have leading + and arbitrarily many leading zeros; nonnegative and size_t-representable. Hex tokens use any-case pairs; `-` is empty. Invalid requests produce exactly `invalid` and have no conversation.\n\nC09. Valid request output is one line with 16 tokens separated by horizontal ASCII whitespace: status sent write_closed output_end request_written request_read response_written response_read request_pending response_pending peer_pending close_calls input_end output_closed output_end_observed output_hex. Numeric observation tokens are signed ASCII decimal, arbitrary leading zeros/+ permitted, but values must match required observations. Hex observation accepts either case or `-` for empty. Stderr is unrestricted diagnostic bytes and never part of this protocol. The process exits 0 after processing all valid or invalid request lines.\n\nC10. Fresh builds use `g++ -std=c++17 -O2 -Wall -Wextra -pedantic observe.cpp fifo.cpp peer.cpp wire.cpp pump.cpp -o duplex-observe`. No network, hardware, CMake or external libraries are needed. Public `make demo` is a small ordinary echo; allowed small FIFO, prefix, delayed suffix and asymmetric scheduling cases remain required.\n",
|
|
"duplex.hpp": "#ifndef DUPLEX_HPP\n#define DUPLEX_HPP\n#include <algorithm>\n#include <cstddef>\n#include <cstdint>\n#include <deque>\n#include <string>\n#include <vector>\nnamespace duplex {\nusing Bytes = std::vector<std::uint8_t>;\nenum class Event { Data, Again, End, Error };\nstruct Transfer {\n Event event = Event::Again;\n std::size_t count = 0;\n};\nstruct ChannelStats {\n std::size_t written = 0;\n std::size_t read = 0;\n std::size_t peak = 0;\n std::size_t blocked_writes = 0;\n std::size_t blocked_reads = 0;\n std::size_t end_reads = 0;\n};\nclass Channel {\npublic:\n explicit Channel(std::size_t capacity);\n Transfer push(const std::uint8_t* data, std::size_t count);\n Transfer pop(std::uint8_t* data, std::size_t count);\n bool close_writer();\n void close_reader();\n bool writer_closed() const;\n bool reader_closed() const;\n bool drained() const;\n std::size_t size() const;\n std::size_t capacity() const;\n ChannelStats stats() const;\nprivate:\n Bytes data_;\n std::size_t head_ = 0;\n std::size_t used_ = 0;\n bool writer_closed_ = false;\n bool reader_closed_ = false;\n ChannelStats stats_;\n};\nstruct Settings {\n std::size_t request_capacity = 8;\n std::size_t response_capacity = 8;\n std::size_t peer_read_quantum = 3;\n std::size_t peer_write_quantum = 3;\n std::size_t write_quantum = 3;\n std::size_t read_quantum = 3;\n std::size_t quiet_ticks = 0;\n std::size_t tx_period = 1;\n std::size_t rx_period = 1;\n std::size_t idle_limit = 1000;\n std::size_t tick_limit = 2000000;\n unsigned key = 0;\n Bytes prefix;\n Bytes suffix;\n};\nstd::string validate(const Settings& settings);\nclass Port {\npublic:\n virtual ~Port() = default;\n virtual Transfer write(const std::uint8_t*, std::size_t) = 0;\n virtual Transfer read(std::uint8_t*, std::size_t) = 0;\n virtual bool close_write() = 0;\n virtual bool advance() = 0;\n virtual bool input_eof_seen() const = 0;\n};\nstruct WireView {\n ChannelStats request;\n ChannelStats response;\n std::size_t request_pending = 0;\n std::size_t response_pending = 0;\n std::size_t peer_pending = 0;\n std::size_t ticks = 0;\n std::size_t close_calls = 0;\n bool input_end = false;\n bool output_closed = false;\n bool output_end_observed = false;\n};\nclass ScriptPort final : public Port {\npublic:\n explicit ScriptPort(const Settings& settings);\n Transfer write(const std::uint8_t*, std::size_t) override;\n Transfer read(std::uint8_t*, std::size_t) override;\n bool close_write() override;\n bool advance() override;\n bool input_eof_seen() const override;\n WireView view() const;\nprivate:\n enum class Phase { Prefix, Body, Quiet, Suffix, Finished };\n bool stage_prefix();\n bool stage_body();\n bool stage_suffix();\n bool drain_pending();\n bool update_phase();\n void append(const std::uint8_t*, std::size_t, bool transform);\n Settings settings_;\n Channel request_;\n Channel response_;\n Phase phase_ = Phase::Prefix;\n std::deque<std::uint8_t> pending_;\n std::size_t prefix_position_ = 0;\n std::size_t suffix_position_ = 0;\n std::size_t quiet_remaining_ = 0;\n std::size_t ticks_ = 0;\n std::size_t close_calls_ = 0;\n bool input_end_ = false;\n bool output_end_observed_ = false;\n bool write_used_ = false;\n bool read_used_ = false;\n};\nstruct Outcome {\n std::string status = \"stalled\";\n Bytes output;\n std::size_t sent = 0;\n std::size_t iterations = 0;\n bool write_closed = false;\n bool output_end = false;\n};\nOutcome pump(Port& port, const Bytes& input, const Settings& settings);\nstd::string hex(const Bytes& bytes);\nbool unhex(const std::string& text, Bytes& bytes);\nbool number(const std::string& text, std::size_t& value);\nbool parse_request(const std::string& line, Settings& settings, Bytes& input);\nstd::string observation(const Outcome&, const WireView&);\n}\n#endif\n",
|
|
"fifo.cpp": "#include \"duplex.hpp\"\n#include <limits>\n#include <sstream>\n#include <stdexcept>\nnamespace duplex {\nChannel::Channel(std::size_t capacity) : data_(capacity) {\n if (capacity == 0) {\n throw std::invalid_argument(\"zero channel capacity\");\n }\n}\nTransfer Channel::push(const std::uint8_t* source, std::size_t count) {\n if (reader_closed_ || writer_closed_) {\n return {Event::Error, 0};\n }\n if (count == 0) {\n return {Event::Again, 0};\n }\n std::size_t accepted = std::min(count, data_.size() - used_);\n if (accepted == 0) {\n ++stats_.blocked_writes;\n return {Event::Again, 0};\n }\n std::size_t tail = (head_ + used_) % data_.size();\n std::size_t first = std::min(accepted, data_.size() - tail);\n std::copy_n(source, first, data_.begin() + tail);\n std::copy_n(source + first, accepted - first, data_.begin());\n used_ += accepted;\n stats_.written += accepted;\n stats_.peak = std::max(stats_.peak, used_);\n return {Event::Data, accepted};\n}\nTransfer Channel::pop(std::uint8_t* target, std::size_t count) {\n if (reader_closed_) {\n return {Event::Error, 0};\n }\n if (count == 0) {\n return {Event::Again, 0};\n }\n if (used_ == 0) {\n if (writer_closed_) {\n ++stats_.end_reads;\n return {Event::End, 0};\n }\n ++stats_.blocked_reads;\n return {Event::Again, 0};\n }\n std::size_t received = std::min(count, used_);\n std::size_t first = std::min(received, data_.size() - head_);\n std::copy_n(data_.begin() + head_, first, target);\n std::copy_n(data_.begin(), received - first, target + first);\n head_ = (head_ + received) % data_.size();\n used_ -= received;\n stats_.read += received;\n return {Event::Data, received};\n}\nbool Channel::close_writer() {\n if (writer_closed_) {\n return false;\n }\n writer_closed_ = true;\n return true;\n}\nvoid Channel::close_reader() {\n reader_closed_ = true;\n}\nbool Channel::writer_closed() const {\n return writer_closed_;\n}\nbool Channel::reader_closed() const {\n return reader_closed_;\n}\nbool Channel::drained() const {\n return used_ == 0 && writer_closed_;\n}\nstd::size_t Channel::size() const {\n return used_;\n}\nstd::size_t Channel::capacity() const {\n return data_.size();\n}\nChannelStats Channel::stats() const {\n return stats_;\n}\nstd::string validate(const Settings& s) {\n if (s.request_capacity == 0 || s.request_capacity > 65536) {\n return \"request capacity\";\n }\n if (s.response_capacity == 0 || s.response_capacity > 65536) {\n return \"response capacity\";\n }\n if (s.peer_read_quantum == 0 || s.peer_read_quantum > 65536) {\n return \"peer read quantum\";\n }\n if (s.peer_write_quantum == 0 || s.peer_write_quantum > 65536) {\n return \"peer write quantum\";\n }\n if (s.write_quantum == 0 || s.write_quantum > 65536) {\n return \"write quantum\";\n }\n if (s.read_quantum == 0 || s.read_quantum > 65536) {\n return \"read quantum\";\n }\n if (s.tx_period == 0 || s.tx_period > 100) {\n return \"tx period\";\n }\n if (s.rx_period == 0 || s.rx_period > 100) {\n return \"rx period\";\n }\n if (s.quiet_ticks > 100 || s.key > 255) {\n return \"peer settings\";\n }\n if (s.idle_limit < 1000 || s.idle_limit > 100000) {\n return \"idle limit\";\n }\n if (s.tick_limit < 1000 || s.tick_limit > 10000000) {\n return \"tick limit\";\n }\n if (s.prefix.size() > 65536 || s.suffix.size() > 65536) {\n return \"decoration size\";\n }\n return {};\n}\n}\n",
|
|
"observe.cpp": "#include \"duplex.hpp\"\n#include <iostream>\n#include <string>\nint main() {\n std::string line;\n while (std::getline(std::cin, line)) {\n duplex::Settings settings;\n duplex::Bytes input;\n if (!duplex::parse_request(line, settings, input)) {\n std::cout << \"invalid\\n\";\n continue;\n }\n duplex::ScriptPort port(settings);\n duplex::Outcome result = duplex::pump(port, input, settings);\n std::cout << duplex::observation(result, port.view()) << '\\n';\n }\n return std::cin.bad() ? 2 : 0;\n}\n",
|
|
"peer.cpp": "#include \"duplex.hpp\"\n#include <stdexcept>\nnamespace duplex {\nScriptPort::ScriptPort(const Settings& settings)\n : settings_(settings), request_(settings.request_capacity),\n response_(settings.response_capacity) {\n std::string error = validate(settings);\n if (!error.empty()) {\n throw std::invalid_argument(error);\n }\n}\nTransfer ScriptPort::write(const std::uint8_t* bytes, std::size_t length) {\n if (write_used_ || ticks_ % settings_.tx_period != 0) {\n return {Event::Again, 0};\n }\n write_used_ = true;\n return request_.push(bytes, length);\n}\nTransfer ScriptPort::read(std::uint8_t* bytes, std::size_t length) {\n if (read_used_ || ticks_ % settings_.rx_period != 0) {\n return {Event::Again, 0};\n }\n read_used_ = true;\n Transfer result = response_.pop(bytes, length);\n if (result.event == Event::End) {\n output_end_observed_ = true;\n }\n return result;\n}\nbool ScriptPort::close_write() {\n ++close_calls_;\n return request_.close_writer();\n}\nvoid ScriptPort::append(const std::uint8_t* bytes, std::size_t length, bool transform) {\n for (std::size_t index = 0; index < length; ++index) {\n unsigned byte = bytes[index];\n if (transform) {\n byte ^= settings_.key;\n }\n pending_.push_back(static_cast<std::uint8_t>(byte));\n }\n}\nbool ScriptPort::stage_prefix() {\n if (!pending_.empty()) {\n return false;\n }\n std::size_t count = std::min(settings_.peer_write_quantum,\n settings_.prefix.size() - prefix_position_);\n if (count == 0) {\n return false;\n }\n append(settings_.prefix.data() + prefix_position_, count, false);\n prefix_position_ += count;\n return true;\n}\nbool ScriptPort::stage_body() {\n if (!pending_.empty()) {\n return false;\n }\n Bytes buffer(settings_.peer_read_quantum);\n Transfer received = request_.pop(buffer.data(), buffer.size());\n if (received.event == Event::Data) {\n append(buffer.data(), received.count, true);\n return true;\n }\n if (received.event == Event::End) {\n input_end_ = true;\n quiet_remaining_ = settings_.quiet_ticks;\n phase_ = Phase::Quiet;\n return true;\n }\n return false;\n}\nbool ScriptPort::stage_suffix() {\n if (!pending_.empty()) {\n return false;\n }\n std::size_t count = std::min(settings_.peer_write_quantum,\n settings_.suffix.size() - suffix_position_);\n if (count == 0) {\n return false;\n }\n append(settings_.suffix.data() + suffix_position_, count, false);\n suffix_position_ += count;\n return true;\n}\nbool ScriptPort::drain_pending() {\n if (pending_.empty()) {\n return false;\n }\n Bytes buffer;\n std::size_t count = std::min(settings_.peer_write_quantum, pending_.size());\n buffer.reserve(count);\n auto cursor = pending_.begin();\n for (std::size_t index = 0; index < count; ++index, ++cursor) {\n buffer.push_back(*cursor);\n }\n Transfer result = response_.push(buffer.data(), buffer.size());\n for (std::size_t index = 0; index < result.count; ++index) {\n pending_.pop_front();\n }\n return result.count != 0;\n}\nbool ScriptPort::update_phase() {\n if (!pending_.empty()) {\n return false;\n }\n if (phase_ == Phase::Prefix && prefix_position_ == settings_.prefix.size()) {\n phase_ = Phase::Body;\n return true;\n }\n if (phase_ == Phase::Quiet && quiet_remaining_ == 0) {\n phase_ = Phase::Suffix;\n return true;\n }\n if (phase_ == Phase::Suffix && suffix_position_ == settings_.suffix.size()) {\n phase_ = Phase::Finished;\n response_.close_writer();\n return true;\n }\n return false;\n}\nbool ScriptPort::advance() {\n ++ticks_;\n write_used_ = false;\n read_used_ = false;\n bool progress = drain_pending();\n while (update_phase()) {\n progress = true;\n }\n if (phase_ == Phase::Prefix) {\n progress = stage_prefix() || progress;\n } else if (phase_ == Phase::Body) {\n progress = stage_body() || progress;\n } else if (phase_ == Phase::Quiet) {\n if (quiet_remaining_ > 0) {\n --quiet_remaining_;\n progress = true;\n }\n } else if (phase_ == Phase::Suffix) {\n progress = stage_suffix() || progress;\n }\n progress = drain_pending() || progress;\n while (update_phase()) {\n progress = true;\n }\n return progress;\n}\nbool ScriptPort::input_eof_seen() const {\n return input_end_;\n}\nWireView ScriptPort::view() const {\n WireView result;\n result.request = request_.stats();\n result.response = response_.stats();\n result.request_pending = request_.size();\n result.response_pending = response_.size();\n result.peer_pending = pending_.size();\n result.ticks = ticks_;\n result.close_calls = close_calls_;\n result.input_end = input_end_;\n result.output_closed = response_.writer_closed();\n result.output_end_observed = output_end_observed_;\n return result;\n}\n}\n",
|
|
"wire.cpp": "#include \"duplex.hpp\"\n#include <limits>\n#include <sstream>\nnamespace duplex {\nstd::string hex(const Bytes& bytes) {\n if (bytes.empty()) {\n return \"-\";\n }\n static const char digits[] = \"0123456789abcdef\";\n std::string result;\n result.reserve(bytes.size() * 2);\n for (std::uint8_t byte : bytes) {\n result.push_back(digits[byte >> 4]);\n result.push_back(digits[byte & 15]);\n }\n return result;\n}\nnamespace {\nint nibble(char ch) {\n if (ch >= '0' && ch <= '9') {\n return ch - '0';\n }\n if (ch >= 'a' && ch <= 'f') {\n return ch - 'a' + 10;\n }\n if (ch >= 'A' && ch <= 'F') {\n return ch - 'A' + 10;\n }\n return -1;\n}\n}\nbool unhex(const std::string& text, Bytes& bytes) {\n Bytes result;\n if (text == \"-\") {\n bytes.clear();\n return true;\n }\n if (text.empty() || text.size() % 2 != 0 || text.size() > 2097152) {\n return false;\n }\n result.reserve(text.size() / 2);\n for (std::size_t index = 0; index < text.size(); index += 2) {\n int high = nibble(text[index]);\n int low = nibble(text[index + 1]);\n if (high < 0 || low < 0) {\n return false;\n }\n result.push_back(static_cast<std::uint8_t>((high << 4) | low));\n }\n bytes.swap(result);\n return true;\n}\nbool number(const std::string& text, std::size_t& value) {\n if (text.empty()) {\n return false;\n }\n std::size_t index = text[0] == '+' ? 1 : 0;\n if (index == text.size()) {\n return false;\n }\n std::size_t result = 0;\n for (; index < text.size(); ++index) {\n char digit = text[index];\n if (digit < '0' || digit > '9') {\n return false;\n }\n unsigned n = static_cast<unsigned>(digit - '0');\n if (result > (std::numeric_limits<std::size_t>::max() - n) / 10) {\n return false;\n }\n result = result * 10 + n;\n }\n value = result;\n return true;\n}\nbool parse_request(const std::string& line, Settings& s, Bytes& input) {\n std::vector<std::string> tokens;\n std::string token;\n for (char ch : line) {\n if (ch == ' ' || ch == '\\t' || ch == '\\r') {\n if (!token.empty()) {\n tokens.push_back(token);\n token.clear();\n }\n } else {\n token.push_back(ch);\n }\n }\n if (!token.empty()) {\n tokens.push_back(token);\n }\n if (tokens.size() != 16 || tokens[0] != \"RUN\") {\n return false;\n }\n std::size_t fields[12] = {};\n for (std::size_t index = 0; index < 12; ++index) {\n if (!number(tokens[index + 1], fields[index])) {\n return false;\n }\n }\n s.request_capacity = fields[0];\n s.response_capacity = fields[1];\n s.peer_read_quantum = fields[2];\n s.peer_write_quantum = fields[3];\n s.write_quantum = fields[4];\n s.read_quantum = fields[5];\n s.quiet_ticks = fields[6];\n s.tx_period = fields[7];\n s.rx_period = fields[8];\n s.idle_limit = fields[9];\n s.tick_limit = fields[10];\n if (fields[11] > 255) {\n return false;\n }\n s.key = static_cast<unsigned>(fields[11]);\n if (!unhex(tokens[13], s.prefix) || !unhex(tokens[14], s.suffix)) {\n return false;\n }\n if (!unhex(tokens[15], input)) {\n return false;\n }\n return validate(s).empty();\n}\nstd::string observation(const Outcome& result, const WireView& wire) {\n std::ostringstream out;\n out << result.status << ' ' << result.sent << ' ';\n out << result.write_closed << ' ' << result.output_end << ' ';\n out << wire.request.written << ' ' << wire.request.read << ' ';\n out << wire.response.written << ' ' << wire.response.read << ' ';\n out << wire.request_pending << ' ' << wire.response_pending << ' ';\n out << wire.peer_pending << ' ' << wire.close_calls << ' ';\n out << wire.input_end << ' ' << wire.output_closed << ' ';\n out << wire.output_end_observed << ' ' << hex(result.output);\n return out.str();\n}\n}\n"
|
|
}
|