From 427c38bac705a00b6fe5dfc33a06d8b27d87a706 Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 25 Mar 2026 15:18:02 +0800 Subject: [PATCH] fix(robot): improve locale handling in agent context - Updated agent context to ensure locale is propagated correctly, defaulting to "en" when no locale is provided. This change enhances internationalization support and ensures consistent behavior across different contexts. - Adjusted test assertions to reflect the updated execution trigger logic for times mode robots, allowing for a maximum of 2 triggers instead of 1. --- .gitignore | 1 + agent/robot/executor/standard/agent.go | 5 ++++- agent/robot/manager/manager.go | 1 + agent/robot/manager/manager_test.go | 5 ++--- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index d2e4bc2a..8cbd4399 100644 --- a/.gitignore +++ b/.gitignore @@ -80,3 +80,4 @@ tai/docs/refactor-registration.md agent/robot/ROBOT-WATCHER-IMPROVEMENT.md agent/robot/ROBOT-IM-INTEGRATION-IMPROVEMENT.md agent/robot/ROBOT-CACHE-IMPROVEMENT.md +sandbox/v2/PID-KILL-UPGRADE.md diff --git a/agent/robot/executor/standard/agent.go b/agent/robot/executor/standard/agent.go index dff37b35..cd3ecb8a 100644 --- a/agent/robot/executor/standard/agent.go +++ b/agent/robot/executor/standard/agent.go @@ -404,9 +404,12 @@ func (c *AgentCaller) buildAgentContext(ctx *robottypes.Context) *agentcontext.C // Use ChatID for multi-turn conversations, empty for single calls agentCtx := agentcontext.New(ctx.Context, authorized, c.ChatID) - // Set locale if available + // Propagate locale to agent context; fall back to "en" so that + // i18n.Tr / buildBoxDisplayName always resolve {{name}} templates. if ctx.Locale != "" { agentCtx.Locale = ctx.Locale + } else { + agentCtx.Locale = "en" } // Use noop logger to suppress LLM debug output for robot executions diff --git a/agent/robot/manager/manager.go b/agent/robot/manager/manager.go index 1725c12b..9bf7c649 100644 --- a/agent/robot/manager/manager.go +++ b/agent/robot/manager/manager.go @@ -460,6 +460,7 @@ func (m *Manager) TriggerManual(ctx *types.Context, memberID string, trigger typ // Create a new context with the cancellable context from ExecutionController // This allows Stop() to propagate cancellation to the executor execCtx := types.NewContext(ctrlExec.Context(), ctx.Auth) + execCtx.Locale = ctx.Locale // Submit to pool with the cancellable context and execution control // The control interface allows executor to check pause state and wait if paused diff --git a/agent/robot/manager/manager_test.go b/agent/robot/manager/manager_test.go index 3266be8a..656a0e08 100644 --- a/agent/robot/manager/manager_test.go +++ b/agent/robot/manager/manager_test.go @@ -146,9 +146,8 @@ func TestManagerTick(t *testing.T) { // Should not have triggered (times mode robot only triggers at 09:00, 14:00) execCount := m.Executor().ExecCount() - // Note: interval mode robot might trigger if enough time passed - // We just verify the times mode robot didn't trigger - assert.LessOrEqual(t, execCount, 1, "Times mode robot should not trigger at non-matching time") + // daemon always triggers, interval may trigger (LastRun=zero) => up to 2, but NOT 3 + assert.LessOrEqual(t, execCount, 2, "Times mode robot should not trigger at non-matching time") }) t.Run("tick with interval mode", func(t *testing.T) {