Delta压缩连续失败降级:整批转存archive低置信度记录(issue #165) #170
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/165-delta-compression-archive-fallback"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #165
What
从 issue #156 拆出的"archive 内容产出方"部分:
run_delta_compression_cycle压缩 LLM 调用连续失败达到阈值时,触发整批当前 delta 原样转存为低置信度归档记录,调用 issue #156 落地的 archive 分条化写入 API。DeltaCompressionFailureStoragePort,record_delta_compression_failure/clear_delta_compression_failures)——per-chat_id 一行,结构仿UnansweredEscalationModel先例,成功压缩即清零arise_delta_compression_archive_threshold(默认 3,ADR-0011 阈值三层分类,同arise_agent_loop_breaker_threshold归属)run_delta_compression_cycle新增分支:连续失败达阈值时不再原样写回 Delta 缓冲,改为调用_archive_failed_delta整批转存(逐条DeltaEntry对应一个ArchiveCandidate,不合并成 blob);转存成功后清零计数,不计入返回的processed(延续既有写回重试分支的约定)PoolExhausted)不计入连续失败计数——无论发生在压缩阶段还是转存阶段自己的 embedding 调用(design-verify 核实到的真实场景:_pool_is_broken前置闸只查reflection池,不保护转存要用到的embedding池,两者相互独立),都走"写回整批 delta + 停整个 cycle",不当作"这个 chat 内容有问题"ArchiveStoragePort/DeltaCompressionFailureStoragePort正式组进StoragePort(32 切片)与CompressionStoragePort(10 切片)——issue #156 落地时刻意没接入,本票是真正需要经由 host 契约调用它的那一票Design-Verify
两轮独立方案 + 对抗式交叉核实 + 合并,核实过程中发现两份原方案都遗漏的两个真实问题并已采纳进最终方案:
PoolExhausted(前置闸不保护 embedding 池),两份原方案的转存代码都用一个 blanketexcept Exception把它吞掉了,会把系统级熔断误判成"这批转存失败"PersistentStorage的计数器实现如果在commit()之后才读返回值,会在真实 SQLAlchemy 引擎下炸出MissingGreenlet(expire_on_commit=True默认值陷阱,同write_knowledge既有教训)Review 修复
两轴 review + 对抗式 Verify 确认 2 处问题并已修复:
_archive_failed_delta逐条串行await embedding_client.embed(...)——这批内容已经被drain_delta从 Postgres 删除,在全部 embedding 调用完成前只存在于函数局部变量里,串行等待让"进程被硬杀导致整批原文永久丢失"的窗口随批量线性变长。已改为asyncio.gather并发发起,把窗口收窄到约一条网络请求的时长(收窄而非消灭——这个风险与整条run_delta_compression_cycle共享同一个"硬杀不经过 Python 异常处理"的既有敞口,issue #94 起就存在,不是本票引入的新问题,已在代码注释里如实说明)Test plan
uv run pytest -q:2027 passeduv run ruff check src/ tests/:全通过uv run lint-imports:2 kept, 0 brokenty check:47 diagnostics(与 main 基线一致,无新增)