Entities become silently unreachable after `deleteEntity`+respawn or `agents stop`/`start` — stale wake/runner bindings
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 冷清
- 技术栈
- docker, postgresql, typescript
调研方向
首先通过 electric-ax agents CLI 以及对 registerTypes()、spawnEntity()、deleteEntity() 和 sendEntityMessage() 的 bridge 调用,复现这两个触发器。结合列出的 PostgreSQL 表,跟踪 agents-server 的 wake/runner 生命周期及其进程内存状态。完成标准是:重启和使用相同 URL 的 respawn 能保留活动 binding,清理过期状态,并且没有活动 binding 的消息绝不会静默收到 204。
由索引模型根据 Issue 内容生成。
描述
Summary
There are two ways to leave a spawned entity silently unreachable. In both, the entity row exists in postgres and the agents UI shows the entity as present, but messages sent to it are never processed. The two have different triggers and slightly different failure signatures, but they look like the same underlying problem: the wake/runner binding for an entity URL is not reconciled, so the entity is "alive" in storage but has nothing wired up to actually run its handler.
Filing them together because a fix for one likely addresses the other.
Environment
@electric-ax/agents-runtime0.2.2@electric-ax/durable-streams-client-beta0.3.1agents-server0.4.x (localelectric-ax agentsDocker stack)electric-axCLI 0.2.2- macOS, Docker Desktop
Setup in all repros: a long-running host process ("the bridge") that calls registerTypes() to register entity types against its own webhook URL, then spawns entities and relays messages to them.
Trigger 1 — entities unreachable after agents stop && agents start (no volume wipe)
Repro
- Start the stack:
electric-ax agents start. - From the bridge:
registerTypes(), thenspawnEntity({ type, id }). Verify the entity wakes and processes asendEntityMessage(works). electric-ax agents stop(no--remove-volumes).electric-ax agents start.- Restart the bridge process.
sendEntityMessageto the entity → server returns HTTP 204, but no wake is ever dispatched to the bridge webhook. The entity never runs. A direct HTTP send to the entity's inbox endpoint behaves the same: 204, silent, no wake.
Scope
Only entities that existed at the moment of agents stop are affected. An entity spawned after the restart works normally — until the next stop.
Diagnostic that isolated it
Changing the entity id to a value that had never been used, then restarting the bridge, produced a fresh entity that woke normally. We then spawned a new entity inside that working post-restart session — it worked — and ran agents stop && agents start a second time. The new entity was now also dead. So the discriminator is the substrate stop event itself, not how recently the entity was spawned or which bridge process created it.
Reading
Entity state in postgres survives the restart intact. The wake-registration that binds "entity URL → webhook URL" is not rebound to the restarted bridge's webhook on agents start, so wake dispatch never fires.
Trigger 2 — entities unreachable after deleteEntity + respawn on the same URL
Repro
- Start the stack and spawn an entity; confirm it wakes on
sendEntityMessage(works). client.deleteEntity('/type/id')→ returns 2xx success.client.spawnEntity({ type, id })again on the same URL → returns success, no error.sendEntityMessageto that URL →409 {"code":"NOT_RUNNING","message":"Entity is stopped"}.
No agents stop is involved — this happens within a single substrate uptime.
What we investigated
- Postgres is not cleaned by
deleteEntity. After step 2,SELECT url FROM entities WHERE url LIKE '/type/%'still returns the row. - A direct SQL purge does not fix it. We
DELETEd the URL's rows directly across all 8 per-entity tables (entities,wake_registrations,entity_dispatch_state,entity_manifest_sources,scheduled_tasks,tag_stream_outbox,wake_notifications,consumer_claims), then respawned. The send still returns409. entity_dispatch_stateis half-initialized after respawn. The row exists, but everyactive_*column (active_consumer_id,active_runner_id,active_epoch,active_claimed_at,active_lease_expires_at) isNULL— no runner is bound.- Only a process restart clears it.
electric-ax agents stop --remove-volumes && electric-ax agents startlets a fresh spawn on the same URL work again. Since a clean postgres alone (via the SQL purge above) does not fix it, the broken state appears to live in agents-server process memory, not in postgres.
Common thread
In both cases: the entity row exists, postgres looks normal, the agents UI shows the entity — but no runner/wake binding is actually live for it. A full process restart of agents-server is the only thing that reliably clears the bad state.
Worst-shaped part
Neither failure surfaces at spawn time. spawnEntity returns success and the agents UI shows the entity green. Trigger 1 is the worse of the two: an inbox write to an orphaned entity returns HTTP 204 — a success response — and the message is silently dropped. Application code has no signal that the message will never be processed. Trigger 2 at least returns an explicit 409.
Suggested fixes
- On
agents start, walk the entity registry and re-validate wake-registrations against the webhook URLs registered by the currentregisterTypes()calls. Rebind rows whose target entity still exists; drop rows whose entity is gone. Log a summary of rehydrated vs. dropped registrations. - Make
deleteEntitytruly destructive — clear postgres rows, in-process cache, and wake/runner bindings — so a URL is genuinely free for reuse; or makespawnEntityon a stale URL re-initialize the in-process lifecycle state and bind a runner. - At minimum: an inbox write or
sendEntityMessageto an entity with no live wake binding should return a loud error (e.g.409/503), never a silent204. A successful HTTP response should mean the message will actually be dispatched.
Workaround
In application code: never reuse an entity URL. Generate a unique suffix per session (e.g. /type/id-<sessionId>); old entities become dead rows in postgres but never collide with new ones. Also avoid agents stop && agents start on a substrate with live entities you still need. Both workarounds leak dead entity rows over time.
- 主要语言
- TypeScript
- 星标
- 10.4k
- 派生
- 399
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
electric-sql/electric 的其他 Issue
-
camelToSnake and snakeCamelMapper() drop the underscore when a digit precedes a camelCase boundary未关闭
难度 2/5 1-3 小时 新手友好度 85/100
electric-sql/electric#4855 ·
-
ShapeStream does not notify subscribers when it gives up on a non-Error value可能已有人在做 @Tyagiquamar 于 19 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
electric-sql/electric#4830 ·
-
@electric-sql/client throws SecurityError on import when the browser blocks site storage (typeof localStorage outside try)可能已有人在做 @mohanedmoh 于 37 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
electric-sql/electric#4826 · 1 条评论 ·
-
agents-chat-starter: spawn PUT goes to the durable-streams proxy, so no entity is created and agents never wake可能已有人在做 @adityavkk 于 133 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
electric-sql/electric#4687 ·
-
feature request triage
难度 2/5 1-3 小时 新手友好度 68/100
electric-sql/electric#4150 · 1 条评论 ·
查看 electric-sql/electric 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
software-mansion/argent#1946 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 63/100
podman-desktop/podman-desktop#20216 ·
维护者通常 1 天内回复
-
[Type] Bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 5 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
omdsh-dev/DSH-better-sidebar#1205 ·
维护者通常 3 天内回复