fix(handoff): bound escalation assessment latency

Co-Authored-By: Codex <noreply@openai.com>
This commit is contained in:
2026-04-27 20:03:14 -04:00
parent fff8338bf2
commit 9bdd9959a8
6 changed files with 77 additions and 5 deletions

View File

@@ -23,10 +23,12 @@ Fixes made:
- The SSE handshake test now calls `stream_escalations()` directly and consumes only the first generator yield, avoiding HTTPX's infinite-stream buffering behavior.
- Handoff manager/API tests stub `_generate_ai_assessment()` with an `AsyncMock`.
- `EscalationBus` normalizes string/UUID account IDs at subscribe/publish/unsubscribe/subscriber_count boundaries, with a regression test.
- Follow-up fix: escalation AI assessment is now latency-bounded by `ESCALATION_AI_ASSESSMENT_TIMEOUT_SECONDS` (default 5s). If it times out, handoff creation proceeds with no assessment instead of blocking on the model/network path.
Verified:
- `pytest tests/test_escalation_bus.py tests/test_handoff_manager.py tests/test_session_handoffs_api.py tests/test_flowpilot_analytics_escalations.py --override-ini=addopts= -q --durations=20``31 passed in 46.95s`
- Same subset with `-n auto``31 passed in 17.80s`
- After the assessment-timeout fix: same subset with `-n auto``32 passed in 17.77s`
- No remaining pytest processes or `resolutionflow%test%` Postgres sessions after the run.
## Resume point
@@ -48,4 +50,4 @@ Verified:
- Do not reintroduce `client.stream()`/ASGITransport tests for infinite SSE responses; test the generator directly or use a real server-level test.
- `DROP SCHEMA public CASCADE` per test is still the dominant cost: DB-backed tests spend ~1.7-2.8s in setup. Use `-n auto` for focused backend loops.
- The bus is acceptable for v1 pilot scale only because Railway is single-replica. Redis pub/sub is the obvious swap when horizontal scaling appears.
- Synchronous `_generate_ai_assessment()` during escalation creation remains product-latency risk; tests are now isolated from it, but the UX path should be watched as the magic-moment screen is built.
- Escalation assessment can be missing when the 5s timeout fires. The handoff-context UI must render a graceful "assessment unavailable/in progress" state rather than treating it as required.