Skip to content

Commit 210ea7a

Browse files
author
Neha Prasad
authored
fix(core): propagate agent logger to combined processor workflow (#16369)
### description - Fixes logger propagation for processor-combined internal workflows so processor step failures use the configured agent logger instead of default console logging. Adds a focused regression test to prevent this from regressing. Related Issue(s) fixes #16364 ### Type of Change [x] Bug fix (non-breaking change that fixes an issue) [x] Test update #### Checklist [x] I have added tests that prove my fix is effective or that my feature works <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## ELI5 When you combine multiple processors into a workflow within an agent, the internal workflow wasn't using the agent's logger. So if something went wrong, errors were printed to the console instead of going through your configured logging system (like DataDog). This PR adds one line of code to make sure the internal workflow uses the agent's logger, so all error logs flow through the proper logging pipeline. --- ## Changes ### agent.ts Added explicit logger propagation in `Agent.combineProcessorsIntoWorkflow()`. After creating the chained processor workflow via `createWorkflow(...)`, the code now calls `workflow.__setLogger(this.logger)` to ensure the internal workflow uses the agent's configured logger instance instead of the default console logger. ### agent-processor.test.ts Added a new regression test under "Workflow as Processor" that verifies logger propagation works correctly. The test creates an input processor that fails, runs it through `agent.generate()`, and confirms that: - The error is properly rejected with "Input processor error" - The agent's `logger.error` is called with a message containing the processor id - The agent's `logger.trackException` is invoked ### Changeset Updated `.changeset/blue-snails-see.md` to document a `patch` release for `@mastra/core` describing the logging fix for processor-combined workflows. --- ## Impact - Processor step failures in combined workflows now route through the configured agent logger, enabling proper log aggregation and structured logging pipelines - Breaking change: None - Tests added: Yes, with focused regression test to prevent future regressions <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 0abde18 commit 210ea7a

3 files changed

Lines changed: 45 additions & 1 deletion

File tree

.changeset/blue-snails-see.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@mastra/core': patch
3+
---
4+
5+
Fixed processor-combined workflows to use the agent logger so processor step failures are logged through the configured logger instead of console output.

packages/core/src/agent/agent-processor.test.ts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { LanguageModelV2Prompt } from '@ai-sdk/provider-v5';
22
import { MockLanguageModelV1 } from '@internal/ai-sdk-v4/test';
33
import { convertArrayToReadableStream, MockLanguageModelV2 } from '@internal/ai-sdk-v5/test';
4-
import { beforeEach, describe, expect, it } from 'vitest';
4+
import { beforeEach, describe, expect, it, vi } from 'vitest';
55
import { z } from 'zod/v4';
6+
import { noopLogger } from '../logger';
67
import type { Processor, ProcessOutputStepArgs } from '../processors/index';
78
import { isProcessorWorkflow } from '../processors/index';
89
import { ProcessorStepInputSchema, ProcessorStepOutputSchema } from '../processors/step-schema';
@@ -2567,6 +2568,43 @@ describe('v1 model - output processors', () => {
25672568
});
25682569

25692570
describe('Workflow as Processor', () => {
2571+
it('should use the agent logger for internal combined processor workflows', async () => {
2572+
const failingProcessor: Processor = {
2573+
id: 'failing-processor',
2574+
processInput: async () => {
2575+
throw new Error('processor failed');
2576+
},
2577+
};
2578+
2579+
const agent = new Agent({
2580+
id: 'logger-propagation-test-agent',
2581+
name: 'Logger Propagation Test Agent',
2582+
instructions: 'You are a helpful assistant.',
2583+
model: new MockLanguageModelV2({
2584+
doGenerate: async () => ({
2585+
content: [{ type: 'text', text: 'should not get here' }],
2586+
finishReason: 'stop',
2587+
usage: { inputTokens: 1, outputTokens: 1, totalTokens: 2 },
2588+
rawCall: { rawPrompt: null, rawSettings: {} },
2589+
warnings: [],
2590+
}),
2591+
}),
2592+
inputProcessors: [failingProcessor],
2593+
});
2594+
2595+
const logger = {
2596+
...noopLogger,
2597+
debug: vi.fn(),
2598+
error: vi.fn(),
2599+
trackException: vi.fn(),
2600+
};
2601+
agent.__setLogger(logger);
2602+
2603+
await expect(agent.generate('trigger failure')).rejects.toThrow('Input processor error');
2604+
expect(logger.error).toHaveBeenCalledWith(expect.stringContaining('processor:failing-processor'));
2605+
expect(logger.trackException).toHaveBeenCalled();
2606+
});
2607+
25702608
describe('input processor workflow', () => {
25712609
it('should execute a workflow as an input processor', async () => {
25722610
let workflowExecuted = false;

packages/core/src/agent/agent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ export class Agent<
848848
},
849849
},
850850
});
851+
workflow.__setLogger(this.logger);
851852

852853
for (const [index, processorOrWorkflow] of validProcessors.entries()) {
853854
// Convert processor to step, or use workflow directly (nested workflows are allowed)

0 commit comments

Comments
 (0)