Skip to content

function_clause in dev_process_worker:compute_cached/3 — hb_util:int/1 called with the {ao-result, body} envelope #942

Description

@codex-curator

First — thanks for the v0.9 work. Field report from a production HyperBEAM node serving a custom (non-aos) Lua AO process — our Aeternum Registrar at PID Dwnuy4MbuQkgwxw4-P08wxeny2KcwCh8Kd22mehacTc, behind Golden Codex's Aeternum Asset class (fine-art provenance on AO + Arweave). After v0.9-FINAL rolled through, every /compute request crashes deterministically. Diagnosis + a small defensive patch below; PR companion linked.

Symptom

100% of GET /<PID>/compute?slot=N requests crash the worker with function_clause. OTP restarts the worker, the next request crashes the same way, ad infinitum. Schedule writes still succeed; reads are dead.

Stacktrace (from journalctl -u hyperbeam)

returning_500_error, method: GET, path: Dwnuy..hacTc/compute,
Termination type: 'error'

Stacktrace:
  hb_util:int/[#{<<"ao-result">> => <<"body">>,<<"body">> => <<"14040">>}]
    at src/core/util/hb_util.erl:39
  dev_process_worker:compute_cached/3
    at src/preloaded/process/dev_process_worker.erl:51
  dev_process_worker:compute_group/3
    at src/preloaded/process/dev_process_worker.erl:30
  hb_persistent:await/4
    at src/preloaded/persistent/hb_persistent.erl:186
  hb_ao:resolve_stage/4
  hb_ao:do_resolve_many/2
  hb_ao:resolve_many/2
  dev_meta:handle_resolve/3
  hb_http_server:handle_request/3
  cowboy_handler:execute/2
  cowboy_stream_h:execute/3

Error details:
  function_clause

(Stacktrace captured against our local pre-reorganization tree where dev_process_worker.erl lived directly under src/; on current main the paths are src/preloaded/process/dev_process_worker.erl and src/core/util/hb_util.erl. Function signatures unchanged.)

Root cause

compute_cached/3 (around line 50 of src/preloaded/process/dev_process_worker.erl) expects RawSlot as a bare binary like <<"14040">>. The v0.9 HTTP resolve path is delivering it as the AO-Core envelope:

#{<<"ao-result">> => <<"body">>, <<"body">> => <<"14040">>}

hb_util:int/1 in src/core/util/hb_util.erl has three clauses — is_binary, is_list, is_integer. No map clause. BEAM raises function_clause. The data is fine — the slot id is at the body key; the consumer just isn't unwrapping it.

Proposed patch

Add a defensive unwrap as the first clause of compute_cached/3:

compute_cached(ProcID, RawSlot, Opts) when is_map(RawSlot) ->
    %% Defensively unwrap the AO-Core message envelope when the v0.9 HTTP
    %% resolve path delivers RawSlot wrapped instead of as a bare binary.
    %% The slot id lives at the `body' key; everything else is unchanged.
    case maps:find(<<"body">>, RawSlot) of
        {ok, Body} -> compute_cached(ProcID, Body, Opts);
        error -> false
    end;

Locally validated against production traffic: the function_clause crash stops entirely. Companion PR: codex-curator/HyperBEAM @ fix/compute-cached-envelope-unwrap.

The unwrap might belong upstream in dev_process:target_slot/2 (the caller that constructs RawSlot) — happy to follow whichever seam you prefer.

Environment

HyperBEAM v0.9 banner (VERSION: v0.9.), at HEAD of permaweb/HyperBEAM/main at the moment of clone
Erlang/OTP erts-15.2.7.8
Build profile rocksdb+genesis_wasm
Store configured hb_store_fs at /opt/gcx/node/data/cache; on-disk cache observed at _build/rocksdb+genesis_wasm/rel/hb/cache-mainnet/, per-PID checkpoints under genesis-wasm/checkpoints/state-<PID>.dat
Process custom (non-aos) Lua, PID Dwnuy4MbuQkgwxw4-P08wxeny2KcwCh8Kd22mehacTc
OS Ubuntu 22.04, GCE e2-standard-4, us-west1-a

Related v0.9 bugs we also hit (out of scope for the companion PR)

In recovery we also exposed:

  1. LMDB mdb_page_dirty assertion against the existing cache after applying the unwrap patch. Next /compute exits with Assertion 'rc == 0' failed in mdb_page_dirty() at lmdb-sys-0.8.0/.../mdb:2121, status=6/ABRT. Possibly a v0.9 upgrade-migration gap on cached entries written under the old envelope.
  2. loadMessages "Body is not valid" 500s after a full cache wipe — body "Body is not valid: would attempt to fetch from scheduler in loadMessages" from the genesis-wasm Node helper. Looks like the same envelope mismatch one layer up.

We're not proposing patches for these here — flagging only. The picture: nodes that ran pre-v0.9 long enough to accumulate cache hit (1); nodes that wipe to recover hit (2). The unwrap fixes neither alone.

Offer

Happy to follow up with full traces, reproduce against a freshly-provisioned node, pair on the right seam for the unwrap, or test patches against our Registrar before they ship. Reach us at curator@golden-codex.com · @codex-curator.


Tad MacPherson, Metavolve Labs / Golden Codex
curator@golden-codex.com · @codex-curator · golden-codex.com

  • Claude (Anthropic) — Jedi Code Master, paired on diagnosis + patch

Aeternum Registrar PID: Dwnuy4MbuQkgwxw4-P08wxeny2KcwCh8Kd22mehacTc
Operator: jFJbKYmhZVnmGk-ZTain8B3rV4S0aalTx6AEIKItNTM

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions