refactor(api): TOML 配置 SSOT、统一错误契约、Auth/事务加固与可观测性 (#33)

配置 SSOT(TOML + .env)
统一错误契约
Auth 与事务边界
Redis / Celery 可靠性:业务 Redis(DB/0)与 Celery broker/backend(DB/1)显式拆分;连接池、sync client
可观测性(OpenTelemetry + LGTM)
This commit is contained in:
Sully
2026-05-22 13:44:50 +08:00
committed by GitHub
parent f09ae248f9
commit 53e0065e3e
298 changed files with 15247 additions and 4344 deletions

View File

@@ -7,6 +7,7 @@ Celery task 只能作为同步入口包装 async service不再维护 sync mem
from sqlalchemy.ext.asyncio import AsyncSession
from app.core.db import transactional
from app.core.logging import get_logger
from app.features.memory.embedding_service import MemoryEmbeddingService
from app.features.memory.ingest_service import MemoryIngestService
@@ -57,7 +58,7 @@ class MemoryService:
async def ingest_transcripts_batch(
self,
user_id: str,
items: list[tuple[str, str, dict | None]],
items: list[tuple[str, str, dict | None, str | None]],
*,
memoir_correlation_id: str | None = None,
) -> list[str]:
@@ -112,71 +113,71 @@ class MemoryService:
async def exclude_chunk(
self, user_id: str, chunk_id: str, *, reason: str = ""
) -> bool:
ok = await set_chunk_excluded(self._db, chunk_id, user_id, True)
if not ok:
return False
stale_count = await mark_facts_stale_for_excluded_chunk(
self._db,
user_id=user_id,
chunk_id=chunk_id,
)
await create_curation_action(
self._db,
user_id=user_id,
action_type="exclude",
target_type="chunk",
target_id=chunk_id,
details={
**({"reason": reason} if reason else {}),
"staled_fact_count": stale_count,
},
)
await self._db.commit()
async with transactional(self._db):
ok = await set_chunk_excluded(self._db, chunk_id, user_id, True)
if not ok:
return False
stale_count = await mark_facts_stale_for_excluded_chunk(
self._db,
user_id=user_id,
chunk_id=chunk_id,
)
await create_curation_action(
self._db,
user_id=user_id,
action_type="exclude",
target_type="chunk",
target_id=chunk_id,
details={
**({"reason": reason} if reason else {}),
"staled_fact_count": stale_count,
},
)
return True
async def restore_chunk(self, user_id: str, chunk_id: str) -> bool:
ok = await set_chunk_excluded(self._db, chunk_id, user_id, False)
if not ok:
return False
await create_curation_action(
self._db,
user_id=user_id,
action_type="restore",
target_type="chunk",
target_id=chunk_id,
details={"fact_restore_policy": "requires_reenrichment"},
)
await self._db.commit()
async with transactional(self._db):
ok = await set_chunk_excluded(self._db, chunk_id, user_id, False)
if not ok:
return False
await create_curation_action(
self._db,
user_id=user_id,
action_type="restore",
target_type="chunk",
target_id=chunk_id,
details={"fact_restore_policy": "requires_reenrichment"},
)
return True
async def confirm_fact(self, user_id: str, fact_id: str) -> bool:
ok = await set_memory_fact_status(self._db, fact_id, user_id, "confirmed")
if not ok:
return False
await create_curation_action(
self._db,
user_id=user_id,
action_type="confirm",
target_type="fact",
target_id=fact_id,
details=None,
)
await self._db.commit()
async with transactional(self._db):
ok = await set_memory_fact_status(self._db, fact_id, user_id, "confirmed")
if not ok:
return False
await create_curation_action(
self._db,
user_id=user_id,
action_type="confirm",
target_type="fact",
target_id=fact_id,
details=None,
)
return True
async def reject_fact(
self, user_id: str, fact_id: str, *, reason: str = ""
) -> bool:
ok = await set_memory_fact_status(self._db, fact_id, user_id, "rejected")
if not ok:
return False
await create_curation_action(
self._db,
user_id=user_id,
action_type="reject",
target_type="fact",
target_id=fact_id,
details={"reason": reason} if reason else None,
)
await self._db.commit()
return ok
async with transactional(self._db):
ok = await set_memory_fact_status(self._db, fact_id, user_id, "rejected")
if not ok:
return False
await create_curation_action(
self._db,
user_id=user_id,
action_type="reject",
target_type="fact",
target_id=fact_id,
details={"reason": reason} if reason else None,
)
return True