Skip to content

Conversation

@cdbartholomew
Copy link
Contributor

Summary

  • Load operation validator extension in main entry point for pre/post operation hooks
  • Add status_code parameter to ValidationResult and OperationValidationError for proper HTTP responses
  • Fix authentication errors to return 401 instead of raising internal errors
  • Re-raise HTTPException in exception handlers to prevent swallowing HTTP errors
  • Add api_key_id to RequestContext for usage tracking
  • Fix reflect background task authentication and internal flag handling

Test plan

  • Verify 401 returned for authentication failures
  • Verify operation validators are called before/after operations
  • Integration tests pass

Enable the operation validator extension to be loaded from environment
configuration and passed to MemoryEngine, allowing pre/post operation
hooks for usage metering, rate limiting, and audit logging.
- Pass API key to background opinion storage task for proper auth
- Add internal flag to RequestContext for tracking internal operations
- Background opinion storage now authenticates correctly with tenant
- Add api_key_id field to RequestContext to track which API key was used
- Enables per-API-key usage analytics in the metering system
- Add status_code parameter to ValidationResult and OperationValidationError
- Convert OperationValidationError to HTTPException with proper status codes
- Fix authentication errors to return 401 instead of raising internal errors
- Re-raise HTTPException in exception handlers to prevent swallowing errors
Resolves merge conflicts in main.py by keeping tenant extension support.
Adds new HindsightConfig parameters (llm_max_concurrent, llm_timeout,
observation_min_facts, observation_top_entities).
- Raise AuthenticationError from memory_engine._authenticate_tenant instead
  of HTTPException so unit tests pass
- Add AuthenticationError handling in HTTP layer to convert to 401 responses
- Fixes failing TestMemoryEngineTenantAuth tests
Returns proper 401 status code for all authentication failures
across all endpoints, not just the ones with explicit handlers.
- Remove redundant individual exception handlers
- Add 'except AuthenticationError: raise' before generic Exception handlers
  to let global handler process auth errors uniformly
This makes the core more generic - it passes tenant_id (which is
extension-agnostic) rather than api_key (which is cloud-specific).

- Add tenant_id field to RequestContext
- Pass tenant_id instead of api_key to background tasks
- Extensions can check internal=True with tenant_id to bypass normal auth
After cleanup of redundant exception handlers, 404 errors were
returning 500 because HTTPException was caught by the generic
except Exception handler. Fixed by combining AuthenticationError
and HTTPException in the re-raise pattern.
@cdbartholomew cdbartholomew merged commit ce45d30 into main Jan 2, 2026
23 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.

3 participants