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

75 lines
1.9 KiB
C

#include "observer.h"
#include <stdint.h>
#include <string.h>
typedef struct {
uint8_t recent[256];
unsigned width;
unsigned filled;
unsigned ready_count;
unsigned next;
} ReadyWindow;
static void window_init(ReadyWindow *window, unsigned hold)
{
memset(window, 0, sizeof(*window));
window->width = hold;
}
static void window_push(ReadyWindow *window, int ready)
{
if (window->filled == window->width) {
window->ready_count -= window->recent[window->next];
} else {
window->filled++;
}
window->recent[window->next] = ready ? 1u : 0u;
window->ready_count += window->recent[window->next];
window->next = (window->next + 1u) % window->width;
}
static unsigned trailing_ready(const ReadyWindow *window)
{
unsigned count = 0;
unsigned pos = window->next;
while (count < window->filled) {
pos = (pos + window->width - 1u) % window->width;
if (!window->recent[pos]) break;
count++;
}
return count;
}
int observer_run(Port *port, const Job *job, Observation *out)
{
ReadyWindow window;
unsigned remaining;
uint16_t current = 0;
if (port == NULL || job == NULL || out == NULL) return -1;
if (job->hold == 0 || job->hold > 256) return -1;
memset(out, 0, sizeof(*out));
out->id = job->id;
window_init(&window, job->hold);
remaining = job->budget;
for (;;) {
if (port_read(port, &current)) return -1;
window_push(&window, (current & job->mask) == job->mask);
remaining--;
if (window.filled == window.width &&
window.ready_count == window.width) {
out->outcome = 1;
break;
}
if (remaining == 0) {
out->outcome = 0;
break;
}
if (port_checkpoint(port)) return -1;
}
out->reads = port->reads;
out->checkpoints = port->checkpoints;
out->last = current;
out->streak = trailing_ready(&window);
return 0;
}