feat(migration): migrate lb4-llm-chat-extension from LangGraph to Mastra [WIP]#20
feat(migration): migrate lb4-llm-chat-extension from LangGraph to Mastra [WIP]#20rohit-sourcefuse wants to merge 3 commits intomainfrom
Conversation
SonarQube reviewer guide
|
Review — WIP Status Assessment (2026-05-04)What's confirmed working in this diffDependency swap is complete and correct. Test infrastructure is solid. Step unit tests follow the correct pattern. Issues to address before merge1. Merge conflicts — must resolve before review can proceedBranch has diverged from `main`. Recent main changes that will conflict:
Action required: `git rebase origin/main` on `feat/mastra`, resolve conflicts, force-push. 2. Commit messages need rewriteThe 3 migration commits have vague, non-conventional messages:
Before merge, squash into a single conventional commit or rewrite each with proper scope. Example:
BREAKING CHANGE: internal execution engine replaced; public API surface preserved 3. Source implementation files not yet in this PRCurrent diff is test-layer + dependencies only. The production source migration (`src/graphs/`, `src/components/db-query/nodes/`, `src/services/generation.service.ts`, `src/transports/sse.transport.ts`) must be added before this can be reviewed for correctness. The integration test will fail until the source is wired. 4. Open architectural decisions (per TDD Rev 4)These need sign-off before implementation is finalised — see discussion doc on Confluence:
Not blocking but worth noting
|




Summary
Migration of
loopback4-llm-chat-extensionfrom LangGraph v2 (LangChain-based) to Mastra v3 (Vercel AI SDK-based).This replaces the LangGraph execution engine and all LangChain provider adapters with Mastra workflows/steps and the Vercel AI SDK, while preserving the existing public API surface (
POST /reply, SSE event protocol, LB4 bindings).TDD: Technical Design Document — Mastra Migration
Type of change
What's in this PR
Dependencies (package.json)
@langchain/*family —@langchain/core,@langchain/community,@langchain/langgraph,langchain,@langchain/anthropic,@langchain/aws,@langchain/cerebras,@langchain/google-genai,@langchain/groq,@langchain/ollama,@langchain/openai,@langfuse/langchainaiv6 (Vercel AI SDK core runtime) +@ai-sdk/amazon-bedrock,@ai-sdk/anthropic,@ai-sdk/cerebras,@ai-sdk/google,@ai-sdk/groq,@ai-sdk/openai,ollama-ai-provider2.0.0→2.1.0Test layer — migrated
src/__tests__/db-query/unit/nodes/(~3,000 lines) —CheckCacheNode,CheckPermissionsNode,ClassifyChangeNode,FailedNode,FixQueryNode,GetColumnsNode,GetTablesNode,IsImprovementNode,SaveDataSetNode,SemanticValidatorNode,SqlGenerationNode,SyntacticValidatorNodeDbQueryGraphandGetTablesNode(LangGraph compile/invoke pattern)src/__tests__/db-query/unit/mastra-steps/— one file per step with pure-function(state, context, deps)signaturesdb-query.workflow.integration.ts— 443-line end-to-end integration test covering 7 scenarios: happy path, retry loop, cache hit, template hit, max-attempts guard, condition routingsrc/__tests__/fixtures/fake-ai-models.ts— shared AI SDK fake models (createFakeLanguageModel,createFakeStreamingLanguageModel,createFakeEmbeddingModel) implementingLanguageModelV3/EmbeddingModelV2interfaces, replacing sinon stubsSource implementation — in progress
Migration of production source files (
src/graphs/,src/components/db-query/nodes/,src/services/,src/transports/) is ongoing. Current phases:What's NOT done yet
src/components/db-query/)main(recent changes: visualizer bar prompt fix, CVE patch)@langfuse/langchain)npm testpassing end-to-endgenerate-querysub-graph (see TDD §14.1)Architecture decisions (see TDD for full context)
Agentwith LB4-registeredIMastraToolimplementationsMastraMemoryreplaces LangGraph thread statestream.usagefrom Vercel AI SDK (post-stream)onStepFinishcallback → sharedeventQueuedrained by SSE generatorexecute()checks (no mid-flow orchestration hook)MastraChatOrchestratorOR register additionalIMastraToolHow to test (once complete)
npm install npm run build npm testRegression baseline: run
lb4-llm-sandboxwithlb4-llm-chat-componentswapped to this branch — all 7 tabs must behave identically to the LangGraph v2 build.Notes for reviewers
mainduring active development — needs rebase before mergePOST /reply, SSE event types, allAiIntegrationBindings.*keys preserved