Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Clamp scoped chat handoffs to controlled execution

rcourtmana886399e5917
diff --git a/docs/release-control/v6/internal/subsystems/ai-runtime.md b/docs/release-control/v6/internal/subsystems/ai-runtime.md
index 64373b8db6..a12e40dc49 100644
--- a/docs/release-control/v6/internal/subsystems/ai-runtime.md
+++ b/docs/release-control/v6/internal/subsystems/ai-runtime.md
@@ -274,7 +274,11 @@ runtime cost control, and shared AI transport surfaces.
The chat runtime must apply any request-local autonomous-mode override to
both the per-request `AgenticLoop` and the cloned `PulseToolExecutor`;
persistent autonomous settings must not leak into scoped approval-required
- handoffs through executor state.
+ handoffs through executor state. When such an override forces approval mode
+ and the saved control level is autonomous, the executor clone must clamp its
+ effective control level to controlled for that request only, so even
+ policy-allowed diagnostic commands require operator approval in scoped
+ handoffs without mutating the user's saved setting.
The Assistant drawer may also render an attached context briefing for that
handoff, but the briefing is runtime context visibility only: it must not
mutate chat control settings, execute tools, or reveal raw command payloads.
diff --git a/internal/ai/chat/service.go b/internal/ai/chat/service.go
index 27e05e2240..e49b4f2e63 100644
--- a/internal/ai/chat/service.go
+++ b/internal/ai/chat/service.go
@@ -179,6 +179,16 @@ func resolveEffectiveControlLevel(
return tools.ControlLevel(cfg.GetControlLevel())
}
+func controlLevelForRequestAutonomousMode(level tools.ControlLevel, requested *bool) tools.ControlLevel {
+ if requested == nil || *requested {
+ return level
+ }
+ if level == tools.ControlLevelAutonomous {
+ return tools.ControlLevelControlled
+ }
+ return level
+}
+
func (s *Service) effectiveControlLevelLocked() tools.ControlLevel {
return resolveEffectiveControlLevel(s.controlLevelResolver, s.cfg)
}
@@ -568,7 +578,9 @@ func (s *Service) ExecuteStream(ctx context.Context, req ExecuteRequest, callbac
if req.AutonomousMode != nil {
autonomousMode = *req.AutonomousMode
}
+ effectiveControlLevel = controlLevelForRequestAutonomousMode(effectiveControlLevel, req.AutonomousMode)
if executor != nil {
+ executor.SetControlLevel(effectiveControlLevel)
executor.SetAutonomousMode(autonomousMode)
}
selectedModel = configuredModel
diff --git a/internal/ai/chat/service_additional_test.go b/internal/ai/chat/service_additional_test.go
index a41ead9957..6e8505d387 100644
--- a/internal/ai/chat/service_additional_test.go
+++ b/internal/ai/chat/service_additional_test.go
@@ -54,6 +54,21 @@ func TestServiceEffectiveControlLevelUsesResolver(t *testing.T) {
}
}
+func TestControlLevelForRequestAutonomousModeClampsAutonomousToControlled(t *testing.T) {
+ requestApprovalMode := false
+ if got := controlLevelForRequestAutonomousMode(tools.ControlLevelAutonomous, &requestApprovalMode); got != tools.ControlLevelControlled {
+ t.Fatalf("expected request approval mode to clamp autonomous control level to %q, got %q", tools.ControlLevelControlled, got)
+ }
+ if got := controlLevelForRequestAutonomousMode(tools.ControlLevelReadOnly, &requestApprovalMode); got != tools.ControlLevelReadOnly {
+ t.Fatalf("expected request approval mode not to upgrade read-only level, got %q", got)
+ }
+
+ requestAutonomousMode := true
+ if got := controlLevelForRequestAutonomousMode(tools.ControlLevelControlled, &requestAutonomousMode); got != tools.ControlLevelControlled {
+ t.Fatalf("expected request autonomous mode not to upgrade controlled entitlement, got %q", got)
+ }
+}
+
func TestServiceUpdateControlSettingsRefreshesEffectiveConfig(t *testing.T) {
service := NewService(Config{
AIConfig: &config.AIConfig{ControlLevel: config.ControlLevelReadOnly},
diff --git a/internal/ai/chat/service_execute_additional_test.go b/internal/ai/chat/service_execute_additional_test.go
index 56d9078fb7..e73ce6fe9f 100644
--- a/internal/ai/chat/service_execute_additional_test.go
+++ b/internal/ai/chat/service_execute_additional_test.go
@@ -205,7 +205,7 @@ func TestService_ExecuteStream_Success(t *testing.T) {
}
}
-func TestService_ExecuteStream_RequestAutonomousOverrideUpdatesToolExecutor(t *testing.T) {
+func TestService_ExecuteStream_RequestAutonomousOverrideClampsToolExecutor(t *testing.T) {
installTestApprovalStore(t, nil)
tmpDir := t.TempDir()
@@ -230,17 +230,17 @@ func TestService_ExecuteStream_RequestAutonomousOverrideUpdatesToolExecutor(t *t
if providerCallCount == 1 {
callback(providers.StreamEvent{
Type: "tool_start",
- Data: providers.ToolStartEvent{ID: "call-restart", Name: "pulse_control"},
+ Data: providers.ToolStartEvent{ID: "call-df", Name: "pulse_control"},
})
callback(providers.StreamEvent{
Type: "done",
Data: providers.DoneEvent{
ToolCalls: []providers.ToolCall{{
- ID: "call-restart",
+ ID: "call-df",
Name: "pulse_control",
Input: map[string]interface{}{
"type": "command",
- "command": "systemctl restart nginx",
+ "command": "df -h",
},
}},
},
@@ -278,7 +278,7 @@ func TestService_ExecuteStream_RequestAutonomousOverrideUpdatesToolExecutor(t *t
approvalSeen := false
err = svc.ExecuteStream(ctx, ExecuteRequest{
SessionID: "sess-request-override",
- Prompt: "restart nginx",
+ Prompt: "check disk space",
AutonomousMode: &approvalRequiredMode,
MaxTurns: 2,
}, func(event StreamEvent) {