Skip to content

symfonic.core.nodes.context_injection

context_injection

ContextInjectionNode — parallel context loader execution with collision detection.

Per ADR-PFX-005/013 and TDD §2.11: Runs all ContextLoaderRegistration entries concurrently via asyncio.gather. Detects state key collisions before merge.

Deprecated: ContextInjectionNode has been removed from the default pipeline. With zero loaders registered, it always returned {} and added overhead with no benefit. Hydration is now handled exclusively by SymfonicAgent._hydrate(). This module is retained for backward compatibility with consumers that register custom context loaders via graph._context_loaders.

ContextCollisionError

Bases: ValueError

Raised when two context loaders write the same state key.

ContextLoaderRegistration dataclass

ContextLoaderRegistration(
    loader: Callable[..., Any],
    required: bool = False,
    timeout_seconds: float = 5.0,
    allow_collision_keys: set[str] = set(),
)

Registration entry for a context loader.

create_context_injection_node

create_context_injection_node(
    registrations: list[ContextLoaderRegistration],
) -> Callable[..., Any]

Factory for ContextInjectionNode.

.. deprecated:: create_context_injection_node is deprecated. ContextInjectionNode has been removed from the default ReactLoopPreset pipeline. Hydration is now handled exclusively by SymfonicAgent._hydrate(). This factory is retained for consumers that wire custom context loaders.

Source code in src/symfonic/core/nodes/context_injection.py
def create_context_injection_node(
    registrations: list[ContextLoaderRegistration],
) -> Callable[..., Any]:
    """Factory for ContextInjectionNode.

    .. deprecated::
        ``create_context_injection_node`` is deprecated. ContextInjectionNode
        has been removed from the default ReactLoopPreset pipeline. Hydration
        is now handled exclusively by ``SymfonicAgent._hydrate()``.
        This factory is retained for consumers that wire custom context loaders.
    """
    warnings.warn(
        "create_context_injection_node is deprecated. "
        "ContextInjectionNode is no longer part of the default pipeline. "
        "Hydration is handled by SymfonicAgent._hydrate().",
        DeprecationWarning,
        stacklevel=2,
    )

    from ..observability.decorators import observed_node

    @observed_node("context_injection", always_log=True)
    async def context_injection(state: dict[str, Any]) -> dict[str, Any]:
        return await _run_loaders_parallel(registrations, state, {})

    return context_injection