Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-14499-copilot-ioscan.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Copilot-only hives can use a tool-less semantic classifier automatically when no model endpoint is configured; a persistent dashboard alert explains when an unavailable required classifier blocks kicks ([#14499](https://github.com/hivecommons/hive/issues/14499)).
36 changes: 33 additions & 3 deletions src/cmd/hive/boot_dashboard_deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,13 @@ func TestBootDashboardWithAdvisoryHookNoStoresIsNoop(t *testing.T) {
}

func TestBootDashboardWithClassifier(t *testing.T) {
t.Run("no endpoint logs and skips", func(t *testing.T) {
t.Run("no endpoint or supported agent logs and skips", func(t *testing.T) {
cfg := bootDashboardConfig()
// Keep this case on the unavailable path despite automatic CLI fallback.
for name, agent := range cfg.Agents {
agent.Backend = "codex"
cfg.Agents[name] = agent
}
on := true
cfg.Ioscan.Enabled = &on
cfg.Ioscan.Classifier.Enabled = &on
Expand All @@ -220,14 +225,19 @@ func TestBootDashboardWithClassifier(t *testing.T) {
b.bootDashboardWith(newBootDashboardFake().deps)

if _, _, installed := b.sched.IoscanHooksForTest(); installed {
t.Fatal("classifier must not install without an endpoint")
t.Fatal("classifier must not install without an endpoint or supported agent")
}
if !strings.Contains(log.String(), "ioscan classifier enabled but not running") {
t.Fatalf("log:\n%s", log.String())
}
})
t.Run("L5 default on, no endpoint installs fail-closed classifier", func(t *testing.T) {
t.Run("L5 default on, no endpoint or supported agent installs fail-closed classifier", func(t *testing.T) {
cfg := bootDashboardConfig()
// Keep this case on the unavailable path despite automatic CLI fallback.
for name, agent := range cfg.Agents {
agent.Backend = "codex"
cfg.Agents[name] = agent
}
on := true
cfg.Ioscan.Enabled = &on
level := 5
Expand All @@ -246,6 +256,26 @@ func TestBootDashboardWithClassifier(t *testing.T) {
t.Fatalf("log:\n%s", log.String())
}
})
t.Run("L5 default on, no endpoint uses Copilot agent", func(t *testing.T) {
cfg := bootDashboardConfig()
on, level := true, 5
cfg.Ioscan.Enabled = &on
cfg.ACMMLevel = &level
b := newBootDashboardBoot(t, cfg)
var log syncLogBuffer
b.logger = slog.New(slog.NewTextHandler(&log, nil))
b.sched = scheduler.New(cfg, b.logger)

b.bootDashboardWith(newBootDashboardFake().deps)

if _, _, installed := b.sched.IoscanHooksForTest(); !installed {
t.Fatal("configured Copilot agent must supply the classifier without an endpoint")
}
if !strings.Contains(log.String(), "ioscan semantic classifier enabled") || !strings.Contains(log.String(), "backend=copilot") {
t.Fatalf("log:\n%s", log.String())
}
})

t.Run("L5 with classifier disabled explicitly skips", func(t *testing.T) {
cfg := bootDashboardConfig()
on, off := true, false
Expand Down
57 changes: 44 additions & 13 deletions src/cmd/hive/ioscan_classifier_boot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package main

import (
"log/slog"
"sort"
"strings"
"time"

"github.com/hivecommons/hive/pkg/config"
Expand All @@ -15,15 +17,27 @@ type ioscanClassifierSink interface {
SetClassifierBudgetPerEval(int)
}

const ioscanClassifierUnavailableAlertID = "ioscan-classifier-unavailable"

type ioscanAlertSink interface {
AddSystemAlert(string, string, string)
ClearSystemAlert(string)
}

// installIoscanClassifier builds the semantic injection classifier when the
// ACMM level (or an explicit setting) enables it. An empty
// ioscan.classifier.backend uses the OpenAI-compatible HTTP endpoint; a named
// backend runs the classifier through that subscription CLI, tool-less, with
// the low per-pass budget and the daily quota. A backend that cannot run
// tool-less is refused with one log line and handled like any classifier
// that cannot be built: withheld text at fail-closed, no classifier at
// fail-open.
func installIoscanClassifier(sched ioscanClassifierSink, cfg *config.Config, logger *slog.Logger, now func() time.Time) {
// ACMM level (or an explicit setting) enables it. Explicit CLI configuration
// wins; otherwise prefer the HTTP endpoint, then a tool-less configured agent CLI.
func installIoscanClassifier(sched ioscanClassifierSink, cfg *config.Config, logger *slog.Logger, now func() time.Time, alerts ...ioscanAlertSink) {
for _, sink := range alerts {
sink.ClearSystemAlert(ioscanClassifierUnavailableAlertID)
}
alertUnavailable := func() {
if classifierClosed := cfg.Ioscan.ClassifierFailClosedAtLevel(cfg.ACMMLevelOrZero()); classifierClosed {
for _, sink := range alerts {
sink.AddSystemAlert(ioscanClassifierUnavailableAlertID, "error", "Input defense classifier is required but unavailable: kicks are being blocked. Configure governor.trajectory/litellm, set ioscan.classifier.backend to claude or copilot, or set ioscan.classifier.fail_mode: open.")
}
}
}
acmmLevel := cfg.ACMMLevelOrZero()
if !cfg.Ioscan.ClassifierEnabledAtLevel(acmmLevel) {
return
Expand All @@ -32,16 +46,33 @@ func installIoscanClassifier(sched ioscanClassifierSink, cfg *config.Config, log
cl := cfg.Ioscan.Classifier
thresholds := ioscan.Thresholds{Warn: cl.WarnThreshold, Block: cl.BlockThreshold}

if backend := cl.CLIBackend(); backend != "" {
endpoint, apiKey, model := cfg.Governor.ResolveReviewer()
backend := cl.CLIBackend()
if backend == "" && strings.TrimSpace(endpoint) == "" {
names := make([]string, 0, len(cfg.Agents))
for name := range cfg.Agents {
names = append(names, name)
}
sort.Strings(names)
for _, name := range names {
candidate := strings.TrimSpace(cfg.Agents[name].Backend)
if ioscan.SupportsToolless(candidate) {
backend = candidate
break
}
}
}
if backend != "" {
// NewCLIClassifier refuses exactly the backends SupportsToolless rejects.
classifier, cerr := ioscan.NewCLIClassifier(backend, cl.Model, cl.CLIDailyQuotaOrDefault(), now)
if cerr != nil {
alertUnavailable()
if classifierFailClosed {
sched.SetClassifier(ioscan.UnavailableClassifier{Err: cerr}, ioscan.Thresholds{})
}
logger.Error("ioscan classifier backend refused: it cannot run with no tools, no MCP, no GitHub token and an empty working directory",
"backend", backend, "accepted", "claude", "fail_closed", classifierFailClosed, "acmm_level", acmmLevel,
"fix", "set ioscan.classifier.backend to claude, or leave it empty to use the model endpoint (Settings → Security → Input Defense)")
"backend", backend, "accepted", "claude,copilot", "fail_closed", classifierFailClosed, "acmm_level", acmmLevel,
"fix", "set ioscan.classifier.backend to claude or copilot, or leave it empty to use the model endpoint (Settings → Security → Input Defense)")
return
}
sched.SetClassifier(ioscan.NewCachedClassifier(classifier, ioscan.DefaultClassifierCacheEntries), thresholds)
Expand All @@ -51,7 +82,6 @@ func installIoscanClassifier(sched ioscanClassifierSink, cfg *config.Config, log
return
}

endpoint, apiKey, model := cfg.Governor.ResolveReviewer()
if cl.Model != "" {
model = cl.Model
}
Expand All @@ -65,12 +95,13 @@ func installIoscanClassifier(sched ioscanClassifierSink, cfg *config.Config, log
})
switch {
case cerr != nil && classifierFailClosed:
alertUnavailable()
// The level requires the classifier and it cannot run: withhold
// untrusted text rather than silently scanning without it.
sched.SetClassifier(ioscan.UnavailableClassifier{Err: cerr}, ioscan.Thresholds{})
logger.Error("ioscan classifier required at this ACMM level but not running; untrusted text is withheld",
"reason", cerr.Error(), "acmm_level", acmmLevel,
"fix", "configure governor.trajectory/litellm, set ioscan.classifier.backend: claude, or set ioscan.classifier.enabled: false or ioscan.classifier.fail_mode: open")
"fix", "configure governor.trajectory/litellm, set ioscan.classifier.backend to claude or copilot, or set ioscan.classifier.fail_mode: open")
case cerr != nil:
logger.Warn("ioscan classifier enabled but not running", "reason", cerr.Error())
default:
Expand Down
48 changes: 46 additions & 2 deletions src/cmd/hive/ioscan_classifier_boot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"time"

"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/dashboard"
"github.com/hivecommons/hive/pkg/ioscan"
)

Expand Down Expand Up @@ -42,11 +43,11 @@ func ioscanBootLogger() (*slog.Logger, *bytes.Buffer) {

var ioscanBootNow = func() time.Time { return time.Date(2026, 10, 24, 12, 0, 0, 0, time.UTC) }

// A backend that cannot run tool-less (copilot, codex, gemini) is refused
// A backend that cannot run tool-less (codex, gemini) is refused
// with one log line. At a fail-closed level the unavailable classifier is
// installed so untrusted text is withheld; at fail-open nothing is installed.
func TestInstallIoscanClassifier_RefusesNonToollessBackend(t *testing.T) {
for _, backend := range []string{"copilot", "codex", "gemini"} {
for _, backend := range []string{"codex", "gemini"} {
t.Run(backend+" fail closed", func(t *testing.T) {
sink := &fakeClassifierSink{}
logger, logs := ioscanBootLogger()
Expand Down Expand Up @@ -125,3 +126,46 @@ func TestInstallIoscanClassifier_DisabledInstallsNothing(t *testing.T) {
t.Fatalf("classifier off at L1 still acted: sets=%d logs=%q", sink.sets, logs.String())
}
}

func TestInstallIoscanClassifierAgentFallbackAndAlert(t *testing.T) {
for _, tc := range []struct {
name, agent, explicit, endpoint, failMode string
cli, alert bool
}{
{name: "endpoint wins", agent: "copilot", endpoint: "https://classifier.invalid"},
{name: "explicit wins", agent: "copilot", explicit: "claude", endpoint: "https://classifier.invalid", cli: true},
{name: "copilot fallback", agent: "copilot", cli: true},
{name: "claude fallback", agent: "claude", cli: true},
{name: "explicit copilot", explicit: "copilot", cli: true},
{name: "unsupported fallback", agent: "codex", alert: true},
{name: "missing backend", alert: true},
{name: "explicit refusal", agent: "copilot", explicit: "gemini", alert: true},
{name: "fail open", agent: "gemini", failMode: "open"},
} {
t.Run(tc.name, func(t *testing.T) {
cfg := ioscanBootConfig(6, tc.explicit, tc.failMode)
cfg.Agents = map[string]config.AgentConfig{"reviewer": {Backend: tc.agent}}
cfg.Governor.Trajectory.Endpoint = tc.endpoint
sink := &fakeClassifierSink{}
logger, _ := ioscanBootLogger()
srv := dashboard.NewServer(0, logger)
installIoscanClassifier(sink, cfg, logger, ioscanBootNow, srv)
if (sink.budget > 0) != tc.cli {
t.Fatalf("CLI budget = %d", sink.budget)
}
alert, ok := alertByID(publishedAlerts(t, srv), ioscanClassifierUnavailableAlertID)
if ok != tc.alert {
t.Fatalf("alert present = %v, want %v", ok, tc.alert)
}
if ok && (!strings.Contains(alert.Message, "kicks are being blocked") || !strings.Contains(alert.Message, "fail_mode: open")) {
t.Fatalf("unhelpful alert: %+v", alert)
}
disabled := false
cfg.Ioscan.Classifier.Enabled = &disabled
installIoscanClassifier(sink, cfg, logger, ioscanBootNow, srv)
if _, ok := alertByID(publishedAlerts(t, srv), ioscanClassifierUnavailableAlertID); ok {
t.Fatal("stale alert after disabling classifier")
}
})
}
}
2 changes: 1 addition & 1 deletion src/cmd/hive/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2775,7 +2775,7 @@ func (b *boot) bootDashboardWith(deps bootDashboardDeps) {
}
}
})
installIoscanClassifier(b.sched, b.cfg, b.logger, time.Now)
installIoscanClassifier(b.sched, b.cfg, b.logger, time.Now, b.dashSrv)
b.agentMgr.SetSandboxAuditCallback(func(agentName, action, detail string) {
b.dashSrv.AuditLog(agentName, action, detail, agentName)
if action == "sandbox_broker_rejected" {
Expand Down
15 changes: 7 additions & 8 deletions src/docs/ioscan.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ioscan:
enabled: true # default: on at ACMM L4–L6, off at L1–L3
fail_mode: closed # default: follows ioscan.fail_mode (closed at L5–L6)
model: "" # empty uses the governor's default model
backend: "" # empty = model endpoint (HTTP); "claude" = tool-less CLI
backend: "" # empty = HTTP or agent CLI fallback; "claude"/"copilot" = CLI
cli_budget_per_eval: 8 # CLI backend only: calls per scheduler pass (max 64)
cli_daily_quota: 500 # CLI backend only: calls per UTC day
warn_threshold: 0.55
Expand Down Expand Up @@ -140,9 +140,8 @@ marker and records a fail-closed entry. `classifier.fail_mode` left unset
follows `ioscan.fail_mode`, so it is `closed` at L5–L6 and `open` below. At
L5–L6 a hive with no model endpoint configured therefore withholds all
untrusted text until one is set, or until the owner sets
`classifier.backend: claude` (see **CLI backend** below),
`classifier.enabled: false` or `classifier.fail_mode: open`. The boot log
says so in one line. A hive whose agents all run on a subscription CLI such
`classifier.backend: claude` or `classifier.backend: copilot` (see **CLI backend** below),
`classifier.enabled: false` or `classifier.fail_mode: open`. The boot log and a persistent dashboard system alert explain when kicks are blocked. A hive whose agents all run on a subscription CLI such
as Copilot has no such endpoint, so this is the usual case there and the
CLI backend is the remedy that keeps the classifier running. The classifier
itself is built at boot, so changing its backend needs a restart.
Expand All @@ -155,21 +154,21 @@ rules alone cover them.

**CLI backend.** A hive with no model endpoint, for example one whose agents
all run on subscription CLIs, can run the classifier through a CLI instead
with `classifier.backend`. Empty (the default) keeps the HTTP endpoint path
exactly as before. The only accepted backend today is `claude`.
with `classifier.backend`. Empty (the default) prefers the HTTP endpoint; when none is resolved, boot selects a tool-less backend from configured agents in agent-name order. Accepted backends are `claude` and `copilot`.

* **Tool-less guarantee.** The CLI is launched with every built-in tool
disabled and no MCP server, in an empty temporary working directory, with
an environment reduced to `PATH`, `HOME`, locale, terminal and the CLI's
own login variables, so no GitHub or hive token reaches a process that
own login variables (including `COPILOT_HOME` and `COPILOT_GITHUB_TOKEN` for Copilot), so no hive GitHub token (`GH_TOKEN`/`GITHUB_TOKEN`) reaches a process that
reads untrusted text. No permission-bypass flag is ever passed. Hooks in
the host's own `~/.claude/settings.json` are turned off for the run with
`--settings '{"disableAllHooks":true}'`, so they never see the text; login,
env and model keys in that file still load, and hooks from managed
settings are the operator's own and still run. Its reply must contain
exactly one valid JSON verdict; anything else is a classifier error and
follows `classifier.fail_mode`.
* **Refused backends.** `copilot`, `codex` and `gemini` have no command-line
* **Copilot.** Uses `--available-tools hive_ioscan_no_tools` (an unknown sentinel, since an empty list is ignored), disables built-in MCPs and custom instructions, and passes the prompt with `-p`. Requires Copilot CLI with these flags (verified with 1.0.103).
* **Refused backends.** `codex` and `gemini` have no verified command-line
flag that removes every tool, so boot refuses them with one log line and
then behaves as for any classifier that cannot be built: at a closed
classifier fail mode untrusted text is withheld, at open the classifier
Expand Down
4 changes: 2 additions & 2 deletions src/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,8 +502,8 @@ type IoscanConfig struct {
// Read both via EnabledAtLevel / FailClosedAtLevel, never raw.
//
// Backend names a subscription CLI (e.g. "claude") that runs the classifier
// tool-less instead of the OpenAI-compatible HTTP endpoint; empty keeps the
// HTTP path. Boot refuses a backend ioscan.SupportsToolless rejects. With a
// tool-less instead of the OpenAI-compatible HTTP endpoint; empty prefers
// HTTP, then falls back to a tool-less configured agent CLI. Boot refuses a backend ioscan.SupportsToolless rejects. With a
// CLI backend, CLIBudgetPerEval replaces the per-pass budget and
// CLIDailyQuota caps calls per UTC day; zero uses the defaults. Read them
// via CLIBudgetPerEvalOrDefault / CLIDailyQuotaOrDefault.
Expand Down
Loading
Loading