Tasks: 004 — Native-async HITL quarantine to Postgres¶
Conventions¶
- Status:
[ ]todo /[~]in-progress /[x]done. - Owner:
@copilot.
T-001 — Make _quarantine and _quarantine_postgres truly async¶
- Refs: FR-1, FR-2, FR-3, FR-4, FR-5, NFR-PERF-1, NFR-COMPAT-1, AC-4
- Owner: @copilot
- Status:
[x] - Files:
backend/app/ingestion/scout.py(edit)- Steps:
- Convert
_quarantinetoasync defandawait self._quarantine_postgres(...). On exception, call new sync helper_quarantine_jsonl(...)andlogger.warning("pending_review postgres write failed (%s); using JSONL", type(exc).__name__). - Convert
_quarantine_postgrestoasync def. Body: lazyimport asyncpg,await asyncpg.connect(dsn),await conn.execute(...),await conn.close()infinally. Remove allasyncio.run/get_running_loopcalls. - Update
run_and_committoawait self._quarantine(result, payload). - Bump
IngestionScout.agent_versionfrom"0.1.0"to"0.1.1". - Verify:
grep -n "asyncio.run\|get_running_loop" backend/app/ingestion/scout.pyreturns no matches.mypy app/ingestion/scout.py --strictclean.
T-002 — Split JSONL fallback + provenance store tag¶
- Refs: FR-3, FR-4, NFR-AUDIT-1, AC-2
- Owner: @copilot
- Status:
[x] - Files:
backend/app/ingestion/scout.py(edit)- Steps:
- Extract the JSONL write block (currently inside
_quarantine) into_quarantine_jsonl(self, result, payload)(sync, fs only). - After Postgres write, emit
provenance.log_agent_call(... output_data={"pending": True, "store": "postgres"} ...). - Keep the existing JSONL-side
provenance.log_agent_call(already setsstore="jsonl"). - Verify: covered by tests in T-003.
T-003 — Tests: postgres-only, asyncpg call shape, no-asyncio-run regression¶
- Refs: AC-1, AC-2, AC-3, AC-4, AC-5, NFR-COVERAGE-1
- Owner: @copilot
- Status:
[x] - Files:
backend/tests/ingestion/test_scout.py(edit)- Steps:
- Update
test_low_confidence_routes_to_pending_jsonlto monkeypatch_quarantine_postgreswith anAsyncMock(side_effect=RuntimeError("no pg"))so the new async signature works (AC-5 / AC-2). - Add
test_low_confidence_routes_to_postgres_when_available: monkeypatch_quarantine_postgreswithAsyncMock(return_value=None); awaitrun_and_commit; assert summary shape and that no JSONL file was created (AC-1). - Add
test_quarantine_postgres_uses_asyncpg_correctly: install a fakeasyncpgmodule viamonkeypatch.setitem(sys.modules, "asyncpg", fake)whoseconnectreturns aMagicMockwithexecute=AsyncMock(),close=AsyncMock(); awaitscout._quarantine_postgres(result, {}); assert SQL containsINSERT INTO pending_reviewandclosewas awaited even whenexecuteraises (AC-3). - Add
test_no_asyncio_run_in_quarantine_path: readapp/ingestion/scout.pysource and assert neither"asyncio.run("nor"get_running_loop"substrings are present (AC-4). - Verify:
cd backend && pytest tests/ingestion/test_scout.py -qall pass.cd backend && pytest --cov=app --cov-fail-under=75≥ 75 %.
T-004 — Backlog hygiene¶
- Refs: NFR-AUDIT-1
- Owner: @copilot
- Status:
[x] - Files:
BACKLOG.md(edit)- Steps:
- Move BL-20260429-02 from
## Opento## Donewith one-line outcome and link to spec 004. - Append any new follow-ups discovered (mirror items from
## Follow-ups Discoveredbelow). - Verify:
python3 scripts/backlog_lint.pyexit 0.
Done-When (Definition of Done)¶
- All tasks
[x]. - All
AC-*fromspec.mdcovered by passing tests. make testgreen (backend ≥ 75 % coverage).- BL-20260429-02 moved to
## Donein BACKLOG.md. ## Follow-ups Discoveredsection below populated.
Follow-ups Discovered¶
Append-only. Mirror each item into BACKLOG.md with a
BL-YYYYMMDD-NNid.
- BL-20260429-17 — infra, low — Introduce a shared
asyncpg.Poolinapp.db.postgresso HITL writes (and future routes) reuse connections instead of doing per-callconnect/close. Surfaced in: specs/004-async-quarantine-postgres NFR-PERF-1.