symfonic.agent.fastapi.memory_create_helpers¶
memory_create_helpers ¶
Shared helpers for the memory-create handlers.
Extracted so memory_create_handlers.py can stay under the 300-LOC
cap with room for the five per-layer handler bodies.
emit_create_audit
async
¶
emit_create_audit(request: Request, scope: FrameworkTenantScope, *, layer: MemoryLayer, resource_id: str, metadata: dict[str, Any] | None = None) -> None
Await the audit record directly so the entry is committed before the handler returns its response.
Using emit_audit_event (fire-and-forget via loop.create_task)
caused a CI-only race: TestClient's per-request event loop tears down
before the scheduled task executes, so drain() always saw an empty
list. Awaiting directly eliminates that window at negligible cost
(the in-memory logger is a lock + list append). Audit failures are
swallowed so a sick audit store can never 500 a user request.
Source code in src/symfonic/agent/fastapi/memory_create_helpers.py
require_layer ¶
Return the layer store or raise 404 if the layer is disabled.
Source code in src/symfonic/agent/fastapi/memory_create_helpers.py
scope_error ¶
Translate a scope refusal into the mapped transport error.
Compatibility shim (CADR-17). This was the fifth place the status ladder was written down (EMAP-1 counted it); it now delegates to the one mapper. Statuses are unchanged — 403 for a security refusal, 400 for an invalid scope value — and the 403 detail converges on the EMAP-4 verbatim string, which the ad-hoc version already began with.