Commit d78a860
authored
fix(materialize_window): empty-extraction sessions are not ok (#167)
Closes the silent-failure mode #166's live deploy surfaced.
## The bug
When ``AI.GENERATE`` failed per-event (e.g., runtime SA missing
``roles/aiplatform.user``), the SDK swallowed the error and
returned an empty graph for every session. The orchestrator's
session loop then:
* Called ``materialize_with_status`` on the empty graph (didn't
raise — the materializer just had nothing to insert).
* Marked the session as ``ok=True``.
* Reported ``sessions_materialized == sessions_discovered``,
``ok=true``, and an EMPTY ``rows_materialized`` dict.
Operators monitoring on ``jsonPayload.ok`` saw "all good" while
the entity tables stayed empty. Hard-to-spot drift.
## The fix
After ``materialize_with_status`` succeeds, sum the per-table
row counts. If the total is zero, treat as a per-session
failure (matching exception semantics — break the loop,
advance checkpoint only to the prior successful session):
* ``ok=False`` on the SessionResult.
* ``error_code="empty_extraction"``.
* ``error_detail`` documents the common causes: missing
``aiplatform.user`` IAM, transient AI.GENERATE rate limit,
or no extractable ontology content in the session's events.
A legitimately empty session (no MAKO decision points) gets
flagged too — better a false-positive that prompts the operator
to look than a silent zero.
The empty-window heartbeat path (``sessions_discovered == 0``)
is untouched: the empty-extraction guard is per-session and
doesn't fire when no sessions were processed. ``ok=true``
remains the right shape for "the cron ran, nothing to do".
## Tests
Three new cases in ``TestEmptyExtractionNotOk``:
* ``test_all_sessions_zero_rows_reports_not_ok`` — every
session extracts to empty; first marked failed, loop breaks,
``ok=false``, ``sessions_materialized=0``, ``sessions_failed=1``,
error_code matches.
* ``test_partial_extraction_partial_failure_conservative_checkpoint`` —
session 1 succeeds with real rows, session 2 empty, session 3
never reached; checkpoint advances ONLY to session 1's
timestamp; materializer called exactly twice (BQ-quota safe).
* ``test_empty_window_remains_ok`` — zero sessions discovered
still produces ``ok=true``; the per-session guard doesn't
flip the heartbeat case.
71/71 focused tests pass (68 prior + 3 new). Full suite 2930
pass.1 parent d830398 commit d78a860
3 files changed
Lines changed: 430 additions & 24 deletions
File tree
- examples/migration_v5/periodic_materialization
- src/bigquery_agent_analytics
- tests
Lines changed: 32 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
415 | | - | |
416 | | - | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
417 | 432 | | |
418 | 433 | | |
419 | 434 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
921 | 921 | | |
922 | 922 | | |
923 | 923 | | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
| 949 | + | |
| 950 | + | |
| 951 | + | |
| 952 | + | |
| 953 | + | |
| 954 | + | |
| 955 | + | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
| 960 | + | |
| 961 | + | |
| 962 | + | |
| 963 | + | |
| 964 | + | |
| 965 | + | |
| 966 | + | |
| 967 | + | |
| 968 | + | |
| 969 | + | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
| 975 | + | |
| 976 | + | |
| 977 | + | |
| 978 | + | |
| 979 | + | |
| 980 | + | |
| 981 | + | |
| 982 | + | |
| 983 | + | |
| 984 | + | |
| 985 | + | |
| 986 | + | |
| 987 | + | |
| 988 | + | |
| 989 | + | |
| 990 | + | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
| 998 | + | |
924 | 999 | | |
925 | 1000 | | |
926 | 1001 | | |
| |||
1266 | 1341 | | |
1267 | 1342 | | |
1268 | 1343 | | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
1269 | 1356 | | |
1270 | 1357 | | |
1271 | 1358 | | |
1272 | 1359 | | |
1273 | 1360 | | |
1274 | | - | |
1275 | | - | |
1276 | | - | |
1277 | | - | |
1278 | | - | |
1279 | | - | |
1280 | | - | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
1281 | 1368 | | |
1282 | 1369 | | |
1283 | 1370 | | |
| |||
0 commit comments