[{"data":1,"prerenderedAt":775},["ShallowReactive",2],{"docs-\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Fmemory":3},{"id":4,"title":5,"body":6,"description":768,"extension":769,"meta":770,"navigation":196,"path":771,"seo":772,"stem":773,"__hash__":774},"docs\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Fmemory.md","Memory",{"type":7,"value":8,"toc":757},"minimark",[9,13,17,29,35,42,47,50,102,105,120,124,131,325,328,356,359,365,369,378,381,393,403,409,412,420,429,511,522,531,538,541,550,553,556,560,563,648,651,712,723,732,737,741,747,750,753],[10,11,5],"h1",{"id":12},"memory",[14,15,16],"p",{},"A cognet has two kinds of memory, and the interesting one is not the persistent one.",[14,18,19,23,24,28],{},[20,21,22],"strong",{},"Module scope is the brain's RAM."," Anything ",[25,26,27],"code",{},"src\u002Fmain.ts"," and its imports hold in\nclosure survives across wakes for as long as the process lives. It is fast, ordinary\nTypeScript, and completely undurable.",[14,30,31,34],{},[20,32,33],{},"The session log is the record."," Every stimulus the cognet received, every output it\nemitted, every action it ran and every result that came back — all of it, in commit\norder, owned by the kernel.",[14,36,37,38,41],{},"The relationship between those two is the whole design: ",[20,39,40],{},"resident memory is a\nprojection of the log, and nothing else."," Lose it and you lose nothing. Rebuild it by\nreplaying. A mind shaped this way cannot drift from its own history, because its history\nis the only thing it's made of.",[43,44,46],"h2",{"id":45},"the-read-side","The read side",[14,48,49],{},"The cognet's access to the log is read-only and deliberately narrow:",[51,52,57],"pre",{"className":53,"code":54,"language":55,"meta":56,"style":56},"language-ts shiki shiki-themes dark-plus","kernel.store.session.get({ after: seq })  \u002F\u002F entries newer than seq, in order\n","ts","",[25,58,59],{"__ignoreMap":56},[60,61,64,68,72,75,77,80,82,86,89,92,95,98],"span",{"class":62,"line":63},"line",1,[60,65,67],{"class":66},"s3F5K","kernel",[60,69,71],{"class":70},"sTNBD",".",[60,73,74],{"class":66},"store",[60,76,71],{"class":70},[60,78,79],{"class":66},"session",[60,81,71],{"class":70},[60,83,85],{"class":84},"sCudf","get",[60,87,88],{"class":70},"({ ",[60,90,91],{"class":66},"after:",[60,93,94],{"class":66}," seq",[60,96,97],{"class":70}," })  ",[60,99,101],{"class":100},"sOLPB","\u002F\u002F entries newer than seq, in order\n",[14,103,104],{},"Synchronous — this is the kernel's live in-memory projection, not a disk read. It returns\nentries only: the same envelopes stimuli arrive as. Kernel telemetry, error machinery,\nand internal spans are not merely filtered out, they are unreachable — the store reads a\nprojection that was already classified by type namespace before the cognet ever asked.",[14,106,107,108,111,112,115,116,119],{},"A cognet cannot write to this log. It emits with ",[25,109,110],{},"kernel.output()"," or requests with\n",[25,113,114],{},"kernel.run()",", and the kernel commits on its behalf. There is no ",[25,117,118],{},"commit"," verb in the\nABI and no way to synthesize one.",[43,121,123],{"id":122},"one-function","One function",[14,125,126,127,130],{},"This is the entire memory system of ",[25,128,129],{},"zero",", the reference cognet:",[51,132,134],{"className":53,"code":133,"language":55,"meta":56,"style":56},"export const state: ZeroState = {\n    entries: [],\n    seq: -1,\n}\n\nexport function sync(): void {\n    for (const entry of kernel.store.session.get({ after: state.seq })) {\n        state.entries.push(entry)\n        state.seq = entry.time.seq\n    }\n}\n",[25,135,136,160,169,185,191,198,218,265,290,314,320],{"__ignoreMap":56},[60,137,138,142,146,150,153,157],{"class":62,"line":63},[60,139,141],{"class":140},"sYbnZ","export",[60,143,145],{"class":144},"scz_3"," const",[60,147,149],{"class":148},"s9McN"," state",[60,151,152],{"class":70},": ",[60,154,156],{"class":155},"sNl3T","ZeroState",[60,158,159],{"class":70}," = {\n",[60,161,163,166],{"class":62,"line":162},2,[60,164,165],{"class":66},"    entries:",[60,167,168],{"class":70}," [],\n",[60,170,172,175,178,182],{"class":62,"line":171},3,[60,173,174],{"class":66},"    seq:",[60,176,177],{"class":70}," -",[60,179,181],{"class":180},"sDGX8","1",[60,183,184],{"class":70},",\n",[60,186,188],{"class":62,"line":187},4,[60,189,190],{"class":70},"}\n",[60,192,194],{"class":62,"line":193},5,[60,195,197],{"emptyLinePlaceholder":196},true,"\n",[60,199,201,203,206,209,212,215],{"class":62,"line":200},6,[60,202,141],{"class":140},[60,204,205],{"class":144}," function",[60,207,208],{"class":84}," sync",[60,210,211],{"class":70},"(): ",[60,213,214],{"class":155},"void",[60,216,217],{"class":70}," {\n",[60,219,221,224,227,230,233,236,239,241,243,245,247,249,251,253,255,257,259,262],{"class":62,"line":220},7,[60,222,223],{"class":140},"    for",[60,225,226],{"class":70}," (",[60,228,229],{"class":144},"const",[60,231,232],{"class":148}," entry",[60,234,235],{"class":144}," of",[60,237,238],{"class":66}," kernel",[60,240,71],{"class":70},[60,242,74],{"class":66},[60,244,71],{"class":70},[60,246,79],{"class":66},[60,248,71],{"class":70},[60,250,85],{"class":84},[60,252,88],{"class":70},[60,254,91],{"class":66},[60,256,149],{"class":66},[60,258,71],{"class":70},[60,260,261],{"class":66},"seq",[60,263,264],{"class":70}," })) {\n",[60,266,268,271,273,276,278,281,284,287],{"class":62,"line":267},8,[60,269,270],{"class":66},"        state",[60,272,71],{"class":70},[60,274,275],{"class":66},"entries",[60,277,71],{"class":70},[60,279,280],{"class":84},"push",[60,282,283],{"class":70},"(",[60,285,286],{"class":66},"entry",[60,288,289],{"class":70},")\n",[60,291,293,295,297,299,302,304,306,309,311],{"class":62,"line":292},9,[60,294,270],{"class":66},[60,296,71],{"class":70},[60,298,261],{"class":66},[60,300,301],{"class":70}," = ",[60,303,286],{"class":66},[60,305,71],{"class":70},[60,307,308],{"class":66},"time",[60,310,71],{"class":70},[60,312,313],{"class":66},"seq\n",[60,315,317],{"class":62,"line":316},10,[60,318,319],{"class":70},"    }\n",[60,321,323],{"class":62,"line":322},11,[60,324,190],{"class":70},[14,326,327],{},"Read it twice, because the important property isn't obvious the first time.",[14,329,330,331,334,335,338,339,342,343,346,347,334,350,352,353,355],{},"On a ",[20,332,333],{},"cold boot",", ",[25,336,337],{},"state.seq"," is ",[25,340,341],{},"-1",", so ",[25,344,345],{},"sync()"," folds the entire history into\nmemory. On a ",[20,348,349],{},"steady-state tick",[25,351,337],{}," is the high-water mark from the last\ntick, so ",[25,354,345],{}," folds only what arrived since.",[14,357,358],{},"Those are the same call. Hydration and iteration are not two code paths that must be kept\nin agreement — they are one operation with a different cursor. There is no separate\n\"restore from disk\" routine to drift out of sync with the live one, because there is no\nseparate routine.",[14,360,361,362,364],{},"The cursor also makes it idempotent. Calling ",[25,363,345],{}," twice folds nothing the second\ntime.",[43,366,368],{"id":367},"why-the-model-is-the-log","Why the model is the log",[14,370,371,373,374,377],{},[25,372,129],{}," holds its context as ",[25,375,376],{},"AxonEntry[]"," — the log, folded into memory, and nothing\nmore. That looks lazy. It is the opposite.",[14,379,380],{},"A model shaped like the log is:",[14,382,383,386,387,389,390,392],{},[20,384,385],{},"Trivially rebuildable."," Cold boot is ",[25,388,345],{}," from ",[25,391,341],{},". No snapshot format, no\nmigration, no version skew between what was persisted and what the code now expects.",[14,394,395,398,399,402],{},[20,396,397],{},"Trivially verifiable."," The resident model must equal ",[25,400,401],{},"store.session.get()",". That's an\nassertion you can actually write, and a class of bug that stops existing.",[14,404,405,408],{},[20,406,407],{},"Free of its own schema."," There's no second representation to design, document, or\nkeep in agreement with the first. The log is already the interchange format for the\nentire platform — every observer, the TUI, the event pipeline, and replay all read the\nsame entries.",[14,410,411],{},"Derived structure — summaries, indexes, embeddings, a spatial map — earns its place the\nday the cognet actually needs it, not before. When it does, it's still a projection: it\nrebuilds from the same replay, and losing it costs a re-fold.",[43,413,415,416,419],{"id":414},"why-stimuli-goes-unused","Why ",[25,417,418],{},"stimuli"," goes unused",[14,421,422,423,425,426,428],{},"Every wake hands the loop body a ",[25,424,418],{}," diff. ",[25,427,129],{}," ignores it:",[51,430,432],{"className":53,"code":431,"language":55,"meta":56,"style":56},"loop(async ({ signal, stop }) => {\n    await phase(\"sync\", async () => {\n        sync()\n    })\n    \u002F\u002F ...\n})\n",[25,433,434,463,488,496,501,506],{"__ignoreMap":56},[60,435,436,439,441,444,447,450,452,455,458,461],{"class":62,"line":63},[60,437,438],{"class":84},"loop",[60,440,283],{"class":70},[60,442,443],{"class":144},"async",[60,445,446],{"class":70}," ({ ",[60,448,449],{"class":66},"signal",[60,451,334],{"class":70},[60,453,454],{"class":66},"stop",[60,456,457],{"class":70}," }) ",[60,459,460],{"class":144},"=>",[60,462,217],{"class":70},[60,464,465,468,471,473,477,479,481,484,486],{"class":62,"line":162},[60,466,467],{"class":140},"    await",[60,469,470],{"class":84}," phase",[60,472,283],{"class":70},[60,474,476],{"class":475},"sKc5r","\"sync\"",[60,478,334],{"class":70},[60,480,443],{"class":144},[60,482,483],{"class":70}," () ",[60,485,460],{"class":144},[60,487,217],{"class":70},[60,489,490,493],{"class":62,"line":171},[60,491,492],{"class":84},"        sync",[60,494,495],{"class":70},"()\n",[60,497,498],{"class":62,"line":187},[60,499,500],{"class":70},"    })\n",[60,502,503],{"class":62,"line":193},[60,504,505],{"class":100},"    \u002F\u002F ...\n",[60,507,508],{"class":62,"line":200},[60,509,510],{"class":70},"})\n",[14,512,513,514,517,518,521],{},"Not an oversight. For a log-derived mind, ",[20,515,516],{},"the log tail is the diff."," Stimuli arrive in\nthe log. So do the cognet's own outputs. So do action results the kernel committed on its\nbehalf. One door, one fold, one ordering — and the results of last tick's ",[25,519,520],{},"run()"," re-enter\nthe model by exactly the same path a user message does.",[14,523,524,525,527,528,530],{},"A cognet that folded ",[25,526,418],{}," separately would have two ingestion paths to keep\nconsistent. ",[25,529,129],{}," has one.",[43,532,534,537],{"id":533},"kill-9-costs-nothing",[25,535,536],{},"kill -9"," costs nothing",[14,539,540],{},"This is the property everything above was built to produce.",[14,542,543,544,546,547,549],{},"Kill the process at any moment. Resident memory vanishes — the folded entries, the\ncursor, every intermediate the brain was holding. Restart it. ",[25,545,345],{}," runs from ",[25,548,341],{},",\nthe model reconstitutes from the durable record, and the cognet resumes.",[14,551,552],{},"Nothing was authoritative in RAM, so nothing authoritative was lost. There is no\nshutdown hook that must run, no flush that must complete, no window during which a crash\ncorrupts state. Durability isn't something the cognet participates in; it's a property of\nthe log, which the cognet cannot write to anyway.",[14,554,555],{},"For a long-running agent this is convenient. For an embodied system that can lose power\nmid-decision, it's the difference between a design that works and one that doesn't.",[43,557,559],{"id":558},"the-private-store","The private store",[14,561,562],{},"Some cognitive state genuinely isn't log-derived — a learned weight, a consolidated\nsummary, a cache that costs real time to rebuild. For that there's a private key\u002Fvalue\nstore, namespaced per cognet:",[51,564,566],{"className":53,"code":565,"language":55,"meta":56,"style":56},"await kernel.store.set(\"checkpoint\", { seq: state.seq, savedAt: Date.now() })\nconst checkpoint = await kernel.store.get(\"checkpoint\")  \u002F\u002F null when absent\n",[25,567,568,617],{"__ignoreMap":56},[60,569,570,573,575,577,579,581,584,586,589,592,595,597,599,601,603,606,609,611,614],{"class":62,"line":63},[60,571,572],{"class":140},"await",[60,574,238],{"class":66},[60,576,71],{"class":70},[60,578,74],{"class":66},[60,580,71],{"class":70},[60,582,583],{"class":84},"set",[60,585,283],{"class":70},[60,587,588],{"class":475},"\"checkpoint\"",[60,590,591],{"class":70},", { ",[60,593,594],{"class":66},"seq:",[60,596,149],{"class":66},[60,598,71],{"class":70},[60,600,261],{"class":66},[60,602,334],{"class":70},[60,604,605],{"class":66},"savedAt:",[60,607,608],{"class":66}," Date",[60,610,71],{"class":70},[60,612,613],{"class":84},"now",[60,615,616],{"class":70},"() })\n",[60,618,619,621,624,626,628,630,632,634,636,638,640,642,645],{"class":62,"line":162},[60,620,229],{"class":144},[60,622,623],{"class":148}," checkpoint",[60,625,301],{"class":70},[60,627,572],{"class":140},[60,629,238],{"class":66},[60,631,71],{"class":70},[60,633,74],{"class":66},[60,635,71],{"class":70},[60,637,85],{"class":84},[60,639,283],{"class":70},[60,641,588],{"class":475},[60,643,644],{"class":70},")  ",[60,646,647],{"class":100},"\u002F\u002F null when absent\n",[14,649,650],{},"Type it by declaration merging:",[51,652,654],{"className":53,"code":653,"language":55,"meta":56,"style":56},"declare global {\n    interface CognetStoreSchema {\n        checkpoint: { seq: number; savedAt: number }\n    }\n}\n",[25,655,656,666,676,704,708],{"__ignoreMap":56},[60,657,658,661,664],{"class":62,"line":63},[60,659,660],{"class":144},"declare",[60,662,663],{"class":66}," global",[60,665,217],{"class":70},[60,667,668,671,674],{"class":62,"line":162},[60,669,670],{"class":144},"    interface",[60,672,673],{"class":155}," CognetStoreSchema",[60,675,217],{"class":70},[60,677,678,681,684,686,688,691,694,697,699,701],{"class":62,"line":171},[60,679,680],{"class":66},"        checkpoint",[60,682,683],{"class":70},": { ",[60,685,261],{"class":66},[60,687,152],{"class":70},[60,689,690],{"class":155},"number",[60,692,693],{"class":70},"; ",[60,695,696],{"class":66},"savedAt",[60,698,152],{"class":70},[60,700,690],{"class":155},[60,702,703],{"class":70}," }\n",[60,705,706],{"class":62,"line":187},[60,707,319],{"class":70},[60,709,710],{"class":62,"line":193},[60,711,190],{"class":70},[14,713,714,715,718,719,722],{},"Writes are atomic and resolve when durable. Reads return ",[25,716,717],{},"null"," when absent ",[20,720,721],{},"or\nunreadable"," — cache doctrine: rebuild, don't crash. That's a deliberate contract. If\nlosing a key can break your cognet, it belonged in the log.",[14,724,725,726,728,729,731],{},"The kernel owns the mechanism entirely. Files today, something else tomorrow, invisible\nto the cognet either way — the contract is ",[25,727,85],{},"\u002F",[25,730,583],{},", not paths.",[14,733,734,736],{},[25,735,129],{}," uses it for exactly one thing: a cursor checkpoint that proves the wiring works.\nIt is never load-bearing. Delete it and the cost is one full re-fold.",[43,738,740],{"id":739},"the-rule","The rule",[742,743,744],"blockquote",{},[14,745,746],{},"Anything that cannot be rebuilt from the log is state you are choosing to be\nresponsible for.",[14,748,749],{},"Resident memory: free to lose. The log: the kernel's problem, not yours. The private\nstore: yours, and it should stay small enough that losing it is an inconvenience rather\nthan an outage.",[14,751,752],{},"Most cognets need nothing beyond the first two.",[754,755,756],"style",{},"html pre.shiki code .s3F5K, html code.shiki .s3F5K{--shiki-default:#9CDCFE}html pre.shiki code .sTNBD, html code.shiki .sTNBD{--shiki-default:#D4D4D4}html pre.shiki code .sCudf, html code.shiki .sCudf{--shiki-default:#DCDCAA}html pre.shiki code .sOLPB, html code.shiki .sOLPB{--shiki-default:#6A9955}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html pre.shiki code .sYbnZ, html code.shiki .sYbnZ{--shiki-default:#C586C0}html pre.shiki code .scz_3, html code.shiki .scz_3{--shiki-default:#569CD6}html pre.shiki code .s9McN, html code.shiki .s9McN{--shiki-default:#4FC1FF}html pre.shiki code .sNl3T, html code.shiki .sNl3T{--shiki-default:#4EC9B0}html pre.shiki code .sDGX8, html code.shiki .sDGX8{--shiki-default:#B5CEA8}html pre.shiki code .sKc5r, html code.shiki .sKc5r{--shiki-default:#CE9178}",{"title":56,"searchDepth":162,"depth":162,"links":758},[759,760,761,762,764,766,767],{"id":45,"depth":162,"text":46},{"id":122,"depth":162,"text":123},{"id":367,"depth":162,"text":368},{"id":414,"depth":162,"text":763},"Why stimuli goes unused",{"id":533,"depth":162,"text":765},"kill -9 costs nothing",{"id":558,"depth":162,"text":559},{"id":739,"depth":162,"text":740},"The log-shaped mind — why cold boot and a steady-state tick are the same operation.","md",{},"\u002Fdocs\u002Fv2\u002Fcognets\u002Fengine\u002Fmemory",{"title":5,"description":768},"docs\u002Fv2\u002Fcognets\u002Fengine\u002Fmemory","Zh4PIU2N2xL4X2tQsZzcf6T_x_HCCpOwS0GZkgenOv4",1785156432065]