Skip to content

feat(core): thread agent and thread identity through the processor surface#18552

Closed
CalebBarnes wants to merge 1 commit into
mainfrom
caleb/processor-context-identity
Closed

feat(core): thread agent and thread identity through the processor surface#18552
CalebBarnes wants to merge 1 commit into
mainfrom
caleb/processor-context-identity

Conversation

@CalebBarnes

Copy link
Copy Markdown
Member

Summary

Processors today have no first-class way to learn which agent, thread, or resource a run belongs to. Consumers that need this (for example the channels output processor) are forced to depend on request-scoped side channels that are not always populated. This PR adds agentId, agentName, threadId, and resourceId as flat optional fields on ProcessorContext, so every processor method receives them directly.

The fields are optional and undefined for non-agent or threadless pipelines, so existing processors keep working unchanged.

const myProcessor: Processor = {
  id: 'my-processor',
  processOutputStream: async ({ part, agentId, threadId, resourceId }) => {
    // agentId, threadId, resourceId now available here
    return part;
  },
};

What changed

  • Added the four identity fields to ProcessorContext (propagates to all method arg types).
  • Added agentId to the ProcessorRunner constructor alongside agentName; threadId/resourceId are passed per-call into the public entry methods.
  • Injected the identity fields into every hand-built processor args object — both the in-process regular-processor objects and the workflow-as-processor inline objects.
  • Added the identity fields to the workflow step schemas and types so they survive the workflow serialization boundary, and spread them into baseContext in both the default and evented workflow executors.
  • Wired agentId (and proper agentName/threadId/resourceId where available) into all non-test ProcessorRunner construction sites.

All four fields are plain strings, so they cross the workflow step serialization boundary safely. No live handles or closures were added to any step schema.

Test plan

  • New cross-path symmetry test in runner.test.ts: a processor receives identical agentId/agentName/threadId/resourceId whether it runs in-process or as a workflow.
  • pnpm build:core — passing.
  • pnpm --filter ./packages/core check (typecheck) — passing.
  • Focused processor tests (src/processors/, 38 files) — passing.
  • Loop, agent, and workflow tests (125 files) — passing.

This is PR #1 of a stack. It is independently useful and unblocks a follow-up that makes the channels output processor self-sufficient.

Processors had no sanctioned way to learn which agent, thread, or resource
a run belonged to, forcing consumers like ChatChannelOutputProcessor to
depend on request-scoped side channels. Add agentId, agentName, threadId,
and resourceId as flat optional fields on ProcessorContext so every
processor method receives them.

Both the in-process ProcessorRunner path and the workflow-as-processor path
carry identical identity fields: identity is added to every hand-built args
object, lives on the workflow step schemas to survive serialization, and is
spread into baseContext in both workflow executors. A cross-path symmetry
test proves a processor receives the same identity regardless of path.

Co-Authored-By: Mastra Code (anthropic/claude-opus-4-8) <noreply@mastra.ai>
@changeset-bot

changeset-bot Bot commented Jun 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 95c066b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 22 packages
Name Type
@mastra/core Minor
mastracode Patch
@mastra/mcp-docs-server Patch
@internal/playground Patch
@mastra/client-js Patch
@mastra/opencode Patch
@mastra/longmemeval Patch
mastra Patch
@mastra/deployer-cloud Minor
@mastra/react Patch
@mastra/playground-ui Patch
@mastra/server Minor
@mastra/deployer Minor
create-mastra Patch
@mastra/express Patch
@mastra/fastify Patch
@mastra/hono Patch
@mastra/koa Patch
@mastra/nestjs Patch
@mastra/next Patch
@mastra/tanstack-start Patch
@mastra/temporal Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 91fc0638-4f83-4aad-a5a3-7ff2f9d85e19

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch caleb/processor-context-identity

Comment @coderabbitai help to get the list of available commands.

@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mastra-docs-1.x Ready Ready Preview, Comment Jun 27, 2026 9:07am
mastra-playground-ui Ready Ready Preview, Comment Jun 27, 2026 9:07am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
mastra-studio-preview Ignored Ignored Jun 27, 2026 9:07am

Request Review

@CalebBarnes

Copy link
Copy Markdown
Member Author

Superseded by #18630. The self-sufficient channels output processor (the only consumer of this identity work) instead sources the run's threadId from the framework-populated MastraMemory request-context key via parseMemoryRequestContext, so threading agentId/agentName/threadId/resourceId through the entire processor surface is no longer required for this work. Closing to avoid a stale stack.

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