HEL-882 evidence: manager review scripts re-run verbatim against e291058 (api repro blocked - 0 provider calls, used unchanged, honest chat.error; sdk repro 1 - exactly 1 loopback HTTP, llm_ops=1, max_retries=0; sdk repro 2 - mid-add swallow now requeues without burning attempts and resumes done with real entry ids after the cap is raised; sdk repro 3 - stub coverage no longer blocks the real rebuild, enqueue 1→tick→done→search hit→no resend proven live by the add-on), deterministic-boundary pinned-install contract re-run 12/12 with final ledger rows persisted before temp cleanup, and the release offline check green across checkout/import/health/fail-closed caps/approved-caps run/data preservation plus the honest mem0 3.11 co-import gap; zero real LLM, zero real embeddings, zero non-loopback outbound, authoritative ledgers untouched
Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
co-authored by
multica-agent
parent
e291058754
commit
59fb06304f
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"head": "e29105875440b88c7951c399ee29c4931bf55a60",
|
||||
"real_llm_requests": 0,
|
||||
"real_embeddings": 0,
|
||||
"embedding_boundary": "deterministic 512-dim; no model loaded",
|
||||
"external_network": "socket.connect rejects non-loopback",
|
||||
"stub_batch": {
|
||||
"backend": "stub",
|
||||
"state": "done"
|
||||
},
|
||||
"mem0_enqueue_count": 1,
|
||||
"mem0_batch_after_tick": {
|
||||
"state": "done",
|
||||
"reason": null,
|
||||
"entry_ids": "[\"38bfb1e0-9f9b-4b1f-85c3-8b437d140e53\"]"
|
||||
},
|
||||
"mem0_hits": [
|
||||
{
|
||||
"id": "38bfb1e0-9f9b-4b1f-85c3-8b437d140e53",
|
||||
"memory": "合成提取记忆HEL874-1"
|
||||
}
|
||||
],
|
||||
"mem0_reenqueue_after_done": 0,
|
||||
"embed_ledger_used": 4,
|
||||
"llm_ledger_used": 1,
|
||||
"deterministic_vector_items": 3
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
# HEL-882 · 硬闸/恢复/发布包修正证据
|
||||
|
||||
读取提交:本目录 JSON 的 `head` 字段(`e29105875440b88c7951c399ee29c4931bf55a60`,
|
||||
最终交付 head 见交付评论——本目录随证据一次追加提交)。全部运行零真实 LLM、
|
||||
零真实嵌入(确定性 512 维替身)、零非回环出站、权威三账零写入。
|
||||
|
||||
## 1. 总管两复现脚本原样复跑(仅改仓库路径与 head)
|
||||
|
||||
脚本:`review_hel882_sdk.py` / `review_hel882_api.py`(与总管附件逐行同构,
|
||||
HEL-874 原版在总管附件)。结果对比:
|
||||
|
||||
| 复现 | e978e87(总管复现) | 本 head(复跑) |
|
||||
| --- | --- | --- |
|
||||
| api:日 token 超限仍发请求 | 1 次 provider 请求、chat.final、已用 2962→5005 | **0 次请求、chat.error、已用 2962 不变**(manager-review-api-rerun.json) |
|
||||
| sdk①:llm_cap=1 撞 500 隐藏重试 | 6 次 HTTP、llm_ops=0、max_retries=2 | **1 次 HTTP、llm_ops=1、max_retries=0**,第二次 add 发送前拒绝(manager-review-sdk-rerun.json) |
|
||||
| sdk②:embed 中途耗尽被吞 | done/[],调 cap 后仍 done、enqueue=0 | **首 tick queued(reason=semantic_add_swallowed_failure:…budget_exhausted,attempts 不耗);调 cap 后同批续跑 done 且 entry_ids 非空** |
|
||||
| sdk③:stub→mem0 同档案 | enqueue=0、真实库无命中 | **enqueue=1**(脚本本身不 tick;补证见 §2) |
|
||||
|
||||
## 2. 补证:stub→mem0 重整全链(真实固定 SDK + 确定性替身)
|
||||
|
||||
`addon_stub_switch_hel882.py` → `HEL-882-sdk-addon-stub-switch.json`:stub 批
|
||||
done 后切 mem0,enqueue=1 → tick → **done + 真实 entry** → search **命中** →
|
||||
再次 enqueue=0(真实完成批不重发)。同边界:零模型加载、禁非回环。
|
||||
|
||||
## 3. 固定安装合同验证(工具本体,确定性边界)
|
||||
|
||||
`real-sdk-hel882.json`:`tools/verify_mem0_real_hel874.py` 12/12 通过;
|
||||
`embedding_boundary` = TextEmbedding 构造前确定性 512 维替身、零模型加载;
|
||||
`final_embed_rows`/`final_llm_used` 在清理临时目录前落盘(逐笔可审计)。
|
||||
e978e87 版真实嵌入勘正见 `../hel874/erratum-hel882.json`。
|
||||
|
||||
## 4. 发布包离线核验
|
||||
|
||||
`release-offline-hel882.json`:`tools/check_release_offline_hel882.py` 全过——
|
||||
R1 空目录 checkout、R2 lock-only venv + PYTHONPATH 服务 import/health
|
||||
(R4-assembly / stub)、R3 未批上限 fail-closed(创建可过、对话在 provider 前
|
||||
拒绝并如实 chat.error)、R4 填批准值后全链(echo 替身、409=数据已在)、
|
||||
R5 停止后数据保留、重开 epoch+1、R6 mem0 同进程导入缺项(3.11 无 wheel,
|
||||
解决路径 deploy/hel874-release.md §4,本卡零下载)。
|
||||
@@ -0,0 +1,106 @@
|
||||
"""HEL-882 add-on to the manager's SDK review: the re-enqueued mem0 batch is
|
||||
actually processed (tick) and becomes searchable — completing the stub→mem0
|
||||
recovery proof (the review script stops after enqueue_count). Same boundary:
|
||||
deterministic 512-dim embedding installed before TextEmbedding construction,
|
||||
socket rejects non-loopback, temp ledger/vector dirs only, zero real LLM
|
||||
(fake 127.0.0.1 gateway), zero real embeddings, zero downloads."""
|
||||
import asyncio
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
ROOT = Path('/home/xiaomo/multica_workspaces/hello-af23464d222e/hel-882-f72ebe62dddc/workdir')
|
||||
REPO = ROOT / 'CyberGril'
|
||||
sys.path.insert(0, str(REPO / 'src'))
|
||||
for name in ('OPENROUTER_API_KEY', 'OPENAI_API_KEY', 'OPENAI_BASE_URL'):
|
||||
os.environ.pop(name, None)
|
||||
spec = importlib.util.spec_from_file_location('contract', REPO / 'tools/verify_mem0_real_hel874.py')
|
||||
contract = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(contract)
|
||||
|
||||
real_connect = socket.socket.connect
|
||||
|
||||
|
||||
def connect(sock, addr):
|
||||
if isinstance(addr, tuple) and addr[0] not in ('127.0.0.1', '::1', 'localhost'):
|
||||
raise AssertionError('addon forbids non-loopback connection')
|
||||
return real_connect(sock, addr)
|
||||
|
||||
|
||||
socket.socket.connect = connect
|
||||
|
||||
import numpy as np
|
||||
import mem0.embeddings.fastembed as embedding_module
|
||||
|
||||
|
||||
class DeterministicEmbedding:
|
||||
embedding_size = 512
|
||||
calls = 0
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
|
||||
def embed(self, texts, *args, **kwargs):
|
||||
for text in ([texts] if isinstance(texts, str) else texts):
|
||||
type(self).calls += 1
|
||||
digest = hashlib.sha256(text.encode()).digest()
|
||||
yield np.array([digest[i % 32] / 255.0 for i in range(512)], dtype=np.float32)
|
||||
|
||||
|
||||
embedding_module.TextEmbedding = DeterministicEmbedding
|
||||
|
||||
from cybergril.memory.semantic import Mem0Backend, SemanticMemory, StubBackend
|
||||
from cybergril.memory.store import Store
|
||||
|
||||
|
||||
async def main():
|
||||
full = os.popen(f'git -C {REPO} rev-parse HEAD').read().strip()
|
||||
result = {'head': full, 'real_llm_requests': 0, 'real_embeddings': 0,
|
||||
'embedding_boundary': 'deterministic 512-dim; no model loaded',
|
||||
'external_network': 'socket.connect rejects non-loopback'}
|
||||
with tempfile.TemporaryDirectory(prefix='hel882-addon-', dir=ROOT) as td:
|
||||
tmp = Path(td)
|
||||
server = contract.start_gateway()
|
||||
try:
|
||||
store = Store(tmp / 'switch.db')
|
||||
with store.conn:
|
||||
store.execute("INSERT INTO chat_message(ts,role,text,turn_id,status) "
|
||||
"VALUES(1,'user','另一条合成原话','t2','sent')")
|
||||
stub = SemanticMemory(store, StubBackend())
|
||||
stub.enqueue_uncovered()
|
||||
await stub.tick()
|
||||
ledger = tmp / 'switch.sqlite3'
|
||||
contract.make_ledger(ledger, 50, 5)
|
||||
cfg = contract.config_for(tmp / 'switch', ledger, port=server.server_address[1],
|
||||
cap=50, llm_cap=5)
|
||||
backend = Mem0Backend(cfg)
|
||||
live = SemanticMemory(store, backend)
|
||||
result['stub_batch'] = dict(store.query_one("SELECT backend,state FROM sem_batch"
|
||||
" WHERE backend='stub'"))
|
||||
result['mem0_enqueue_count'] = live.enqueue_uncovered()
|
||||
await live.tick()
|
||||
batch = dict(store.query_one("SELECT state,reason,entry_ids FROM sem_batch"
|
||||
" WHERE backend='mem0'"))
|
||||
result['mem0_batch_after_tick'] = batch
|
||||
result['mem0_hits'] = await backend.search('另一条合成原话')
|
||||
result['mem0_reenqueue_after_done'] = live.enqueue_uncovered()
|
||||
result['embed_ledger_used'] = backend.ledger.used()
|
||||
result['llm_ledger_used'] = backend.llm_guard.used()
|
||||
backend._memory.llm.client.close()
|
||||
await backend.aclose()
|
||||
store.close()
|
||||
finally:
|
||||
server.shutdown()
|
||||
server.server_close()
|
||||
result['deterministic_vector_items'] = DeterministicEmbedding.calls
|
||||
out = ROOT / 'HEL-882-sdk-addon-stub-switch.json'
|
||||
out.write_text(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"daily_tokens_limit": 1,
|
||||
"used_before": 2962,
|
||||
"used_after": 2962,
|
||||
"provider_requests_after_exhaustion": 0,
|
||||
"events": [
|
||||
"chat.error"
|
||||
],
|
||||
"real_llm_requests": 0,
|
||||
"real_embeddings": 0
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
{
|
||||
"head": "e29105875440b88c7951c399ee29c4931bf55a60",
|
||||
"real_llm_requests": 0,
|
||||
"real_embeddings": 0,
|
||||
"embedding_boundary": "deterministic 512-dimensional vectors; no model loaded",
|
||||
"external_network": "socket.connect rejects all non-loopback hosts",
|
||||
"llm_cap_1_failure_retries": {
|
||||
"add_attempts": 2,
|
||||
"loopback_http_requests": 1,
|
||||
"llm_ledger_used": 1,
|
||||
"errors": [
|
||||
"LLMError",
|
||||
"SemanticBudgetError"
|
||||
],
|
||||
"openai_client_max_retries": 0
|
||||
},
|
||||
"embed_exhaustion_mid_add": {
|
||||
"embed_cap_at_start": 1,
|
||||
"after_first_tick": {
|
||||
"state": "queued",
|
||||
"reason": "semantic_add_swallowed_failure:refused:semantic_embed_budget_exhausted",
|
||||
"entry_ids": null,
|
||||
"attempts": 0
|
||||
},
|
||||
"after_raise_cap_and_tick": {
|
||||
"state": "done",
|
||||
"reason": null,
|
||||
"entry_ids": "[\"2ccf2ee9-0dc2-45c5-8804-a866c69b6549\"]",
|
||||
"attempts": 1
|
||||
},
|
||||
"uncovered_requeued": 0,
|
||||
"embed_ledger_used": 4
|
||||
},
|
||||
"stub_to_mem0_same_archive": {
|
||||
"prior_batch": {
|
||||
"backend": "stub",
|
||||
"state": "done",
|
||||
"entry_ids": "[\"stub-1\"]"
|
||||
},
|
||||
"mem0_enqueue_count": 1,
|
||||
"mem0_hits": []
|
||||
},
|
||||
"deterministic_vector_items": 5
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
{
|
||||
"started": "2026-10-26T15:22:27Z",
|
||||
"embedding_boundary": "deterministic 512-dimensional vectors installed before TextEmbedding construction; no model loaded; zero real embeddings",
|
||||
"external_network": "socket.connect rejects all non-loopback hosts",
|
||||
"install": {
|
||||
"python": "3.10.12",
|
||||
"mem0ai": "2.2.1",
|
||||
"qdrant-client": "1.20.0",
|
||||
"fastembed": "0.9.1",
|
||||
"mem0_path": "/home/xiaomo/multica_workspaces/hello-af23464d222e/hel-857-2cf6dc7dfc87/workdir/hel857-venv/lib/python3.10/site-packages/mem0",
|
||||
"module_sha256": {
|
||||
"memory/main.py": "f329ca4a17af1fbefb32ac10d4cc7ae7ddbdb7435a87eb74c30915cff98b8b7c",
|
||||
"memory/storage.py": "5f5ecdadd2b260fd14f36a0f338336eb760275465dd1056a99a47e1ef07702bd",
|
||||
"embeddings/fastembed.py": "3ec2ae87df5d0bebedb8b5471366c3412975847458499f66097f7b8c9ac8c9b8",
|
||||
"llms/openai.py": "37e6d3c22b55df0731740f4e0868b95bd480ce44363227fe53461db328c5f67e",
|
||||
"vector_stores/qdrant.py": "da570579d5cad69e6f123fdfe32b725235a25604e70047666bec763ba6e2bf43"
|
||||
},
|
||||
"source_tarball_sha256": "9dcef9303ebcec116eec6739f01b8b35bd24459de6a569686b4d19b9412dda23"
|
||||
},
|
||||
"adapter_has_llm_guard": true,
|
||||
"checks": [
|
||||
{
|
||||
"name": "C1_construct",
|
||||
"ok": true,
|
||||
"detail": "client_path=sdk-vector-store-client"
|
||||
},
|
||||
{
|
||||
"name": "C2_add_anchor_payload",
|
||||
"ok": true,
|
||||
"detail": "created=True payload_keys=['created_at', 'data', 'hash', 'input_sha256', 'src_group', 'text_lemmatized', 'turn_ids', 'turn_roles']"
|
||||
},
|
||||
{
|
||||
"name": "C2_add_user_scope",
|
||||
"ok": true,
|
||||
"detail": "user_id present in stored payload"
|
||||
},
|
||||
{
|
||||
"name": "C2_add_ledger_shape",
|
||||
"ok": true,
|
||||
"detail": "embed_items=3 llm_calls=1"
|
||||
},
|
||||
{
|
||||
"name": "C3_extraction_input_set",
|
||||
"ok": true,
|
||||
"detail": "old_memory=True new_row=True history_carry=True"
|
||||
},
|
||||
{
|
||||
"name": "C3b_unshared_canary_never_outbound",
|
||||
"ok": true,
|
||||
"detail": "queued_public_batches=2 leaked=False anchor_taint=False"
|
||||
},
|
||||
{
|
||||
"name": "C4_search_filters",
|
||||
"ok": true,
|
||||
"detail": "hits=3"
|
||||
},
|
||||
{
|
||||
"name": "C4_search_single_debit",
|
||||
"ok": true,
|
||||
"detail": "embed_delta=1 (pre-fix=2)"
|
||||
},
|
||||
{
|
||||
"name": "C6_concurrency_cap",
|
||||
"ok": true,
|
||||
"detail": "outcomes=['ok', 'refused'] used=3 cap=3"
|
||||
},
|
||||
{
|
||||
"name": "C7_reopen_after_close",
|
||||
"ok": true,
|
||||
"detail": "hits_after_reopen=3"
|
||||
},
|
||||
{
|
||||
"name": "C5_embed_zero_refuses",
|
||||
"ok": true,
|
||||
"detail": "err=semantic_embed_budget_not_approved llm_sent=0"
|
||||
},
|
||||
{
|
||||
"name": "C5_llm_zero_refuses",
|
||||
"ok": true,
|
||||
"detail": "err=semantic_llm_budget_not_approved llm_sent=0"
|
||||
}
|
||||
],
|
||||
"embed_rows_after_first_add": [
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:search"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:batch:add"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:add"
|
||||
}
|
||||
],
|
||||
"final_embed_rows": [
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:search"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:batch:add"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:add"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:search"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:batch:add"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:add"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:search"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:batch:add"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:add"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:search"
|
||||
},
|
||||
{
|
||||
"kind": "dense",
|
||||
"items": 1,
|
||||
"note": "product:search"
|
||||
}
|
||||
],
|
||||
"final_llm_used": 3,
|
||||
"finished": "2026-10-26T15:22:29Z",
|
||||
"gateway_requests_total": 3,
|
||||
"failures": [],
|
||||
"temp_dir": "/tmp/multica-task-2170941/hel874-real-sdk-oawg5lsd"
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
{
|
||||
"started": "2026-10-26T15:29:53Z",
|
||||
"venv_python": "/home/xiaomo/multica_workspaces/hello-af23464d222e/hel-874-db7635e6b65e/workdir/CyberGril/.venv311/bin/python",
|
||||
"venv_python_version": "3.11.16",
|
||||
"checks": [
|
||||
{
|
||||
"name": "R1_checkout_fresh_dir",
|
||||
"ok": true,
|
||||
"detail": "cloned tracked source into /tmp/multica-task-2170941/hel882-release-mxps8kap/cybergril-hel874/current"
|
||||
},
|
||||
{
|
||||
"name": "R2_service_imports_product",
|
||||
"ok": true,
|
||||
"detail": ""
|
||||
},
|
||||
{
|
||||
"name": "R6_mem0_coimport_status_recorded",
|
||||
"ok": true,
|
||||
"detail": "import mem0 → ModuleNotFoundError: No module named 'mem0' (resolution path in deploy/hel874-release.md §4; no download in this check)"
|
||||
},
|
||||
{
|
||||
"name": "R2_service_serves_health",
|
||||
"ok": true,
|
||||
"detail": "version=R4-assembly semantic=stub"
|
||||
},
|
||||
{
|
||||
"name": "R3_create_status_recorded",
|
||||
"ok": true,
|
||||
"detail": "create status=201(409=前次运行的档案仍在,也是保留数据的表现)"
|
||||
},
|
||||
{
|
||||
"name": "R3_dialogue_refused_honestly",
|
||||
"ok": true,
|
||||
"detail": "http=200 events=b'data: {\"t\": \"chat.error\", \"epoch\": 1, \"turn_id\": \"00000000-0000-4000-8000-000000000001\", \"phi\": \"\\xe5\\xa5\\xb9\\xe8\\xbf\\x99\\xe4\\xbc\\x9a\\xe5\\x84\\xbf\\xe6\\xb2\\xa1\\xe6\\x8e\\xa5\\xe4\\xb8\\x8a\\xe8\\xaf'"
|
||||
},
|
||||
{
|
||||
"name": "R4_service_restarts_on_same_data",
|
||||
"ok": true,
|
||||
"detail": "epoch=2"
|
||||
},
|
||||
{
|
||||
"name": "R5_epoch_bumped_on_reopen",
|
||||
"ok": true,
|
||||
"detail": "1 → 2"
|
||||
},
|
||||
{
|
||||
"name": "R4_companion_created_offline",
|
||||
"ok": true,
|
||||
"detail": "status=409"
|
||||
},
|
||||
{
|
||||
"name": "R4_dialogue_stream_http",
|
||||
"ok": true,
|
||||
"detail": "status=200 events=b'data: {\"t\": \"chat.delta\", \"epoch\": 2, \"turn_id\": \"00000000-0000-4000-8000-000000000002\", \"delta\": \"\\xe6\\x89\\xb9\"}\\n\\ndata: {\"t\": \"c'"
|
||||
},
|
||||
{
|
||||
"name": "R4_messages_roundtrip",
|
||||
"ok": true,
|
||||
"detail": "roles=['user', 'user', 'companion']"
|
||||
},
|
||||
{
|
||||
"name": "R5_data_dir_preserved",
|
||||
"ok": true,
|
||||
"detail": "['companion.db']"
|
||||
},
|
||||
{
|
||||
"name": "R5_companion_row_survives_restart",
|
||||
"ok": true,
|
||||
"detail": "companion rows=1"
|
||||
}
|
||||
],
|
||||
"mem0_import_in_release_venv": "ModuleNotFoundError: No module named 'mem0'",
|
||||
"failures": [],
|
||||
"finished": "2026-10-26T15:29:55Z"
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
"""Independent real application test with deterministic fake provider."""
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
ROOT = Path('/home/xiaomo/multica_workspaces/hello-af23464d222e/hel-882-f72ebe62dddc/workdir')
|
||||
sys.path[:0] = [str(ROOT / 'CyberGril/src'), str(ROOT / 'CyberGril/tests')]
|
||||
from fastapi.testclient import TestClient
|
||||
from test_r4_api import r4_app
|
||||
from test_api import CREATE, turn, events
|
||||
|
||||
with tempfile.TemporaryDirectory(prefix='hel874-api-review-', dir=ROOT) as td:
|
||||
app, provider = r4_app(Path(td), semantic='off')
|
||||
with TestClient(app) as client:
|
||||
assert client.post('/api/companion', json=CREATE).status_code == 201
|
||||
guard = app.state.life.router.guard
|
||||
guard.config.daily_tokens = 1
|
||||
guard.record(1, 'review_budget_already_used')
|
||||
used_before = guard.used
|
||||
calls_before = len(provider.calls)
|
||||
response = turn(client, '合成测试:额度用完后仍能发出请求吗')
|
||||
result = {'daily_tokens_limit': 1, 'used_before': used_before,
|
||||
'used_after': guard.used, 'provider_requests_after_exhaustion': len(provider.calls)-calls_before,
|
||||
'events': [e['t'] for e in events(response)],
|
||||
'real_llm_requests': 0, 'real_embeddings': 0}
|
||||
(ROOT / 'HEL-874-api-independent.json').write_text(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
@@ -0,0 +1,134 @@
|
||||
"""Independent review: actual pinned SDK, deterministic embedding boundary only."""
|
||||
import asyncio
|
||||
import hashlib
|
||||
import importlib.util
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import socket
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
ROOT = Path('/home/xiaomo/multica_workspaces/hello-af23464d222e/hel-882-f72ebe62dddc/workdir')
|
||||
REPO = ROOT / 'CyberGril'
|
||||
sys.path.insert(0, str(REPO / 'src'))
|
||||
for name in ('OPENROUTER_API_KEY', 'OPENAI_API_KEY', 'OPENAI_BASE_URL'):
|
||||
os.environ.pop(name, None)
|
||||
spec = importlib.util.spec_from_file_location('contract', REPO / 'tools/verify_mem0_real_hel874.py')
|
||||
contract = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(contract)
|
||||
|
||||
# Block every network connection except our loopback fake HTTP server.
|
||||
real_connect = socket.socket.connect
|
||||
def connect(sock, addr):
|
||||
if isinstance(addr, tuple) and addr[0] not in ('127.0.0.1', '::1', 'localhost'):
|
||||
raise AssertionError('review forbids non-loopback connection')
|
||||
return real_connect(sock, addr)
|
||||
socket.socket.connect = connect
|
||||
|
||||
import numpy as np
|
||||
import mem0.embeddings.fastembed as embedding_module
|
||||
class DeterministicEmbedding:
|
||||
embedding_size = 512
|
||||
calls = 0
|
||||
def __init__(self, *args, **kwargs):
|
||||
pass
|
||||
def embed(self, texts, *args, **kwargs):
|
||||
for text in ([texts] if isinstance(texts, str) else texts):
|
||||
type(self).calls += 1
|
||||
digest = hashlib.sha256(text.encode()).digest()
|
||||
yield np.array([digest[i % 32] / 255.0 for i in range(512)], dtype=np.float32)
|
||||
embedding_module.TextEmbedding = DeterministicEmbedding
|
||||
|
||||
from cybergril.memory.semantic import Mem0Backend, SemanticMemory, StubBackend
|
||||
from cybergril.memory.store import Store
|
||||
|
||||
async def main():
|
||||
result = {'head': 'e29105875440b88c7951c399ee29c4931bf55a60',
|
||||
'real_llm_requests': 0, 'real_embeddings': 0,
|
||||
'embedding_boundary': 'deterministic 512-dimensional vectors; no model loaded',
|
||||
'external_network': 'socket.connect rejects all non-loopback hosts'}
|
||||
with tempfile.TemporaryDirectory(prefix='hel874-independent-', dir=ROOT) as td:
|
||||
tmp = Path(td)
|
||||
server = contract.start_gateway()
|
||||
try:
|
||||
ledger = tmp / 'retry.sqlite3'
|
||||
contract.make_ledger(ledger, 50, 1)
|
||||
cfg = contract.config_for(tmp / 'retry', ledger, port=server.server_address[1], cap=50, llm_cap=1)
|
||||
backend = Mem0Backend(cfg)
|
||||
normal_post = contract.FakeGateway.do_POST
|
||||
requests = []
|
||||
def fail_post(handler):
|
||||
handler.rfile.read(int(handler.headers.get('content-length') or 0))
|
||||
requests.append(handler.path)
|
||||
body = b'{"error":{"message":"review controlled 500"}}'
|
||||
handler.send_response(500)
|
||||
handler.send_header('content-type', 'application/json')
|
||||
handler.send_header('content-length', str(len(body)))
|
||||
handler.end_headers()
|
||||
handler.wfile.write(body)
|
||||
contract.FakeGateway.do_POST = fail_post
|
||||
rows = [{'text': '合成测试钥匙在第三个花盆下面', 'turn_id': 't1', 'role': 'user', 'message_id': 1}]
|
||||
errors = []
|
||||
for _ in range(2):
|
||||
try:
|
||||
await backend.add_group(rows, {}, 'retry')
|
||||
except Exception as exc:
|
||||
errors.append(type(exc).__name__)
|
||||
result['llm_cap_1_failure_retries'] = {
|
||||
'add_attempts': 2, 'loopback_http_requests': len(requests),
|
||||
'llm_ledger_used': backend.llm_guard.used(), 'errors': errors,
|
||||
'openai_client_max_retries': backend._memory.llm.client.max_retries}
|
||||
backend._memory.llm.client.close()
|
||||
await backend.aclose()
|
||||
contract.FakeGateway.do_POST = normal_post
|
||||
|
||||
ledger2 = tmp / 'exhaust.sqlite3'
|
||||
contract.make_ledger(ledger2, 1, 5)
|
||||
cfg2 = contract.config_for(tmp / 'exhaust', ledger2, port=server.server_address[1], cap=1, llm_cap=5)
|
||||
backend2 = Mem0Backend(cfg2)
|
||||
store = Store(tmp / 'exhaust.db')
|
||||
with store.conn:
|
||||
store.execute("INSERT INTO chat_message(ts,role,text,turn_id,status) VALUES(1,'user',?,'t1','sent')", (rows[0]['text'],))
|
||||
semantic = SemanticMemory(store, backend2)
|
||||
semantic.enqueue_uncovered()
|
||||
await semantic.tick()
|
||||
before = dict(store.query_one('SELECT state,reason,entry_ids,attempts FROM sem_batch'))
|
||||
backend2.ledger.cap = 50
|
||||
await semantic.tick()
|
||||
after = dict(store.query_one('SELECT state,reason,entry_ids,attempts FROM sem_batch'))
|
||||
result['embed_exhaustion_mid_add'] = {
|
||||
'embed_cap_at_start': 1, 'after_first_tick': before,
|
||||
'after_raise_cap_and_tick': after,
|
||||
'uncovered_requeued': semantic.enqueue_uncovered(),
|
||||
'embed_ledger_used': backend2.ledger.used()}
|
||||
backend2._memory.llm.client.close()
|
||||
await backend2.aclose()
|
||||
store.close()
|
||||
|
||||
store2 = Store(tmp / 'switch.db')
|
||||
with store2.conn:
|
||||
store2.execute("INSERT INTO chat_message(ts,role,text,turn_id,status) VALUES(1,'user','另一条合成原话','t2','sent')")
|
||||
stub = SemanticMemory(store2, StubBackend())
|
||||
stub.enqueue_uncovered()
|
||||
await stub.tick()
|
||||
ledger3 = tmp / 'switch.sqlite3'
|
||||
contract.make_ledger(ledger3, 50, 5)
|
||||
cfg3 = contract.config_for(tmp / 'switch', ledger3, port=server.server_address[1], cap=50, llm_cap=5)
|
||||
backend3 = Mem0Backend(cfg3)
|
||||
live = SemanticMemory(store2, backend3)
|
||||
result['stub_to_mem0_same_archive'] = {
|
||||
'prior_batch': dict(store2.query_one('SELECT backend,state,entry_ids FROM sem_batch')),
|
||||
'mem0_enqueue_count': live.enqueue_uncovered(),
|
||||
'mem0_hits': await backend3.search('另一条合成原话')}
|
||||
backend3._memory.llm.client.close()
|
||||
await backend3.aclose()
|
||||
store2.close()
|
||||
finally:
|
||||
server.shutdown()
|
||||
server.server_close()
|
||||
result['deterministic_vector_items'] = DeterministicEmbedding.calls
|
||||
(ROOT / 'HEL-874-sdk-independent.json').write_text(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
print(json.dumps(result, ensure_ascii=False, indent=2))
|
||||
|
||||
asyncio.run(main())
|
||||
@@ -114,7 +114,10 @@ def main() -> None:
|
||||
parser.add_argument("--current", default=None)
|
||||
parser.add_argument("out", nargs="?", default="hel882-release-check.json")
|
||||
args = parser.parse_args()
|
||||
venv_python = Path(args.venv).resolve()
|
||||
# Keep the venv python path as given: these are typically symlinks into the
|
||||
# base interpreter, and resolving them would bypass the venv's pyvenv.cfg
|
||||
# (dropping site-packages — the classic "no module named yaml" trap).
|
||||
venv_python = Path(args.venv)
|
||||
REPORT["venv_python"] = str(venv_python)
|
||||
REPORT["venv_python_version"] = subprocess.run(
|
||||
[str(venv_python), "-c", "import sys;print(sys.version.split()[0])"],
|
||||
@@ -133,14 +136,14 @@ def main() -> None:
|
||||
["git", "clone", "--quiet", "--no-hardlinks", f"file://{REPO}", str(current)],
|
||||
capture_output=True, text=True, cwd=tmp)
|
||||
check("R1_checkout_fresh_dir", cloned.returncode == 0 and (current / "src").is_dir(),
|
||||
cloned.stderr.strip()[:200] or f"cloned tracked source into {current}")
|
||||
cloned.stderr.strip()[:600] or f"cloned tracked source into {current}")
|
||||
|
||||
# R2 — lock-only venv can import and serve the product (PYTHONPATH=<current>/src)
|
||||
probe = subprocess.run(
|
||||
[str(venv_python), "-c", "import cybergril.api, cybergril.memory.semantic"],
|
||||
capture_output=True, text=True, cwd=current,
|
||||
env=dict(os.environ, PYTHONPATH=str(current / "src")))
|
||||
check("R2_service_imports_product", probe.returncode == 0, probe.stderr.strip()[:200])
|
||||
check("R2_service_imports_product", probe.returncode == 0, probe.stderr.strip()[:600])
|
||||
|
||||
# R6 — exact mem0 co-import status in the same lock-only venv (no downloads here)
|
||||
mem0_probe = subprocess.run([str(venv_python), "-c", "import mem0"],
|
||||
|
||||
Reference in New Issue
Block a user