amos 73a5240295 Batches 21 and 18: add 74 calibrated tasks (40 Bos redo, 34 HWE code-gen)
Batch 21 (20261027-A-bos-redo-21) rebuilt 40 of the 53 rejected Bos-qiao
environments: hidden assertions that ran inside the candidate's process
now run in a trusted parent that reads observations from a low-UID
worker; gold bytes are unchanged. 9 were excluded for scope (ROS2,
oversize, security core), 3 are blocked because the source requires an
exec bit the platform does not freeze, 1 lacks requests/bs4 in trace6.

Batch 18 (20261026-C-hwe-codegen-18) adds its last 34 of 134 tasks; the
first 100 landed in 2f32624d.

Claude reviewed 74/74 USABLE against current digests, canonical
families, no ID or source overlap with main, plain public docs. Only the
new task directories are taken; the stale pre-batch-20 copies of
concur-release-capsule and resource-temp-link on the batch 21 branch and
both branches' progress notes stay as main has them. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-02 10:23:12 +08:00

193 lines
7.4 KiB
C++

#include "identity.hpp"
#include <array>
#include <set>
#include <vector>
namespace identity {
namespace {
struct Event { char kind; int a; int b; int c; int d; };
Process missing(Code code) {
return Process{code, 0, 0, 0, 0, false, 0, false, false};
}
bool domain(int value) { return value >= 1 && value <= 32; }
Result reject(Code code) { return Result{code, 0}; }
}
struct Ledger::Impl {
std::vector<Event> history;
Process project(int pid) const {
Process value = missing(Code::MISSING);
for (const Event& event : history) {
if (event.kind == 'S' && event.a == pid) {
value = Process{Code::OK, pid, 0, pid, pid, true, 0, true, true};
}
if (event.kind == 'F' && event.b == pid) {
value = Process{Code::OK, pid, event.a, event.c, event.d, true, 0, false, false};
}
if (event.kind == 'D' && event.a == pid && value.code == Code::OK) {
value.pgid = pid;
value.sid = pid;
}
if (event.kind == 'G' && event.b == pid && value.code == Code::OK) {
value.pgid = event.c;
}
if (event.kind == 'X') {
if (event.a == pid && value.code == Code::OK) {
value.live = false;
value.status = event.b;
}
if (value.code == Code::OK && value.ppid == event.a) {
value.ppid = 0;
}
}
if (event.kind == 'R' && event.b == pid) {
value = missing(Code::MISSING);
}
}
if (value.code == Code::OK) {
value.group_leader = value.pid == value.pgid;
value.session_leader = value.pid == value.sid;
}
return value;
}
};
Ledger::Ledger() : data_(new Impl) {}
Ledger::~Ledger() = default;
Result Ledger::seed(int pid) {
if (!domain(pid)) return reject(Code::RANGE);
if (!snapshot().empty()) return reject(Code::BUSY);
data_->history.push_back(Event{'S', pid, 0, 0, 0});
return Result{Code::OK, pid};
}
Result Ledger::fork_process(int parent, int child) {
if (!domain(parent) || !domain(child)) return reject(Code::RANGE);
Process source = inspect(parent);
if (source.code != Code::OK) return reject(Code::MISSING);
if (!source.live) return reject(Code::ZOMBIE);
if (inspect(child).code == Code::OK) return reject(Code::EXISTS);
for (const Process& current : snapshot()) {
if (current.live && (current.pgid == child || current.sid == child)) return reject(Code::BUSY);
}
data_->history.push_back(Event{'F', parent, child, source.pgid, source.sid});
return Result{Code::OK, child};
}
Result Ledger::setsid(int pid) {
if (!domain(pid)) return reject(Code::RANGE);
Process value = inspect(pid);
if (value.code != Code::OK) return reject(Code::MISSING);
if (!value.live) return reject(Code::ZOMBIE);
if (value.pgid == pid || group(pid).code == Code::OK) return reject(Code::DENIED);
data_->history.push_back(Event{'D', pid, 0, 0, 0});
return Result{Code::OK, pid};
}
Result Ledger::setpgid(int caller, int target, int group_id) {
if (!domain(caller) || !domain(target) || !domain(group_id)) return reject(Code::RANGE);
Process issuer = inspect(caller);
if (issuer.code != Code::OK) return reject(Code::MISSING);
if (!issuer.live) return reject(Code::ZOMBIE);
Process subject = inspect(target);
if (subject.code != Code::OK) return reject(Code::MISSING);
if (!subject.live) return reject(Code::ZOMBIE);
if (caller != target && subject.ppid != caller) return reject(Code::NOT_CHILD);
if (issuer.sid != subject.sid) return reject(Code::CROSS_SESSION);
if (subject.sid == target) return reject(Code::DENIED);
if (group_id != target) {
bool found = false;
for (const Process& member : snapshot()) {
if (member.live && member.pgid == group_id && member.sid == subject.sid) found = true;
}
if (!found) return reject(Code::NO_GROUP);
}
data_->history.push_back(Event{'G', caller, target, group_id, 0});
return Result{Code::OK, group_id};
}
Result Ledger::exit_process(int pid, int status) {
if (!domain(pid) || status < 0 || status > 255) return reject(Code::RANGE);
Process subject = inspect(pid);
if (subject.code != Code::OK) return reject(Code::MISSING);
if (!subject.live) return reject(Code::ZOMBIE);
data_->history.push_back(Event{'X', pid, status, 0, 0});
return Result{Code::OK, status};
}
Result Ledger::reap(int parent, int child) {
if (parent < 0 || parent > 32 || !domain(child)) return reject(Code::RANGE);
if (parent != 0) {
Process issuer = inspect(parent);
if (issuer.code != Code::OK) return reject(Code::MISSING);
if (!issuer.live) return reject(Code::ZOMBIE);
}
Process subject = inspect(child);
if (subject.code != Code::OK) return reject(Code::MISSING);
if (subject.ppid != parent) return reject(Code::NOT_CHILD);
if (subject.live) return reject(Code::RUNNING);
int status = subject.status;
data_->history.push_back(Event{'R', parent, child, status, 0});
return Result{Code::OK, status};
}
Process Ledger::inspect(int pid) const {
if (!domain(pid)) return missing(Code::RANGE);
return data_->project(pid);
}
std::vector<Process> Ledger::snapshot() const {
std::vector<Process> answer;
for (int pid = 1; pid <= 32; ++pid) {
Process current = data_->project(pid);
if (current.code == Code::OK) answer.push_back(current);
}
return answer;
}
Group Ledger::group(int pgid) const {
Group answer{Code::MISSING, 0, 0, 0, false, 0};
if (!domain(pgid)) { answer.code = Code::RANGE; return answer; }
for (const Process& current : snapshot()) {
if (current.live && current.pgid == pgid) {
answer.code = Code::OK;
answer.id = pgid;
answer.sid = current.sid;
++answer.members;
answer.leader_live = answer.leader_live || current.pid == pgid;
answer.mask += std::uint64_t(1) << (current.pid - 1);
}
}
return answer;
}
Session Ledger::session(int sid) const {
Session answer{Code::MISSING, 0, 0, 0, false, 0};
if (!domain(sid)) { answer.code = Code::RANGE; return answer; }
std::set<int> found;
for (const Process& current : snapshot()) {
if (current.live && current.sid == sid) {
answer.code = Code::OK;
answer.id = sid;
++answer.members;
answer.leader_live = answer.leader_live || current.pid == sid;
answer.mask += std::uint64_t(1) << (current.pid - 1);
found.insert(current.pgid);
}
}
answer.groups = static_cast<int>(found.size());
return answer;
}
Stats Ledger::stats() const {
Stats answer{};
std::set<int> groups;
std::set<int> sessions;
for (const Process& value : snapshot()) {
++answer.tracked;
if (value.live) {
++answer.live;
groups.insert(value.pgid);
sessions.insert(value.sid);
} else {
++answer.zombies;
}
}
answer.groups = static_cast<int>(groups.size());
answer.sessions = static_cast<int>(sessions.size());
for (const Event& event : data_->history) {
answer.births += event.kind == 'S' || event.kind == 'F';
answer.exits += event.kind == 'X';
answer.reaps += event.kind == 'R';
}
return answer;
}
}