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.
This commit is contained in:
Max 2026-03-25 15:18:02 +08:00
parent dc941636c3
commit 427c38bac7
4 changed files with 8 additions and 4 deletions

1
.gitignore vendored
View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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) {