LearnNewsExamplesConnect
Frontmatter
assigneesneo-gpt-sophie
createdAtMar 25, 2026, 9:10 PM
updatedAtNov 7, 2026, 1:27 AM
githubUrlhttps://github.com/neomjs/neo/issues/9553
authortobiu
commentsCount4
parentIssuenull
subIssues[]
subIssuesCompleted0
subIssuesTotal0
contentTrust
projected
quarantined0
signals[]
blockedBy[x] 20472 Fetch drops request headers before native dispatch
blocking[]
closedAtNov 7, 2026, 1:27 AM

Feature: Implement Pipeline Interceptor System (Middleware)

Closed v13.4.0/archive-v13-4-0-chunk-2 enhancementhelp wantedno auto closeaiarchitecturecore
tobiu
tobiu commented on Mar 25, 2026, 9:10 PM

Goal

Implement a middleware/interceptor system for Neo.data.Pipeline to allow cross-cutting concerns to be handled declaratively.

Description

As the Data Pipeline architecture matures, we need a way to inject logic at key stages of the data lifecycle (pre-request, post-response, post-parse).

Requirements:

  1. Support request interceptors (e.g., adding Auth headers, logging params).
  2. Support response interceptors (e.g., global error handling, refreshing tokens).
  3. Interceptors must support async execution.
  4. Allow global interceptors to be registered at the Neo.worker.Data level.
  5. Pipelines should allow instance-specific interceptors that merge with globals.

Implementation intake — Sophie, 2026-11-06

The original five requirements and post-parse intent remain. Current Pipeline stage replacement and telemetry do not provide this composition. The request-header prerequisite is delivered by #20472 / #20473. The design-read record holds the cache, stream and consumer-loading falsifiers.

Beneficiary: an application defines an ordinary Neo interceptor class once and composes it globally or on a Pipeline, rather than wrapping each request or replacing transport/parser implementations. Existing Pipelines without configured interceptors keep their request/result and telemetry contracts. Callable configuration cannot cross worker IPC, so behavior lives in classes and only class names, explicit module paths and data options cross that boundary.

Prescription checked: src/data/Pipeline.mjs owns stage ordering and cache identity; src/worker/Data.mjs owns remote registration/loading. New src/data/interceptor/Base.mjs and Chain.mjs hold the public hook contract and one ordered, owned handler snapshot. They use Neo.core.Base, Neo.setupClass, normal class/config creation and ready(). No second registry of live Pipelines, code-string evaluation, storage service or transport-specific authentication implementation.

Contract Ledger

Surface Contract Failure / lifetime Decisive evidence
interceptors construction config; await pipeline.setInterceptors(descriptors) Ordered local descriptors. Normal App imports provide module; serialized Data descriptors carry className and modulePath. Replacement/clear is explicit and awaited. Reject callable data options and borrowed instances before serialization. A failed replacement preserves the previous admitted chain. App/Data composition, replacement and malformed-config controls.
await Pipeline.setGlobalInterceptors(descriptors) Globals belong to the executing realm. Each operation uses global handlers before local handlers in declaration order. Empty array clears globals. Replacements affect existing Pipelines' subsequent operations; in-flight snapshots remain alive until their uses settle, then retire exactly once. Hold A in an old handler; replace, finish B, release A; repeated unused replacements.
await Neo.worker.Data.setPipelineInterceptors({interceptors}) Remote entry updates the Data realm's global chain, using Data's production-scoped loader. Check preload results and exported class identity; never substitute App's test-only loader. Actual custom consumer class executes in Data, not merely present in a bundle.
Interceptor request, response, responseError, postParse methods Await each method. undefined keeps the prior value. Response rejection handlers can recover by returning a replacement; throwing or returning undefined retains rejection. Later handlers receive the resulting success/rejection state. Context names the executing Pipeline, operation, method and effective params. Request/parser/post-parse failures propagate. No implicit token refresh or extra retry loop. Push has no request/HTTP-response stage. Ordered async transforms, Fetch rejection/recovery, unchanged no-hook control and push controls.
Completed-read cache Request preparation runs before lookup. Key effective request inputs; final shaped results are cached. Hits skip transport/response/post-parse work. Unsupported cache-key values stay uncached. Reuse invalidateReadCache and map-entry identity. A stale chain after delayed request preparation neither hits nor inserts a newer-policy snapshot. Header variation, hit/miss, chain swap and out-of-order completion controls.
Streaming and destruction Await post-parse work at each Stream emission, preserving chunk order and the existing terminal summary. Data-worker chunks/progress must reach the App-side Pipeline through the existing message pattern. Streams remain uncached. No publication after owner destruction; no async Observable listener or shared current-operation slot. Delayed chunk transforms, cancellation/destruction, App/Data real streaming rows.
Consumer module paths Reuse the existing scoped apps/, examples/, docs/app/, src/data/ loader contract. For installed source consumers, reuse the extra package-depth hop already used by App.mjs:769–775; compiled contexts retain workerContextRebasePlugin. Unsupported/escaping paths and class mismatches refuse. The broader provisional URL redesign stays on #17884. Source consumer 200/404 red control, packed consumer runtime and built-context acceptance.

Acceptance Criteria

  • All five original requirements plus awaited post-parse processing are implemented through the contract above; no application-owned per-request wrapper is required.
  • Global/local order, success/rejection transformation, replacement and exact-once retirement are covered with deterministic lifecycle and failure controls.
  • Cache hits, effective request variation and old-chain preparation/completion races preserve per-Pipeline ownership without a live-Pipeline registry.
  • Progressive App/Data streaming and unsolicited pushes preserve arrival order, terminal behavior and destruction boundaries; existing no-hook controls pass.
  • A real consumer application loads its custom class through production paths in both execution realms; counted HTTP sees the prepared headers and the caller sees awaited transforms. Source and built/packed evidence are stated separately.
  • Full units, affected browser controls and build/loader checks pass; the existing data guide and Structural Inventory explain the opt-in API and ownership.

Intake disposition

Accept and sharpen; no original intent removed. Created 2026-03-25, updated today: pre-stale under the current 90-day marker workflow, with an existing no auto close exemption. No open prerequisite remains; the closed Fetch dependency is retained as provenance. Current-source/history and all-state title sweep found stage/cache/telemetry additions, not delivered interceptors. Memory semantic hits were unrelated; live source and the recorded peer reads are the positive authority. Graph pre-brief: issue-9553.

ADR successor-risk: no-adr-impact for Pipeline hook composition. The package-depth adjustment follows the existing installed-consumer convention; it does not graduate or redefine #17884's provisional root contract. Placement: data-domain classes beside the connection/parser/normalizer families; the existing data inventory row will name the new role. No Brain or AiConfig changes.

Origin Session ID: 7367b697-abdc-4e46-963d-5c57378b3551

tobiu assigned to @tobiu on Mar 25, 2026, 9:10 PM
tobiu added the enhancement label on Mar 25, 2026, 9:10 PM
tobiu added the ai label on Mar 25, 2026, 9:10 PM
tobiu added the architecture label on Mar 25, 2026, 9:10 PM
tobiu added the core label on Mar 25, 2026, 9:10 PM
tobiu added the help wanted label on Mar 25, 2026, 9:51 PM
tobiu added the no auto close label on Mar 25, 2026, 9:51 PM
tobiu unassigned from @tobiu on Mar 26, 2026, 4:19 PM
tobiu removed the not-code-ready label on Jul 6, 2026, 3:21 PM
tobiu removed the needs-design label on Jul 6, 2026, 3:22 PM