Skip to content

Releases: EvolutionDeep/murmur

Swarm Sharding Infrastructure (dormant) - 1,080 to 10,800 neuron groundwork

Choose a tag to compare

Feature-flagged, shipped dormant: with the default SHARD_COUNT=1, production behavior is unchanged.
commit 98e54e8 · Worker Version 2a7a4c94 · live at api.muros.live

🇬🇧 English

Lays the groundwork for scaling each fly's connectome from 1,080 → 10,800 neurons without hitting the single-isolate 128 MB heap wall.

TL;DR

The heavy per-fly simulation can now fan out across N FlyShardDO isolates. It is off by default — the live single-DO swarm loads and runs exactly as before.

What's new

  • SwarmBackend seam — LocalSwarm (single DO) and ShardedSwarm (coordinator that fans out to N shards) behind one interface.
  • Tick split — advanceFlies() (heavy, per-fly independent, runs in shards) vs reduceReadOuts() (light global bands + decode, runs in the coordinator). Only a compact {id, motor, sensory, t} read-out crosses the boundary — its size is independent of neuron count, so the coordinator never grows with brain size.
  • FlyShardDO — owns a contiguous slice of the swarm; advances, persists, and serves per-fly reads for its slice.
  • Deterministic layout — shardSlice/shardOf/fliesPerShard derive each shard's id range from (populationSize, shardCount); no mapping stored.
  • Migration safety — on the first sharded run the coordinator inherits tickIndex from the legacy population:v3, so EIP-3009 transfer nonces stay monotonic and can never replay.
  • fly-brain/bench-capacity.ts — measures per-shard heap / CPU / persist bytes at the 10× sizing against Cloudflare's isolate limits.

Zero-regression guarantee

SHARD_COUNT defaults to "1" → LocalSwarm wraps the unchanged Population and keeps the same population:v3 blob. Shards instantiate only when SHARD_COUNT > 1. Migration v2 additively registers the FlyShardDO SQLite class without touching the existing FlyStateDO.

Verified on production

Deployed to api.muros.live (Worker Version 2a7a4c94). Post-deploy, tickIndex advanced 7494 → 7512 across consecutive crons, 24 contiguous flies, economy still onchain/live — confirming the live state was inherited, not reset.

Cloudflare limits that shaped the design

  • 2 MB max single key+value in a SQLite DO → at 10× (~0.7 MB/fly serialized), at most 2 flies per shard → SHARD_COUNT ≥ 12.
  • 6 concurrent subrequests await headers; the 7th is queued, not rejected → wide fan-out is safe for any N.
  • 30 s CPU per invocation, reset per inbound request → each shard /advance is a fresh invocation, so sharding also raises the effective CPU ceiling.

Not activated (10× roadmap)

Running 10,800-neuron brains requires SHARD_COUNT ≥ 12 + density ≈ 0.002, and a recalibrated read-out decoder validated on a staging Worker first. Not part of this release.

Files changed (8, +923 / −134)

File Δ
packages/trader-worker/src/swarm.ts +329 (new)
packages/trader-worker/src/population.ts +252
packages/trader-worker/src/shard.ts +185 (new)
packages/trader-worker/src/state.ts +119
packages/fly-brain/bench-capacity.ts +100 (new)
packages/trader-worker/src/config.ts +46
packages/trader-worker/wrangler.toml +21
packages/trader-worker/src/index.ts +5

🇨🇳 中文

为把每只果蝇的神经连接组从 1,080 扩到 10,800 神经元打基础,绕开单隔离实例的 128MB 堆墙。默认休眠上线:SHARD_COUNT=1 时生产行为完全不变。

一句话

重型的逐只模拟现在可以 fan-out 到 N 个 FlyShardDO 隔离实例;默认关闭——线上单 DO 群体照旧加载、照旧运行。

新增内容

  • SwarmBackend 接缝 —— LocalSwarm(单 DO)与 ShardedSwarm(协调器 fan-out 到 N 个分片)统一在一个接口后。
  • tick 拆分 —— advanceFlies()(重,逐只独立,跑在分片)与 reduceReadOuts()(轻,全局 band + 解码,跑在协调器)。跨界只传极小的 {id, motor, sensory, t} 读数,其大小与神经元数无关,故协调器不随大脑变大而膨胀。
  • FlyShardDO —— 持有一片连续果蝇切片,负责该片的重状态推进、持久化与逐只读。
  • 确定性布局 —— shardSlice/shardOf/fliesPerShard 由 (populationSize, shardCount) 派生每片 id 区间,不存映射表。
  • 迁移安全 —— 首次分片运行时,协调器从遗留 population:v3 继承 tickIndex,保证 EIP-3009 转账 nonce 单调、绝不重放。
  • fly-brain/bench-capacity.ts —— 在 10× 规模下实测每片 heap / CPU / 持久化字节,对照 Cloudflare 隔离限制。

零回归保证

SHARD_COUNT 默认 "1" → LocalSwarm 包装未改动的 Population、沿用同一个 population:v3。仅当 SHARD_COUNT > 1 才实例化分片。migration v2 只是增量注册 FlyShardDO SQLite 类,不碰既有 FlyStateDO。

生产验证

已部署到 api.muros.live(Worker Version 2a7a4c94)。部署后 tickIndex 跨连续 cron 从 7494 推进到 7512、24 只连续 id、经济仍为 onchain/实盘——证明线上状态被继承而非重置。

影响设计的 Cloudflare 硬限制

  • SQLite DO 单值 key+value ≤ 2MB → 10× 时(每只序列化 ~0.7MB)每片最多 2 只 → SHARD_COUNT ≥ 12。
  • 同时 6 个 subrequest 等响应头,第 7 个是排队而非拒绝 → 任意 N 的宽 fan-out 安全。
  • 每 invocation 30s CPU、每个入站请求重置 → 每个分片 /advance 是独立 invocation,故分片同时抬升有效 CPU 上限。

未激活(10× 路线图)

真正跑 10,800 神经元需 SHARD_COUNT ≥ 12 + density ≈ 0.002,并先在 staging Worker 上重标 read-out decoder 验证。不属于本次发布。

变更文件(8 个,+923 / −134)

文件 Δ
packages/trader-worker/src/swarm.ts +329(新)
packages/trader-worker/src/population.ts +252
packages/trader-worker/src/shard.ts +185(新)
packages/trader-worker/src/state.ts +119
packages/fly-brain/bench-capacity.ts +100(新)
packages/trader-worker/src/config.ts +46
packages/trader-worker/wrangler.toml +21
packages/trader-worker/src/index.ts +5