Skip to content

fix(harness): stamp taskId on remote subagent forwarded events - #2575

Merged
oss-maintainer merged 1 commit into
mainfrom
fix/remote-subagent-event-taskid-metadata
Aug 5, 2026
Merged

fix(harness): stamp taskId on remote subagent forwarded events#2575
oss-maintainer merged 1 commit into
mainfrom
fix/remote-subagent-event-taskid-metadata

Conversation

@chickenlj

Copy link
Copy Markdown
Collaborator

Summary

  • Remote streamEvents forwarding now sets AgentEvent.metadata.taskId (AgentEvent.METADATA_TASK_ID) alongside source, so two same-turn calls to the same remote subagent remain correlatable to distinct TaskRecords
  • RemoteEventCodec.toAgentEvent copies wire taskId into that metadata key; AgentEvent.withMetadataEntry supports merge-safe updates
  • Docs (en/zh subagent + message-and-event) updated

Test plan

  • mvn -pl agentscope-core,agentscope-harness -am test -Dtest=AgentSpawnToolRemoteHelpersTest,RemoteEventCodecTest
  • Reproduce SRE demo chat with two remote spawns of the same agent; confirm [SRE_DEMO_MAIN_EVENT] ... taskId= is non-null and distinct per spawn
  • Confirm source remains parentSession/agentId (identity), while taskId identifies the task run

Source alone cannot distinguish two same-turn remote calls to the same
agent; attach metadata.taskId so consumers can correlate events to the
harness TaskRecord / Agent Protocol task.
Copilot AI review requested due to automatic review settings August 5, 2026 15:20

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves traceability for remote subagent event forwarding in the harness by ensuring forwarded AgentEvents carry a stable metadata.taskId (in addition to source). This allows multiple same-turn invocations of the same remote agent (same source path) to still be correlated back to distinct harness task executions.

Changes:

  • Add AgentEvent.METADATA_TASK_ID and a merge-safe AgentEvent.withMetadataEntry(...) helper for updating metadata without clobbering existing entries.
  • Stamp forwarded remote events with both source and metadata.taskId via AgentSpawnTool.tagRemoteForwardedEvent(...).
  • Ensure RemoteEventCodec.toAgentEvent(...) copies wire taskId into metadata.taskId, and update docs + tests accordingly.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
docs/v2/zh/docs/harness/subagent.md Documents metadata.taskId on forwarded remote subagent events for correlation.
docs/v2/zh/docs/building-blocks/message-and-event.md Adds getMetadata() documentation and notes remote forwarding sets taskId.
docs/v2/en/docs/harness/subagent.md Documents metadata.taskId on forwarded remote subagent events for correlation.
docs/v2/en/docs/building-blocks/message-and-event.md Adds getMetadata() documentation and notes remote forwarding sets taskId.
agentscope-harness/src/test/java/io/agentscope/harness/agent/tool/AgentSpawnToolRemoteHelpersTest.java Tests that remote-forwarded events preserve metadata while setting source + metadata.taskId.
agentscope-harness/src/test/java/io/agentscope/harness/agent/subagent/protocol/RemoteEventCodecTest.java Tests that wire taskId is copied into AgentEvent metadata.
agentscope-harness/src/main/java/io/agentscope/harness/agent/tool/AgentSpawnTool.java Implements tagging of forwarded remote events with source and metadata.taskId.
agentscope-harness/src/main/java/io/agentscope/harness/agent/subagent/protocol/RemoteEventCodec.java Copies wire taskId onto AgentEvent.METADATA_TASK_ID during DTO→event mapping.
agentscope-core/src/main/java/io/agentscope/core/event/AgentEvent.java Introduces the well-known metadata key and a merge-safe per-entry metadata updater.

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

@oss-maintainer
oss-maintainer merged commit dc0884e into main Aug 5, 2026
11 of 12 checks passed
@oss-maintainer
oss-maintainer deleted the fix/remote-subagent-event-taskid-metadata branch August 5, 2026 15:38
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.

3 participants