memleaf 0.2.43__tar.gz → 0.2.44__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {memleaf-0.2.43 → memleaf-0.2.44}/CHANGELOG.md +7 -0
- {memleaf-0.2.43/src/memleaf.egg-info → memleaf-0.2.44}/PKG-INFO +4 -2
- {memleaf-0.2.43 → memleaf-0.2.44}/README.en.md +3 -1
- {memleaf-0.2.43 → memleaf-0.2.44}/README.md +3 -1
- memleaf-0.2.44/docs/extraction-latency.md +50 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/pyproject.toml +1 -1
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/__init__.py +1 -1
- memleaf-0.2.44/src/memleaf/extraction_budget.py +199 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/extraction_capability.py +6 -7
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/extraction_work_state.py +9 -66
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/hermes_provider/plugin.yaml +1 -1
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/process_jobs.py +13 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/processing.py +15 -26
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/single_pass_plan.py +3 -4
- {memleaf-0.2.43 → memleaf-0.2.44/src/memleaf.egg-info}/PKG-INFO +4 -2
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf.egg-info/SOURCES.txt +1 -0
- memleaf-0.2.43/src/memleaf/extraction_budget.py +0 -280
- {memleaf-0.2.43 → memleaf-0.2.44}/LICENSE +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/MANIFEST.in +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/docs/capture-budget-design.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/docs/config-migrations.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/docs/core-refactor.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/docs/evidence-retention.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/docs/gate-evidence-boundary.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/docs/general-processing.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/docs/hermes-mcp-runtime.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/docs/processing-quality-acceptance.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/docs/v0.2.26-processing-status.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/examples/README.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/examples/basic_usage.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/examples/mcp_stdio.ndjson +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/install.ps1 +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/install.sh +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/setup.cfg +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/__main__.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/adapters/__init__.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/adapters/antigravity.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/adapters/base.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/adapters/codex.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/adapters/hermes.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/admission.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/batch_review.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/budget.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/capture.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/cli.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/compaction.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/config.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/create_coordinator.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/credentials.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/evidence_budget.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/evidence_policy.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/evidence_structure.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/evidence_syntax.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/frontmatter.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/hermes_provider/README.md +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/hermes_provider/__init__.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/hermes_provider/_mcp_client.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/hermes_provider/_provider.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/hermes_provider/_shared.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/hermes_provider/evidence_budget.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/hermes_runtime.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/host_events.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/host_runtime.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/inbox.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/index.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/inspection.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/installer.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/llm/__init__.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/llm/base.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/llm/claude_compatible.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/llm/gemini.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/llm/openai_compatible.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/llm/router.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/llm/thinking.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/locking.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/mcp_server.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/memory_commit.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/memory_planner.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/memory_writer.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/model_discovery.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/model_execution.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/models.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/native_index.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/native_registration.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/parallel_model.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/planning_context.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/process_common.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/process_journal.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/process_owner.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/prompts.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/provenance.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/recording_policy.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/redaction.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/retention.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/retrieval.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/retrieval_gate.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/scope_maintenance.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/scope_state.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/service.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/single_pass_memory_planner.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/source_policy.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/state_layout.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/summary_batch.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/target_reconciliation.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/turn_audit.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/turn_plan.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/update_coordinator.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/update_review.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/validation.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf/vault.py +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf.egg-info/dependency_links.txt +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf.egg-info/entry_points.txt +0 -0
- {memleaf-0.2.43 → memleaf-0.2.44}/src/memleaf.egg-info/top_level.txt +0 -0
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to memleaf are documented here.
|
|
4
4
|
|
|
5
|
+
## 0.2.44 — 2026-09-12
|
|
6
|
+
|
|
7
|
+
- Correct the extraction latency policy: ten seconds is an advisory performance target, not a cancellation or commit deadline. Remove the fixed six-second primary cap and eight-second shared window; single-pass HTTP requests now honor `llm.request_timeout`, including the one bounded format repair.
|
|
8
|
+
- Accept valid, Core-checked results after the target and recover frozen background plans without expiring them by old wall-clock timestamps. Keep durable request counts, damaged-state handling, revision/ownership validation and normal transport errors intact.
|
|
9
|
+
- Add structural per-turn extraction timing to synchronous results and background job result/error summaries. Track planning/commit time, slow attempts and failed attempts separately; a fast failure is not counted as successful target achievement. No prompt, response, credential or memory body is added to these metrics.
|
|
10
|
+
- Keep tests local-only and leave the hosted build/smoke CI policy unchanged. Real-provider latency and quality acceptance remain separate; removing premature cancellation is not a measured ten-second performance claim.
|
|
11
|
+
|
|
5
12
|
## 0.2.43 — 2026-09-12
|
|
6
13
|
|
|
7
14
|
- Keep regression tests, live-acceptance helpers, and implementation/release plans in local checkouts rather than the Git tree or source distribution.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: memleaf
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.44
|
|
4
4
|
Summary: A local-first Markdown memory core for AI agents
|
|
5
5
|
Author: memleaf contributors
|
|
6
6
|
License-Expression: MIT
|
|
@@ -23,7 +23,7 @@ Dynamic: license-file
|
|
|
23
23
|
|
|
24
24
|
[English](README.en.md) · [PyPI](https://pypi.org/project/memleaf/) · [GitHub](https://github.com/miffyblueboo/memleaf)
|
|
25
25
|
|
|
26
|
-
> **版本:0.2.
|
|
26
|
+
> **版本:0.2.44。**
|
|
27
27
|
> 记忆只从用户与 Agent 的可见对话提炼。Agent 已在回复中整理的事实、项目进展和明确待办可作为来源;邮件、附件、网页和终端等工具原文不进入记忆提炼。模型负责保留原话中的不确定性,现有记忆仅用于比较、去重和更新。Markdown 仍是唯一事实源。
|
|
28
28
|
> **当前版本支持 Hermes 和 Codex。** Antigravity(反重力)不检测、不安装、不配置。
|
|
29
29
|
|
|
@@ -85,6 +85,8 @@ Hermes 使用原生 MemoryProvider 维护生命周期,并通过 MCP 获取 Sco
|
|
|
85
85
|
|
|
86
86
|
## 记忆提炼规则
|
|
87
87
|
|
|
88
|
+
**10 秒是自动提炼的性能目标,不是失败阈值。** HTTP 请求遵循 `llm.request_timeout`(默认 120 秒);正常返回且通过 Core 校验的结果不会仅因超过 10 秒而丢弃。模型单次请求、有限修复和逐轮提交保留,耗时与是否完成分别统计。详见 [提炼耗时与超时](docs/extraction-latency.md)。
|
|
89
|
+
|
|
88
90
|
memleaf 不把每句话都保存为记忆。处理一轮完整的 user + assistant 可见文本时,模型先判断是否存在明确的未来复用价值:
|
|
89
91
|
|
|
90
92
|
- `CREATE`:没有相关现存记忆,创建一条原子、可独立理解的记忆;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
[中文](README.md) · [PyPI](https://pypi.org/project/memleaf/) · [GitHub](https://github.com/miffyblueboo/memleaf)
|
|
6
6
|
|
|
7
|
-
> **Version: 0.2.
|
|
7
|
+
> **Version: 0.2.44.**
|
|
8
8
|
> Automatic extraction now uses only the current turn's visible user input and final assistant reply. Raw tool output, attachments, web/file/terminal payloads and legacy tool-evidence bodies are not new source evidence; existing or retrieved memory remains comparison context rather than source authority. Background processing is persisted as a local job and can be checked through the read-only `process_status` MCP tool; failed work remains retryable and fail closed. The release also tightens source/date grounding, target reconciliation, duplicate/no-op handling and semantic review before writes. Markdown remains the sole source of truth with no SQLite runtime dependency. Acceptance covers deterministic regression suites and synthetic inputs; it does not claim real-mail or customer-business acceptance.
|
|
9
9
|
> **The current release supports Hermes and Codex.** Antigravity is not detected, installed, or configured.
|
|
10
10
|
|
|
@@ -64,6 +64,8 @@ Hermes uses a native MemoryProvider for lifecycle handling and obtains the Scope
|
|
|
64
64
|
|
|
65
65
|
## Memory admission and maintenance
|
|
66
66
|
|
|
67
|
+
**Ten seconds is an extraction performance target, not a failure deadline.** HTTP requests honor `llm.request_timeout` (120 seconds by default). A valid, Core-checked response is not discarded just because processing exceeds ten seconds. Single-pass planning, bounded repair and per-turn commits remain; completion and latency are measured separately. See [extraction latency and timeouts](docs/extraction-latency.md).
|
|
68
|
+
|
|
67
69
|
memleaf does not save every sentence. When a complete visible user + assistant turn is processed, the model first evaluates whether it has concrete future reuse value:
|
|
68
70
|
|
|
69
71
|
- `CREATE`: no related active memory exists, so create one atomic, self-contained memory;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
[English](README.en.md) · [PyPI](https://pypi.org/project/memleaf/) · [GitHub](https://github.com/miffyblueboo/memleaf)
|
|
6
6
|
|
|
7
|
-
> **版本:0.2.
|
|
7
|
+
> **版本:0.2.44。**
|
|
8
8
|
> 记忆只从用户与 Agent 的可见对话提炼。Agent 已在回复中整理的事实、项目进展和明确待办可作为来源;邮件、附件、网页和终端等工具原文不进入记忆提炼。模型负责保留原话中的不确定性,现有记忆仅用于比较、去重和更新。Markdown 仍是唯一事实源。
|
|
9
9
|
> **当前版本支持 Hermes 和 Codex。** Antigravity(反重力)不检测、不安装、不配置。
|
|
10
10
|
|
|
@@ -66,6 +66,8 @@ Hermes 使用原生 MemoryProvider 维护生命周期,并通过 MCP 获取 Sco
|
|
|
66
66
|
|
|
67
67
|
## 记忆提炼规则
|
|
68
68
|
|
|
69
|
+
**10 秒是自动提炼的性能目标,不是失败阈值。** HTTP 请求遵循 `llm.request_timeout`(默认 120 秒);正常返回且通过 Core 校验的结果不会仅因超过 10 秒而丢弃。模型单次请求、有限修复和逐轮提交保留,耗时与是否完成分别统计。详见 [提炼耗时与超时](docs/extraction-latency.md)。
|
|
70
|
+
|
|
69
71
|
memleaf 不把每句话都保存为记忆。处理一轮完整的 user + assistant 可见文本时,模型先判断是否存在明确的未来复用价值:
|
|
70
72
|
|
|
71
73
|
- `CREATE`:没有相关现存记忆,创建一条原子、可独立理解的记忆;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
# 提炼耗时与请求超时
|
|
2
|
+
|
|
3
|
+
## 性能目标与失败条件分开
|
|
4
|
+
|
|
5
|
+
日常自动提炼以 10 秒内完成为性能目标,但到第 10 秒不会主动报失败,也不会丢弃已正常返回并通过 Core 校验的结果。超过目标说明本次处理偏慢,不说明记忆无效或没有需要保存的信息。
|
|
6
|
+
|
|
7
|
+
v0.2.42 / v0.2.43 的固定 6 秒首请求、8 秒准备加模型窗口、10 秒提交前拒绝属于错误的目标实现,当前修正移除了这些时间闸门。修正本身不代表真实模型的 P50/P95 已达标。
|
|
8
|
+
|
|
9
|
+
HTTP 请求使用已有配置:
|
|
10
|
+
|
|
11
|
+
```yaml
|
|
12
|
+
llm:
|
|
13
|
+
request_timeout: 120
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
这个参数仍按现有规则校验(1~240 秒,可用小数),并传到 HTTP transport。single-pass 不再静默把它缩短为 6 秒。第二次结构修复请求使用相同的配置,不再只分到原来 8 秒窗口的剩余时间。请求超时是 transport 的等待限制,不是整个后台任务的端到端完成保证;host/Python callback 仍由其宿主负责请求超时与取消。
|
|
17
|
+
|
|
18
|
+
真正的请求超时、网络故障、无效模型输出、目标版本冲突、写入失败仍然是失败或未完成,不能伪装为 `NO_CHANGE`。相应 inbox、journal 和恢复锚点保留,是否提交仍由 Core 校验决定。
|
|
19
|
+
|
|
20
|
+
## 保留的调用与提交约束
|
|
21
|
+
|
|
22
|
+
普通 B3 自动提炼仍以一次结构化模型调用为正常路径,格式/结构修复最多一次。固定安全路由保留实际 outbound 请求计数和持久化预占,不增加隐藏 host-to-API fallback。并未恢复 Gate → Summary → Review 多阶段主路径。
|
|
23
|
+
|
|
24
|
+
每轮仍先读取持久状态、规划、校验、提交,再处理下一轮;一轮超过目标不会占用下一轮的“时间许可”。compaction 仍不在普通提炼的关键路径上。
|
|
25
|
+
|
|
26
|
+
旧 `extraction_request_budget.json` 中的 `started_at_epoch` 可以兼容读取,但不再作为请求或提交的过期时间。已消耗的 `requests` 不清零,损坏的计数账本也不会被当作空文件重建。FrozenTurn 的恢复不需要重新申请模型时间窗口;现有内容摘要、版本、所有权和写入校验保持不变。
|
|
27
|
+
|
|
28
|
+
这不是一个自动重放所有历史失败任务的迁移。旧 inbox 不会被清空;需要通过正常处理/重试入口继续处理,不能删除正确性状态来强行重新获取请求额度。
|
|
29
|
+
|
|
30
|
+
## 只记录结构化耗时
|
|
31
|
+
|
|
32
|
+
处理结果新增 `extraction_metrics`,后台 `process_status` 的 result/error 和尝试汇总保留同样的数字字段:
|
|
33
|
+
|
|
34
|
+
| 字段 | 含义 |
|
|
35
|
+
| --- | --- |
|
|
36
|
+
| `target_duration_ms` | 固定观测目标 10000 毫秒,不参与失败判断 |
|
|
37
|
+
| `turn_count` | 本次测量的 turn 尝试数量 |
|
|
38
|
+
| `failed_turn_count` | 抛出处理异常的 turn 尝试数量 |
|
|
39
|
+
| `over_target_turn_count` | 耗时超过目标的 turn 尝试数量,可能成功也可能失败 |
|
|
40
|
+
| `successful_within_target_count` | 无处理异常且在目标内结算的尝试数量 |
|
|
41
|
+
| `total_duration_ms` | 被测 turn 尝试的耗时之和 |
|
|
42
|
+
| `max_turn_duration_ms` | 最慢一次 turn 尝试耗时 |
|
|
43
|
+
| `planning_duration_ms` | 读取状态、准备上下文、模型调用和本地计划校验耗时 |
|
|
44
|
+
| `commit_duration_ms` | 从进入提交阶段到提交和预算清理返回的耗时 |
|
|
45
|
+
|
|
46
|
+
每轮计时从选中该 turn 后、读取其处理状态前开始。它不包括排队、worker 启动及 `process()` 开头的整批 inbox claim 扫描;不能把该指标冒充用户可见端到端耗时。跨 worker 重启会产生新的尝试,旧进程的 wall-clock 起点不再限制新进程执行。
|
|
47
|
+
|
|
48
|
+
“无处理异常”包括合法 `NO_CHANGE` 和正常返回的部分处理;语义完整性仍由既有 `coverage_status`、deferred 数量、`memories_written` 和任务状态判断。因此耗时统计不替代提炼质量验收。快速失败不计入 `successful_within_target_count`。
|
|
49
|
+
|
|
50
|
+
`model_metrics` 继续分别提供模型请求耗时、调用/修复次数和输入输出长度等信息。以上结构化统计不新增正文、prompt、response 或凭证存储。
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"""Local-first Markdown memory core for AI agents."""
|
|
2
2
|
|
|
3
|
-
__version__ = "0.2.
|
|
3
|
+
__version__ = "0.2.44"
|
|
4
4
|
|
|
5
5
|
from .config import DEFAULT_CONFIG, default_config, load_config, save_config
|
|
6
6
|
from .frontmatter import FrontmatterError, dump_frontmatter, dump_yaml, load_yaml, parse_frontmatter
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"""Outbound-request accounting and advisory extraction latency metrics.
|
|
2
|
+
|
|
3
|
+
Ten seconds is a performance target, not permission to cancel useful work or
|
|
4
|
+
discard a valid memory. The transport owns the configured request timeout;
|
|
5
|
+
this module only limits request count and observes complete-turn latency.
|
|
6
|
+
"""
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import time
|
|
10
|
+
from collections.abc import Callable
|
|
11
|
+
from typing import Any, Iterable, Mapping
|
|
12
|
+
|
|
13
|
+
from .llm import ModelError
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
MAX_MODEL_REQUESTS = 2
|
|
17
|
+
TARGET_TOTAL_SECONDS = 10.0
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class SinglePassBudgetBackend:
|
|
21
|
+
"""Limit one logical B3 turn to two actual provider requests.
|
|
22
|
+
|
|
23
|
+
``single_pass_safe`` routes map one complete() call to one request, without
|
|
24
|
+
hidden host-to-API fallback. The optional durable reservation preserves
|
|
25
|
+
consumed attempts across worker restarts. Neither the first request nor
|
|
26
|
+
its repair overrides the transport's configured ``llm.request_timeout``.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
single_pass_safe = True
|
|
30
|
+
|
|
31
|
+
def __init__(
|
|
32
|
+
self,
|
|
33
|
+
backend: Any,
|
|
34
|
+
*,
|
|
35
|
+
reserve_request: Callable[[], int | None] | None = None,
|
|
36
|
+
):
|
|
37
|
+
if not hasattr(backend, "complete"):
|
|
38
|
+
raise TypeError("single-pass backend must expose complete()")
|
|
39
|
+
if reserve_request is not None and not callable(reserve_request):
|
|
40
|
+
raise TypeError("reserve_request must be callable")
|
|
41
|
+
self._backend = backend
|
|
42
|
+
self._requests = 0
|
|
43
|
+
self._reserve_request = reserve_request
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def provider(self) -> str:
|
|
47
|
+
return str(getattr(self._backend, "provider", "unknown"))
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def model(self) -> str:
|
|
51
|
+
return str(getattr(self._backend, "model", "unknown"))
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def parallel_safe(self) -> bool:
|
|
55
|
+
return getattr(self._backend, "parallel_safe", False) is True
|
|
56
|
+
|
|
57
|
+
@property
|
|
58
|
+
def structured_batch_safe(self) -> bool:
|
|
59
|
+
return getattr(self._backend, "structured_batch_safe", False) is True
|
|
60
|
+
|
|
61
|
+
@property
|
|
62
|
+
def request_count(self) -> int:
|
|
63
|
+
return self._requests
|
|
64
|
+
|
|
65
|
+
def _request_ordinal(self, *, purpose: str) -> int:
|
|
66
|
+
if self._requests >= MAX_MODEL_REQUESTS:
|
|
67
|
+
raise ModelError(
|
|
68
|
+
"single-pass extraction budget exhausted",
|
|
69
|
+
code="model_timeout",
|
|
70
|
+
stage=purpose or "single_pass",
|
|
71
|
+
)
|
|
72
|
+
if self._reserve_request is None:
|
|
73
|
+
return self._requests + 1
|
|
74
|
+
try:
|
|
75
|
+
ordinal = self._reserve_request()
|
|
76
|
+
except Exception as error:
|
|
77
|
+
raise ModelError(
|
|
78
|
+
"single-pass extraction request budget cannot be reserved",
|
|
79
|
+
code="model_timeout",
|
|
80
|
+
stage=purpose or "single_pass",
|
|
81
|
+
) from error
|
|
82
|
+
if type(ordinal) is not int or not 1 <= ordinal <= MAX_MODEL_REQUESTS:
|
|
83
|
+
raise ModelError(
|
|
84
|
+
"single-pass extraction budget exhausted",
|
|
85
|
+
code="model_timeout",
|
|
86
|
+
stage=purpose or "single_pass",
|
|
87
|
+
)
|
|
88
|
+
return ordinal
|
|
89
|
+
|
|
90
|
+
def complete(
|
|
91
|
+
self,
|
|
92
|
+
prompt: str,
|
|
93
|
+
*,
|
|
94
|
+
system: str = "",
|
|
95
|
+
purpose: str = "",
|
|
96
|
+
temperature: float = 0.0,
|
|
97
|
+
) -> str:
|
|
98
|
+
self._request_ordinal(purpose=purpose)
|
|
99
|
+
# Count only after durable reservation succeeds. A kill from this point
|
|
100
|
+
# onward still consumes that attempt, without imposing a wall deadline.
|
|
101
|
+
self._requests += 1
|
|
102
|
+
return self._backend.complete(
|
|
103
|
+
prompt,
|
|
104
|
+
system=system,
|
|
105
|
+
purpose=purpose,
|
|
106
|
+
temperature=temperature,
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
def consume_call_metrics(self) -> dict[str, Any]:
|
|
110
|
+
consume = getattr(self._backend, "consume_call_metrics", None)
|
|
111
|
+
if not callable(consume):
|
|
112
|
+
return {}
|
|
113
|
+
try:
|
|
114
|
+
value = consume()
|
|
115
|
+
except Exception:
|
|
116
|
+
return {}
|
|
117
|
+
return dict(value) if isinstance(value, Mapping) else {}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
class ExtractionTiming:
|
|
121
|
+
"""Observe one processing attempt; never authorize or reject a write.
|
|
122
|
+
|
|
123
|
+
This monotonic timer includes local planning/context, model work, validation
|
|
124
|
+
and commit. A worker restart begins a new measured attempt; persisted wall
|
|
125
|
+
timestamps from older releases are not latency-based write restrictions.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
def __init__(self, *, clock: Any = None):
|
|
129
|
+
self._clock = time.monotonic if clock is None else clock
|
|
130
|
+
self._started = self._clock()
|
|
131
|
+
self._commit_started: float | None = None
|
|
132
|
+
|
|
133
|
+
def begin_commit(self) -> None:
|
|
134
|
+
self._commit_started = self._clock()
|
|
135
|
+
|
|
136
|
+
def finish(self, *, failed: bool = False) -> dict[str, int]:
|
|
137
|
+
ended = self._clock()
|
|
138
|
+
seconds = max(0.0, ended - self._started)
|
|
139
|
+
commit_started = self._commit_started
|
|
140
|
+
planning_end = ended if commit_started is None else commit_started
|
|
141
|
+
return {
|
|
142
|
+
"target_duration_ms": int(TARGET_TOTAL_SECONDS * 1000),
|
|
143
|
+
"turn_count": 1,
|
|
144
|
+
"failed_turn_count": int(failed),
|
|
145
|
+
"over_target_turn_count": int(seconds > TARGET_TOTAL_SECONDS),
|
|
146
|
+
"successful_within_target_count": int(not failed and seconds <= TARGET_TOTAL_SECONDS),
|
|
147
|
+
"total_duration_ms": int(seconds * 1000),
|
|
148
|
+
"max_turn_duration_ms": int(seconds * 1000),
|
|
149
|
+
"planning_duration_ms": int(max(0.0, planning_end - self._started) * 1000),
|
|
150
|
+
"commit_duration_ms": int(max(0.0, ended - planning_end) * 1000),
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def aggregate_extraction_metrics(values: Iterable[Mapping[str, Any]]) -> dict[str, int]:
|
|
155
|
+
"""Sum allowlisted numeric metrics; never copy arbitrary content to status."""
|
|
156
|
+
|
|
157
|
+
summed = (
|
|
158
|
+
"turn_count", "failed_turn_count", "over_target_turn_count",
|
|
159
|
+
"successful_within_target_count", "total_duration_ms",
|
|
160
|
+
"planning_duration_ms", "commit_duration_ms",
|
|
161
|
+
)
|
|
162
|
+
result = {key: 0 for key in summed}
|
|
163
|
+
result["target_duration_ms"] = int(TARGET_TOTAL_SECONDS * 1000)
|
|
164
|
+
result["max_turn_duration_ms"] = 0
|
|
165
|
+
for value in values:
|
|
166
|
+
if not isinstance(value, Mapping):
|
|
167
|
+
continue
|
|
168
|
+
for key in (*summed, "max_turn_duration_ms"):
|
|
169
|
+
item = value.get(key)
|
|
170
|
+
if type(item) is not int or item < 0:
|
|
171
|
+
continue
|
|
172
|
+
if key == "max_turn_duration_ms":
|
|
173
|
+
result[key] = max(result[key], item)
|
|
174
|
+
else:
|
|
175
|
+
result[key] += item
|
|
176
|
+
return result
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
def budget_single_pass_backend(
|
|
180
|
+
backend: Any,
|
|
181
|
+
*,
|
|
182
|
+
reserve_request: Callable[[], int | None] | None = None,
|
|
183
|
+
) -> SinglePassBudgetBackend:
|
|
184
|
+
if isinstance(backend, SinglePassBudgetBackend):
|
|
185
|
+
return backend
|
|
186
|
+
return SinglePassBudgetBackend(
|
|
187
|
+
backend,
|
|
188
|
+
reserve_request=reserve_request,
|
|
189
|
+
)
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
__all__ = [
|
|
193
|
+
"MAX_MODEL_REQUESTS",
|
|
194
|
+
"TARGET_TOTAL_SECONDS",
|
|
195
|
+
"ExtractionTiming",
|
|
196
|
+
"aggregate_extraction_metrics",
|
|
197
|
+
"SinglePassBudgetBackend",
|
|
198
|
+
"budget_single_pass_backend",
|
|
199
|
+
]
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"""Capability checks for unified automatic extraction.
|
|
2
2
|
|
|
3
|
-
Protocol compatibility and
|
|
4
|
-
A backend may understand the B3
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
8/10-second budget only to ``single_pass_safe`` transports.
|
|
3
|
+
Protocol compatibility and transport request accounting are separate.
|
|
4
|
+
A backend may understand the B3 contract without exposing a bounded transport.
|
|
5
|
+
``single_pass_safe`` identifies routes suitable for outbound-request counting;
|
|
6
|
+
HTTP requests use the configured timeout, not the advisory ten-second target.
|
|
8
7
|
"""
|
|
9
8
|
from __future__ import annotations
|
|
10
9
|
|
|
@@ -44,14 +43,14 @@ def _direct_protocol_capable(backend: Any) -> bool:
|
|
|
44
43
|
return override
|
|
45
44
|
# Raw Python callbacks are adapted by ModelExecutor into
|
|
46
45
|
# CallableBackend. They can consume memleaf's B3 prompt, but are not
|
|
47
|
-
#
|
|
46
|
+
# transport-timeout safe because caller-owned code may ignore
|
|
48
47
|
# timeout/cancellation entirely.
|
|
49
48
|
return True
|
|
50
49
|
return False
|
|
51
50
|
|
|
52
51
|
|
|
53
52
|
def supports_single_pass_protocol(backend: Any) -> bool:
|
|
54
|
-
"""Return B3 protocol capability without claiming
|
|
53
|
+
"""Return B3 protocol capability without claiming transport guarantees."""
|
|
55
54
|
|
|
56
55
|
if _direct_protocol_capable(backend):
|
|
57
56
|
return True
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"""Durable request
|
|
1
|
+
"""Durable request-count state for one background extraction work item.
|
|
2
2
|
|
|
3
3
|
A detached worker can die after a provider request but before memleaf records a
|
|
4
4
|
normal model failure. The process-job ID survives that worker restart, so use
|
|
@@ -6,11 +6,10 @@ it as the stable work identity and reserve each outbound single-pass request
|
|
|
6
6
|
*before* dispatch. A restarted worker therefore cannot reopen the two-call
|
|
7
7
|
automatic budget for the same turn.
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
model-budget ledger.
|
|
9
|
+
Older releases also recorded a wall-clock start. Those timestamps are accepted
|
|
10
|
+
for compatibility but never used to shorten requests or forbid a later commit.
|
|
11
|
+
Request counters, not elapsed time, remain authoritative across restarts.
|
|
12
|
+
Deterministic no-write turns never consult this model-request ledger.
|
|
14
13
|
|
|
15
14
|
This state contains only control identifiers, counters, and timestamps; never
|
|
16
15
|
prompts, responses, evidence bodies, credentials, or exception text.
|
|
@@ -19,11 +18,9 @@ from __future__ import annotations
|
|
|
19
18
|
|
|
20
19
|
import math
|
|
21
20
|
import os
|
|
22
|
-
import time
|
|
23
21
|
from pathlib import Path
|
|
24
22
|
from typing import Any, Mapping
|
|
25
23
|
|
|
26
|
-
from .extraction_budget import TARGET_TOTAL_SECONDS
|
|
27
24
|
from .locking import atomic_write_json, read_json
|
|
28
25
|
|
|
29
26
|
|
|
@@ -73,8 +70,8 @@ def _normalize_turn_state(value: Any) -> dict[str, Any]:
|
|
|
73
70
|
|
|
74
71
|
Earlier builds on this development branch persisted ``turns[turn_id]`` as
|
|
75
72
|
an integer request count. Treat that as the same consumed request count
|
|
76
|
-
with no historical wall-clock start.
|
|
77
|
-
|
|
73
|
+
with no historical wall-clock start. Existing timestamps are preserved for
|
|
74
|
+
compatibility only; no request ordinal is reset and no expiry is inferred.
|
|
78
75
|
"""
|
|
79
76
|
|
|
80
77
|
if type(value) is int and 0 <= value <= 2:
|
|
@@ -215,59 +212,6 @@ def active_background_work_id(
|
|
|
215
212
|
return active_id
|
|
216
213
|
|
|
217
214
|
|
|
218
|
-
def begin_turn_budget(
|
|
219
|
-
vault: Any,
|
|
220
|
-
*,
|
|
221
|
-
work_id: str,
|
|
222
|
-
turn_id: str,
|
|
223
|
-
wall_clock: Any = time.time,
|
|
224
|
-
) -> float:
|
|
225
|
-
"""Persist/recover one logical turn start and return elapsed wall seconds.
|
|
226
|
-
|
|
227
|
-
The timestamp is written immediately before model-backed planning/context
|
|
228
|
-
preparation. A restarted worker therefore receives only the remainder of
|
|
229
|
-
the original 8/10 second windows. If the wall clock moves backwards, fail
|
|
230
|
-
closed by reporting the full total budget as already consumed rather than
|
|
231
|
-
granting extra time.
|
|
232
|
-
"""
|
|
233
|
-
|
|
234
|
-
if not _valid_identifier(work_id, maximum=200):
|
|
235
|
-
raise ExtractionWorkStateError("invalid extraction work id")
|
|
236
|
-
if not _valid_identifier(turn_id, maximum=800):
|
|
237
|
-
raise ExtractionWorkStateError("invalid extraction turn id")
|
|
238
|
-
now = wall_clock()
|
|
239
|
-
if not _valid_epoch(now):
|
|
240
|
-
raise ExtractionWorkStateError("invalid extraction wall clock")
|
|
241
|
-
now_value = float(now)
|
|
242
|
-
with vault.lock():
|
|
243
|
-
state = _read_budget_state_unlocked(vault)
|
|
244
|
-
work = _work_unlocked(state, work_id=work_id)
|
|
245
|
-
turns = work["turns"]
|
|
246
|
-
turn_state = turns.get(turn_id)
|
|
247
|
-
changed = False
|
|
248
|
-
if turn_state is None:
|
|
249
|
-
if len(turns) >= _MAX_TURNS_PER_WORK:
|
|
250
|
-
raise ExtractionWorkStateError("extraction work turn budget is full")
|
|
251
|
-
turn_state = {"requests": 0, "started_at_epoch": now_value}
|
|
252
|
-
turns[turn_id] = turn_state
|
|
253
|
-
changed = True
|
|
254
|
-
else:
|
|
255
|
-
turn_state = _normalize_turn_state(turn_state)
|
|
256
|
-
turns[turn_id] = turn_state
|
|
257
|
-
if turn_state["started_at_epoch"] is None:
|
|
258
|
-
turn_state["started_at_epoch"] = now_value
|
|
259
|
-
changed = True
|
|
260
|
-
if changed:
|
|
261
|
-
atomic_write_json(_budget_path(vault), state, mode=0o600)
|
|
262
|
-
started = turn_state["started_at_epoch"]
|
|
263
|
-
if not _valid_epoch(started):
|
|
264
|
-
raise ExtractionWorkStateError("invalid extraction work start time")
|
|
265
|
-
started_value = float(started)
|
|
266
|
-
if now_value < started_value:
|
|
267
|
-
return TARGET_TOTAL_SECONDS
|
|
268
|
-
return now_value - started_value
|
|
269
|
-
|
|
270
|
-
|
|
271
215
|
def reserve_model_request(vault: Any, *, work_id: str, turn_id: str) -> int | None:
|
|
272
216
|
"""Atomically reserve the next provider request and return ordinal 1/2.
|
|
273
217
|
|
|
@@ -288,8 +232,8 @@ def reserve_model_request(vault: Any, *, work_id: str, turn_id: str) -> int | No
|
|
|
288
232
|
if turn_state is None:
|
|
289
233
|
if len(turns) >= _MAX_TURNS_PER_WORK:
|
|
290
234
|
raise ExtractionWorkStateError("extraction work turn budget is full")
|
|
291
|
-
#
|
|
292
|
-
#
|
|
235
|
+
# Keep the existing on-disk shape. A timestamp is not required for
|
|
236
|
+
# request accounting and must not become a hidden expiry again.
|
|
293
237
|
turn_state = {"requests": 0, "started_at_epoch": None}
|
|
294
238
|
turns[turn_id] = turn_state
|
|
295
239
|
else:
|
|
@@ -331,7 +275,6 @@ def complete_turn_budget(vault: Any, *, work_id: str, turn_id: str) -> bool:
|
|
|
331
275
|
__all__ = [
|
|
332
276
|
"ExtractionWorkStateError",
|
|
333
277
|
"active_background_work_id",
|
|
334
|
-
"begin_turn_budget",
|
|
335
278
|
"complete_turn_budget",
|
|
336
279
|
"reserve_model_request",
|
|
337
280
|
]
|
|
@@ -21,6 +21,7 @@ from pathlib import Path
|
|
|
21
21
|
from typing import Any, Mapping
|
|
22
22
|
|
|
23
23
|
from .locking import atomic_write_json, read_json
|
|
24
|
+
from .extraction_budget import aggregate_extraction_metrics
|
|
24
25
|
from .service import Memleaf
|
|
25
26
|
from .vault import Vault, safe_component
|
|
26
27
|
|
|
@@ -396,6 +397,9 @@ def _safe_result(value: Any) -> dict[str, Any]:
|
|
|
396
397
|
model_metrics = _safe_model_metrics(value.get("model_metrics"))
|
|
397
398
|
if model_metrics:
|
|
398
399
|
result["model_metrics"] = model_metrics
|
|
400
|
+
extraction_metrics = value.get("extraction_metrics")
|
|
401
|
+
if isinstance(extraction_metrics, Mapping):
|
|
402
|
+
result["extraction_metrics"] = aggregate_extraction_metrics([extraction_metrics])
|
|
399
403
|
for key in ("coverage_status", "external_evidence_status"):
|
|
400
404
|
if isinstance(value.get(key), str):
|
|
401
405
|
result[key] = value[key][:80]
|
|
@@ -483,6 +487,7 @@ def _aggregate_attempt_results(attempts: list[Any]) -> dict[str, Any]:
|
|
|
483
487
|
if ids:
|
|
484
488
|
aggregate["memory_ids"] = ids
|
|
485
489
|
metric_values: list[Mapping[str, Any]] = []
|
|
490
|
+
extraction_values: list[Mapping[str, Any]] = []
|
|
486
491
|
for attempt in attempts:
|
|
487
492
|
if not isinstance(attempt, Mapping):
|
|
488
493
|
continue
|
|
@@ -493,6 +498,11 @@ def _aggregate_attempt_results(attempts: list[Any]) -> dict[str, Any]:
|
|
|
493
498
|
value = container.get("model_metrics")
|
|
494
499
|
if isinstance(value, Mapping):
|
|
495
500
|
metric_values.append(value)
|
|
501
|
+
extraction = container.get("extraction_metrics")
|
|
502
|
+
if isinstance(extraction, Mapping):
|
|
503
|
+
extraction_values.append(extraction)
|
|
504
|
+
if extraction_values:
|
|
505
|
+
aggregate["extraction_metrics"] = aggregate_extraction_metrics(extraction_values)
|
|
496
506
|
metrics = _aggregate_model_metrics(metric_values)
|
|
497
507
|
if metrics:
|
|
498
508
|
aggregate["model_metrics"] = metrics
|
|
@@ -529,6 +539,9 @@ def _safe_error(error: BaseException) -> dict[str, Any]:
|
|
|
529
539
|
model_metrics = _safe_model_metrics(getattr(error, "model_metrics", None))
|
|
530
540
|
if model_metrics:
|
|
531
541
|
result["model_metrics"] = model_metrics
|
|
542
|
+
extraction_metrics = getattr(error, "extraction_metrics", None)
|
|
543
|
+
if isinstance(extraction_metrics, Mapping):
|
|
544
|
+
result["extraction_metrics"] = aggregate_extraction_metrics([extraction_metrics])
|
|
532
545
|
return result
|
|
533
546
|
|
|
534
547
|
|