[Bug]: cascade row stays processing forever when its terminal write (mark_failed / mark_done) fails once
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
调研方向
Start with _process_one in src/everos/memory/cascade/worker.py and trace how terminal-write failures interact with scanning in reconciler.py and claims and orphan recovery in md_change_state.py. Run the replay test described in the issue, which injects a one-time failure into mark_failed and mark_done. Done means a transient terminal-write failure no longer leaves a row stuck in processing.
由索引模型根据 Issue 内容生成。
描述
Area
src/everos
What happened?
_process_one writes the row's terminal state from inside its except branches (src/everos/memory/cascade/worker.py:854-892: mark_failed; and mark_done after a successful handler run). When that terminal write itself raises once (database is locked under contention with the watcher, scanner or a CLI cascade sync), the exception propagates out of the task, drain_once's gather raises, _run_loop logs cascade_worker_drain_failed and carries on. Nothing retries the terminal write:
- the scanner skips a
processingrow whose mtime is unchanged (reconciler.py:96-102); - claims take only
pendingrows (md_change_state.py:230-294); recover_orphan_processingruns at startup only (:374-390).
The row stays processing until the process restarts or the md is edited; cascade status counts it as pending forever; /health stays green (one drain exception is below _DRAIN_FAILURE_ALERT_THRESHOLD = 3, and the next drains succeed with nothing to claim). For the mark_done case the index is already correct and only the row is stuck; for the mark_failed case the failure is also never shown by cascade fix. Item 5 of #542, now replayed.
Expected: a row leaves processing on every path (the terminal write is retried, or a stale processing row is reclaimed).
Steps to reproduce
Real scanner / worker / EpisodeHandler / repositories; the embedder raises an unrecoverable error for one file (bad) and works for the other (good); mark_failed and mark_done are wrapped to raise database is locked on their first call only.
- Both files scanned:
{'pending': 2}.drain_once()raisesRuntimeError: sqlite3.OperationalError: database is locked (in mark_failed). - After the drain:
bad row=processing, good row=processing, good index rows=1(good's index write landed, only its terminal write was lost). - Three more
scan_once()+drain_once()passes: no decisions, nothing claimed, both rows stillprocessing;worker.health().reasons() == []. - Control:
recover_orphan_processing()(a restart) returns 2, the next drain landsbad row=failed/retryable=False, good row=done.
replay test (~2 s, real scanner / worker / EpisodeHandler / SQLite / LanceDB; put both files in one directory and run uv run pytest <test file> -q -s)
test_replay_5_mark_failed_raises.py:
"""Replay of #542 item 5: when ``mark_failed`` (or ``mark_done``) itself fails once,
the row stays ``processing`` for good.
``_process_one`` calls ``mark_failed`` inside its ``except`` branch
(worker.py:854-892); an exception there propagates out of the task, ``drain_once``'s
``gather`` raises, ``_run_loop`` logs ``cascade_worker_drain_failed`` and carries
on. Nothing retries the terminal write: the scanner skips a ``processing`` row whose
mtime is unchanged (reconciler.py:96-102) and claims take only ``pending``. The row
sits in ``processing`` (shown as ``pending`` by ``cascade status``) until a restart
(``recover_orphan_processing``) or an edit of the md. Same for ``mark_done``, with
the index already correct.
Run: uv run pytest .work_context/replay_542/test_replay_5_mark_failed_raises.py -q -s
"""
from __future__ import annotations
import asyncio
from typing import Any
from unittest import mock
from _harness import DIM, Harness
from everos.component.embedding import EmbeddingProvider
M = 1_700_000_000.0
class _Embedder(EmbeddingProvider):
"""Raises an unrecoverable error for texts carrying ``BAD``."""
dim = DIM
async def embed(self, text: str) -> list[float]:
if "BAD" in text:
raise RuntimeError("unrecoverable: cannot embed this entry")
return [0.1] * DIM
async def embed_batch(self, texts: Any) -> list[list[float]]:
return [await self.embed(t) for t in texts]
def _raise_once(real: Any, name: str) -> Any:
calls = {"n": 0}
async def flaky(*a: Any, **k: Any) -> Any:
calls["n"] += 1
if calls["n"] == 1:
raise RuntimeError(
f"sqlite3.OperationalError: database is locked (in {name})"
)
return await real(*a, **k)
return flaky
async def _replay() -> None:
h = await Harness().open(_Embedder())
try:
worker = h.worker()
# bad: the handler fails unrecoverably; good: it succeeds
await h.write("bad", 1, "BAD content", M)
await h.write("good", 2, "fine content", M)
await h.scanner.scan_once()
assert (await h.counts()) == {"pending": 2}
with (
mock.patch.object(
h.state_repo,
"mark_failed",
_raise_once(h.state_repo.mark_failed, "mark_failed"),
),
mock.patch.object(
h.state_repo,
"mark_done",
_raise_once(h.state_repo.mark_done, "mark_done"),
),
):
try:
await worker.drain_once()
raised = None
except (
Exception
) as exc: # what _run_loop catches and logs as cascade_worker_drain_failed
raised = f"{type(exc).__name__}: {exc}"
await asyncio.sleep(0.2) # let the sibling task in the gather finish
print(f" drain_once raised: {raised}")
rb, rg = await h.row("bad"), await h.row("good")
print(
f" after the drain: bad row={rb.status}, good row={rg.status}, good index rows={await h.indexed('good')}"
)
assert rb.status == "processing" and rg.status == "processing"
assert (await h.indexed("good")) == 1, (
"good's index write landed; only the terminal write was lost"
)
# later scans and drains never touch them: mtime unchanged + processing -> scanner skips; claims take only pending
for _ in range(3):
decisions = await h.scanner.scan_once()
assert not decisions
assert (await worker.drain_once()) == 0
rb, rg = await h.row("bad"), await h.row("good")
print(
f" after 3 scan+drain passes: bad row={rb.status}, good row={rg.status}, counts={await h.counts()}"
)
assert rb.status == "processing" and rg.status == "processing"
health = worker.health()
print(f" worker health reasons: {health.reasons()!r}")
# control: a restart's orphan recovery frees them (mark_failed / mark_done work from now on)
n = await h.state_repo.recover_orphan_processing()
await worker.drain_once()
rb, rg = await h.row("bad"), await h.row("good")
print(
f" control, after restart recovery ({n} rows) + drain: bad row={rb.status}/retryable={rb.retryable}, good row={rg.status}"
)
assert rb.status == "failed" and rb.retryable is False and rg.status == "done"
finally:
await h.close()
def test_terminal_write_failing_once_leaves_the_row_processing_for_good() -> None:
asyncio.run(_replay())
_harness.py:
"""Shared harness for the #542 replays: real scanner / worker / EpisodeHandler on a
temp memory root, real ``md_change_state`` repository (temp SQLite), real LanceDB
table; the embedder is injected per replay, the tokenizer is a stand-in."""
from __future__ import annotations
import datetime as dt
import shutil
import tempfile
from pathlib import Path
from typing import Any
from unittest import mock
from sqlmodel import SQLModel
import everos.component.embedding.accessor as acc
from everos.component.embedding import EmbeddingCapability, EmbeddingProvider
from everos.component.tokenizer import Tokenizer
from everos.config import LanceDBSettings, SqliteSettings
from everos.core.persistence import (
MemoryRoot,
create_session_factory,
create_system_engine,
)
from everos.core.persistence.lancedb import LanceRepoBase, open_lancedb_connection
from everos.infra.persistence.index import Episode
from everos.infra.persistence.lancedb.repos.episode import _EpisodeRepo
from everos.infra.persistence.markdown import EpisodeWriter
from everos.infra.persistence.predicate import eq
from everos.infra.persistence.sqlite.repos.md_change_state import _MdChangeStateRepo
from everos.memory.cascade import scanner as scanner_mod
from everos.memory.cascade import worker as worker_mod
from everos.memory.cascade.handlers import HandlerDeps
from everos.memory.cascade.handlers.episode import EpisodeHandler
from everos.memory.cascade.scanner import CascadeScanner
from everos.memory.cascade.worker import CascadeWorker
DATE = dt.date(2026, 5, 14)
DIM = 1024
class _Tokenizer(Tokenizer):
def tokenize(self, text: str) -> list[str]:
return [t for t in text.split() if t]
def tokenize_batch(self, texts: Any) -> list[list[str]]:
return [self.tokenize(t) for t in texts]
def entry(owner: str, n: int, content: str) -> tuple[dict[str, Any], dict[str, Any]]:
return (
{
"owner_id": owner,
"session_id": "s1",
"timestamp": "2026-05-14T10:00:00+00:00",
"parent_type": "memcell",
"parent_id": f"mc_{n}",
"sender_ids": [owner],
},
{"Subject": "T", "Summary": "S", "Content": content},
)
def rel(owner: str) -> str:
return f"default_app/default_project/users/{owner}/episodes/episode-{DATE.isoformat()}.md"
class Harness:
def __init__(self) -> None:
self.tmp = Path(tempfile.mkdtemp(prefix="replay542_"))
self.root = MemoryRoot(self.tmp / "root")
self.root.ensure()
self.engine = create_system_engine(self.root.system_db, SqliteSettings())
self.factory = create_session_factory(self.engine)
self.state_repo = _MdChangeStateRepo(session_factory=self.factory)
self.index: Any = None
self.patches: list[Any] = []
self.writer = EpisodeWriter(self.root)
self.scanner = CascadeScanner(self.root, scan_interval_seconds=3600.0)
async def open(self, embedder: EmbeddingProvider) -> Harness:
async with self.engine.begin() as conn:
await conn.run_sync(SQLModel.metadata.create_all)
LanceRepoBase._reset_locks_for_tests()
conn = await open_lancedb_connection(self.root.lancedb_dir, LanceDBSettings())
table = await conn.create_table(Episode.TABLE_NAME, schema=Episode)
self.index = _EpisodeRepo(table=table)
acc._capability = EmbeddingCapability(provider=embedder)
self.patches = [
mock.patch.object(scanner_mod, "md_change_state_repo", self.state_repo),
mock.patch.object(scanner_mod, "get_session_factory", lambda: self.factory),
mock.patch.object(worker_mod, "md_change_state_repo", self.state_repo),
mock.patch.object(EpisodeHandler, "index_repo", self.index),
]
for p in self.patches:
p.start()
return self
def handler(self) -> EpisodeHandler:
return EpisodeHandler(
HandlerDeps(memory_root=self.root, tokenizer=_Tokenizer())
)
def worker(self, **overrides: Any) -> CascadeWorker:
kw: dict[str, Any] = dict(
batch_size=10,
handler_concurrency=2,
max_retry=0,
retry_backoff_seconds=0.0,
poll_interval_seconds=3600.0,
optimize_min_interval_seconds=0.0,
optimize_heartbeat_seconds=3600.0,
optimize_rebuild_interval_seconds=3600.0,
)
kw.update(overrides)
return CascadeWorker({"episode": self.handler()}, **kw)
async def write(self, owner: str, n: int, content: str, mtime: float) -> Path:
await self.writer.append_entries(owner, [entry(owner, n, content)], date=DATE)
path = self.root.root / rel(owner)
import os
os.utime(path, (mtime, mtime))
return path
async def row(self, owner: str) -> Any:
return next(
(r for r in await self.state_repo.list_all() if r.md_path == rel(owner)),
None,
)
async def counts(self) -> dict[str, int]:
out: dict[str, int] = {}
for r in await self.state_repo.list_all():
out[r.status] = out.get(r.status, 0) + 1
return out
async def indexed(self, owner: str) -> int:
return len(await self.index.find_where(eq("md_path", rel(owner))))
async def close(self) -> None:
for p in self.patches:
p.stop()
await self.engine.dispose()
shutil.rmtree(self.tmp, ignore_errors=True)
Relation to other issues
#542 item 5; a lease on processing rows (last_attempt_at age) would also cover #545's startup-recovery variant.
Environment
OS: macOS 15 (Darwin 24.6.0)
Python: 3.12
Commit: 5b0979b (v1.5.1)
Possible fixes (not decided)
- Retry the terminal write (bounded, with backoff) inside
_process_one, and if it still fails leave the rowpendingrather thanprocessing. - Treat a
processingrow older than a lease as orphaned inclaim_pending_batch/ the scanner, so a lost terminal write heals on the next drain instead of the next restart.
- 主要语言
- Python
- 星标
- 13.3k
- 派生
- 926
- 平均合并
- 19 小时 14 分钟
- 30 天内合并 PR
- 27
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
EverMind-AI/EverOS 的其他 Issue
-
难度 2/5 半天 新手友好度 62/100
EverMind-AI/EverOS#414 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 25/100
EverMind-AI/EverOS#558 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 67/100
EverMind-AI/EverOS#551 ·
维护者通常 1 天内回复
-
[Bug]: cascade retry budget is forgotten by a restart during the inline backoff; a row can retry forever without becoming failed可能已有人在做 @feiiiiii5 于 4 天前认领。 未关闭bug
难度 4/5 3-5 天 新手友好度 56/100
EverMind-AI/EverOS#549 ·
维护者通常 1 天内回复
-
[Bug]: one hung cascade handler stalls the whole projection while /health stays healthy可能已有人在做 @feiiiiii5 于 1 天前认领。 未关闭bug
难度 4/5 3-5 天 新手友好度 52/100
EverMind-AI/EverOS#547 ·
维护者通常 1 天内回复
查看 EverMind-AI/EverOS 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
FinanceFlash/unvibecode#509 ·
-
难度 1/5 1 小时以内 新手友好度 82/100
FAIRmat-NFDI/nomad-distro-dev#161 ·
-
bug v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/python-sdk#3821 · 1 条评论 ·
维护者通常 1 天内回复
-
bug severity:low
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 2 天内回复
-
Log-odds calibration uses upper middle score instead of median for even candidate sets可能已有人在做 @flysheep-ai 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复