CRAP Score Improvements: unified_synthesis_handler: 52.8 → 22 (57% reduction) poll_workflow_result: 38.4 → 0 (REMOVED, split into helpers) DRY Improvements: - Extracted JWT token extraction to handlers/jwt_utils.rs (shared) - Extracted workflow builders to handlers/workflow_builder.rs - Extracted polling logic to handlers/workflow_poller.rs - Removed duplicate code: -50 LOC across modules Architecture: ├─ jwt_utils.rs: extract_jwt_token() ├─ workflow_builder.rs: WorkflowBuilder + WorkflowQueryBuilder ├─ workflow_poller.rs: poll_workflow_until_complete(), response parsing └─ handlers use shared utilities Testability: + 18 new unit tests for builders + polling + 6 new unit tests for JWT utils + Mock-friendly response parsers (parse_workflow_status, etc.) SRP Improvements: ├─ unified_synthesis_handler: Route + orchestrate (NOT parse/build) ├─ execute_reasoning_workflow(): Build + poll + parse (single concern) ├─ poll_workflow_until_complete(): ONLY polling (retries, timeout) └─ Response parsers: ONLY extraction (no business logic) Compilation: ✅
- Add SynthesisClient.execute_workflow() for POST /workflow - Wired agent_handler to call START_WORKFLOW via gateway - JWT token propagated to all workflow operations - Store workflow_id/run_id in temporal_workflow_links table (migration 005) - Document full Temporal integration flow Temporal.io gRPC ← (gateway translates REST) ← POST /workflow api.riotpiao.com ↓ Agent handler receives workflow_id/run_id ↓ Store in temporal_workflow_links (external reference table) ↓ Query status via DESCRIBE_WORKFLOW action Architecture: Temporal owns execution, Memory DB owns reasoning traces + links Compilation: ✅