Download Game! Currently 71 players. Last logged in:UglinessAnksLotheacMalcom

Blitzer's Blog >> 73033

Back to blogs index
Posted: 14 Oct 2026 17:00 [ permalink ]
Here is the LPC test script. Because save_object_bytecode serializes the
calling object's own blueprint, this script will effectively back up its own
genetic code to Cloudflare KV, wait for the network confirmation, pull the
code back down as a new blueprint, and clone a duplicate of itself.
Save this as tests/fixtures/kv_test.c:
void run_test() {
    int *msg;
    string status;
    string data;
    int new_clone;

    write("=== CF KV Distributed Bytecode Test ===
");
    write("1. Saving current bytecode to Cloudflare KV Edge...
");

    // Fire the async HTTP PUT to Cloudflare
    save_object_bytecode("kv://test_blueprint_v1");

    while(1) {
        // Suspend VM context (0% CPU) until Cloudflare responds
        msg = read_mail();
        
        if (msg != 0) {
            status = msg[0];
            data = msg[1];

            if (status == "KV_SAVE_OK") {
                write(">>> [SUCCESS] Bytecode stored in Cloudflare KV!
");
                write("2. Restoring bytecode from edge network...
");
                
                // Fire the async HTTP GET
                restore_object_bytecode("kv://test_blueprint_v1");
            } 
            else if (status == "KV_RESTORE_OK") {
                write(">>> [SUCCESS] Bytecode downloaded from edge!
");
                write("3. Cloning restored object...
");
                
                // The KV plugin automatically registers downloaded bytecode 
                // under the prefix 'kv_blueprint_' + key
                new_clone = clone_object("kv_blueprint_test_blueprint_v1");
                
                write(">>> [SUCCESS] Object materialized from edge memory!
");
                write("=== Test Complete ===
");
                return; // Exit loop, terminating the green-thread context
            }
            else {
                write(">>> [ERROR] Cloudflare KV Operation Failed: ");
                write(status);
                write("
");
                return;
            }
        }
    }
}

How to Run It
Boot your HAUKI REPL:
node src/repl/repl.js

Load the file and trigger the test:
load tests/fixtures/kv_test.c
call 0 run_test

What You Should See
 * The engine prints the initial write() statements and pauses. The virtual
CPU is actively yielding.
 * A fraction of a second later (depending on your ping to the nearest
Cloudflare edge node), the async network promise resolves. The KV plugin drops
the KV_SAVE_OK array into the object's mailbox and pushes the context back
onto the run queue.
 * The while(1) loop resumes, triggers the download, and goes back to sleep.
 * When KV_RESTORE_OK arrives, it calls clone_object on the newly injected AST
blueprint and successfully exits.
If this runs cleanly, your engine is now capable of live process migration. A
human or AI agent could design an object in one environment, serialize its AST
to the KV edge, and a completely different HAUKI server in another country
could download and materialize it instantly.