-
Notifications
You must be signed in to change notification settings - Fork 0
[Audit] Consolidate duplicated dialect/DB/chain helpers into shared modules #1313
Copy link
Copy link
Closed
Closed
Copy link
Labels
agent:codexAssign to Codex agentAssign to Codex agentagents:formattedIssue has been formatted to AGENT_ISSUE_TEMPLATEIssue has been formatted to AGENT_ISSUE_TEMPLATEenhancementNew feature or requestNew feature or requestpriority:normalNormal-priority weekly repo-review workNormal-priority weekly repo-review workstatus: readyReady for Orchestrator opener pickupReady for Orchestrator opener pickuptestingTests or coverage workTests or coverage work
Description
Activity
Metadata
Metadata
Assignees
Labels
agent:codexAssign to Codex agentAssign to Codex agentagents:formattedIssue has been formatted to AGENT_ISSUE_TEMPLATEIssue has been formatted to AGENT_ISSUE_TEMPLATEenhancementNew feature or requestNew feature or requestpriority:normalNormal-priority weekly repo-review workNormal-priority weekly repo-review workstatus: readyReady for Orchestrator opener pickupReady for Orchestrator opener pickuptestingTests or coverage workTests or coverage work
Why
The dual-dialect DB layer is implemented by per-module copies of the same helpers instead of shared functions, so every new flow re-implements (and can drift on) dialect handling. Verified copies at
e5764a5:_placeholder(conn)/_is_sqlite(conn)(pick?vs%s,isinstance(conn, sqlite3.Connection)) duplicated across 12 modules:etl/{activism_detection,activism_flow,conviction_flow,daily_diff_flow,digest_flow,edgar_flow,evaluation_flow,ingest_flow,news_flow}.py,api/{signals,chat,activism}.py._columns/_get_columns(SQLitePRAGMA/pragma_table_infovs PGinformation_schema.columns) inetl/digest_flow.py:84,etl/edgar_flow.py:62,api/search.py:47.api_usagetable DDL inetl/evaluation_flow.py:101,llm/cost_tracking.py:25,adapters/base.py:83/102._extract_json_text(chains/filing_summary.py:169,chains/holdings_analysis.py:155),_cursor_rows_to_dicts(same two),_guard_context/_acquire_connection(chains/rag_search.py,chains/nl_query.py),_normalize_cik(api/managers.py:245,scripts/seed_universe.py:23,scripts/resolve_aliases.py:29).Est. ~210 LOC of duplication; the risk is divergence (a fix applied to one copy and not the others) — the same defect class behind several other audit findings.
Scope
Consolidate the duplicated dialect/DB/chain helpers into shared locations (
adapters/base.pyfor DB;chains/utils.pyfor chain helpers; autilsnormalizer for CIK) and update call sites to import them.Non-Goals
check_dialect_portability.pygate semantics.Tasks
is_sqlite(conn),get_placeholder(conn),get_table_columns(conn, table), and publicensure_api_usage_schema(conn)toadapters/base.py; replace the 12+3+3 call sites.extract_json_text()androws_to_dicts()tochains/utils.py; replace the chain copies. Centralize_guard_context/_acquire_connection.normalize_cik()and replace the 3 copies.Acceptance Criteria
_placeholdercopy in any module trips the single-definition gate.Implementation Notes
Audit baseline:
main@e5764a5on 2026-06-28. Call sites enumerated by the duplication sweep (Code/Audits/Manager-Database/2026-06-28-02-duplication-quality.md).