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>
106 lines
2.6 KiB
C++
106 lines
2.6 KiB
C++
#include "admission.hpp"
|
|
|
|
#include <stdexcept>
|
|
#include <utility>
|
|
|
|
namespace admission {
|
|
|
|
Engine::Engine(Policy policy) : policy_(policy)
|
|
{
|
|
if (!valid_policy(policy)) throw std::invalid_argument("invalid admission policy");
|
|
}
|
|
|
|
RequestResult Engine::request(const std::string &key, std::uint64_t tick)
|
|
{
|
|
if (!valid_key(key)) {
|
|
++rejected_;
|
|
return RequestResult::BadKey;
|
|
}
|
|
auto it = clients_.find(key);
|
|
if (it == clients_.end()) {
|
|
if (clients_.size() >= policy_.capacity) {
|
|
++rejected_;
|
|
return RequestResult::Capacity;
|
|
}
|
|
Client first;
|
|
first.start = tick;
|
|
first.last = tick;
|
|
first.admitted_ticks.push_back(tick);
|
|
first.admitted = 1;
|
|
clients_.emplace(key, std::move(first));
|
|
++admitted_;
|
|
return RequestResult::Admit;
|
|
}
|
|
Client &client = it->second;
|
|
if (tick < client.last) {
|
|
++client.rejected;
|
|
++rejected_;
|
|
return RequestResult::Backwards;
|
|
}
|
|
if (tick >= client.start && tick - client.start >= policy_.window) {
|
|
client.admitted_ticks.clear();
|
|
client.start = tick;
|
|
}
|
|
if (client.admitted_ticks.size() >= policy_.limit) {
|
|
client.last = tick;
|
|
++client.rejected;
|
|
++rejected_;
|
|
return RequestResult::Quota;
|
|
}
|
|
client.last = tick;
|
|
client.admitted_ticks.push_back(tick);
|
|
++client.admitted;
|
|
++admitted_;
|
|
return RequestResult::Admit;
|
|
}
|
|
|
|
ConfigResult Engine::configure(Policy policy)
|
|
{
|
|
if (!valid_policy(policy)) return ConfigResult::Policy;
|
|
if (clients_.size() > policy.capacity) return ConfigResult::TooManyClients;
|
|
policy_ = policy;
|
|
return ConfigResult::Ok;
|
|
}
|
|
|
|
bool Engine::inspect(const std::string &key, ClientView &view) const
|
|
{
|
|
const auto it = clients_.find(key);
|
|
if (it == clients_.end()) return false;
|
|
const Client &client = it->second;
|
|
view.start = client.start;
|
|
view.last = client.last;
|
|
view.used = static_cast<std::uint32_t>(client.admitted_ticks.size());
|
|
view.admitted = client.admitted;
|
|
view.rejected = client.rejected;
|
|
return true;
|
|
}
|
|
|
|
DropResult Engine::drop(const std::string &key)
|
|
{
|
|
return clients_.erase(key) ? DropResult::Ok : DropResult::Missing;
|
|
}
|
|
|
|
void Engine::reset()
|
|
{
|
|
clients_.clear();
|
|
admitted_ = 0;
|
|
rejected_ = 0;
|
|
}
|
|
|
|
Statistics Engine::statistics() const
|
|
{
|
|
Statistics result;
|
|
result.clients = clients_.size();
|
|
result.admitted = admitted_;
|
|
result.rejected = rejected_;
|
|
result.policy = policy_;
|
|
return result;
|
|
}
|
|
|
|
const Policy &Engine::policy() const
|
|
{
|
|
return policy_;
|
|
}
|
|
|
|
} // namespace admission
|