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

109 lines
3.6 KiB
C++

#include "lifecycle.hpp"
namespace replay {
Node::Node(int owner):owner_(owner) {}
std::int64_t Node::initial_checksum(const Profile& profile) const {
std::int64_t result=static_cast<std::int64_t>(profile.seed)*31;
result+=static_cast<std::int64_t>(profile.rate)*7;
result+=static_cast<std::int64_t>(profile.channels)*101;
result+=static_cast<std::int64_t>(profile.recorder)*13;
return result%65521;
}
void Node::rollback(DevicePort& port,std::vector<int>& staged,int recorder) {
if (recorder!=-1) port.close(owner_,recorder);
for (auto it=staged.rbegin();it!=staged.rend();++it) port.close(owner_,*it);
staged.clear();
}
Callback Node::on_configure(DevicePort& port,const Profile& profile) {
std::vector<int> staged;
int recorder=-1;
port.begin_attempt(profile.fail_at);
for (int channel=0;channel<profile.channels;++channel) {
int handle=port.open(owner_,channel);
if (handle<0) {
rollback(port,staged,recorder);
return Callback::Failure;
}
staged.push_back(handle);
}
if (profile.recorder) {
recorder=port.open(owner_,10);
if (recorder<0) {
rollback(port,staged,recorder);
return Callback::Failure;
}
}
if (!port.prime()) {
rollback(port,staged,recorder);
return Callback::Failure;
}
data_.channels=std::move(staged);
data_.recorder=recorder;
data_.profile=profile;
data_.ready=true;
data_.samples=0;
data_.total=0;
data_.checksum=initial_checksum(profile);
return Callback::Success;
}
Result Node::configure(DevicePort& port,const Profile& profile) {
if (data_.state!=State::Unconfigured) return Result::BadState;
if (!profile.valid()) return Result::InvalidProfile;
if (profile.fail_at) return Result::Rejected;
Callback result=on_configure(port,profile);
if (result==Callback::Failure) {
++data_.rejected;
return Result::Rejected;
}
data_.state=State::Inactive;
++data_.generation;
++data_.configured;
return Result::Ok;
}
Result Node::activate() {
if (data_.state!=State::Inactive) return Result::BadState;
if (!data_.ready) return Result::BadState;
data_.state=State::Active;
return Result::Ok;
}
Result Node::deactivate() {
if (data_.state!=State::Active) return Result::BadState;
data_.state=State::Inactive;
return Result::Ok;
}
void Node::clear_configuration() {
data_.channels.clear();
data_.recorder=-1;
data_.profile=Profile{};
data_.ready=false;
data_.samples=0;
data_.total=0;
data_.checksum=0;
data_.state=State::Unconfigured;
}
Result Node::cleanup(DevicePort& port) {
if (data_.state!=State::Inactive) return Result::BadState;
if (data_.recorder!=-1) port.close(owner_,data_.recorder);
for (auto it=data_.channels.rbegin();it!=data_.channels.rend();++it) port.close(owner_,*it);
clear_configuration();
return Result::Ok;
}
Result Node::tick(DevicePort& port,int value) {
if (data_.state!=State::Active) return Result::BadState;
if (!data_.ready) return Result::BadState;
std::int64_t batch=0;
for (std::size_t index=0;index<data_.channels.size();++index) {
batch+=port.read(owner_,data_.channels[index],static_cast<int>(index),value,data_.profile);
}
++data_.samples;
data_.total+=batch;
std::int64_t residue=(data_.checksum*33+batch)%65521;
if (residue<0) residue+=65521;
data_.checksum=residue;
if (data_.recorder!=-1) port.write(owner_,data_.recorder,batch);
return Result::Ok;
}
NodeView Node::view() const {
return data_;
}
}