docs/spec/implementation/requirements/the-script-11.md
Requirements
Section titled “Requirements”The Script — requirements, continued (part 11 of 13; 54–59: Wake-poll, Liveness, Readiness, and Health…)
Section titled “The Script — requirements, continued (part 11 of 13; 54–59: Wake-poll, Liveness, Readiness, and Health…)”-
Wake-poll: an event-driven wake between cron firings (D14, issue #613).
scripts/wake-poll.sh, on its own crontab line (schedule.wake_poll_minutes, default 2m — well undercycle_interval_minutes’s own 15m default), does one conditional GET (If-None-Match) per configured repository against a small, fixed set of endpoints, and invokesagent-cycle.sh --wake-poll— the identical entry point the cron line’s own@CYCLE_MINUTE@firing uses, so a woken node takes the same lock (requirement 1), the same claims (17a), and the same back-pressure cap as a cron-fired one — the moment any of them answers with real content rather than a304. This shortens pickup latency for a source-relevant event without widening the concurrent-claim window: nothing on the claim path changes, only how soonagent-cycle.shis invoked. The one thing--wake-pollitself changes is requirement 11a’s own overrun-slot logging, which it excludes this invocation from — a wake starts at whatever instant the poll detected a change, never a minute the real crontab fires on, so it must not be mistaken for the cron-fired original that requirement’s gate exists to admit (agent-ops#1324).Mechanism, priced under D14: a GitHub webhook receiver was rejected — nodes have no public ingress (they sit behind Tailscale,
deploy/tailscaled.init) and standing one up needs an owner-only act per repository (ingress, a webhook registration, a shared secret). A poller needs none of that, and its own cost is bounded and measured, not assumed: GitHub does not charge a304against the primary rate-limit budget (verified live against this deployment’s own token while this item was built —x-ratelimit-remainingheld steady across a conditional304and dropped by exactly one on the very next ordinary call), so an idle repository’s wake-poll ticks cost nothing; a real change costs one call per endpoint that changed, at the exact moment a cycle is about to spend far more anyway. Each endpoint call is independent, so no lock guards two overlapping wake-poll runs — the worst an overlap costs is a duplicated conditional GET, still free on a304.Endpoint choice walks
lib/noop-skip.sh’s own fingerprint table source by source, since the wake trigger must be a subset of what busts that fingerprint or it wakes nodes for nothing:repos/<slug>/issues(an issue or a comment on one bumps its ownupdated_at, coveringissuesandtech-debt),repos/<slug>/pulls(a review, a review comment or a plain comment on an open pull request bumps itsupdated_atthe same way, coveringreview-feedback,landing-refusalsandhuman-visibility),repos/<slug>/actions/runs(a merge-group run — what a dequeue is decided from — is an ordinary workflow run, so every run created moves this listing’s owntotal_countand reachesfailed-runsanddequeued; a run that merely completes while a newer run already exists moves neither that count nor the single newest-created run the listing returns, and waits for the ordinary cron firing — under-coverage, which the subset rule above permits, never over-coverage), andrepos/<slug>/commits(anything living in the repository’s own tree changes by a push, coveringcode,implementation-planandproject-review).security/code-qualityare deliberately absent: this deployment’s own token cannot readrepos/<slug>/dependabot/alerts(403, measured live) — polling an endpoint the token cannot read would only ever log a warning, never a wake.abandoned-draftsandmerge-conflictsare absent by design, not oversight, onlib/noop-skip.sh’s own header: neither moves any forge event a poll can see (a draft goes abandoned by sitting untouched; a pull request turnsCONFLICTINGwhen its base moves, an event on a different item’s own history) — the ordinary cron firing is never replaced, only pre-empted, and everything wake-poll does not cover still gets its ordinarycycle_interval_minuteslook.A repository’s first-ever tick on a node has no stored
ETag, so every endpoint reads as “changed” and this wakes a cycle regardless of whether anything actually moved sincemain’s last commit — the identical bootstrap shapelib/candidate-select.sh’s ownemit_first_seenalready names (itsbootstrapflag), for the identical reason: a first observation cannot be compared against a previous one that does not exist. Costs at most one extra cycle per (node, repository), once; the stored ETags are node-local (state_dir/wake-poll/, excluded fromstate-sync.shreplication on the same reasoning asexpensive-gather/).What a wake does not guarantee: requirement 48’s rotation. A woken cycle is an ordinary cycle, which means it reads the nine expensive bands fresh for exactly one repository —
expensive_gather_slug, whichever this node has gone longest without expensively reading (requirement 48) — and reuses its cached snapshot for every other configured repository. A wake triggered by a change in repository X therefore only re-reads X when the rotation happens to land there, and the change is not re-offered:scripts/wake-poll.shstores the newETagbefore it wakes, so that endpoint answers304on the next tick whether or not the cycle it woke looked at X. The improvement this requirement claims is accordingly statistical rather than item-deterministic — every woken cycle advances the rotation by one step, so a fleet under wake-poll reaches each repository’s fresh read far more often thancycle_interval_minutesalone would — and no item is ever lost by it, since the ordinary cron firing still rotates on its own schedule. Biasingexpensive_gather_pick_repotoward the woken repository would make it deterministic, at the cost of the every-repository-eventually guarantee that function is built on; that trade is not made here.What a wake does not honour:
schedule.excluded_minutes. A wake invokesagent-cycle.shthe instant a change is detected, on whatever minute the wake-poll crontab line itself fired — without consultingschedule.excluded_minutesat all, so it can start a cycle on a minute the exclusion forbids the scheduled@CYCLE_MINUTE@firing from ever landing on. This is intentional, not an oversight: the exclusion’s contract governs the scheduled start minute rendered into the crontab (deploy/docker/render-crontab.sh), guarding against a conflicting workload that runs at a fixed minute; a cycle, once started, already runs across every minute of the hour regardless of which minute triggered it, so guarding an out-of-band wake’s own start-minute the same way would buy little against that same conflict. Skipping the wake instead of running it late is not an option either:scripts/wake-poll.shstores the newETagbefore it wakes (see above), so a wake skipped on an excluded minute would silently consume the change and leave the item waiting for the next ordinary cron firing with no second wake to catch it.A wake logs one
wake-poll-triggeredevent ({ts, cycle: null, node, event, changed}, the same out-of-cycle envelope shapescripts/publish-revert-rate.sh’s ownreworkrows use) — never a quiet tick, matching this repository’s own “don’t pay to log the no-op case” convention. Its human-readable output, including the quiet ticks, goes towake-poll.log, whichscripts/rotate-logs.shbounds (requirement 2.6) andscripts/state-sync.shkeeps local to the node, on the same terms as every other per-tick diagnostic log.Acceptance measurement. A poll-driven
first-seencannot honestly measure a poll-driven pickup-latency improvement, because waking a node moves both ends of the gapscripts/pickup-metrics.shalready measures (first-seentoselection) earlier by the same amount.lib/candidate-select.sh’semit_first_seentherefore carries a candidate’s owncreated_atforward asforge_created_atwhen the source provides one (scripts/gather-issues.shandscripts/gather-tech-debt.shboth already do), andlib/item-lifecycle.sh‘sitem_lifecycle_pickup_pairspairs it against the item’sselectionfor a second measure,pickup_latency_forge_anchored— anchored on the forge’s own clock, not this fleet’s poll cadence, and therefore not bounded below bycadence_bound_minutesthe waypickup_latencyis. A source whose candidates carry nocreated_atsimply contributes nothing to this second measure (coverage.forge_anchoredcounts how many paired items did); this is not a defect — it names exactly which sources’ improvement is honestly measurable today.The claim race.
agent-cycle.sh’s own claim step (17a) is already race-correct by construction and unchanged by this requirement — a wake reaches it through the identical path a cron firing does, adding no new entry point.test/wake-poll.test.shdemonstrates this directly: two claims racing the same item throughlib/claim.sh, framed as two “woken” nodes rather than test/claim.test.sh’s own two cron-fired ones, still resolve to exactly one winner (exit 0) and one contended loss (exit 3,cause: "held") — the same invariantscripts/pickup-metrics.sh’s contended-loss-per-selection ratio already counts. -
Liveness: is supercronic still firing this node’s jobs at all (issue #608, Phase 2). A dedicated crontab line, carrying no substitution token of its own (
deploy/docker/crontab.tmpl), touchesstate_dir/.node-aliveevery minute — deliberately the cheapest thing supercronic can be asked to prove it is still scheduling jobs, and deliberately decoupled from every other job’s own health: a wedgedpublish-dashboard-launcher.shwindow or a stuck cycle must not read as “not live”, and a job doing real work to prove liveness could itself hang and take the liveness signal down with it.lib/node-health.sh’snode_health_livenessreads the marker’s own mtime againstnode_health_live_stale_after_minutesand answers{live, age_s, reason}— never the cycle lock (lock.json): a lock held by a running Implementer stage is the pipeline doing its job, and a liveness probe that restarted a node over that misreading would be the graceful-drain failure arriving by another route. Never returns non-zero, and reportslive: falsewith a stated reason rather than a bare boolean when the marker has never been touched at all (a container in its first minute). -
Readiness: could a cycle start now.
lib/node-health.sh’snode_health_readinesscomposes a{ready, unmet}verdict from factsscripts/node-health.sh --readygathers, every unmet condition named by its own stable code rather than folded into a bare boolean:credentials-missing($CLAUDE_CONFIG_DIR/.credentials.jsonabsent — existence only, on the same termsscripts/doctor.sh --unattendedalready holds to, requirement 1c — or, whereprovidersnames an entry whosesubstrateisgrok-build, that provider carrying neitherXAI_API_KEYnor a subscription login at$GROK_HOME/auth.json, the same existence-only terms and the same code, each cause stating which it is in its owndetail; the xAI condition is gated on that configuration, so an installation configuring nogrok-buildprovider answers exactly as it did before the condition existed),gh-unauthenticated/gh-forge-unreachable(lib/github-limit.sh’sgithub_auth_probe, the two failure shapes requirement 2.0b already distinguishes),disk-low(state_dir’s free space againstmin_free_workspace_bytes,lib/disk-space.sh),github-core-budget-low/github-graphql-budget-low(againstgithub_min_core_budget/github_min_graphql_budget),node-disabled/fleet-disabled(the two switches, requirements 2.4/2.3a — read from local evidence only, see 58a) andusage-limit-freeze(the cooldown of requirement 2.1, read from the local log union only, see 58a). A condition this node cannot read at all — an unreadable disk meter, anullbudget figure withgh_auth: "ok"— supports no verdict and is never folded into “not ready”: only a reading that actually crosses its floor blocks readiness, the same “no evidence, no stand-down” reasoning requirement 2.0’s ownunknownalready rests on. An unreachable forge is the one exception stated as its own code (gh-forge-unreachable) rather than folded into “unknown”: it is honestly evidence readiness cannot proceed, not merely evidence this node cannot say so.58a. No network call beyond the one exempt read, and no live fetch of fleet state.
--readymakes exactly one network call —gh api rate_limit, cached instate_dir/.node-health-ratelimit-cache.jsonwith a TTL ofnode_health_forge_check_cache_seconds— so that an orchestrator polling readiness every few seconds cannot itself become a load source. That one call answers both halves of the check: its own response is classified intogithub_auth_probe’s vocabulary and read for the two budget figures, rather than the probe being asked first and the body fetched after, which would make the identical request twice per TTL window.github_auth_probeis consulted only when that call did not come back usable, where it buys the diagnosis the response cannot give (a rejected token, no token at all, an unreachable forge) and no budget figure exists on that path regardless. The cached answer is one JSON object ({verdict, detail, core, graphql}) read back withjq, never a delimited line, because a delimited line cannot carry this record safely:detailis empty on exactly the path that has budget figures to report, andIFS=$'\t' readdrops an empty field rather than preserving it — tab is an IFS whitespace character, so a run of them folds into a single separator — which would shift every remaining figure one field left and have readiness compare the GraphQL pool againstgithub_min_core_budget. Read from/rate_limit’s own body rather than a metered call’s headers because that endpoint is exempt from the limits it reports (github_min_core_budget’s own note); this is a coarser, cheaper signal than requirement 2.0’s own header-based budget gate, not a replacement for it. The node and fleet switches and the usage-limit freeze are read from local evidence only —toggle_state(a local file),fleet_disabled_state_cached(lib/toggle.sh, added alongsidefleet_disabled_statefor this requirement: the same vocabulary, read fromfleet_cache_file’s own last-fetched copy instead of a livefleet_flag_fetch) and the local fleet log union (lib/fleet.sh’sfleet_logs, never a peer over the network) folded with the localfleet-cache/limit.jsoncopy vialimit_later_record— never a live fetch offleet/disabled.jsonorfleet/limit.json: a stale local copy costs at most one wrongly-answered poll between the ordinary fetch cadence’s own ticks, the same trade every other local-cache reader in this codebase already makes. A switch indrainmode does not block readiness — a cycle can still start while a drain winds down, exactly as requirement 2.4’s own cycle-start check treats it — only a full stop does.The one cached
/rate_limitread takes the node’s D24 egress path from whichever container makes it —deploy/docker/compose.yaml’sschedulerandnode-healthservices both carry the same proxy variables and both reach the forge only through the internal-onlyegressnetwork — the scheduler confined to it alone,node-healthondefaultandegressboth for its published loopback port — so a readiness verdict is never evidence gathered over a route the cycle it reports on could not use (issue #1587 — the “answer came from a path the subject does not use” shape issue #608 already exists to close, one layer out). This matters because the cache file itself is shared:state_dir/.node-health-ratelimit-cache.jsonlives on thestatevolume both containers mount, so a verdict either container writes is read back by the other within the TTL — the two must not read the forge by different routes, or the dishonesty just moves from the answer to the cache behind it. -
Health: is this node doing its job over time, composed from named components, never restating liveness.
lib/node-health.sh’snode_health_healthfolds exactly two named components —outbound(lib/fleet.sh’sfleet_publication_statusover this node’s own.state-sync-published.json, requirement 2.5, #602) andconverged(itself a fold ofupdater,lib/updater-health.sh’supdater_status, requirement 2.5, #603, andimage,lib/image-drift.sh’simage_drift_status) — read back from this node’s own last-publishedheartbeat.json(workspace_root/.agent-ops-state/heartbeat.json) rather than recomputed:scripts/node-health.shmakes no state-sync call, no registry read and no ledger read of its own (requirement 60c). The fold (node_health_fold, used at both theconvergedlevel and the top level, so the two can never compose differently):failif anything folded isfail;unknownif anything isunknownand nothing isfail;okonly when everything folded isok. A component whose source does not exist yet — no heartbeat has ever been published, or it predates a field — readsunknown, neverok: the 2026-08-08 failure of two nodes self-certifying freshness for four days is exactly the green-endpoint-that-means-nothing this composition rule exists to close.59a.
updaterandimagecomponent mappings.updater:stuck(a fault only a human clears) isfail;rolledanddeferring(both ordinary, the second self-resolving) areok;null(no ledger evidence yet) isunknown.image:currentisok;unverified(a registry read that failed, or an image with no revision label) isunknown;behindisokwhile the registry’s newest image is younger thanimage_behind_grace_hours(a roll waits for a cycle in flight, so this is routine) andfailonce it is older, or onceregistry_created_atcannot be read at all — mirroringdashboard/index.html’s ownimageLinecolouring exactly (an unreadable age reads the same as “past grace” there too), so the endpoint and the dashboard page can never disagree about what “behind” means;null(this node runs no CI-stamped image, or the heartbeat predates this field) isunknown.