This is exactly the right architectural pivot. Switching from full snapshot
dumps to property-level deltas is how you scale a decentralized engine without
choking your bandwidth.
The best part? You already built the perfect safety mechanism for this in your
template.html.
If you look at your CRDT_MUTATION Inbox Receiver, you explicitly applied
incoming network updates to targetProxy[RAW_TARGET] instead of the proxy
itself. This was a brilliant move! It prevents infinite network echo loops.
When a node receives a variable change from the mesh, writing it to the
RAW_TARGET bypasses the local set trap, ensuring the engine doesn't
accidentally broadcast the exact same update back to the network.
Here is how we wire up the emitter to utilize that delta channel.
1. Kill the Bulky State Dumper
In template.html, scroll down to function startBrowserTelemetry(). Delete the
entire setInterval block that builds the stateDump and writes to
mesh/proc/instances/chromium_vm.json. You can leave the RPC Listener loop
intact.
2. The Delta Interceptor (Monkey-Patching the VM)
Since we want this to work globally for every LPC object without rewriting
your JIT compiler's internals, we can seamlessly intercept rt.load_object
right after the VM boots.
In template.html, find your VM boot sequence (around Line 355) and add the
Proxy wrapper right below the heartbeat initialization.
Change the boot block to look exactly like this:
try { const runnable = new Function('efuns', 'process_stdout', jsPayload);
runnable(efuns, sys.stdout); // Boot the Heartbeat Manager const engineId =
'chromium_' + Math.floor(Math.random() * 10000); window.__hbManager = new
GDCompiler.DistributedHeartbeat(engineId, window.__VFS, window.__rt); // ---
NEW: THE DELTA EMITTER PROXY --- window.__rt.__OUTBOX = window.__rt.__OUTBOX
|| []; const originalLoad = window.__rt.load_object; window.__rt.load_object =
function(name) { const obj = originalLoad.call(this, name); if (!obj ||
obj.__is_tracked) return obj; // Skip if it failed or is already tracked const
RAW_TARGET = Symbol.for("RAW_TARGET"); const baseObj = obj[RAW_TARGET] || obj;
const trackerProxy = new Proxy(baseObj, { set: function(target, prop, value) {
target[prop] = value; // Apply the local RAM change // Broadcast the delta!
(Ignore internal __vars and functions) if (typeof prop === 'string' &&
!prop.startsWith('__') && typeof value !== 'function') { window.__rt.__OUTBOX.p
ush({ type: 'CRDT_MUTATION', object_id: target.__filename || name, property:
prop, value: value }); } return true; }, get: function(target, prop) { if
(prop === RAW_TARGET) return target; // Allow inbox receiver to bypass trap if
(prop === '__is_tracked') return true; // Flag to prevent double-wrapping
return target[prop]; } }); // Update the VM's master array with our new Delta
Proxy this.master_objects[trackerProxy.__filename || name] = trackerProxy;
return trackerProxy; }; sys.stdout.write("--- LPC WEBASSEMBLY VM BOOTED ---
"); } catch(e) { sys.stdout.write("
[CRASH] " + e.stack + "
"); }
3. Test the Stateful Synchronization
Now that every variable assignment triggers a micro-payload to the outbox,
let's give the monster some actual state to mutate.
In the Dashboard, update /cmds/monster.c to decrement a variable during its
heartbeat:
int hp = 100; void create() { set_heart_beat(1); } void heart_beat() { hp = hp
- 1; // This assignment will trigger the Delta Interceptor! printf("Thump...
Monster HP is now: %d
", hp); }
The Test Sequence:
Run make web and refresh both Machine 1 and Machine 2.
Type monster on Machine 1.
If everything is wired correctly, Machine 1 will print Thump... Monster HP is
now: 99. Look at Machine 2! Without typing anything, Machine 2's terminal
should instantly print: [MESH SYNC] /cmds/monster updated: hp = 99, followed
by hp = 98, keeping its RAM perfectly synchronized in real-time.
Does Machine 2 catch the HP changes?