feat(v4, kernel): ONE adaptive heartbeat -- it paces itself on the Stadium's resident heat; every VM ticks on it, in lockstep

Captain Bob, 2026-11-17: "The adaptive heartbeat is its own thing ... It has its own independent RWOT and slope
provider. Only one output from the entire stadium is used as a load measurement for heart rate pacing. ... ONE
AS IN THE NUMBER 1 heartbeat (the adaptive one) runs the entire system." Ruled one at a time: the kernel's
heartbeat; resident heat its one input; held in POST; the Stadium charged as before today
(docs/v4.0.0/plans/2026-11-17-one-adaptive-heartbeat.md, its first version kept as superseded).

- kernel/src/heartbeat.c, timer.h: heartbeat_pace_from(load) -- its own window of samples, its own slope
  provider (v4's inference arithmetic) every HEARTBEAT_PACE_EVERY samples, Loop #7 setting its own period
  (not stable 20% faster, stable 25% slower, 1/4..4x the 10 ms base). No source (v3's path): nothing runs.
- kernel/src/vm/stadium.c: stadium_resident_heat_total(), read only -- the one output it paces by.
- v4/system/mesh.c, mesh.h: the owner's clock read at every fabric step; each tick delivered, one by one, to
  every node present -- its heartbeat cycle run, active, idle or blocked alike. The tick by execution, the
  nodes' own Loop #7 and the heartrate callback are gone.
- kernel/src/v4/sk_v4.c: the clock gives the heartbeat's bottom half its turn; 0 until POST has ended.
- Tests first, each seen to fail (does not build): kernel/tests/test_heartbeat.c (11 checks),
  test_stadium_node.c (16), test_mesh_boot.c's lockstep checks. Seven Phase 7 checks that assumed the tick by
  execution now drive the test's heartbeat (ruled). POST 990/990 with v3's heat cases as written;
  mesh-boot 103, -on 112, -noop 100, san-mesh-boot 103, every v4 program at both widths, every kernel host
  test: 0 failures. The full `sanitize` target not run (it outlasts the foreground limit).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-17 20:55:14 +00:00
parent 4a5c9bfd42
commit 00be537503
12 changed files with 462 additions and 88 deletions
+10 -8
View File
@@ -198,10 +198,10 @@ typedef struct {
} v4_mesh_window;
typedef struct {
uint64_t tick; /* the node's heartbeat cycles (v3's tick_count): by execution, as v3 */
uint32_t check_counter; /* executions since the last cycle: v3's, tokens and words run */
v4_cell tokens_seen; /* (TOKENS) when last added in */
uint32_t cycle_every; /* V4_MESH_CHECK_FREQUENCY */
uint64_t tick; /* the ONE adaptive heartbeat's tick (the mesh's `tick`), the same on every
* node: every node advances one tick on each of its ticks, active or not
* (Captain Bob, 2026-11-17; plan 2026-11-17-one-adaptive-heartbeat) */
uint8_t ticking; /* not 0: the node's physics is set up, and it runs its cycle on each tick */
uint64_t decay_slope_q48;
uint8_t l3_decay; /* L8's gate on Loop #3 */
uint8_t l2_window; /* L8's gate on Loop #2 */
@@ -225,7 +225,6 @@ typedef struct {
uint64_t last_inference_tick;
uint8_t inference_early_exited;
uint64_t inference_runs, inference_early_exits;
uint64_t tick_target_ns; /* v3's tick_target_ns: HEARTBEAT_TICK_NS, a quarter to four times it */
/* the opcodes' physics (ruling 7): their records, the one before, their decay slope, their inference */
v4_mesh_opcode op[V4_MESH_OPCODES];
uint32_t prev_op; /* V4_MESH_NO_WORD: none yet */
@@ -275,8 +274,10 @@ struct v4_mesh {
v4_mesh_account *accounts;
unsigned char *is_word;
v4_mesh_physics *physics; /* `capacity` of them: each node's (#189, Phase 7) */
/* Loop #7 on Hera: the kernel's heartbeat period, re-armed (v3: heartbeat_set_adaptive_period_ns; may be 0) */
void (*heartrate)(void *self, uint64_t kernel_period_ns);
/* THE ONE ADAPTIVE HEARTBEAT's tick, as the owner has it (the kernel: its heartbeat's ticks since POST ended --
* held, 0, until then); 0: no heartbeat, the tick never moves. Read at every fabric step; each new tick is
* delivered to every node. The heartbeat paces itself (kernel/src/heartbeat.c): nothing here paces it. */
uint64_t (*clock)(void *self);
/* memory for a word's transition counters, zeroed, and given back (pipelining; may be 0: none recorded) */
void *(*alloc)(void *self, unsigned long bytes);
void (*release)(void *self, void *p);
@@ -287,6 +288,7 @@ struct v4_mesh {
/* ---- the mesh's own ---- */
v4_fabric f;
v4_manage m;
uint64_t tick; /* the last of the heartbeat's ticks delivered to every node */
unsigned hera_place;
v4_cell cells[V4_MESH_NUCLEUS_CELLS]; /* the nucleus as a capsule of F18 cells */
unsigned cell_count, given; /* how many; how many given to Hera */
@@ -323,7 +325,7 @@ const v4_mesh_account *v4_mesh_account_at(const v4_mesh *ms, unsigned place, v4_
* it choose again from there. */
void v4_mesh_l8_force(v4_mesh *ms, unsigned place, unsigned card, int hold);
/* Every node's tick set to `tick` (for tests: a node's tick is its own count of heartbeat cycles). */
/* The tick, and so every node's, set to `tick`, no cycle run (for tests). */
void v4_mesh_set_tick(v4_mesh *ms, uint64_t tick);
/* A word's state flags (V4_MESH_STATE_*), or 0 if xt is not a word's. */