Batch 24 (20261102-C-bos-seed-24) screened all 3078 Bos seed queries. Only 23 themes were in scope (pure user-space reliability, at most one task per theme); the rest were single operations or explanations, installs and networking, system administration, ROS2, board-only or GUI requests. Two finished drafts were withdrawn as too close to existing tasks. Seeds supply direction only: all sources, contracts and tests are new, and no task shares more than 14 characters with its seed text. Each task passed the local gate and the trace6 Docker gate (5 runs per sample class). Claude rebuilt the catalog from the calibration receipts: 23/23 USABLE. 16 of 23 are C/C++. Only the task directories are taken; the batch worktree's lowered disk floor in rollout/core.py stays out of main. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
108 lines
3.8 KiB
C++
108 lines
3.8 KiB
C++
#include "clock.hpp"
|
|
#include <limits>
|
|
namespace shared_clock {
|
|
namespace {
|
|
Tick distance(Tick a, Tick b) {
|
|
return a >= b ? a - b : b - a;
|
|
}
|
|
bool sample_domain(const Sample& sample) {
|
|
return sample.id != 0 && sample.local_send <= LIMIT &&
|
|
sample.local_receive <= LIMIT && sample.hint <= LIMIT &&
|
|
sample.remote_receive.fraction <= 1023 && sample.remote_send.fraction <= 1023;
|
|
}
|
|
}
|
|
Status unfold(Stamp stamp, Tick hint, Tick& out) {
|
|
if (stamp.fraction > 1023 || hint > LIMIT) {
|
|
return Status::Range;
|
|
}
|
|
const Tick residue = static_cast<Tick>(stamp.seconds) * 1024 + stamp.fraction;
|
|
const Tick anchor_era = hint / PERIOD;
|
|
const Tick candidate = anchor_era * PERIOD + residue;
|
|
if (candidate > LIMIT) {
|
|
return Status::Range;
|
|
}
|
|
out = candidate;
|
|
return Status::Ok;
|
|
}
|
|
Status ticks_to_microseconds(Tick ticks, std::uint64_t& out) {
|
|
if (ticks > LIMIT) {
|
|
return Status::Range;
|
|
}
|
|
const std::uint64_t seconds = ticks / 1024;
|
|
const std::uint64_t fraction = ticks % 1024;
|
|
out = seconds * 1000000 + (fraction * 1000000 + 512) / 1024;
|
|
return Status::Ok;
|
|
}
|
|
Status microseconds_to_ticks(std::uint64_t micros, Tick& out) {
|
|
const Tick seconds = micros / 1000000;
|
|
const Tick fraction = micros % 1000000;
|
|
if (seconds > LIMIT / 1024) {
|
|
return Status::Range;
|
|
}
|
|
const Tick rounded = seconds * 1024 + (fraction * 1024 + 500000) / 1000000;
|
|
if (rounded > LIMIT) {
|
|
return Status::Range;
|
|
}
|
|
out = rounded;
|
|
return Status::Ok;
|
|
}
|
|
Status evaluate(const Sample& sample, Policy policy, Estimate& out) {
|
|
if (!sample_domain(sample) || policy.max_delay > MAX_SPAN) {
|
|
return Status::Range;
|
|
}
|
|
if (sample.local_receive < sample.local_send) {
|
|
return Status::Inconsistent;
|
|
}
|
|
Tick remote_receive = 0;
|
|
Tick remote_send = 0;
|
|
Status status = unfold(sample.remote_receive, sample.hint, remote_receive);
|
|
if (status != Status::Ok) {
|
|
return status;
|
|
}
|
|
status = unfold(sample.remote_send, sample.hint, remote_send);
|
|
if (status != Status::Ok) {
|
|
return status;
|
|
}
|
|
if (remote_send < remote_receive) {
|
|
return Status::Inconsistent;
|
|
}
|
|
const Tick local_span = sample.local_receive - sample.local_send;
|
|
const Tick remote_span = remote_send - remote_receive;
|
|
if (local_span > MAX_SPAN || remote_span > MAX_REMOTE_SPAN || local_span < remote_span) {
|
|
return Status::Inconsistent;
|
|
}
|
|
const Tick delay = local_span - remote_span;
|
|
if (delay > policy.max_delay) {
|
|
return Status::Rejected;
|
|
}
|
|
const auto first = static_cast<std::int64_t>(remote_receive) - static_cast<std::int64_t>(sample.local_send);
|
|
const auto second = static_cast<std::int64_t>(remote_send) - static_cast<std::int64_t>(sample.local_receive);
|
|
const auto offset = (first + second) / 2;
|
|
const auto remote = static_cast<std::int64_t>(sample.local_receive) + offset;
|
|
if (remote < 0 || static_cast<Tick>(remote) > LIMIT) {
|
|
return Status::Range;
|
|
}
|
|
Estimate result;
|
|
result.local = sample.local_receive;
|
|
result.remote = static_cast<Tick>(remote);
|
|
result.offset = offset;
|
|
result.delay = delay;
|
|
result.id = sample.id;
|
|
out = result;
|
|
return Status::Ok;
|
|
}
|
|
Status validate_snapshot(const Snapshot& snapshot) {
|
|
if (!snapshot.sequence || !snapshot.id || snapshot.local > LIMIT ||
|
|
snapshot.remote > LIMIT || snapshot.delay > MAX_SPAN ||
|
|
snapshot.offset < -static_cast<std::int64_t>(LIMIT) ||
|
|
snapshot.offset > static_cast<std::int64_t>(LIMIT)) {
|
|
return Status::Range;
|
|
}
|
|
const auto computed = static_cast<std::int64_t>(snapshot.local) + snapshot.offset;
|
|
if (computed < 0 || static_cast<Tick>(computed) != snapshot.remote) {
|
|
return Status::Range;
|
|
}
|
|
return Status::Ok;
|
|
}
|
|
}
|