fix: address PR #836 review — forward task_producer to MCP contexts + cleanups
🔴 nc_get_vector_sync_status reported pending=0 for INGEST_QUEUE=postgres: the AppContext/OAuthAppContext per-session yields snapshotted the stream fields but never forwarded task_producer, so lifespan_ctx.task_producer was always None. Convert task_producer to a @property that reads _vector_sync_state live (like eviction_task_group), removing the snapshot field so the yields can't drop it. Add a regression test pinning the contract on both contexts. 🟡 Remove the unused _RECLAIM_TASK_NAME constant. 🟡 get_procrastinate_conninfo: warn + document that DATABASE_URL query params (application_name, connect_timeout, …) are dropped. 🟡 worker: open the procrastinate App once — apply_ingest_queue_schema gains manage_connection=False so the worker reuses its own open connector instead of a redundant open/close before run_worker_async. 🟢 Clarify the apply-schema broad-except comment (non-race errors re-raise) and document the deliberate Any typing in ingest_status.get_ingest_pending. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
63e073c224
commit
cfdef3c2c5
@@ -355,10 +355,18 @@ class AppContext:
|
||||
storage: "RefreshTokenStorage | None" = None
|
||||
document_send_stream: MemoryObjectSendStream | None = None
|
||||
document_receive_stream: MemoryObjectReceiveStream | None = None
|
||||
task_producer: "TaskProducer | None" = None
|
||||
shutdown_event: anyio.Event | None = None
|
||||
scanner_wake_event: anyio.Event | None = None
|
||||
|
||||
@property
|
||||
def task_producer(self) -> "TaskProducer | None":
|
||||
# Read dynamically from the module-level singleton (like
|
||||
# eviction_task_group) rather than snapshotting at yield time — that way
|
||||
# a session can't observe a stale ``None`` and the per-session yields
|
||||
# can't forget to forward it (the bug this property replaces). The
|
||||
# vector-sync status tool reads this for postgres-backend job counts.
|
||||
return _vector_sync_state.task_producer
|
||||
|
||||
@property
|
||||
def eviction_task_group(self) -> TaskGroup | None:
|
||||
# Read dynamically from the module-level singleton instead of
|
||||
@@ -381,10 +389,14 @@ class OAuthAppContext:
|
||||
server_client_id: str | None = None # MCP server's OAuth client ID (static or DCR)
|
||||
document_send_stream: MemoryObjectSendStream | None = None
|
||||
document_receive_stream: MemoryObjectReceiveStream | None = None
|
||||
task_producer: "TaskProducer | None" = None
|
||||
shutdown_event: anyio.Event | None = None
|
||||
scanner_wake_event: anyio.Event | None = None
|
||||
|
||||
@property
|
||||
def task_producer(self) -> "TaskProducer | None":
|
||||
# See AppContext.task_producer for rationale.
|
||||
return _vector_sync_state.task_producer
|
||||
|
||||
@property
|
||||
def eviction_task_group(self) -> TaskGroup | None:
|
||||
# See AppContext.eviction_task_group for rationale.
|
||||
@@ -606,8 +618,8 @@ async def app_lifespan_basic(server: FastMCP) -> AsyncIterator[AppContext]:
|
||||
document_receive_stream=_vector_sync_state.document_receive_stream,
|
||||
shutdown_event=_vector_sync_state.shutdown_event,
|
||||
scanner_wake_event=_vector_sync_state.scanner_wake_event,
|
||||
# eviction_task_group is exposed via @property (reads
|
||||
# _vector_sync_state at access time, not snapshot).
|
||||
# task_producer and eviction_task_group are exposed via @property
|
||||
# (read _vector_sync_state at access time, not snapshot).
|
||||
)
|
||||
finally:
|
||||
logger.info("Shutting down BasicAuth session")
|
||||
@@ -1239,8 +1251,8 @@ def get_app(transport: str = "streamable-http", enabled_apps: list[str] | None =
|
||||
document_receive_stream=_vector_sync_state.document_receive_stream,
|
||||
shutdown_event=_vector_sync_state.shutdown_event,
|
||||
scanner_wake_event=_vector_sync_state.scanner_wake_event,
|
||||
# eviction_task_group is exposed via @property (reads
|
||||
# _vector_sync_state at access time, not snapshot).
|
||||
# task_producer and eviction_task_group are exposed via
|
||||
# @property (read _vector_sync_state at access time).
|
||||
)
|
||||
finally:
|
||||
logger.info("Shutting down MCP server")
|
||||
|
||||
Reference in New Issue
Block a user