fix(awooop): chunk run context lookups
All checks were successful
CD Pipeline / tests (push) Successful in 1m20s
Code Review / ai-code-review (push) Successful in 13s
CD Pipeline / build-and-deploy (push) Successful in 3m55s
CD Pipeline / post-deploy-checks (push) Successful in 1m47s

This commit is contained in:
Your Name
2026-05-31 16:47:01 +08:00
parent b92025a829
commit aee92bc7a3
2 changed files with 108 additions and 44 deletions

View File

@@ -19,6 +19,7 @@ from src.api.v1.platform.operator_runs import (
from src.services.ollama_failover_manager import OllamaEndpoint, OllamaRoutingResult
from src.services.ollama_health_monitor import HealthReport, HealthStatus
from src.services.platform_operator_service import (
_RUN_CONTEXT_QUERY_CHUNK_SIZE,
_ai_route_health_map,
_ai_route_lane_state,
_ai_route_policy_order,
@@ -31,6 +32,7 @@ from src.services.platform_operator_service import (
_cicd_event_item_from_row,
_collect_run_incident_ids,
_is_source_correlation_applied_link,
_iter_run_context_batches,
_legacy_mcp_timeline_status,
_legacy_mcp_timeline_summary,
_list_filter_context_limit,
@@ -1973,6 +1975,34 @@ def test_list_filter_context_limit_scales_with_candidate_rows() -> None:
assert _list_filter_context_limit(10000) == 20000
def test_run_context_batches_stay_under_asyncpg_parameter_ceiling() -> None:
runs = [
SimpleNamespace(
run_id=UUID(int=index + 1),
trigger_ref=str(UUID(int=index + 10_000)),
)
for index in range((_RUN_CONTEXT_QUERY_CHUNK_SIZE * 2) + 7)
]
batches = _iter_run_context_batches(runs)
assert [len(batch["run_ids"]) for batch in batches] == [
_RUN_CONTEXT_QUERY_CHUNK_SIZE,
_RUN_CONTEXT_QUERY_CHUNK_SIZE,
7,
]
assert batches[0]["trigger_ref_to_run"][str(UUID(int=10_000))] == UUID(int=1)
for batch in batches:
worst_case_inbound_params = (
len(batch["run_ids"])
+ len(batch["trigger_refs"])
+ len(batch["trigger_event_ids"])
)
assert len(batch["run_ids"]) <= _RUN_CONTEXT_QUERY_CHUNK_SIZE
assert worst_case_inbound_params <= _RUN_CONTEXT_QUERY_CHUNK_SIZE * 3
assert worst_case_inbound_params < 32_767
def test_timeline_sort_key_normalizes_datetime_and_iso_string() -> None:
fallback = datetime(2026, 5, 14, 10, 0, 0)
keys = [