Skip to content

Propagate request context through async task payloads#273

Merged
nicoloboschi merged 1 commit intomainfrom
fix/propagate-request-context-in-async-tasks
Feb 2, 2026
Merged

Propagate request context through async task payloads#273
nicoloboschi merged 1 commit intomainfrom
fix/propagate-request-context-in-async-tasks

Conversation

@cdbartholomew
Copy link
Contributor

Summary

  • Pass tenant_id and api_key_id through the task payload dict in submit_async_retain and submit_async_consolidation
  • Restore these fields into RequestContext in the _handle_batch_retain and _handle_consolidation worker handlers
  • Ensures downstream operations (consolidation, mental model refreshes) triggered by async workers retain the original caller's request context

Context

When async tasks were submitted, the worker handlers created RequestContext(internal=True) without preserving the caller's tenant_id or api_key_id. This meant any downstream operations that needed request context (e.g., extension hooks, mental model refreshes triggered after consolidation) could not identify the originating tenant.

The submit_async_consolidation and submit_async_refresh_mental_model paths already propagated this context correctly. This fix closes the gap for submit_async_retain and updates _handle_consolidation to also restore context from the payload.

Test plan

  • Verify submit_async_retain includes _tenant_id and _api_key_id in task payload
  • Verify _handle_batch_retain restores context from payload
  • Verify submit_async_consolidation includes _tenant_id and _api_key_id in task payload
  • Verify _handle_consolidation restores context from payload
  • Run existing test suite (uv run pytest tests/ -v)

The batch_retain and consolidation task handlers created internal
RequestContext objects without tenant_id or api_key_id. This meant
downstream operations (consolidation, mental model refreshes) triggered
by async workers lost the original caller's request context.

Fix by passing tenant_id and api_key_id through the task payload dict
in submit_async_retain and submit_async_consolidation, then restoring
them in the corresponding handlers (_handle_batch_retain,
_handle_consolidation).
@nicoloboschi nicoloboschi merged commit 44d9125 into main Feb 2, 2026
24 of 26 checks passed
slayoffer added a commit to slayoffer/hindsight that referenced this pull request Feb 3, 2026
Merged 7 upstream commits:
- Fix: load operation validator extension in worker process (vectorize-io#280)
- fix: custom pg schema is not reliable (vectorize-io#278)
- feat(embed): add hindsight-embed profiles (vectorize-io#277)
- feat: support for codex and claude-code as llm (vectorize-io#276)
- feat: print version during startup (vectorize-io#275)
- feat(openclaw): add llmProvider/llmModel plugin config options (vectorize-io#274)
- Propagate request context through async task payloads (vectorize-io#273)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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