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:
- Support
request interceptors (e.g., adding Auth headers, logging params).
- Support
response interceptors (e.g., global error handling, refreshing tokens).
- Interceptors must support
async execution.
- Allow global interceptors to be registered at the
Neo.worker.Data level.
- 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
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
Goal
Implement a middleware/interceptor system for
Neo.data.Pipelineto 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:
requestinterceptors (e.g., adding Auth headers, logging params).responseinterceptors (e.g., global error handling, refreshing tokens).asyncexecution.Neo.worker.Datalevel.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.mjsowns stage ordering and cache identity;src/worker/Data.mjsowns remote registration/loading. Newsrc/data/interceptor/Base.mjsandChain.mjshold the public hook contract and one ordered, owned handler snapshot. They useNeo.core.Base,Neo.setupClass, normal class/config creation andready(). No second registry of live Pipelines, code-string evaluation, storage service or transport-specific authentication implementation.Contract Ledger
interceptorsconstruction config;await pipeline.setInterceptors(descriptors)module; serialized Data descriptors carryclassNameandmodulePath. Replacement/clear is explicit and awaited.await Pipeline.setGlobalInterceptors(descriptors)await Neo.worker.Data.setPipelineInterceptors({interceptors})request,response,responseError,postParsemethodsundefinedkeeps the prior value. Response rejection handlers can recover by returning a replacement; throwing or returningundefinedretains rejection. Later handlers receive the resulting success/rejection state. Context names the executing Pipeline, operation, method and effective params.invalidateReadCacheand map-entry identity. A stale chain after delayed request preparation neither hits nor inserts a newer-policy snapshot.apps/,examples/,docs/app/,src/data/loader contract. For installed source consumers, reuse the extra package-depth hop already used byApp.mjs:769–775; compiled contexts retainworkerContextRebasePlugin.Acceptance Criteria
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 closeexemption. 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