Skip to content

Conversation

@IMax153
Copy link
Collaborator

@IMax153 IMax153 commented Feb 5, 2026

Summary

Adds the core streaming pipeline for the Amp TypeScript SDK, porting the Rust streaming architecture to TypeScript/Effect:

  • ProtocolStream: Stateless Arrow Flight streaming with reorg detection. Validates block continuity across networks and emits Data, Watermark, and Reorg messages.
  • TransactionalStream: Wraps ProtocolStream with exactly-once semantics — transaction IDs, crash recovery via persistent StateStore, rewind detection for uncommitted transactions, and explicit commit control via CommitHandle.
  • CdcStream: Wraps TransactionalStream with a BatchStore for at-least-once CDC delivery. Transforms DataInsert, UndoDelete (with lazy batch iterator), and auto-commits watermarks internally.

Also includes project structure improvements:

  • Refactored models.ts into core/domain.ts with core.ts barrel
  • Split monolithic arrow-flight.ts into subdirectory module (errors.ts, types.ts, transport.ts, service.ts)
  • Added rulesync for managing coding agent configuration
  • Removed unused manifest-builder module
  • Added specs for transactional-stream and cdc-stream

Service Dependency Chain

CdcStream → TransactionalStream → ProtocolStream → ArrowFlight → Transport
          → BatchStore              → StateStore

Test plan

  • 197 tests pass (pnpm test)
  • Type check clean (pnpm check:recursive)
  • Formatting clean (dprint check)
  • ProtocolStream: 43 tests (reorg detection, validation)
  • TransactionalStream: 57 tests (state actor, algorithms, memory store)
  • CdcStream: 17 tests (batch store conformance, stream integration)
  • Arrow Flight IPC: 40 tests (roundtrip)

🤖 Generated with Claude Code

IMax153 and others added 13 commits February 5, 2026 13:25
Adds streamProtocol method to ArrowFlight service that wraps streamQuery
with protocol-level message handling:

- Data: New records with block ranges
- Reorg: Chain reorganization detected with invalidation ranges
- Watermark: Confirmation that block ranges are complete

Includes validation logic ported from Rust implementation:
- validatePrevHash: Genesis vs non-genesis block rules
- validateNetworks: Network consistency across batches
- validateConsecutiveness: Hash chain and gap detection

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Implements a full transactional layer on top of the protocol stream,
providing exactly-once semantics for data processing:

- Transaction IDs: Monotonically increasing IDs for each event
- StateStore: Pluggable persistence via Context.Tag (InMemoryStateStore included)
- Watermark Buffer: Tracks watermarks for reorg recovery point calculation
- CommitHandle: Explicit commit control with idempotent semantics
- Rewind Detection: Detects and invalidates uncommitted transactions on restart
- Retention Window: Prunes old watermarks outside configurable block window

Also adds protocol-stream reorg tests ported from the Rust implementation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactors the protocol stream functionality from ArrowFlight into its own
ProtocolStream Context.Tag service:

- Add protocol-stream/service.ts with ProtocolStream service definition
- Remove streamProtocol, detectReorgs, and related code from arrow-flight.ts
- Update TransactionalStream to depend on ProtocolStream instead of ArrowFlight
- Update exports in protocol-stream/index.ts

This improves separation of concerns and allows the protocol stream logic
to be used independently or replaced with alternative implementations.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace subdirectory index.ts barrel files with root-level .ts files
that serve as the public API for each module:

- protocol-stream/index.ts → protocol-stream.ts
- transactional-stream/index.ts → transactional-stream.ts

The package.json exports field (./* → ./src/*.ts) already supports this
pattern, so imports like "@edgeandnode/amp/protocol-stream" resolve to
the new root-level files.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace vitest imports with @effect/vitest and convert all tests to
it.effect with per-test Effect.provide for isolation. Remove runWithStore,
runWithState, and runWithActor helpers. Use Effect.exit instead of
Effect.runPromiseExit for failure tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Effect is already lazy, so wrapping service methods in `() =>` thunks
is redundant. Convert all zero-arg thunk methods to plain Effect values
across StateStore, StateActor, CommitHandle, and AdminApi interfaces.
Also remove unused imports/variables in reorg.test.ts.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ubdirectory

Move all domain models from src/models.ts to src/core/domain.ts with a
src/core.ts barrel, and split the monolithic src/arrow-flight.ts into
errors.ts, types.ts, transport.ts, and service.ts submodules — matching
the existing protocol-stream/transactional-stream directory pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Port Rust CDC stream to TypeScript/Effect. Wraps TransactionalStream with
a BatchStore to persist batch content, enabling Delete events with original
data during reorgs and rewinds.

- CdcEvent union: Insert (data forwarding) and Delete (lazy batch iterator)
- BatchStore service: pluggable persistence (append, seek, load, prune)
- InMemoryBatchStore: Ref-backed reference implementation
- CdcStream service: Data→Insert, Undo→Delete, Watermark auto-commit+prune
- 17 tests covering batch store conformance and stream integration

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@IMax153 IMax153 changed the title Add ProtocolStream and TransactionalStream Add streaming pipeline: ProtocolStream, TransactionalStream, CdcStream Feb 10, 2026
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.

1 participant