feat(v4): Phase 7 Task 2a -- decay, heat, temperature and the rolling window at every call (#189)

As v3's physics_pre_execute, in its order (Captain Bob, 2026-11-13: "Every call, as v3"): a word's heat
decays by the ticks since its last touch at the node's decay slope (Q48.16, v3's arithmetic), unless
frozen or L8 has Loop #3 off; +1; its temperature smoothed 3:1; its ID into the node's Rolling Window of
Truth (4096, warm at 1024, a diversity check due every 512). The kernel's heartbeat is read at each call.
Pipelining and the hot-words cache ruled "Built, off as v3" (Task 2b). Test first: test_mesh_boot.c, 56
checks. amd64 boots, RESULT: PASS, 146 s against Phase 2's 142 s. Not pushed (held).

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-13 20:32:36 +00:00
parent 922451cf52
commit b880a6eaed
8 changed files with 145 additions and 7 deletions
@@ -31,6 +31,12 @@
5. **Mama's 20 cases** run as they are, on v4 words with v3's names mapped to v4's equivalents; **the 5. **Mama's 20 cases** run as they are, on v4 words with v3's names mapped to v4's equivalents; **the
C modules** (ACL, break_me) are rewritten for v4. Inventory and rulings: `docs/v4.0.0/POST-PARITY.md`. C modules** (ACL, break_me) are rewritten for v4. Inventory and rulings: `docs/v4.0.0/POST-PARITY.md`.
6. **Pipelining and the hot-words cache: "Built, off as v3"** (2026-11-13). Asked first "Build a
hot-words cache" (in front of FIND, in F18/StarForth, as v3 promotes into its own); then it was found
that v3 as built has both off (`ENABLE_PIPELINING`, `ENABLE_HOTWORDS_CACHE`: `n` in
`Kconfig.physics` and `kernel/Makefile`), so v3's boot records no transitions and uses no cache.
Ruled: both written and tested, behind the same two build options, off by default as in v3.
## What ruling 3 brings in ## What ruling 3 brings in
v3's POST is 26 modules (`v3/src/test_runner/modules/`, about 1,050 cases; v3's bare-metal boot says v3's POST is 26 modules (`v3/src/test_runner/modules/`, about 1,050 cases; v3's bare-metal boot says
@@ -84,7 +90,14 @@ Phase 4).
L8's Loop #3 gate); `v4_mesh_state_flags`. Immediate and hidden are read from the node's header L8's Loop #3 gate); `v4_mesh_state_flags`. Immediate and hidden are read from the node's header
when asked, so they are never stale. v3's `mass_bytes` is only ever set, never read, in v3: not when asked, so they are never stale. v3's `mass_bytes` is only ever set, never read, in v3: not
kept until a word reads it. kept until a word reads it.
### Task 2: the per-call loops at `call` (decay on touch, window, transitions) -- measured ### Task 2a: the per-call loops at `call` -- decay on touch, heat, temperature, the rolling window -- measured
- [x] Test first (`test_mesh_boot.c`, 56 checks): heat +1 a call; decay by the ticks since at v3's
slope and arithmetic (6 ticks: 1; 3 ticks: 0); none for a frozen word, none while L8 has Loop #3
off; the temperature; the window.
- [x] `mesh.c`'s call hook, in v3's order; the kernel's heartbeat read at each call (`ticks`). Until
Task 3 brings L8, Loop #2 and #3 are on (v3's boot sets both off and lets its card decide).
- [x] Measured: amd64 boot 146 s, against Phase 2's 142 s (about +3%).
### Task 2b: pipelining (transitions, the likely next word, speculation) and the hot-words cache in front of FIND, behind `ENABLE_PIPELINING` and `ENABLE_HOTWORDS_CACHE`, off as v3
### Task 3: the per-tick loops (tuner, slope, background decay, L8, inference, snapshot) ### Task 3: the per-tick loops (tuner, slope, background decay, L8, inference, snapshot)
### Task 4: the words that read and set them (`FREEZE-WORD`, the inference words, ...), and their POST ### 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 5: the StarForth words (Phase 3's: `init.4th`, `starforth.4th`), and their POST
+2
View File
@@ -78,6 +78,7 @@ static uint32_t sk_v4_charge_ids[V4_MESH_WORD_IDS];
static uint64_t sk_v4_charge_calls[V4_MESH_WORD_IDS]; static uint64_t sk_v4_charge_calls[V4_MESH_WORD_IDS];
static uint32_t sk_v4_charge_n; static uint32_t sk_v4_charge_n;
static v4_mesh_physics sk_v4_physics[SK_V4_PLACES]; /* each node's physics: its tick, decay slope, L8's gates (#189, Phase 7) */ static v4_mesh_physics sk_v4_physics[SK_V4_PLACES]; /* each node's physics: its tick, decay slope, L8's gates (#189, Phase 7) */
static uint64_t sk_v4_heartbeat_ticks(void) { return heartbeat_ticks(); } /* what decay is measured by, as v3's VM tick */
static void sk_v4_charge_one(void *ctx, v4_cell id, v4_uheat_t calls) static void sk_v4_charge_one(void *ctx, v4_cell id, v4_uheat_t calls)
{ {
(void)ctx; (void)ctx;
@@ -311,6 +312,7 @@ void sk_v4_boot(void (*chain)(void), const BootDisk *boot_disk)
} }
sk_v4_mesh.forgot = sk_v4_forgot; sk_v4_mesh.forgot = sk_v4_forgot;
sk_v4_mesh.physics = sk_v4_physics; sk_v4_mesh.physics = sk_v4_physics;
sk_v4_mesh.ticks = sk_v4_heartbeat_ticks;
sk_v4_mesh.out = sk_v4_out; sk_v4_mesh.key = sk_v4_key; sk_v4_mesh.out = sk_v4_out; sk_v4_mesh.key = sk_v4_key;
sk_v4_mesh.words = sk_v4_words; sk_v4_mesh.word_count = sizeof sk_v4_words / sizeof sk_v4_words[0]; sk_v4_mesh.words = sk_v4_words; sk_v4_mesh.word_count = sizeof sk_v4_words / sizeof sk_v4_words[0];
sk_v4_mesh.serve = sk_v4_serve; sk_v4_mesh.serve = sk_v4_serve;
+1
View File
@@ -0,0 +1 @@
Development boot, not acceptance evidence (2026-11-13): amd64 with #189 Phase 7 Task 2a (decay, heat, temperature and the rolling window at every call). RESULT: PASS; Stadium words promotions=141, CONSERVED; dict_hash 0xa854ba15b437d288 unchanged. The boot took 146 s (Phase 2: 142 s; about +3%). The protocol run is the evidence.
Binary file not shown.
+17 -1
View File
@@ -73,10 +73,22 @@ typedef struct {
/* Each node's physics (v3's VM fields): its heartbeat's tick, the decay slope (Q48.16 heat a tick; /* Each node's physics (v3's VM fields): its heartbeat's tick, the decay slope (Q48.16 heat a tick;
* v3's INITIAL_DECAY_SLOPE_Q48, which the inference engine tunes), and L8's gate on Loop #3. */ * v3's INITIAL_DECAY_SLOPE_Q48, which the inference engine tunes), and L8's gate on Loop #3. */
#define V4_MESH_INITIAL_DECAY_SLOPE_Q48 21845u #define V4_MESH_INITIAL_DECAY_SLOPE_Q48 21845u
#define V4_MESH_WINDOW 4096u /* v3's ROLLING_WINDOW_SIZE */
#define V4_MESH_WINDOW_WARM 1024u /* executions before the window is warm, as v3 */
#define V4_MESH_ADAPTIVE_CHECK 512u /* v3's ADAPTIVE_CHECK_FREQUENCY: executions between diversity checks */
typedef struct { typedef struct {
uint64_t tick; uint64_t tick;
uint64_t decay_slope_q48; uint64_t decay_slope_q48;
uint8_t l3_decay; uint8_t l3_decay; /* L8's gate on Loop #3 */
uint8_t l2_window; /* L8's gate on Loop #2 */
/* the Rolling Window of Truth (Loop #2; v3's RollingWindowOfTruth): the IDs of the words called, in order */
uint32_t history[V4_MESH_WINDOW];
uint32_t window_pos; /* where the next is written */
uint64_t total_executions;
uint32_t effective_window_size; /* may shrink from V4_MESH_WINDOW (Loop #5) */
uint32_t adaptive_check_accumulator;
uint8_t is_warm;
uint8_t adaptive_pending; /* the heartbeat should check the window's diversity */
} v4_mesh_physics; } v4_mesh_physics;
typedef struct v4_mesh v4_mesh; typedef struct v4_mesh v4_mesh;
@@ -113,6 +125,7 @@ struct v4_mesh {
v4_mesh_account *accounts; v4_mesh_account *accounts;
unsigned char *is_word; unsigned char *is_word;
v4_mesh_physics *physics; /* `capacity` of them: each node's (#189, Phase 7) */ v4_mesh_physics *physics; /* `capacity` of them: each node's (#189, Phase 7) */
uint64_t (*ticks)(void); /* the heartbeat's tick count, read at each call (0: v4_mesh_set_tick's) */
/* a word has gone, its ID free for the next: the owner forgets what it keeps by it (may be 0) */ /* a word has gone, its ID free for the next: the owner forgets what it keeps by it (may be 0) */
void (*forgot)(void *self, unsigned place, v4_cell id); void (*forgot)(void *self, unsigned place, v4_cell id);
void *self; void *self;
@@ -152,6 +165,9 @@ int v4_mesh_busy(const v4_mesh *ms);
/* A word's record on the node in `place`, by its xt: 0 if that is not a word's xt. */ /* A word's record on the node in `place`, by its xt: 0 if that is not a word's xt. */
const v4_mesh_account *v4_mesh_account_at(const v4_mesh *ms, unsigned place, v4_cell xt); const v4_mesh_account *v4_mesh_account_at(const v4_mesh *ms, unsigned place, v4_cell xt);
/* The heartbeat's tick, for every node (v3's vm->heartbeat.tick_count): what decay is measured by. */
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. */ /* A word's state flags (V4_MESH_STATE_*), or 0 if xt is not a word's. */
unsigned v4_mesh_state_flags(const v4_mesh *ms, unsigned place, v4_cell xt); unsigned v4_mesh_state_flags(const v4_mesh *ms, unsigned place, v4_cell xt);
+69 -5
View File
@@ -182,14 +182,71 @@ static void words_gone(unsigned place, const v4_node *n, v4_cell w)
} }
} }
/* at `call` (exec.h): a word's record counts one; any other target, nothing */ /* Loop #3, on touch (v3's physics_metadata_apply_linear_decay): the ticks since, times the decay slope
* (Q48.16), off the heat -- not for a frozen word, not while L8 has Loop #3 off */
static void decay(v4_mesh_account *a, const v4_mesh_physics *p, uint64_t elapsed)
{
uint64_t amount;
if ((a->state_flags & V4_MESH_STATE_FROZEN) || elapsed == 0 || !p->l3_decay) return;
amount = (elapsed * p->decay_slope_q48) >> 16;
if (amount == 0) return;
a->heat = amount >= a->heat ? 0 : a->heat - amount;
}
/* the temperature (v3's physics_metadata_touch): the heat in Q8, smoothed 3:1 */
static uint16_t temperature(v4_uheat_t heat, uint16_t prior)
{
uint64_t scaled;
uint16_t target;
if (heat == 0) return 0;
scaled = (uint64_t)heat << 8;
target = scaled > 65535u ? 65535u : (uint16_t)scaled;
return (uint16_t)((3u * prior + target) / 4u);
}
/* Loop #2 (v3's rolling_window_record_execution): the word's ID into the window */
static void window_record(v4_mesh_physics *p, uint32_t id)
{
p->history[p->window_pos] = id;
p->window_pos = (p->window_pos + 1u) % V4_MESH_WINDOW;
p->total_executions++;
if (p->total_executions >= V4_MESH_WINDOW_WARM && !p->is_warm) p->is_warm = 1;
if (p->is_warm && ++p->adaptive_check_accumulator >= V4_MESH_ADAPTIVE_CHECK) {
p->adaptive_check_accumulator = 0;
p->adaptive_pending = 1;
}
}
/* at `call` (exec.h), on a word -- any other target, nothing -- in v3's order (physics_pre_execute,
* V3-PARITY.md 2.1; Captain Bob, 2026-11-13: "Every call, as v3"): decay by the ticks since, heat +1,
* the count the Stadium is charged by, the temperature, the rolling window */
static void on_call(void *ctx, v4_node *n, v4_cell target) static void on_call(void *ctx, v4_node *n, v4_cell target)
{ {
unsigned place = place_of_device(ctx); unsigned place = place_of_device(ctx);
v4_cell id; v4_cell id;
v4_mesh_account *a;
if (!is_word(place, target)) return; if (!is_word(place, target)) return;
id = n->mem[target - 4]; id = n->mem[target - 4];
if (id >= 0 && id < (v4_cell)V4_MESH_WORD_IDS) { accounts_of(place)[id].calls++; accounts_of(place)[id].since++; } if (id < 0 || id >= (v4_cell)V4_MESH_WORD_IDS) return;
a = &accounts_of(place)[id];
if (the->physics) {
v4_mesh_physics *p = &the->physics[place];
if (the->ticks) p->tick = the->ticks();
decay(a, p, p->tick - a->last_decay_tick);
a->last_decay_tick = p->tick;
a->heat++;
a->temperature_q8 = temperature(a->heat, a->temperature_q8);
if (p->l2_window) window_record(p, (uint32_t)id);
}
a->calls++;
a->since++;
}
void v4_mesh_set_tick(v4_mesh *ms, uint64_t tick)
{
unsigned k;
if (!ms->physics) return;
for (k = 0; k < ms->capacity; k++) ms->physics[k].tick = tick;
} }
/* is the entry at xt named `name`? (dict.f18: the name's word address at xt-2, its count byte, then its /* is the entry at xt named `name`? (dict.f18: the name's word address at xt-2, its count byte, then its
@@ -228,9 +285,16 @@ static void words_attach(unsigned place, v4_fabric_node *x)
x->n.mem[im->word_forgotten] = gone; x->n.mem[im->word_forgotten] = gone;
} }
if (the->physics) { /* the node's physics, as v3's VM starts */ if (the->physics) { /* the node's physics, as v3's VM starts */
the->physics[place].tick = 0; v4_mesh_physics *p = &the->physics[place];
the->physics[place].decay_slope_q48 = V4_MESH_INITIAL_DECAY_SLOPE_Q48; uint64_t tick = p->tick; /* the heartbeat's, which goes on */
the->physics[place].l3_decay = 1; unsigned char *z = (unsigned char *)p;
unsigned long i;
for (i = 0; i < sizeof *p; i++) z[i] = 0;
p->tick = tick;
p->decay_slope_q48 = V4_MESH_INITIAL_DECAY_SLOPE_Q48;
p->l3_decay = 1;
p->l2_window = 1; /* v3: "No config yet: recorded" */
p->effective_window_size = V4_MESH_WINDOW;
} }
x->es.on_call = on_call; x->es.on_call = on_call;
x->es.on_call_ctx = &the->kernel[place]; x->es.on_call_ctx = &the->kernel[place];
+39
View File
@@ -199,6 +199,45 @@ int main(void)
CHECK(v4_mesh_state_flags(&ms, 0, xt) == 0, "and none for SQ"); CHECK(v4_mesh_state_flags(&ms, 0, xt) == 0, "and none for SQ");
} }
r = line(V4_MESH_HERA, "FORGET IMM", &how); r = line(V4_MESH_HERA, "FORGET IMM", &how);
/* Phase 7, Task 2a: at every call, as v3's physics_pre_execute -- decay by the ticks since, heat +1,
* the temperature, the rolling window (Captain Bob, 2026-11-13: "Every call, as v3") */
{
v4_mesh_physics *p = &ms.physics[0];
const v4_mesh_account *a;
uint64_t total0;
r = line(V4_MESH_HERA, ": P7 DUP * ; ' P7 .", &how);
a = v4_mesh_account_at(&ms, 0, (v4_cell)strtol(r, 0, 10));
v4_mesh_set_tick(&ms, 100);
total0 = p->total_executions;
r = line(V4_MESH_HERA, "2 P7 3 P7 4 P7 + + .", &how);
CHECK(strcmp(r, "29 ") == 0 && a && a->heat == 3 && a->last_decay_tick == 100,
"three calls: heat 3, decayed at tick 100 (%lu)", a ? (unsigned long)a->heat : 0ul);
CHECK(p->total_executions >= total0 + 3 && p->history[(p->window_pos + V4_MESH_WINDOW - 1u) % V4_MESH_WINDOW]
!= (uint32_t)-1, "the rolling window took them (%lu)", (unsigned long)(p->total_executions - total0));
CHECK(a && a->temperature_q8 > 0, "and the temperature rose: %u", a ? a->temperature_q8 : 0u);
v4_mesh_set_tick(&ms, 106); /* six ticks at 21845 (1/3 a tick, Q48.16): 1 heat */
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 3 && a->last_decay_tick == 106, "six ticks on: one heat decayed, one added: %lu",
a ? (unsigned long)a->heat : 0ul);
v4_mesh_set_tick(&ms, 109); /* three ticks: 65535 >> 16 = 0, as v3 */
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 4, "three ticks decay nothing, as v3's arithmetic: %lu", a ? (unsigned long)a->heat : 0ul);
((v4_mesh_account *)a)->state_flags |= V4_MESH_STATE_FROZEN;
v4_mesh_set_tick(&ms, 409);
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 5, "a frozen word does not decay: %lu", a ? (unsigned long)a->heat : 0ul);
((v4_mesh_account *)a)->state_flags &= (uint8_t)~V4_MESH_STATE_FROZEN;
p->l3_decay = 0;
v4_mesh_set_tick(&ms, 709);
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 6, "nor any word while L8 has Loop #3 off: %lu", a ? (unsigned long)a->heat : 0ul);
p->l3_decay = 1;
v4_mesh_set_tick(&ms, 1009);
r = line(V4_MESH_HERA, "2 P7 .", &how);
CHECK(a && a->heat == 1, "and with it on, 300 ticks take all six, then one: %lu", a ? (unsigned long)a->heat : 0ul);
v4_mesh_set_tick(&ms, 0);
r = line(V4_MESH_HERA, "FORGET P7", &how);
}
r = line(V4_MESH_HERA, "3 SQ .", &how); r = line(V4_MESH_HERA, "3 SQ .", &how);
CHECK(strcmp(r, "9 ") == 0 && a && a->calls == 1, "a call to it counts one: %lu", a ? (unsigned long)a->calls : 0ul); CHECK(strcmp(r, "9 ") == 0 && a && a->calls == 1, "a call to it counts one: %lu", a ? (unsigned long)a->calls : 0ul);
r = line(V4_MESH_HERA, "5 SQ 6 SQ + .", &how); r = line(V4_MESH_HERA, "5 SQ 6 SQ + .", &how);