Repository navigation
Conversation
…ansfer stack Pin foreground transfer_task sub-sessions so parallel delegations cannot misroute each other, track active foreground transfers as a token-indexed stack in agentRouter, update active transfer entries on in-session handoff, and resolve session-scoped agent names for stream logging and telemetry. Signed-off-by: nasagong <83327025+nasagong@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4156
Problem
When multiple
transfer_tasktool calls run concurrently in the same turn:PinAgentis unset for root parents), so parallel transfers resolve their agent from the sharedagentRouter.currentand misroute each other.swapCurrentAgentrestores from a single entry-timesharedsnapshot, corruptingcurrentAgentwhen parallel transfers overlap, exit out of order, or run alongside ahandoff.loop.gologs and records telemetry/OTel attributes fromr.currentAgentName()instead of the session's resolved agent.Fix
pkg/runtime/agent_delegation.go: Always pintransfer_taskchildren (PinAgent = true), distinguish foreground/nested transfers from background pinned sessions viar.agents.isActiveTransfer(parent.ID), and emitAgentInfofor the actualrestoredAgent.pkg/runtime/agent_router.go&pkg/runtime/routing.go: Track active foreground transfers as a token-indexed stack withtransferBaseunder a singlemu(lock-freeatomic.Pointerreads unchanged, never held across event emission or hooks), deferSettotransferBasewhile transfers are active, and update active transfer entries on in-sessionhandoff/force_handoffviaupdateTransferAgent.pkg/runtime/loop.go: Resolve stream start logs, telemetry, and OTel span attributes viar.sessionAgentName(sess).transfer_taskisolation, paralleltransfer_task+handoff, paralleltransfer_task+run_skillfork, and childhandoff/force_handofffollowed by nestedtransfer_task.Verification
task formatgo test -race ./pkg/runtime/...task build