Skip to content

feat(api): add minimal session events timeline pipeline#28

Merged
naory merged 5 commits intomainfrom
feat/session-events-minimal-timeline
Mar 8, 2026
Merged

feat(api): add minimal session events timeline pipeline#28
naory merged 5 commits intomainfrom
feat/session-events-minimal-timeline

Conversation

@naory
Copy link
Copy Markdown
Owner

@naory naory commented Mar 8, 2026

Summary

  • add a simplified append-only session_events model (id, session_id, event_type, created_at, metadata) with migration + indexes
  • introduce typed session events and a single emitter helper, then mirror only the first 5 lifecycle events into timeline records
  • expose timeline response as eventType / createdAt / metadata and standardize metadata shape for the first 5 events
  • enforce post-write boundary emission ordering (decision event after decision persistence; settlement verified before close)
  • add focused tests for emitter inserts, timeline ordering, boundary emissions, and event ordering

Test plan

  • pnpm --filter api test -- test/events/emitSessionEvent.test.ts test/events/getSessionTimeline.test.ts test/routes/sessions.test.ts test/routes/gate.test.ts test/db/queries.session-events.test.ts
  • pnpm --filter api test -- test/db/queries.session-events.test.ts test/routes/gate.test.ts test/stripeWebhook.test.ts test/services/paymentWatcher.matching.test.ts

Made with Cursor

NAOR YUVAL added 3 commits March 8, 2026 15:54
Implement a minimal append-only session_events pipeline with typed event names, standardized metadata for the first five lifecycle events, and a timeline API response for immediate observability. Add focused tests for emitter inserts, ordered timeline reads, and boundary event emission ordering.

Made-with: Cursor
Document that non-UUID legacy session_ids are intentionally discarded during normalization and emit a migration notice with the discarded-row count. Rename the session-events test suite to reflect metadata standardization scope.

Made-with: Cursor
Keep session timeline ordering deterministic with created_at plus id, and update sprint observability docs to reflect the API contract change to eventType/createdAt/metadata.

Made-with: Cursor
@naory
Copy link
Copy Markdown
Owner Author

naory commented Mar 8, 2026

Contract change note for reviewers:

  • /api/sessions/:sessionId/timeline response shape has changed from { event, timestamp } to { eventType, createdAt, metadata }.
  • Updated docs in docs/LIFECYCLE_OBSERVABILITY_ANDTIMELINE_SPRINT.md to match this API contract.
  • Timeline ordering is deterministic as ORDER BY created_at ASC, id ASC in both helper and DB query path.

I also verified there is currently no apps/driver consumer of this timeline endpoint.

Make db.getSessionTimeline delegate to events/getSessionTimeline so timeline SQL ordering and shape are maintained in one canonical helper.

Made-with: Cursor
@naory
Copy link
Copy Markdown
Owner Author

naory commented Mar 8, 2026

Follow-up refactor pushed:

  • db.getSessionTimeline(...) now delegates to events/getSessionTimeline.ts.
  • This keeps timeline SQL (ORDER BY created_at ASC, id ASC) and selected columns in one canonical query path.

Stop gate exit flow when insertPolicyDecision fails by returning a 500 and structured error log, and add regression coverage to ensure decision events and pending intents are not emitted after persistence failure.

Made-with: Cursor
@naory naory merged commit f54d85e into main Mar 8, 2026
1 check failed
@naory naory deleted the feat/session-events-minimal-timeline branch March 8, 2026 15:53
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.

1 participant