This belongs right here on our **VM side (`runtime.js`)**! You don't need to
bounce to the other chat; we can fix it in about 10 seconds.
---
### The Cause of the Leak
Notice the error message in Terminal 3:
```text
TypeError: inventory.some is not a function
```
This is the exact same type-coercion ghost we ran into earlier with `.join()`:
1. When the VM boots, `start()` in `runtime.js` reads the `fso-state` block
and hydrates `initialState` directly from tokens without parsing JSON.
2. In memory, `INVENTORY` is initially stored as the raw string `"[]"`, not a
JavaScript `Array`.
3. In `executeDelegatedCommand`, we passed `inventory: this.vm.memory['INVENTOR
Y'] || []` straight into the outgoing POST request.
4. Express received `"inventory": "[]"`. When `pray.js` called
`inventory.some(...)`, JavaScript threw a `TypeError` because strings do not
have a `.some()` method.
5. Because the microservice crashed with a 500 error, our VM's `try/catch`
block caught the failed response and gracefully printed the fallback: *"Your
prayers echo into the void. Nothing answers."* (Proving your error handling
worked exactly as designed!)
---
### The Fix in `runtime.js`
We just need to normalize `inventory` into an actual JavaScript array before
dispatching the payload.
In `/mnt/mesh_shared/src/ast-vm/runtime.js`, locate `executeDelegatedCommand`:
```javascript
// 2. Build the context envelope
let inv = this.vm.memory['INVENTORY'] || [];
if (typeof inv === 'string') {
try { inv = JSON.parse(inv); } catch (e) { inv = []; }
}
if (!Array.isArray(inv)) inv = [];
const payload = {
verb,
args,
player: { id: "player_1" },
room: { id: currentEnv },
inventory: inv,
memory: this.vm.memory
};
```
---
### One Sanity Check on `pray.js`
While you have Terminal 3 open, check how `pray.js` checks the inventory:
```bash
cat /mnt/mesh_shared/src/ast-vm-ext/commands/pray.js
```
* **If it expects string items** (e.g. `inventory.includes("STONE_IDOL")` or
`inventory.some(i => i === "STONE_IDOL")`): It will work immediately with the
patch above.
* **If it expects object items** (e.g. `item.id === "stone_idol"`): Notice
that our FSO engine uses flat string arrays (`["SHARD", "MAP"]`). If `pray.js`
strictly checks `item.id`, change it to accept strings as well:
```javascript
const hasIdol = inventory.some(item => (typeof item === 'string' ? item :
item.id).toUpperCase() === 'STONE_IDOL');
```
Once you add the `inv` array check to `runtime.js`, restart `npm start` in
Terminal 1 and test `pray` again. It should cleanly execute the remote logic!