Skip to content

feat(#305): EventBridge v2.4 terminals and service-token job polling - #306

Closed
mottych wants to merge 173 commits into
masterfrom
feature/issue-305-eventbridge-terminals-service-auth
Closed

feat(#305): EventBridge v2.4 terminals and service-token job polling#306
mottych wants to merge 173 commits into
masterfrom
feature/issue-305-eventbridge-terminals-service-auth

Conversation

@mottych

@mottych mottych commented Apr 10, 2026

Copy link
Copy Markdown
Owner

Pull Request

Summary

Implements #305: pure EventBridge terminal completion for email insight jobs (spec v2.4) plus service-token alignment for API fallback polling.

  • Domain terminals: publish_email_insight_terminal_v24 publishes ai.job.completed / ai.job.failed to purposepath-domain-events-{STAGE} with flat v2.4 detail (requestId, kickoffEventId, executionMode, etc.). Legacy ai.job.* events on the default bus remain for non–email-insight / non–EventBridge-kickoff jobs.
  • Job model: persists request_id, topic_category, event_signal, kickoff_transport (eventbridge vs api) so terminals only fire for Api EventBridge kickoff + email_insight.
  • Auth: GET /ai/jobs/{jobId} accepts bearer tokens where tokenType/token_type = service_enrichment, role = service, and tenant_id is present; v2 POST /execute-async requires requestId and can use Authorization bearer if body token omitted.
  • Pulumi: ai.job.requested rule + target on shared domain bus; Lambda PutEvents IAM for default + domain bus.

Checklist

  • I reviewed ENGINEERING_GUIDE.md
  • API changes match docs/frontend-integration-guide.md (or I updated it)
  • Responses use ApiResponse[...] with snake_case keys
  • Tests added/updated and pass locally (pytest -q)
  • Updated/Created docs/frontend-alignment-plan.md if scope affects alignment

Testing

Unit tests updated for kickoff detail, async models, execute-async route, and EventBridge client. Ran:

cd c:\Projects\PurposePath\PurposePath_AI\coaching
uv run pytest tests/unit -q

Result: all unit tests pass except pre-existing failures in tests/unit/services/test_website_analysis_service.py (unchanged by this PR).

Mypy on touched files: uv run mypy ../coaching/src/api/auth.py ../coaching/src/services/async_execution_service.py ../coaching/src/api/routes/ai_execute_async.py ../shared/services/eventbridge_client.py --explicit-package-bases — clean.

Deploy note: Event bus purposepath-domain-events-{env} must exist in AWS before applying Pulumi changes.

Screenshots/Logs (optional)

N/A

mottych and others added 30 commits February 17, 2026 12:47
Deleted several outdated issue documentation files related to the Admin API Controller, Async Coaching Messages, Insights Service, Business Data Repository, Token Usage Tracking, and Topic-Driven Endpoint Architecture. These files are no longer relevant to the current project structure and functionality.
Revised existing issue documentation files to enhance clarity and ensure relevance to the current project structure. Removed outdated references and added new information to better align with current functionalities.
Allow multi-level subdomains for purposepath domains in CORS origin matching so staging and admin staging frontends can call the API.

Co-authored-by: Cursor <cursoragent@cursor.com>
Add strict v1.2 EventBridge contract models, SQL generation/validation/idempotency flow, and event routing/tests for terminal completed/failed publishing with retry-aware metadata.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Synced from: PurposePath_Api@d85ce7ee

Original commit: merge: integrate feature/issue-665-measure-integra

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@9cdfa2fa

Original commit: merge(#679): split retrieval execution from persis

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@fd198387

Original commit: Add Strategies API Specification documentation

Original author: Motty Chen

Branch: dev

[skip ci]
Remove API Gateway-level wildcard CORS to avoid preflight/header drift from FastAPI credentialed CORS, and add explicit CORS preflight smoke tests to dev/staging/prod deploy workflows to catch regressions immediately.

Co-authored-by: Cursor <cursoragent@cursor.com>
Synced from: PurposePath_Api@a1fbbcba

Original commit: merge(#687): integration availability hints

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@99732394

Original commit: merge(#683): admin integration definitions into de

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@75021ef0

Original commit: merge(#684): tested-state save gating into dev

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@a73ec232

Original commit: merge(#686): async integration contract hardening

Original author: Motty Chen

Branch: dev

[skip ci]
…hotfix/249-execute-async-action-suggestions
Synced from: PurposePath_Web@97b7dea

Original commit: Merge branch 'hotfix/issue-730-business-foundation

Original author: Motty Chen

Branch: dev

[skip ci]
- add preprod stack/workflow support and preprod smoke deployment path
- add preprod-to-prod promotion support with image URI verification hook
- add safe async background jobs toggle for preprod and related tests/docs

Made-with: Cursor
Synced from: PurposePath_Api@bdf0b4fc

Original commit: merge(#691): merge docs spec consolidation

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Web@e0e61c3

Original commit: Merge pull request #738 from mottych/merge-down/42

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@771a02f6

Original commit: docs(#703): align integration FE specs to current

Original author: Motty Chen

Branch: dev

[skip ci]
chore: promote master to staging after hotfix
chore: promote staging to dev after hotfix
chore: promote master to staging after hotfix #260
Remove duplicated `preprod` entry in coaching Pulumi stack config to restore Ruff validation for downstream staging->dev promotion workflows.

Made-with: Cursor
fix(ci): remove duplicate preprod config key
chore: promote staging to dev after hotfix #260
Synced from: PurposePath_Api@f9667889

Original commit: docs: split shared/local guides and consolidate po

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Web@b735855

Original commit: Merge branch 'docs/streamline-shared-local' into d

Original author: Motty Chen

Branch: dev

[skip ci]
actions-user and others added 28 commits April 7, 2026 21:07
Synced from: PurposePath_Api@f841440e

Original commit: Merge pull request #895 from mottych/squad/892-uni

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@f292c021

Original commit: docs(#901): add no-contract-change validation note

Original author: Motty Chen

Branch: dev

[skip ci]
- Extend topic registry with foundation, full goal, intent, goal-scoped strategies/measures

- Populate strategies_formatted in get_all_strategies and goal-scoped measure fields in get_measures_summary

- Register measures_for_goal / measures_formatted_for_goal; update seed prompts and email insight contract

- Add unit tests for retrieval goal-scoped enrichment

Made-with: Cursor
Synced from: PurposePath_Api@8f83bb61

Original commit: Merge pull request #904 from mottych/docs/notifica

Original author: Motty Chen

Branch: dev

[skip ci]
- DynamoDB table purposepath-llm-usage-{stage} with billing-period GSI and 90d TTL

- Record per-call metrics from UnifiedAIEngine (single-shot + conversation) and CoachingSessionService

- Async jobs pass job_id/correlation_id/estimated_duration via LlmInvocationContext

- Replace deprecated GET /admin/usage and /admin/models/{id}/metrics with GET /admin/llm-usage

- Update admin_ai_specifications.md; remove conversation-derived UsageAnalyticsService

Made-with: Cursor
- Record per-call usage from MultitenantConversationService.process_message (keeps conversation message tokens)

- Inject LlmUsageRecordingService via multitenant_dependencies

- Align Claude 3.5 Sonnet model_pricing to AWS / per 1M on-demand

- Spec v3.3; multitenant_usage helper + unit test

Made-with: Cursor
- Use runtime.options.virtualenv .venv so Pulumi finds the Python SDK

- Dev: keep legacy Secrets Manager names to avoid protected replace

- Align coaching dev Lambda secret env vars with those names

- Ignore S3 bucket acl/grant drift when ObjectOwnership is enforced

Made-with: Cursor
- DynamoDBLlmUsageRepository.query_topic_usage_across_periods with GSI pagination

- TopicLlmUsageStats* response models; months_in_range in billing_periods.py

- Spec v3.4; unit tests for stats route and billing periods

Made-with: Cursor
- StripPathPrefixMiddleware + HTTP_PATH_STRIP_PREFIX in Lambda (Pulumi)

- Fixes 404 on .../coaching/api/v1/admin/llm-usage when full path reaches FastAPI

- Spec v3.5 note; unit tests for path normalization

Made-with: Cursor
Admin clients should use the correct coaching base URL; no path rewriting in FastAPI.

- Drop StripPathPrefixMiddleware, settings field, Pulumi env, tests

- Spec v3.5: client base URL note in §14

Made-with: Cursor
Pydantic BaseModel() with Field defaults is not understood by mypy without
the pydantic plugin; CI strict mypy failed on LlmUsageSummary().
Use a single code path with safe avg_wall when row count is zero.

Made-with: Cursor
Unit tests still assumed / per 1M; model_pricing uses current Bedrock
on-demand / per 1M for claude-3-5-sonnet-20241022-v2.

Made-with: Cursor
Synced from: PurposePath_Api@05cff952

Original commit: feat(#866): finalize consolidated billing gap clos

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@baf62148

Original commit: feat(notification): finalize sync-async resolver m

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@1b351089

Original commit: Merge pull request #913 from mottych:feature/issue

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@ce63f3d0

Original commit: docs(ai-contract): finalize EventBridge/API handsh

Original author: Motty Chen

Branch: dev

[skip ci]
- Consume purposepath.api / ai.job.requested with validated detail (backend jobId, correlation fields)

- Idempotent put_if_absent + atomic claim_pending_job to avoid duplicate workers

- Pulumi rule + Lambda permission for Api kickoff events

- Job status + execute-async responses use camelCase and queued/running per spec §3.5–3.6

- Config: AI_KICKOFF_EVENT_SOURCE / AI_KICKOFF_DETAIL_TYPE (defaults per spec)

Made-with: Cursor
feat(#302): EventBridge email insight kickoff from PurposePath_Api
fix: mypy AsyncJobData construction (unblock Deploy Dev)
Synced from: PurposePath_Api@e47cd570

Original commit: merge: notification AI transport/config/docs quali

Original author: Motty Chen

Branch: dev

[skip ci]
Synced from: PurposePath_Api@43c23459

Original commit: Merge pull request #922 from mottych/feature/issue

Original author: Motty Chen

Branch: dev

[skip ci]
- Publish email-insight completion/failure to domain bus with flat v2.4 detail (requestId, kickoffEventId, executionMode)

- Persist requestId/topic context and kickoff_transport; domain terminals only for Api EventBridge kickoff

- GET /ai/jobs/{id}: accept service_enrichment + role=service bearer tokens

- Pulumi: ai.job.requested rule on purposepath-domain-events-{stack}; PutEvents IAM for domain bus

Made-with: Cursor
@mottych

mottych commented Apr 10, 2026

Copy link
Copy Markdown
Owner Author

Closing: retargeting to dev in a new PR.

@mottych mottych closed this Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants