From cc00a6f193d2a1f808e9a45ddefceecf97d91eac Mon Sep 17 00:00:00 2001 From: Viet Tran Date: Wed, 11 Mar 2026 07:57:51 +0700 Subject: [PATCH] fix: route delegate session keys to correct agent loop (#127) Delegate session keys (delegate:{uuid8}:{agentKey}:{delegationId}) were not parsed by makeSchedulerRunFunc, causing fallback to default agent ID which doesn't exist in managed-mode DBs. Add switch/case to handle both agent: and delegate: prefixes. --- cmd/gateway_consumer_process.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/cmd/gateway_consumer_process.go b/cmd/gateway_consumer_process.go index f67143ef..4b5f5439 100644 --- a/cmd/gateway_consumer_process.go +++ b/cmd/gateway_consumer_process.go @@ -14,10 +14,20 @@ import ( // It extracts the agentID from the session key and routes to the correct agent loop. func makeSchedulerRunFunc(agents *agent.Router, cfg *config.Config) scheduler.RunFunc { return func(ctx context.Context, req agent.RunRequest) (*agent.RunResult, error) { - // Extract agentID from session key (format: agent:{agentId}:{rest}) + // Extract agentID from session key. + // Supported formats: + // agent:{agentId}:{rest} + // delegate:{sourceUUID8}:{targetAgentKey}:{delegationId} agentID := cfg.ResolveDefaultAgentID() - if parts := strings.SplitN(req.SessionKey, ":", 3); len(parts) >= 2 && parts[0] == "agent" { - agentID = parts[1] + if parts := strings.SplitN(req.SessionKey, ":", 4); len(parts) >= 2 { + switch parts[0] { + case "agent": + agentID = parts[1] + case "delegate": + if len(parts) >= 3 { + agentID = parts[2] + } + } } loop, err := agents.Get(agentID)