Repository navigation
Description
What are you really trying to do?
Encode failure messages and stack traces, as the Temporal docs recommend for sensitive error text,
with dataConverter: { failureConverterPath } pointing at
new DefaultFailureConverter({ encodeCommonAttributes: true }), on a Client and Worker that also use
StrandsPlugin.
Describe the bug
StrandsPlugin passes dataConverter: { failureConverterPath: require.resolve('./failure-converter') }
to SimplePlugin as a value (typescript/strands-agents/src/plugin.ts). SimplePlugin merges it
over the existing data converter, so the plugin's path replaces the caller's. A data converter holds
one failure converter path, so the caller's converter is gone, with no error or warning. Activity,
Workflow and Workflow Task failures then go to Event History in plain text, with their stack traces.
History cannot be re-encoded later.
Setting the caller's path again in a plugin placed after StrandsPlugin brings the encoding back,
but drops Strands' own converter, which types interrupts as StrandsInterrupt.
The Python plugin has the same problem: #153.
Minimal Reproduction
Three files in one folder. With StrandsPlugin on the Client and Worker, the script records an
Activity failure, a Workflow failure, and a Workflow Task failure from an interrupt-shaped error
thrown in Workflow code, then reads them from History.
caller-failure-converter.cjs:
'use strict';
// The caller's failure converter: messages and stack traces go into an encoded payload.
const { DefaultFailureConverter } = require('@temporalio/common');
exports.failureConverter = new DefaultFailureConverter({ encodeCommonAttributes: true });workflows.cjs:
'use strict';
const { ApplicationFailure, proxyActivities } = require('@temporalio/workflow');
const { failingActivity } = proxyActivities({ startToCloseTimeout: '10 seconds', retry: { maximumAttempts: 1 } });
// An Activity failure, then a Workflow failure, each with a secret in its message.
exports.failTwice = async function failTwice(secret) {
await failingActivity(secret).catch(() => undefined);
throw ApplicationFailure.create({ message: `workflow failed with ${secret}`, nonRetryable: true });
};
// An interrupt-shaped error, which Strands' failure converter stores as type StrandsInterrupt.
exports.interruptInWorkflow = async function interruptInWorkflow(secret) {
throw Object.assign(new Error(`interrupt for ${secret}`), {
interrupts: [{ toJSON: () => ({ id: 'i-1', name: 'approve', reason: secret, source: 'workflow' }) }],
});
};repro.cjs:
'use strict';
// A Client and Worker set the caller's failure converter (encodeCommonAttributes: true) and add
// StrandsPlugin. Expected: failures in History are "Encoded failure", as without the plugin, and
// Strands' interrupt rewrite still applies. Exits 0 when both hold, 1 otherwise.
// node repro.cjs (needs @temporalio/client, worker, testing, common, workflow,
// @temporalio/strands-agents and @strands-agents/sdk in node_modules)
const path = require('node:path');
const { Client } = require('@temporalio/client');
const { ApplicationFailure } = require('@temporalio/common');
const { TestWorkflowEnvironment } = require('@temporalio/testing');
const { Worker, Runtime, DefaultLogger } = require('@temporalio/worker');
const { StrandsPlugin } = require('@temporalio/strands-agents');
Runtime.install({ logger: new DefaultLogger('ERROR') });
const dataConverter = { failureConverterPath: path.join(__dirname, 'caller-failure-converter.cjs') };
const activities = {
async failingActivity(secret) {
throw ApplicationFailure.create({ message: `activity failed with ${secret}`, nonRetryable: true });
},
};
const show = (f) => ({ message: f.message, type: f.applicationFailureInfo?.type, encoded: Boolean(f.encodedAttributes) });
async function main() {
const cli = process.env.TEMPORAL_CLI; // optional: an installed Temporal CLI instead of a download
const env = await TestWorkflowEnvironment.createLocal(
cli ? { server: { executable: { type: 'existing-path', path: cli } } } : undefined
);
try {
const client = new Client({ connection: env.connection, dataConverter, plugins: [new StrandsPlugin()] });
const worker = await Worker.create({
connection: env.nativeConnection,
taskQueue: 'repro',
workflowsPath: path.join(__dirname, 'workflows.cjs'),
activities,
dataConverter,
plugins: [new StrandsPlugin()],
});
const result = await worker.runUntil(async () => {
const failed = await client.workflow.start('failTwice', { taskQueue: 'repro', workflowId: 'fail', args: ['SECRET-42'] });
await failed.result().catch(() => undefined);
const events = (await failed.fetchHistory()).events;
const interrupted = await client.workflow.start('interruptInWorkflow', { taskQueue: 'repro', workflowId: 'interrupt', args: ['SECRET-42'] });
let wft;
while (!wft) {
await new Promise((r) => setTimeout(r, 200));
wft = (await interrupted.fetchHistory()).events.find((e) => e.workflowTaskFailedEventAttributes);
}
await interrupted.terminate();
return {
activityFailure: show(events.find((e) => e.activityTaskFailedEventAttributes).activityTaskFailedEventAttributes.failure),
workflowFailure: show(events.find((e) => e.workflowExecutionFailedEventAttributes).workflowExecutionFailedEventAttributes.failure),
interruptFailure: show(wft.workflowTaskFailedEventAttributes.failure),
};
});
console.log(JSON.stringify(result));
const encoded = (f) => f.message === 'Encoded failure' && f.encoded;
const ok =
encoded(result.activityFailure) &&
encoded(result.workflowFailure) &&
encoded(result.interruptFailure) &&
result.interruptFailure.type === 'StrandsInterrupt';
console.log(ok ? 'PASS: the caller\'s converter and Strands\' rewrite both apply' : 'FAIL: History differs from the expected');
process.exitCode = ok ? 0 : 1;
} finally {
await env.teardown();
}
}
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});node repro.cjs # with @temporalio/client, worker, testing, common, workflow, @temporalio/strands-agents and @strands-agents/sdk installedOutput with @temporalio/strands-agents 1.24.0, and the same on main at c664a34:
{"activityFailure":{"message":"activity failed with SECRET-42","type":"","encoded":false},"workflowFailure":{"message":"workflow failed with SECRET-42","type":"","encoded":false},"interruptFailure":{"message":"interrupt:approve","type":"StrandsInterrupt","encoded":false}}
FAIL: History differs from the expected
Expected: every message is Encoded failure with encodedAttributes, as without the plugin, and the
interrupt still has type StrandsInterrupt.
Environment/Versions
- OS and processor: Linux container on Apple Silicon (not OS-specific)
- Temporal Version:
@temporalio/strands-agents1.24.0 (the latest release) with
@strands-agents/sdk1.6.0, andtypescript/strands-agentsatmain(c664a34) with its
locked@strands-agents/sdk1.19.0;@temporalio/*1.24.0; Node 24.22.0; Temporal CLI 1.9.1 - Are you using Docker or Kubernetes or building Temporal from source? A local dev server
(TestWorkflowEnvironment.createLocal)
Additional context
Proposed fix, with a test and a version gate: pass dataConverter as a function. With no caller
converter, keep Strands' module. With one, point failureConverterPath at a small generated module
that applies Strands' rewrite to the error and its cause chain, then the caller's converter, so the
Worker also bundles it into Workflow code. Always encode with the caller's converter. In Workflow
code, decode with it only in runs that record a patched() marker at start, so a caller converter
that decodes failures into other errors does not change what open runs see on replay.
This is a breaking change: Client and Activity code, and new runs, get the errors the caller's
converter returns instead of the SDK default ones. A PR follows.
A cleaner path would be SDK support for composing failure converters (a path list, or a plugin hook
that receives the loaded converter). The data converter only takes module paths, so a plugin cannot
wrap the caller's converter without a module of its own.
Activity