Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions docs/en/rfcs/1417_topic_memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,22 @@ minutes. The Supervisor may continue checking a failed key, but Topic Worker's d
The attempt counter is committed before Source projection; each provider reservation is committed before I/O. The
third attempt may finish using the remaining provider budget; a subsequent attempt is refused. An exhausted request
or token allowance records `window_provider_budget_exceeded`, and an exhausted attempt count is reported as
`window_attempt_limit`. The selector reads terminal frontiers before materializing Sources or spawning another Worker.
`window_attempt_limit`. Before dispatch, a Topic-owned metadata probe checks the current Cursor, target/Source head
and work-budget row, including legacy rows whose attempt count is exhausted but whose failure code is empty.
The probe does not select or materialize Sources, estimate tokens, or construct models. The Worker selector and
pre-I/O reservations retain their guards against changes after admission; an already started third attempt may finish.

A durable rejection enters terminal waiting rather than ordinary failure backoff. It does not launch another Worker,
consume provider allowance, increase the failure counter, acknowledge the invocation, or advance progress. The
Supervisor checks metadata again after five minutes, on a new explicit flush, or at automatic admission. A changed
allowance or Cursor can make the key eligible again without restarting. Transient failures keep their existing backoff.
The first observed rejection or changed diagnostic emits `artifact_processing.blocked` with its stage, error code,
Family, binding, Scope, attempted Window range and attempt/request/token counters. Unchanged cached rechecks are quiet.
Deduplication is bounded and local to the Supervisor term; restart or cache eviction may report the condition again.
Evicted terminal keys remain protected by the domain gate and are revisited through bounded durable-intent discovery;
terminal cache pressure does not pause other Scope admission.
Failed metadata rechecks retain the last terminal block, its waiting interval and log deduplication. Exhausting the
Supervisor's shared admission time allowance yields control without attributing another failure to the Scope.

A terminal frontier retains its Sources, Cursor, Pending, and later same-Scope Sources. It is not a NOOP, success, or
permission to skip evidence. Other Scope keys remain processable. A retry that succeeds within the remaining allowance
Expand All @@ -745,9 +760,10 @@ conflicts and leadership loss are control signals and do not increase the ordina
Cursor and Head conflicts use a fixed short retry deadline rather than immediate redispatch. The conflicting target
releases its current page while delayed, so frozen suffix targets continue to make progress without a hot loop.

Logs include at least the binding, Scope, Window range, stage, error code, exception type, failure count, retry delay,
Supervisor generation, Worker ID, and traceback. They must not contain original Source content, Prompts, complete model
outputs, or secrets.
Console and JSON operational logs retain the binding, Family, Scope, Window range, stage, error code and applicable
budget/retry counters. Actual Worker errors retain the child's stage, exception type and Worker identity. Sanitized
stack locations are available in internal Worker failure diagnostics; operational formatters do not serialize arbitrary
extras or traceback payloads. Logs must not contain original Source content, Prompts, complete model outputs, or secrets.

## HTTP, MCP, and Prepared Context

Expand Down
26 changes: 25 additions & 1 deletion docs/en/rfcs/1515_artifact_processing_supervisor.md
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,31 @@ the key moves to the delayed queue. When due and its type has capacity, it retur

Backoff remains in memory. Restart or leadership change may retry an accepted failed invocation immediately, then
rebuild the backoff sequence; it never skips the failed business position. Permanent errors may continue consuming
invocation resources and must be found through observability; the first version does not discard them automatically.
invocation resources unless the domain can identify a durable rejection before dispatch; input is never discarded
automatically.

A binding may register a metadata-only `work_block` probe for all dispatch paths. Its domain owns the rejection's
identity, stage, code and operational counters; the Supervisor does not interpret Family-specific budget tables or
error-code lists. A blocked key remains unacknowledged and waits for a five-minute metadata recheck, new explicit
request, or automatic admission. Unchanged cached checks neither spawn Workers nor add failures or repeated error
logs. The bounded waiting cache cannot make an evicted key eligible: every dispatch still runs the probe. Terminal
cache eviction schedules bounded durable-intent rediscovery without applying the transient overflow gate to healthy
Scopes. Log deduplication is local to the current term and bounded cache, rather than a persisted exactly-once promise.

Workers retain their own domain guards. A durable rejection reached after admission is returned as sanitized typed
failure metadata carrying the same block, so the Supervisor can enter waiting without treating it as another execution
failure. Other errors preserve ordinary backoff. Metadata-probe failures are isolated to the affected key and back off;
they do not revoke the shared Supervisor term. No Source selection, token estimation or model work moves to the parent.
Admission checks share a bounded time allowance per Family per cycle, so a page of slow probes yields to other Families.
The shared allowance decides whether another check starts; it does not shorten a check already in flight. Each probe
owns a full bounded I/O timeout, independent of earlier Scopes. A cycle may finish its last probe after the shared
allowance expires; probe work is bounded by the shared allowance plus one probe timeout. This yields to other Families
without charging an unrelated Scope a failure. A failed terminal recheck retains its blocked interval, block identity
and failure history. Its first or changed probe error emits
`artifact_processing.block_recheck_failed` as a warning; repeated identical errors stay quiet until a successful check.
The attempted request generation is remembered even when the check fails, so ordinary wakes cannot repeatedly bypass
the interval, while a newer explicit request can still recheck promptly. A probe's own timeout, distinct from shared
allowance expiry, remains a genuine probe error.

Memory owns a persisted per-Scope window reduction for generation timeouts. A failed extraction can
halve the next window without advancing its Source cursor or acknowledging the invocation; the
Expand Down
18 changes: 15 additions & 3 deletions docs/zh/rfcs/1417_topic_memory.md
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,18 @@ retry_states[(binding_name, scope_id)] = {
采用带抖动的指数退避:约 30 秒、1 分钟、2 分钟,直至约 30 分钟上限。Supervisor 可继续检查失败键,但 Topic
Worker 的持久额度限制整窗重算次数。尝试计数在 Source 投影前提交,provider 额度在调用前提交。第三次尝试可用剩余
provider 额度完成工作,但不能再开始第四次。请求或 token 额度耗尽记录 `window_provider_budget_exceeded`,尝试次数
耗尽报告 `window_attempt_limit`。Selector 在 materialize Source 或启动 Worker 前检查终止状态。
耗尽报告 `window_attempt_limit`。派发前由 Topic 领域的 metadata probe 检查当前 Cursor、target/Source head 和额度
记录;尝试次数已耗尽但 failure code 仍为空的旧记录也能识别。检查不选择或 materialize Source、不估算 token,
也不构造模型。Worker 内 Selector 和调用前预留继续保留检查,防止准入后状态发生变化;已开始的第三次尝试仍可完成。

持久拒绝进入终止等待,不按普通失败退避反复启动 Worker,不消耗 provider 额度、不增加失败计数,也不确认调用完成
或推进进度。Supervisor 在五分钟后、新的显式 flush 或自动准入时重新检查 metadata;额度或 Cursor 经明确修复后
可直接恢复处理,无需重启。暂时错误继续采用原有退避。首次发现终止或诊断发生变化时输出 `artifact_processing.blocked`,
包含 stage、error code、Family、binding、Scope、已尝试的 Window 范围和尝试/请求/token 计数;缓存内状态未变化的
检查保持安静。日志去重缓存有界且仅在当前 Supervisor 任期内有效,重启或缓存淘汰后可能再次报告该状态。
淘汰的终止键仍由领域准入检查保护,并通过有界的持久调用发现重新检查;终止缓存压力不暂停其他 Scope 的准入。
metadata 重新检查出错时保留已知终止状态、等待间隔和日志去重信息;Supervisor 共享准入时间额度耗尽时让出控制,
不将正在检查的 Scope 记成新的失败。

终止的 frontier 保留 Source、Cursor、Pending 以及同 Scope 尾部;不会视为 NOOP、成功或跳过证据的授权。其他 Scope
仍可处理。剩余额度内重试成功后仍按原合同发布,并继续处理尾部。不提供自动额度重置、retry/reset API 或 quarantine
Expand All @@ -658,8 +669,9 @@ failure code,不保存 prompt、Source 原文或模型输出。可结合 Curso
Cursor 与 Head conflict 使用固定的短 retry deadline,而不是立即重新派发;冲突目标在延后期间释放当前页,使冻结
尾页继续推进且不会形成热循环。

日志至少包含 binding、scope、Window 范围、stage、error code、异常类型、失败次数、重试延迟、Supervisor
generation、worker ID 和 traceback;不得记录 Source 原文、Prompt、模型完整输出或密钥。
Console 和 JSON 运维日志保留 binding、Family、Scope、Window 范围、stage、error code 及适用的额度/重试计数。
实际 Worker 错误保留子进程的 stage、异常类型和 Worker 身份。内部 Worker 失败诊断保留脱敏的栈位置;运维 formatter
不序列化任意 extra 或 traceback 内容。不得记录 Source 原文、Prompt、模型完整输出或密钥。

## HTTP、MCP 与 Prepared Context

Expand Down
20 changes: 19 additions & 1 deletion docs/zh/rfcs/1515_artifact_processing_supervisor.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,25 @@ Supervisor 不替处理器作业务授权。显式触发在领域 API 接受意
- leadership lost 是控制事件:停止该 Supervisor 的派发和提交,交给新的有效任期恢复。

退避只放内存。重启或换主后可以立即重试已接受的失败调用,随后重新建立退避序列;这不会跳过其业务失败位置。
永久错误可能持续消耗调用成本,需要通过可观测性发现,首版不自动弃置。
若领域不能在派发前识别持久拒绝,永久错误仍可能消耗调用成本;不会自动弃置输入。

binding 可注册仅检查 metadata 的 `work_block` probe,覆盖全部派发路径。拒绝状态的身份、stage、code 和运维计数
由领域定义,Supervisor 不解释 Family 专有额度表或错误码列表。终止键保持未确认,等待五分钟后的 metadata
检查、新的显式请求或自动准入。缓存内状态未变化时不启动 Worker、不增加失败计数,也不反复写错误日志。
等待缓存有界;淘汰不会授权执行,每次派发仍须检查 probe。终止缓存淘汰通过有界的持久调用发现重新检查,
不把普通失败的容量退避应用到正常 Scope。日志去重仅在当前任期和缓存内生效,不承诺持久的 exactly-once 日志。

Worker 保留自己的领域检查;准入后遇到持久拒绝时,通过脱敏的类型化失败 metadata 返回同一 block,Supervisor
据此进入等待,不计为新的执行失败。其他错误继续按普通退避处理。metadata probe 出错时只延后对应键,
不会作废共享 Supervisor 任期。Source 选择、token 估算和模型工作仍在子进程中完成。
每轮每个 Family 的准入检查共享有限的时间额度,检查变慢的一整页 Scope 也须让出控制循环,使其他 Family 继续运行。
共享额度只决定是否开始下一次检查,不缩短已经开始的检查。每个 probe 获得完整且有界的 I/O 超时,与前面 Scope
耗用的时间无关。最后一次检查可以在共享额度耗尽后结束,整轮 probe 工作不超过共享额度加一次 probe 超时;随后
让出其他 Family,不误算无关 Scope 失败。终止键重新检查出错时保留阻塞间隔、block 身份和原有失败历史,首次或变化
的检查错误以 warning 输出
`artifact_processing.block_recheck_failed`;相同错误在检查成功前不重复报告。失败检查仍记录已尝试的请求 generation,
普通唤醒不能反复绕过间隔,更新的显式请求仍可及时重新检查。probe 自身抛出的超时与共享额度耗尽区分,按实际检查
错误处理。

Memory 在生成超时后按 Scope 持久化缩窗上限。失败的提取可以将下一次窗口减半,但不推进 Source 游标,
也不确认调用;缩窗上限跨 Worker 更换保留,在已观察到的积压消费完成时清除。该更新受游标 CAS 和当前
Expand Down
15 changes: 11 additions & 4 deletions src/powercontext/builtin/persistence/topic_memory_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ def exhausted_reason(row: Mapping[Any, Any]) -> str:
return ""


async def require_topic_memory_work_available(
async def load_topic_memory_work_budget(
connection: AsyncConnection, scope_id: str, binding_name: str, source_after: int
) -> None:
"""Cheap selector guard: terminal frontiers never spawn or reproject Sources."""
) -> Mapping[Any, Any] | None:
"""Read one authoritative frontier's metadata without changing its allowance."""
table = TOPIC_MEMORY_WORK_BUDGETS_TABLE
row = (
return (
(
await connection.execute(
select(table).where(
Expand All @@ -81,6 +81,13 @@ async def require_topic_memory_work_available(
.mappings()
.one_or_none()
)


async def require_topic_memory_work_available(
connection: AsyncConnection, scope_id: str, binding_name: str, source_after: int
) -> None:
"""Worker-side guard before Source materialization and projection."""
row = await load_topic_memory_work_budget(connection, scope_id, binding_name, source_after)
if row is not None and (reason := exhausted_reason(row)):
raise TopicMemoryGenerationError(reason)

Expand Down
Loading
Loading