-
Notifications
You must be signed in to change notification settings - Fork 0
Workflow Engine State Management and Persistence
Referenced Files in This Document
- execution-trace-store.ts
- memory-store.ts
- store.ts
- store-methods.ts
- store-init.ts
- qdrant-memory-store.ts
- qdrant-memory-updates.ts
- qdrant-memory-retrieval.ts
- key-value-store-factory.ts
- key-value-store.ts
- redis-cache.ts
- oidc-state-store.ts
- forward-runtime-store.ts
- activate-refinement-store.ts
- store-artifact.ts
- qdrant-snapshots.ts
- Introduction
- Project Structure
- Core Components
- Architecture Overview
- Detailed Component Analysis
- Dependency Analysis
- Performance Considerations
- Troubleshooting Guide
- Conclusion
- Appendices
This document explains how workflow states are captured, serialized, and persisted across multiple storage backends. It covers the execution trace store for audit trails and debugging, state checkpointing strategies, incremental updates, conflict resolution, integration with Qdrant for vector-based retrieval, and a memory store for structured data persistence. It also documents migration patterns, version compatibility handling, and backup/restore procedures, along with examples of custom serializers and storage adapters.
The state management and persistence logic is implemented under services:
- Memory store layer for structured data persistence and adapter orchestration
- Qdrant-backed vector store for semantic search and retrieval
- Key-value store abstraction for cache and session-like state
- Specialized stores for OIDC state, forward runtime, activation refinement, and artifacts
- Execution trace store for durable audit logs
graph TB
subgraph "Workflow Runtime"
A["Forward Runtime Store"]
B["Activate Refinement Store"]
C["OIDC State Store"]
end
subgraph "Persistence Layer"
D["Memory Store (structured)"]
E["Qdrant Store (vector)"]
F["Key-Value Store (cache/session)"]
G["Execution Trace Store"]
end
A --> D
A --> E
B --> D
C --> F
D --> E
D --> F
G --> F
Diagram sources
- forward-runtime-store.ts
- activate-refinement-store.ts
- oidc-state-store.ts
- memory-store.ts
- qdrant-memory-store.ts
- key-value-store-factory.ts
- execution-trace-store.ts
Section sources
- Memory Store: Orchestrates structured persistence and coordinates with Qdrant for vector indexing and retrieval. Provides initialization, CRUD methods, and artifact handling.
- Qdrant Store: Manages vector collections, point upserts, and retrieval by similarity or filters. Includes snapshotting utilities.
- Key-Value Store Abstraction: Factory-backed cache/session store used by OIDC state, execution traces, and other transient or semi-persistent state.
- Execution Trace Store: Appends immutable audit entries to a durable backend for replay and debugging.
- Forward Runtime Store: Holds ephemeral per-run context and checkpoints during forward execution.
- Activate Refinement Store: Persists intermediate refinement state for activation flows.
- OIDC State Store: Stores short-lived OAuth/OIDC state using the key-value store.
Section sources
- memory-store.ts
- store.ts
- store-methods.ts
- store-init.ts
- qdrant-memory-store.ts
- qdrant-memory-updates.ts
- qdrant-memory-retrieval.ts
- qdrant-snapshots.ts
- key-value-store-factory.ts
- key-value-store.ts
- redis-cache.ts
- execution-trace-store.ts
- forward-runtime-store.ts
- activate-refinement-store.ts
- oidc-state-store.ts
- store-artifact.ts
The system separates concerns between structured state (memory store), vector state (Qdrant), and transient/cache state (key-value store). The memory store acts as the primary coordinator, persisting structured records and synchronizing embeddings to Qdrant. The execution trace store writes append-only events to the key-value store for auditability.
sequenceDiagram
participant Client as "Caller"
participant Mem as "Memory Store"
participant KV as "Key-Value Store"
participant Q as "Qdrant Store"
participant Trace as "Execution Trace Store"
Client->>Mem : "Upsert structured record"
Mem->>KV : "Persist structured payload"
Mem->>Q : "Index vectors and metadata"
Mem-->>Client : "Ack success"
Client->>Trace : "Append audit event"
Trace->>KV : "Append entry"
Trace-->>Client : "Ack success"
Client->>Mem : "Search by similarity"
Mem->>Q : "Vector query with filters"
Q-->>Mem : "Top matches"
Mem->>KV : "Load full records"
Mem-->>Client : "Ranked results"
Diagram sources
- memory-store.ts
- qdrant-memory-store.ts
- qdrant-memory-retrieval.ts
- key-value-store-factory.ts
- execution-trace-store.ts
Purpose:
- Append-only audit trail for workflow steps, tool calls, and outcomes.
- Supports querying recent traces and exporting for debugging.
Key behaviors:
- Serializes trace entries into a stable format before writing.
- Uses the key-value store as the backing for durability and ordering guarantees.
- Provides helpers to batch-append and paginate reads.
flowchart TD
Start(["Append Trace"]) --> Serialize["Serialize Entry"]
Serialize --> Validate["Validate Schema"]
Validate --> WriteKV["Write to Key-Value Store"]
WriteKV --> Success{"Write OK?"}
Success --> |Yes| ReturnOK["Return Ack"]
Success --> |No| RetryOrFail["Retry or Fail Fast"]
RetryOrFail --> ReturnOK
Diagram sources
Section sources
Responsibilities:
- Initialize and configure storage backends.
- Provide CRUD operations for structured records.
- Coordinate artifact persistence and lifecycle.
- Synchronize embeddings to Qdrant when applicable.
Initialization flow:
- Loads configuration, validates environment, and sets up both memory and Qdrant clients.
- Performs readiness checks and optional migrations.
CRUD and synchronization:
- Upserts structured records to the key-value store.
- Computes and persists vectors to Qdrant, ensuring idempotency via unique IDs.
- On delete, removes both structured and vector representations.
classDiagram
class MemoryStore {
+init()
+upsert(record)
+get(id)
+delete(id)
+search(query)
}
class QdrantStore {
+upsertPoint(point)
+query(filter)
+deletePoint(id)
}
class KeyValueStore {
+set(key, value)
+get(key)
+del(key)
}
MemoryStore --> QdrantStore : "indexes vectors"
MemoryStore --> KeyValueStore : "persists records"
Diagram sources
- memory-store.ts
- store.ts
- store-methods.ts
- store-init.ts
- qdrant-memory-store.ts
- key-value-store-factory.ts
- key-value-store.ts
Section sources
Capabilities:
- Point upserts with payloads containing structured metadata.
- Similarity search with optional filters (e.g., space, tags).
- Snapshotting utilities for backups and restores.
Update and retrieval flows:
- Incremental updates use idempotent upserts keyed by record ID.
- Retrieval combines vector scores with metadata filters to rank results.
sequenceDiagram
participant MS as "Memory Store"
participant QS as "Qdrant Store"
MS->>QS : "Upsert point (id, vector, payload)"
MS->>QS : "Delete point on record removal"
MS->>QS : "Query(vector, filter, limit)"
QS-->>MS : "Points with scores"
Diagram sources
Section sources
Abstraction:
- Factory creates a concrete implementation based on configuration (e.g., Redis).
- Provides set/get/del semantics with TTL support where applicable.
Backends:
- Redis-backed cache for high-throughput, low-latency access.
- Used by OIDC state, execution traces, and other transient state.
classDiagram
class KeyValueStoreFactory {
+create(config)
}
class RedisCache {
+set(key, value, ttl?)
+get(key)
+del(key)
}
KeyValueStoreFactory --> RedisCache : "instantiates"
Diagram sources
Section sources
- OIDC State Store: Short-lived state for OAuth/OIDC flows; uses key-value store with TTL.
- Forward Runtime Store: Per-run runtime state and checkpoints; supports incremental updates and recovery.
- Activate Refinement Store: Intermediate state for activation refinement; durable until completion.
graph LR
KV["Key-Value Store"] --> O["OIDC State Store"]
KV --> FR["Forward Runtime Store"]
KV --> AR["Activate Refinement Store"]
Diagram sources
- oidc-state-store.ts
- forward-runtime-store.ts
- activate-refinement-store.ts
- key-value-store-factory.ts
Section sources
High-level dependencies:
- Memory Store depends on Qdrant Store and Key-Value Store.
- Execution Trace Store depends on Key-Value Store.
- Specialized stores depend on Key-Value Store.
- Qdrant Store depends on Qdrant client and snapshot utilities.
graph TB
MS["Memory Store"] --> Q["Qdrant Store"]
MS --> KV["Key-Value Store"]
ET["Execution Trace Store"] --> KV
ORS["OIDC State Store"] --> KV
FRS["Forward Runtime Store"] --> KV
ARS["Activate Refinement Store"] --> KV
Diagram sources
- memory-store.ts
- qdrant-memory-store.ts
- key-value-store-factory.ts
- execution-trace-store.ts
- oidc-state-store.ts
- forward-runtime-store.ts
- activate-refinement-store.ts
Section sources
- memory-store.ts
- qdrant-memory-store.ts
- key-value-store-factory.ts
- execution-trace-store.ts
- oidc-state-store.ts
- forward-runtime-store.ts
- activate-refinement-store.ts
- Batched writes: Prefer batching upserts to Qdrant and key-value store to reduce round trips.
- Idempotency: Use stable IDs to avoid duplicate points and records.
- TTL tuning: Configure appropriate TTLs for OIDC and runtime state to prevent unbounded growth.
- Search optimization: Apply metadata filters alongside vector queries to narrow result sets early.
- Serialization efficiency: Keep payloads compact and schema-stable to minimize serialization overhead.
[No sources needed since this section provides general guidance]
Common issues and resolutions:
- Missing or invalid configuration: Ensure all required keys for Qdrant and key-value store are present and valid.
- Vector index mismatch: Verify collection names and payload schemas align with expectations.
- Stale cache entries: Clear or refresh key-value store entries if inconsistent state is observed.
- Trace gaps: Confirm append-only semantics and monotonic ordering in the key-value backend.
Operational tips:
- Inspect recent traces via the execution trace store to pinpoint failures.
- Use Qdrant snapshots to validate vector integrity and restore from known-good states.
- Monitor key-value store latency and errors to detect bottlenecks.
Section sources
The state management layer combines structured persistence, vector search, and transient caching to support robust workflow execution. The execution trace store ensures auditability, while Qdrant enables powerful semantic retrieval. With clear separation of responsibilities and idempotent operations, the system scales reliably and remains debuggable.
[No sources needed since this section summarizes without analyzing specific files]
- Periodic snapshots: Save current state at safe points to enable fast recovery.
- Incremental deltas: Persist only changed fields to reduce write amplification.
- Conflict resolution: Use last-write-wins with version counters or compare-and-set semantics where supported by the backend.
[No sources needed since this section provides general guidance]
- Schema versioning: Include version fields in serialized payloads and apply migrations on read/write paths.
- Backward-compatible changes: Add new fields with defaults; avoid removing existing fields abruptly.
- Rollout strategy: Support dual-read paths during transition periods to ensure continuity.
[No sources needed since this section provides general guidance]
- Structured data: Export from key-value store periodically; import during restore.
- Vector data: Use Qdrant snapshots to capture and restore vector collections.
- Traces: Archive append-only logs for compliance and post-mortem analysis.
Section sources
Guidelines:
- Define a stable serialization contract with explicit versioning.
- Implement adapters that conform to the key-value store interface for pluggable backends.
- Provide unit tests for roundtrip serialization and error paths.
Example references:
- See the key-value store factory and implementations for adapter patterns.
- Review specialized stores for usage examples of custom serialization and TTL policies.
Section sources
-
- Authentication and Authorization Model
- Model Context Protocol (MCP) Fundamentals
- Tool and Adapter System
- Memory and Semantic Search System
- Workflow Orchestration Engine