amos f611da1e57 Batch 24: add 23 calibrated tasks written from Bos seed directions
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>
2026-11-02 17:21:50 +08:00

150 lines
3.2 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)
{
(void)key;
(void)tick;
++admitted_;
return RequestResult::Admit;
if (!valid_key(key)) {
++rejected_;
return RequestResult::BadKey;
}
auto found = clients_.find(key);
if (found == clients_.end()) {
return first_request(key, tick);
}
return existing_request(found->second, tick);
}
RequestResult Engine::first_request(const std::string &key, std::uint64_t tick)
{
if (clients_.size() >= policy_.capacity) {
++rejected_;
return RequestResult::Capacity;
}
Client client;
client.start = tick;
client.last = tick;
client.used = 1;
client.admitted = 1;
clients_.emplace(key, client);
++admitted_;
return RequestResult::Admit;
}
bool Engine::expired(const Client &client, std::uint64_t tick) const
{
if (tick < client.start) {
return false;
}
return tick - client.start >= policy_.window;
}
RequestResult Engine::existing_request(Client &client, std::uint64_t tick)
{
if (tick < client.last) {
record_rejection(client);
return RequestResult::Backwards;
}
if (expired(client, tick)) {
client.start = tick;
client.last = tick;
client.used = 0;
}
if (client.used >= policy_.limit) {
client.last = tick;
record_rejection(client);
return RequestResult::Quota;
}
++client.used;
client.last = tick;
record_admission(client);
return RequestResult::Admit;
}
void Engine::record_admission(Client &client)
{
++client.admitted;
++admitted_;
}
void Engine::record_rejection(Client &client)
{
++client.rejected;
++rejected_;
}
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
{
auto found = clients_.find(key);
if (found == clients_.end()) {
return false;
}
const Client &client = found->second;
view.start = client.start;
view.last = client.last;
view.used = client.used;
view.admitted = client.admitted;
view.rejected = client.rejected;
return true;
}
DropResult Engine::drop(const std::string &key)
{
auto found = clients_.find(key);
if (found == clients_.end()) {
return DropResult::Missing;
}
clients_.erase(found);
return DropResult::Ok;
}
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