M-INTEROCEPTION P2: chronoception — age the activation field by measured wall-clock delta (ENGRAM_CHRONOCEPTION, default OFF)

The felt passage of time is the cooling of the activation field, not a tick
count and not an elapsed-seconds readout. engram_age_field(delta_ms) cools the
field (working_memory_weight + background_activation) by the caller's MEASURED
wall-clock delta with a pure exponential exp(-dt/TC) — no per-call floor — so it
is exactly scale-invariant: N ticks summing to the same elapsed time produce the
same total cooling. It returns the cooling MAGNITUDE (1-exp(-dt/TC), a bounded
[0,1) drift signal), never elapsed seconds.

Reboot = anesthesia: a global last-tick wall-clock stamp is persisted to a
sidecar (chrono_last_tick) in the data dir. engram_age_field_catchup() reads it
on boot, applies ONE cooling for the whole unconscious gap, refreshes the stamp,
and reports the magnitude — timestamps are bookkeeping to COMPUTE the drift,
never the felt signal. TC env-tunable via ENGRAM_CHRONO_TC (default 3600s).

All inert unless ENGRAM_CHRONOCEPTION is set → OFF path byte-identical.

MEASURED on a copy (throwaway HOME, TC=3600s):
- Cooling scales with dt, matching 1-exp(-dt/TC) to 1e-6: dt=600s->0.1535,
  1800s->0.3935, 3600s->0.6321, 7200s->0.8647.
- Scale-invariance EXACT: age(dt) once vs age(dt/N) N times gives identical
  field sum (|delta|=0.0) for N=2, 10, 100.
- Reboot catch-up over a 1h gap cooled the field 0.60->0.4415 in one shot,
  magnitude 0.6321, bounded in [0,1).
- Flag OFF: age & catchup return 0, field untouched (sum 1.2).
ASan+UBSan clean.
This commit is contained in:
2026-08-12 23:41:09 -05:00
parent 5f6ce5ca1f
commit 0af39df16f
5 changed files with 267 additions and 0 deletions
+69
View File
@@ -11836,6 +11836,75 @@ el_val_t engram_resolve_data_dir(void) {
return el_wrap_str(el_strdup(engramdir));
}
/* ── M-INTEROCEPTION P2: chronoception (ENGRAM_CHRONOCEPTION, default OFF) ────
* Design §9. The felt passage of time is the COOLING of the activation field,
* not a tick count and not an elapsed-seconds readout. engram_age_field cools
* the field (working_memory_weight + background_activation) by the MEASURED
* wall-clock delta the caller supplies, using a pure exponential exp(-dt/TC).
*
* SCALE-INVARIANCE is the whole point and is structural: the cooling is a pure
* multiply with NO per-call floor, so age(dt) applied once is bit-close to
* age(dt/N) applied N times N ticks that sum to the same elapsed time produce
* the same total cooling. (A per-call snap-to-floor would break this, which is
* why there isn't one here.)
*
* Reboot = anesthesia: a global last-tick wall-clock stamp is persisted to a
* sidecar in the data dir. On boot, engram_age_field_catchup reads it, applies
* ONE cooling for the whole unconscious gap, and reports the COOLING MAGNITUDE
* how far the field drifted NEVER the elapsed seconds (timestamps are
* bookkeeping to COMPUTE the drift, never the felt signal).
*
* All inert unless ENGRAM_CHRONOCEPTION is set OFF path byte-identical. */
static int eg_chronoception_on(void){
static int cached=-1;
if(cached<0){ const char* s=getenv("ENGRAM_CHRONOCEPTION"); cached=(s&&s[0]&&s[0]!='0')?1:0; }
return cached;
}
/* Field cooling time-constant in seconds; default = conversational span. */
static double eg_chrono_tc(void){ const char* s=getenv("ENGRAM_CHRONO_TC"); double v=s?atof(s):ENGRAM_CARRY_TC; if(!(v>0.0))v=ENGRAM_CARRY_TC; return v; }
el_val_t engram_age_field(el_val_t delta_ms){
if(!eg_chronoception_on()) return el_from_float(0.0);
double dt_ms=(double)(int64_t)delta_ms;
if(dt_ms<=0.0) return el_from_float(0.0);
double factor=exp(-(dt_ms/1000.0)/eg_chrono_tc()); /* pure exponential, no floor */
EngramStore* g=engram_get();
for(int64_t i=0;i<g->node_count;i++){
g->nodes[i].working_memory_weight *= factor;
g->nodes[i].background_activation *= factor;
}
return el_from_float(1.0-factor); /* cooling magnitude in [0,1), NOT seconds */
}
static void eg_chrono_tick_path(char* out, size_t cap){
el_val_t dd=engram_resolve_data_dir();
snprintf(out, cap, "%s/chrono_last_tick", EL_CSTR(dd));
}
/* Persist the global last-tick stamp (call each tick / before shutdown). */
el_val_t engram_chrono_persist_tick(void){
if(!eg_chronoception_on()) return (el_val_t)(int64_t)0;
char path[1200]; eg_chrono_tick_path(path,sizeof path);
FILE* f=fopen(path,"w"); if(!f) return (el_val_t)(int64_t)0;
fprintf(f,"%lld\n",(long long)engram_now_ms()); fclose(f);
return (el_val_t)(int64_t)1;
}
/* Boot-time one-shot catch-up. Reads the persisted last-tick, cools the field
* for the whole elapsed gap in a single application, refreshes the tick, and
* returns the COOLING MAGNITUDE (never elapsed seconds). 0 if no prior tick. */
el_val_t engram_age_field_catchup(void){
if(!eg_chronoception_on()) return el_from_float(0.0);
char path[1200]; eg_chrono_tick_path(path,sizeof path);
FILE* f=fopen(path,"r"); if(!f) return el_from_float(0.0);
long long last=0; int ok=fscanf(f,"%lld",&last); fclose(f);
if(ok!=1 || last<=0) return el_from_float(0.0);
int64_t now=engram_now_ms();
double dt_ms=(double)(now-last);
if(dt_ms<=0.0) return el_from_float(0.0);
el_val_t mag=engram_age_field((el_val_t)(int64_t)dt_ms);
f=fopen(path,"w"); if(f){ fprintf(f,"%lld\n",(long long)now); fclose(f); }
return mag;
}
/* ── Integrity: store-level write-protection (§18.1, §18.3) ──────────────────
* The protected set is DERIVED from the self-graph at call time, not hardcoded:
* the self root and the values hub, plus every node adjacent to either (in