Skip to content

feat(context): add structured request context storage using AsyncLocalStorage - #153

Open
Aj-Kayvee wants to merge 1 commit into
ASTROIDX556:mainfrom
Aj-Kayvee:feat/structured-request-context-async-local-storage
Open

feat(context): add structured request context storage using AsyncLocalStorage#153
Aj-Kayvee wants to merge 1 commit into
ASTROIDX556:mainfrom
Aj-Kayvee:feat/structured-request-context-async-local-storage

Conversation

@Aj-Kayvee

Copy link
Copy Markdown

Closes #80

Summary

Implements a structured, typed request context store built on Node's AsyncLocalStorage, giving every request a single, request-scoped snapshot of routing metadata, the resolved principal, and arbitrary request-scoped values that propagates through all async continuations.

Changes

  • src/common/context/request-context.ts - new RequestContext store (single AsyncLocalStorage):
    • Structured RequestContextData grouped into identity (requestId, correlationId, traceId, method, path, url, ip, userAgent, startedAt), principal (userId, organizationId, agentId, role, authMethod), timings, and data.
    • Typed getters (getRequestId, getCorrelationId, getTraceId, getMethod, getPath, getStartedAt, getUserId, getOrganizationId, getAgentId, getPrincipal).
    • setPrincipal, setData/getData, and markTiming/getTiming for request-scoped state.
    • Safe no-op behaviour when no request context is active.
  • src/common/interceptors/request-context.interceptor.ts - new global interceptor that seeds the context on every HTTP request, resolving identity from JWT auth or implicit organization/agent headers.
  • src/app.module.ts - registers RequestContextInterceptor globally ahead of the existing agent-trace interceptor.
  • Tests - request-context.spec.ts and request-context.interceptor.spec.ts (vitest).

Verification

  • npm run typecheck - passes
  • npm run lint - passes
  • npm run test - 251 tests pass (30 files), including 12 new tests

…lStorage

Implement a structured, typed request context store backed by
AsyncLocalStorage (RequestContext) that captures routing metadata, resolved
principal and request-scoped values for the lifetime of each HTTP request.

- Add RequestContext store with typed identity/principal getters, scoped
  data storage and timing recording, propagated through async continuations
- Add RequestContextInterceptor that seeds the context on every request,
  resolving identity from JWT auth or implicit org/agent headers
- Register the interceptor globally ahead of the existing agent trace
  interceptor
- Add unit tests for the store and interceptor

Closes ASTROIDX556#80
@drips-wave

drips-wave Bot commented Aug 30, 2026

Copy link
Copy Markdown

@Aj-Kayvee Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@mergekeeper

mergekeeper Bot commented Aug 30, 2026

Copy link
Copy Markdown

MergeKeeper review

Scope: in scope for linked issue #80.
Verdict: clean

Successfully implements structured request context storage using AsyncLocalStorage and a global interceptor with comprehensive test coverage.

Reviewed commit: 1f6b0e63b568077798d2aa625d9a2a3310a87d38.
CI and merge eligibility are checked separately.

@mergekeeper mergekeeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Successfully implements structured request context storage using AsyncLocalStorage and a global interceptor with comprehensive test coverage.

@mergekeeper

mergekeeper Bot commented Aug 30, 2026

Copy link
Copy Markdown

MergeKeeper merge status

Status: blocked
PR state: open
Mergeability: mergeable
Checked commit: 1f6b0e63b568077798d2aa625d9a2a3310a87d38.

Reason:
GitHub pull request merge request failed with 405: 4 of 4 required status checks are expected.

Next steps:
This required status check is enforced directly by the repository's branch rules, independent of MergeKeeper's own CI evaluation — a maintainer merge override cannot bypass it unless MergeKeeper is authorized to.

  1. Wait for the check to pass, or fix the underlying failure.
  2. To let an explicit override bypass this check going forward, add the MergeKeeper GitHub App as a Bypass actor on the ruleset (Settings → Rules → Rulesets → the ruleset → Bypass list).

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 structured request context storage using AsyncLocalStorage

1 participant