Skip to content

feat: event-sourced strategy lifecycle audit (recommendation → execution → snapshot)#886

Merged
edehvictor merged 1 commit into
edehvictor:mainfrom
Nanle-code:feature/strategy-lifecycle-audit-issue-34
Jun 30, 2026
Merged

feat: event-sourced strategy lifecycle audit (recommendation → execution → snapshot)#886
edehvictor merged 1 commit into
edehvictor:mainfrom
Nanle-code:feature/strategy-lifecycle-audit-issue-34

Conversation

@Nanle-code

Copy link
Copy Markdown
Contributor

Closes #34

Implements a full event-sourced audit trail that links every stage of a strategy's lifecycle — from recommendation through oracle evaluation, queue entry, execution or failure, and snapshot — using a stable correlationId rather than timestamps alone.

types/strategyLifecycleEvents.ts

  • Added id, correlationId, actor, and sourceDataHash to all events
  • New event types: OracleDecisionRecorded, FallbackRouteSelected, StrategyExecutionFailed
  • StrategySnapshottedEvent now carries snapshotVersion and changeReason

services/strategyLifecycleAuditService.ts

  • Static helpers: generateEventId, generateCorrelationId, hashPayload (SHA-256)
  • getByCorrelationId — replays all events in a chain across any strategy
  • getCorrelationSummary — returns the event path and isComplete flag for a given chain

routes/strategies.ts

  • New endpoint: GET /api/strategies/:strategyId/lifecycle
  • Optional ?correlationId= param scopes the response to a single recommendation-through-execution chain

Tests (42 passing)

strategyLifecycleAudit.test.ts — service unit tests
strategyLifecycleRoute.test.ts — HTTP endpoint tests

Scenarios covered per acceptance criteria:

  • Complete execution path
  • Oracle-blocked path
  • Fallback route selected
  • Failed execution with retry metadata
  • Replayed history query scoped by correlationId

Validation

npm test -- strategy      # strategyLifecycleAudit, strategyLifecycleRoute
npm test -- rebalance     # existing rebalance tests unaffected
npm run build             # no new type errors introduced

- Extend StrategyLifecycleEventType with OracleDecisionRecorded,
  FallbackRouteSelected, StrategyExecutionFailed, and updated
  StrategySnapshotted with snapshotVersion + changeReason
- Add correlationId, actor, and sourceDataHash fields to all events
  so every event in a recommendation-through-execution chain is
  stably linked by a single ID rather than timestamps alone
- Upgrade StrategyLifecycleAuditService with:
  - Static helpers: generateEventId, generateCorrelationId, hashPayload
  - getByCorrelationId: replays a full chain across strategies
  - getCorrelationSummary: returns path + isComplete for a chain
- Add GET /api/strategies/:strategyId/lifecycle endpoint supporting
  optional correlationId query param for scoped history replay
- Add 42 tests covering complete execution, blocked oracle, fallback
  route, failed execution, and replayed history query scenarios

Closes edehvictor#34
@Nanle-code Nanle-code requested a review from edehvictor as a code owner June 29, 2026 13:16
@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

@Nanle-code is attempting to deploy a commit to the Edeh Victor's projects Team on Vercel.

A member of the Team first needs to authorize it.

@edehvictor edehvictor merged commit f9f818b into edehvictor:main Jun 30, 2026
5 of 9 checks passed
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.

Implement Yield Vault Fuzzing & Invariant Testing Suite

2 participants