Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 14 additions & 10 deletions backend/app/lineage_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@
"order by created_at desc, post_id desc limit $3"
).format(eligibility=SOURCE_POST_ELIGIBILITY_SQL.format(alias="source_post"))

_RECONSTRUCTION_SOURCE_SQL = (
"select post_id, post_title, voc_type_code, created_at, corporate_entity_id, "
"process_unit_id, thread_group_key, secondary_grouping_key "
"from source_post where {eligibility}"
).format(eligibility=SOURCE_POST_ELIGIBILITY_SQL.format(alias="source_post"))

_VISIBLE_LINEAGE_SOURCE_SQL = (
"select post_id, post_title, voc_type_code, visibility_code, "
"corporate_entity_id, process_unit_id, thread_group_key, created_at "
"from source_post where {eligibility}"
).format(eligibility=SOURCE_POST_ELIGIBILITY_SQL.format(alias="source_post"))
Comment on lines +59 to +69

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 Info: SQL extraction preserves the original queries

The new _RECONSTRUCTION_SOURCE_SQL and _VISIBLE_LINEAGE_SOURCE_SQL reproduce the removed inline queries. SOURCE_POST_ELIGIBILITY_SQL.format(alias="source_post") resolves {alias} to a brace-free string, so the outer .format(eligibility=...) cannot re-interpret braces. Column lists match exactly.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.



def estimated_weight_channels(llm: AdjudicationClient | None) -> set[str]:
"""Return the channels that one live reconstruction can actually use."""
Expand Down Expand Up @@ -420,11 +432,7 @@ def __init__(self, active_channels: set[str]) -> None:

async def _load_lineage_records(conn: asyncpg.Connection) -> list[Record]:
"""Load the eligible source snapshot used by one reconstruction."""
rows = await conn.fetch(
"select post_id, post_title, voc_type_code, created_at, corporate_entity_id, "
"process_unit_id, thread_group_key, secondary_grouping_key "
f"from source_post where {SOURCE_POST_ELIGIBILITY_SQL.format(alias='source_post')}"
)
rows = await conn.fetch(_RECONSTRUCTION_SOURCE_SQL)
return records_from_source_posts(rows)


Expand Down Expand Up @@ -521,11 +529,7 @@ def _interval_payload(row: Mapping[str, Any]) -> dict[str, Any]:

async def _fetch_visible_lineage_rows(conn: asyncpg.Connection, can_see_post):
"""One ABAC-filtered ``source_post`` scan plus one edge-table read."""
posts = await conn.fetch(
"select post_id, post_title, voc_type_code, visibility_code, "
"corporate_entity_id, process_unit_id, thread_group_key, created_at "
f"from source_post where {SOURCE_POST_ELIGIBILITY_SQL.format(alias='source_post')}"
)
posts = await conn.fetch(_VISIBLE_LINEAGE_SOURCE_SQL)
visible_all = [row for row in posts if can_see_post(row)]
edge_rows = await conn.fetch(
"select parent_post_id, child_post_id, fused_score, "
Expand Down
2 changes: 1 addition & 1 deletion backend/app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ async def lifespan(app: FastAPI):
timeout=load_settings().orchestrator_answer_timeout_seconds
),
embedding_factory=_embedding_client,
claim_verification_factory=lambda: _claim_verification_client(),
claim_verification_factory=_claim_verification_client,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Claim-verification factory loses late binding

Passing _claim_verification_client directly instead of lambda: _claim_verification_client() binds the original function at lifespan startup, when run_global_ask_worker captures the factory. A later reassignment of the module global no longer reaches the worker, which the neighboring chat_factory lambda deliberately preserves. Tests that swap in a fake verifier after startup (test_ask) are ignored, so external-verification assertions fail.

Suggested change
claim_verification_factory=_claim_verification_client,
claim_verification_factory=lambda: _claim_verification_client(),
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

)
)
app.state.global_ask_worker = global_ask_worker
Expand Down
Loading