0af39df16f
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.
96 lines
4.0 KiB
C
96 lines
4.0 KiB
C
/* test_interoception_p2_chrono.c — M-INTEROCEPTION Priority 2.
|
|
* Chronoception: engram_age_field(delta_ms) + reboot catch-up
|
|
* (ENGRAM_CHRONOCEPTION, default OFF).
|
|
*
|
|
* Uses loaded snapshots with KNOWN working_memory_weight / background_activation
|
|
* so the field is deterministic without depending on activation. (engram_load
|
|
* halves WM on boot — the laundering step — so snapshot wm 1.0 -> 0.5 resident.)
|
|
*
|
|
* Modes:
|
|
* once <dir> <dt_ms> — age the field once by dt; save field.json.
|
|
* split <dir> <dt_ms> <N> — age by dt/N, N times; save field.json.
|
|
* (once vs split must match: scale-invariance.)
|
|
* catchup <dir> <gap_ms> — write a last-tick gap_ms in the past, then
|
|
* engram_age_field_catchup(); print MAGNITUDE.
|
|
* offcheck <dir> <dt_ms> — flag OFF: age returns 0 and field is untouched.
|
|
*/
|
|
#include "el_runtime.h"
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/time.h>
|
|
|
|
static el_val_t S(const char* s){ return EL_STR(s); }
|
|
|
|
static void write_seed(const char* dir){
|
|
char p[1024]; snprintf(p,sizeof p,"%s/seed.json",dir);
|
|
FILE* f=fopen(p,"w");
|
|
fprintf(f,"{\"nodes\":["
|
|
"{\"id\":\"f1\",\"content\":\"field node 1\",\"node_type\":\"Concept\",\"label\":\"f1\","
|
|
"\"salience\":0.9,\"confidence\":1.0,\"working_memory_weight\":1.0,\"background_activation\":0.5},"
|
|
"{\"id\":\"f2\",\"content\":\"field node 2\",\"node_type\":\"Concept\",\"label\":\"f2\","
|
|
"\"salience\":0.8,\"confidence\":1.0,\"working_memory_weight\":0.8,\"background_activation\":0.4},"
|
|
"{\"id\":\"f3\",\"content\":\"field node 3\",\"node_type\":\"Concept\",\"label\":\"f3\","
|
|
"\"salience\":0.7,\"confidence\":1.0,\"working_memory_weight\":0.6,\"background_activation\":0.3}"
|
|
"],\"edges\":[]}");
|
|
fclose(f);
|
|
}
|
|
static void load_seed(const char* dir){
|
|
char p[1024]; snprintf(p,sizeof p,"%s/seed.json",dir);
|
|
write_seed(dir);
|
|
if(!engram_load(S(p))){ fprintf(stderr,"load failed\n"); exit(2); }
|
|
}
|
|
static void save_field(const char* dir){
|
|
char p[1024]; snprintf(p,sizeof p,"%s/field.json",dir);
|
|
engram_save(S(p));
|
|
}
|
|
|
|
int main(int argc,char** argv){
|
|
if(argc<3){ fprintf(stderr,"usage: %s <once|split|catchup|offcheck> <dir> ...\n",argv[0]); return 2; }
|
|
const char* mode=argv[1];
|
|
const char* dir =argv[2];
|
|
|
|
if(!strcmp(mode,"once")){
|
|
double dt=atof(argv[3]);
|
|
load_seed(dir);
|
|
el_val_t mag=engram_age_field((el_val_t)(int64_t)dt);
|
|
printf("MAGNITUDE %.10f\n", el_to_float(mag));
|
|
save_field(dir);
|
|
return 0;
|
|
}
|
|
if(!strcmp(mode,"split")){
|
|
double dt=atof(argv[3]); int N=atoi(argv[4]); if(N<1)N=1;
|
|
load_seed(dir);
|
|
double sub=dt/(double)N;
|
|
for(int i=0;i<N;i++) engram_age_field((el_val_t)(int64_t)sub);
|
|
save_field(dir);
|
|
printf("SPLIT dt=%.0f N=%d sub=%.4f\n", dt, N, sub);
|
|
return 0;
|
|
}
|
|
if(!strcmp(mode,"catchup")){
|
|
double gap=atof(argv[3]);
|
|
load_seed(dir);
|
|
/* Write a last-tick gap_ms in the past. ENGRAM_DATA_DIR is set == dir by
|
|
* the runner, so the sidecar the runtime reads is <dir>/chrono_last_tick. */
|
|
struct timeval tv; gettimeofday(&tv,NULL);
|
|
long long now_ms=(long long)tv.tv_sec*1000+tv.tv_usec/1000;
|
|
long long last=now_ms-(long long)gap;
|
|
char p[1200]; snprintf(p,sizeof p,"%s/chrono_last_tick",dir);
|
|
FILE* f=fopen(p,"w"); fprintf(f,"%lld\n",last); fclose(f);
|
|
el_val_t mag=engram_age_field_catchup();
|
|
printf("CATCHUP_MAGNITUDE %.10f\n", el_to_float(mag));
|
|
save_field(dir);
|
|
return 0;
|
|
}
|
|
if(!strcmp(mode,"offcheck")){
|
|
double dt=atof(argv[3]);
|
|
load_seed(dir);
|
|
el_val_t mag=engram_age_field((el_val_t)(int64_t)dt);
|
|
el_val_t magc=engram_age_field_catchup();
|
|
printf("OFF age_mag=%.10f catchup_mag=%.10f\n", el_to_float(mag), el_to_float(magc));
|
|
save_field(dir);
|
|
return 0;
|
|
}
|
|
fprintf(stderr,"unknown mode %s\n",mode); return 2;
|
|
}
|