From b5d99ba98bbc5f6c9263eaefdb11c42c6441b535 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 00:10:46 +0000 Subject: [PATCH] feat(v4): Phase 7 Task 3 -- the heartbeat snapshot; the loops complete (#189) Each cycle publishes v3's HeartbeatSnapshot: the tick, the window's width and fill, the decay slope, and the dictionary's heat as inference last counted it (words over 50, cooling, the heat in all). One copy, not v3's two, which are for its heartbeat thread. With it every loop v3 runs before its prompt runs on v4's word records on every node. Test first: test_mesh_boot.c 73 checks, 81 on. Not pushed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm --- ...ngine-step4-phase7-the-loops-and-parity.md | 4 +++- v4/include/v4/mesh.h | 7 +++++++ v4/system/mesh.c | 20 +++++++++++++++++++ v4/tests/test_mesh_boot.c | 4 ++++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/docs/v4.0.0/plans/2026-11-13-engine-step4-phase7-the-loops-and-parity.md b/docs/v4.0.0/plans/2026-11-13-engine-step4-phase7-the-loops-and-parity.md index bb0f09cf..b46d1cca 100644 --- a/docs/v4.0.0/plans/2026-11-13-engine-step4-phase7-the-loops-and-parity.md +++ b/docs/v4.0.0/plans/2026-11-13-engine-step4-phase7-the-loops-and-parity.md @@ -143,7 +143,9 @@ Phase 4). through `card_bits` -- v3 applies the card's number, one bit off (#196; ruled "v4 correct, v3 as is"). `v4_mesh_l8_force` as v3's `ssm_l8_force_config`. Test first (67 checks; 75 on). amd64 PASS, 156 s. -- [ ] The snapshot. +- [x] The snapshot (v3's `heartbeat_publish_snapshot`): each cycle, the tick, window, slope and the + dictionary's heat as inference counted it (v3's `*_at_check`). One copy: v3 double-buffers for its + heartbeat thread, which v4 has no counterpart of. Test first (73 checks; 81 on). ### Task 4: the words that read and set them (`FREEZE-WORD`, the inference words, ...), and their POST ### Task 5: the StarForth words (Phase 3's: `init.4th`, `starforth.4th`), and their POST ### Task 6: the ACL (Phase 4's: `ACL.4th`, the word card, the countdown), and its POST diff --git a/v4/include/v4/mesh.h b/v4/include/v4/mesh.h index a0c0e72e..7cc94647 100644 --- a/v4/include/v4/mesh.h +++ b/v4/include/v4/mesh.h @@ -179,6 +179,13 @@ typedef struct { 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 dictionary as inference last counted it (v3's *_at_check): words over heat 50, words cooling (heat + * 1..9), the heat in all; and the snapshot each cycle publishes (v3's HeartbeatSnapshot) */ + uint64_t hot_at_check, stale_at_check, total_heat_at_check; + struct { + uint64_t tick, decay_slope_q48, hot, stale, total_heat; + uint32_t window_width, fill; + } snapshot; } v4_mesh_physics; typedef struct v4_mesh v4_mesh; diff --git a/v4/system/mesh.c b/v4/system/mesh.c index c9a9bc76..bcaf145c 100644 --- a/v4/system/mesh.c +++ b/v4/system/mesh.c @@ -535,6 +535,18 @@ static void inference_tick(unsigned place, v4_mesh_physics *p) if (!p->is_warm || !x) return; p->inference_runs++; window_service(p); + { /* the dictionary's heat, counted (as v3's) */ + uint64_t hot = 0, stale = 0, total = 0; + unsigned k; + for (k = 0; k < V4_MESH_WORD_IDS; k++) { + const v4_mesh_account *a = &accounts_of(place)[k]; + if (!a->xt) continue; + if (a->heat > V4_MESH_HOT_HEAT) hot++; + else if (a->heat > 0 && a->heat < 10) stale++; + total += a->heat; + } + p->hot_at_check = hot; p->stale_at_check = stale; p->total_heat_at_check = total; + } /* the heat of each word in the window, the newest `span` of them, oldest first (v3's extract_heat_trajectory) */ have = p->total_executions < V4_MESH_WINDOW ? p->total_executions : V4_MESH_WINDOW; span = p->effective_window_size < have ? p->effective_window_size : have; @@ -571,6 +583,14 @@ static void heartbeat_cycle(unsigned place, v4_mesh_physics *p) background_decay(place, p); window_service(p); l8_update(p); + /* the snapshot (v3's heartbeat_publish_snapshot) */ + p->snapshot.tick = p->tick; + p->snapshot.window_width = p->effective_window_size; + p->snapshot.fill = (uint32_t)(p->total_executions < V4_MESH_WINDOW ? p->total_executions : V4_MESH_WINDOW); + p->snapshot.decay_slope_q48 = p->decay_slope_q48; + p->snapshot.hot = p->hot_at_check; + p->snapshot.stale = p->stale_at_check; + p->snapshot.total_heat = p->total_heat_at_check; } /* at `call` (exec.h), on a word -- any other target, nothing -- in v3's order (physics_pre_execute, diff --git a/v4/tests/test_mesh_boot.c b/v4/tests/test_mesh_boot.c index 517cba73..97463e0a 100644 --- a/v4/tests/test_mesh_boot.c +++ b/v4/tests/test_mesh_boot.c @@ -232,6 +232,10 @@ int main(void) CHECK(heartrates > 0 && heartrate_ns == (p->tick_target_ns * 10000000ULL) / HEARTBEAT_TICK_NS, "and on Hera re-armed the kernel's heartbeat: %lu ns", (unsigned long)heartrate_ns); CHECK(!p->inference.early_exited ? p->last_inference_tick > 0 : 1, "a full run marks its tick"); + CHECK(p->snapshot.tick == p->tick && p->snapshot.window_width == p->effective_window_size + && p->snapshot.decay_slope_q48 == p->decay_slope_q48 && p->snapshot.fill == V4_MESH_WINDOW + && p->snapshot.total_heat == p->total_heat_at_check && p->total_heat_at_check > 0, + "the cycle's snapshot: its tick, window, slope, and the dictionary's heat as inference counted it"); r = line(V4_MESH_HERA, "FORGET IW", &how); }