diff --git a/internal/app/agentworker/mcp_providers_test.go b/internal/app/agentworker/mcp_providers_test.go index f0a540f5f..16d89e9a6 100644 --- a/internal/app/agentworker/mcp_providers_test.go +++ b/internal/app/agentworker/mcp_providers_test.go @@ -47,10 +47,6 @@ func (f *fakeMCPEngine) Discover(context.Context) ([]tools.ToolEntry, error) { return f.entries, f.discoverErr } -func (f *fakeMCPEngine) Health(context.Context) plugin.Health { - return plugin.Health{Status: plugin.HealthHealthy} -} - func (f *fakeMCPEngine) Stop(context.Context) error { f.stops++ return f.stopErr diff --git a/internal/plugin/host.go b/internal/plugin/host.go index 79972f562..2430a8e13 100644 --- a/internal/plugin/host.go +++ b/internal/plugin/host.go @@ -178,40 +178,11 @@ func validateIdentifiers(kind string, values []string, required bool) error { return nil } -// LifecycleState is the host-owned state of a module. -type LifecycleState string - -const ( - StateRegistered LifecycleState = "registered" - StateStarting LifecycleState = "starting" - StateRunning LifecycleState = "running" - StateStopping LifecycleState = "stopping" - StateStopped LifecycleState = "stopped" - StateFailed LifecycleState = "failed" -) - -// HealthStatus is a module's self-reported operational health. -type HealthStatus string - -const ( - HealthUnknown HealthStatus = "unknown" - HealthHealthy HealthStatus = "healthy" - HealthDegraded HealthStatus = "degraded" - HealthUnhealthy HealthStatus = "unhealthy" -) - -// Health is a point-in-time module health report. -type Health struct { - Status HealthStatus - Message string -} - // Module is the capability host's metadata and lifecycle contract. Domain // operations belong to typed capability-family interfaces, not here. type Module interface { Manifest() Manifest Start(context.Context) error - Health(context.Context) Health Stop(context.Context) error } @@ -249,21 +220,10 @@ func (m *legacyModule) Start(context.Context) error { return nil } -func (m *legacyModule) Health(context.Context) Health { - return Health{Status: HealthHealthy} -} - func (m *legacyModule) Stop(context.Context) error { return nil } -// ModuleStatus combines host-owned lifecycle state with module-reported health. -type ModuleStatus struct { - Manifest Manifest - State LifecycleState - Health Health -} - type hostState uint8 const ( @@ -278,7 +238,6 @@ const ( type registeredModule struct { module Module manifest Manifest - state LifecycleState } // Host validates module manifests and coordinates cross-family lifecycle. @@ -328,7 +287,6 @@ func (h *Host) Register(module Module) error { h.modules[manifest.ID] = ®isteredModule{ module: module, manifest: manifest, - state: StateRegistered, } h.registration = append(h.registration, manifest.ID) return nil @@ -360,22 +318,18 @@ func (h *Host) Start(ctx context.Context) error { started := make([]string, 0, len(order)) for _, id := range order { - h.setModuleState(id, StateStarting) module := h.module(id) if err := safeStart(ctx, id, module); err != nil { - h.setModuleState(id, StateFailed) rollback := append(append([]string(nil), started...), id) rollbackCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), rollbackTimeout) failedStops, rollbackErr := h.stopIDs(rollbackCtx, reverseClone(rollback)) cancel() - h.setModuleState(id, StateFailed) h.mu.Lock() h.started = reverseClone(failedStops) h.state = hostFailed h.mu.Unlock() return errors.Join(err, rollbackErr) } - h.setModuleState(id, StateRunning) started = append(started, id) } @@ -386,34 +340,6 @@ func (h *Host) Start(ctx context.Context) error { return nil } -// Health returns an immutable snapshot of module lifecycle and health. -func (h *Host) Health(ctx context.Context) []ModuleStatus { - h.opMu.Lock() - defer h.opMu.Unlock() - - h.mu.RLock() - statuses := make([]ModuleStatus, 0, len(h.registration)) - modules := make([]Module, 0, len(h.registration)) - for _, id := range h.registration { - entry := h.modules[id] - statuses = append(statuses, ModuleStatus{ - Manifest: entry.manifest.clone(), - State: entry.state, - Health: Health{Status: HealthUnknown}, - }) - modules = append(modules, entry.module) - } - h.mu.RUnlock() - - for i := range statuses { - if statuses[i].State != StateRunning { - continue - } - statuses[i].Health = safeHealth(ctx, statuses[i].Manifest.ID, modules[i]) - } - return statuses -} - // Stop stops started modules in reverse dependency order. It attempts every // stop even when one module returns an error or panics. func (h *Host) Stop(ctx context.Context) error { @@ -442,18 +368,6 @@ func (h *Host) Stop(ctx context.Context) error { return err } -// Manifests returns immutable snapshots in registration order. -func (h *Host) Manifests() []Manifest { - h.mu.RLock() - defer h.mu.RUnlock() - - out := make([]Manifest, 0, len(h.registration)) - for _, id := range h.registration { - out = append(out, h.modules[id].manifest.clone()) - } - return out -} - func (h *Host) startOrderLocked() ([]string, error) { const ( unvisited uint8 = iota @@ -496,14 +410,11 @@ func (h *Host) stopIDs(ctx context.Context, ids []string) ([]string, error) { var errs []error var failed []string for _, id := range ids { - h.setModuleState(id, StateStopping) if err := safeStop(ctx, id, h.module(id)); err != nil { - h.setModuleState(id, StateFailed) failed = append(failed, id) errs = append(errs, err) continue } - h.setModuleState(id, StateStopped) } return failed, errors.Join(errs...) } @@ -514,12 +425,6 @@ func (h *Host) module(id string) Module { return h.modules[id].module } -func (h *Host) setModuleState(id string, state LifecycleState) { - h.mu.Lock() - defer h.mu.Unlock() - h.modules[id].state = state -} - func (h *Host) ensureModulesLocked() { if h.modules == nil { h.modules = make(map[string]*registeredModule) @@ -577,27 +482,6 @@ func safeStart(ctx context.Context, id string, module Module) (err error) { return nil } -func safeHealth(ctx context.Context, id string, module Module) (health Health) { - defer func() { - if recovered := recover(); recovered != nil { - health = Health{ - Status: HealthUnhealthy, - Message: fmt.Sprintf("plugin module %q health panic: %v", id, recovered), - } - } - }() - health = module.Health(ctx) - switch health.Status { - case HealthUnknown, HealthHealthy, HealthDegraded, HealthUnhealthy: - return health - default: - return Health{ - Status: HealthUnhealthy, - Message: fmt.Sprintf("plugin module %q returned invalid health status %q", id, health.Status), - } - } -} - func safeStop(ctx context.Context, id string, module Module) (err error) { defer func() { if recovered := recover(); recovered != nil { diff --git a/internal/plugin/host_contract_test.go b/internal/plugin/host_contract_test.go index 6a20cc578..fef6eaae6 100644 --- a/internal/plugin/host_contract_test.go +++ b/internal/plugin/host_contract_test.go @@ -51,12 +51,12 @@ func TestCapabilityHostContractExists(t *testing.T) { } } - for _, name := range []string{"Manifest", "Module", "LifecycleState", "Health", "Host"} { + for _, name := range []string{"Manifest", "Module", "Host"} { if !types[name] { t.Errorf("plugin package does not define %s", name) } } - for _, name := range []string{"Register", "Start", "Health", "Stop", "Manifests"} { + for _, name := range []string{"Register", "Start", "Stop"} { if !hostMethods[name] { t.Errorf("plugin.Host does not define %s", name) } diff --git a/internal/plugin/host_test.go b/internal/plugin/host_test.go index bc05eb7dc..0116bbcfb 100644 --- a/internal/plugin/host_test.go +++ b/internal/plugin/host_test.go @@ -87,34 +87,6 @@ func TestHostRegisterRejectsDuplicateAndMutationAfterStart(t *testing.T) { } } -func TestHostManifestsAreImmutableSnapshots(t *testing.T) { - t.Parallel() - - host := plugin.NewHost() - manifest := validManifest("immutable") - if err := host.Register(&fakeModule{manifest: manifest}); err != nil { - t.Fatal(err) - } - - manifest.Capabilities[0] = "mutated-at-source" - manifest.Dependencies = append(manifest.Dependencies, "source-dependency") - - first := host.Manifests() - if len(first) != 1 { - t.Fatalf("Manifests() length = %d, want 1", len(first)) - } - first[0].Capabilities[0] = "mutated-at-caller" - first[0].Dependencies = append(first[0].Dependencies, "caller-dependency") - - second := host.Manifests() - if got := second[0].Capabilities[0]; got != "tools" { - t.Fatalf("stored capability = %q, want tools", got) - } - if len(second[0].Dependencies) != 0 { - t.Fatalf("stored dependencies = %v, want empty", second[0].Dependencies) - } -} - func TestHostStartsInDependencyOrderAndStopsInReverse(t *testing.T) { t.Parallel() @@ -273,26 +245,6 @@ func TestHostRegisterContainsManifestPanics(t *testing.T) { } } -func TestHostHealthRejectsInvalidProviderStatus(t *testing.T) { - t.Parallel() - - host := plugin.NewHost() - module := &fakeModule{ - manifest: validManifest("invalid-health"), - health: plugin.Health{Status: "surprising"}, - } - if err := host.Register(module); err != nil { - t.Fatal(err) - } - if err := host.Start(context.Background()); err != nil { - t.Fatal(err) - } - status := host.Health(context.Background())[0] - if status.Health.Status != plugin.HealthUnhealthy || !strings.Contains(status.Health.Message, "invalid health status") { - t.Fatalf("health status = %+v", status) - } -} - func TestHostStopContinuesAfterErrorsAndPanics(t *testing.T) { t.Parallel() @@ -377,9 +329,6 @@ func TestHostStartupRollbackIsBoundedAndRetryable(t *testing.T) { if got := module.stopContextErrors[0]; got != nil { t.Fatalf("rollback Stop() context error = %v, want original cancellation detached", got) } - if got := statusByID(host.Health(context.Background()), module.manifest.ID).State; got != plugin.StateFailed { - t.Fatalf("failed module state = %q, want failed after successful or failed rollback cleanup", got) - } if err := host.Stop(context.Background()); err != nil { t.Fatalf("Stop() retry error = %v", err) } @@ -388,46 +337,6 @@ func TestHostStartupRollbackIsBoundedAndRetryable(t *testing.T) { } } -func TestHostHealthIsPanicSafeAndSnapshotBased(t *testing.T) { - t.Parallel() - - host := plugin.NewHost() - healthy := &fakeModule{ - manifest: validManifest("healthy"), - health: plugin.Health{Status: plugin.HealthHealthy, Message: "ready"}, - } - panicky := &fakeModule{manifest: validManifest("panicky"), healthPanic: true} - for _, module := range []*fakeModule{healthy, panicky} { - if err := host.Register(module); err != nil { - t.Fatal(err) - } - } - - before := host.Health(context.Background()) - for _, status := range before { - if status.State != plugin.StateRegistered || status.Health.Status != plugin.HealthUnknown { - t.Fatalf("pre-start status = %+v, want registered/unknown", status) - } - } - - if err := host.Start(context.Background()); err != nil { - t.Fatal(err) - } - after := host.Health(context.Background()) - if got := statusByID(after, "healthy"); got.State != plugin.StateRunning || got.Health.Status != plugin.HealthHealthy { - t.Fatalf("healthy status = %+v", got) - } - if got := statusByID(after, "panicky"); got.State != plugin.StateRunning || got.Health.Status != plugin.HealthUnhealthy || - !strings.Contains(got.Health.Message, "panic") { - t.Fatalf("panicky status = %+v", got) - } - - after[0].Manifest.Capabilities[0] = "caller-mutation" - if got := host.Health(context.Background())[0].Manifest.Capabilities[0]; got != "tools" { - t.Fatalf("stored health manifest capability = %q, want tools", got) - } -} - func TestAdaptLegacyCreatesMetadataOnlyLifecycleModule(t *testing.T) { t.Parallel() @@ -446,9 +355,6 @@ func TestAdaptLegacyCreatesMetadataOnlyLifecycleModule(t *testing.T) { if err := module.Start(context.Background()); err != nil { t.Fatal(err) } - if health := module.Health(context.Background()); health.Status != plugin.HealthHealthy { - t.Fatalf("legacy health = %+v, want healthy", health) - } if err := module.Stop(context.Background()); err != nil { t.Fatal(err) } @@ -520,8 +426,6 @@ type fakeModule struct { stopContextErrors []error startPanic bool stopPanic bool - healthPanic bool - health plugin.Health manifestPanic bool } @@ -561,13 +465,6 @@ func (m *fakeModule) Start(context.Context) error { return m.startErr } -func (m *fakeModule) Health(context.Context) plugin.Health { - if m.healthPanic { - panic("health panic") - } - return m.health -} - func (m *fakeModule) Stop(ctx context.Context) error { m.events.add("stop:" + m.manifest.ID) m.stopCount++ @@ -582,12 +479,3 @@ func (m *fakeModule) Stop(ctx context.Context) error { } return m.stopErr } - -func statusByID(statuses []plugin.ModuleStatus, id string) plugin.ModuleStatus { - for _, status := range statuses { - if status.Manifest.ID == id { - return status - } - } - return plugin.ModuleStatus{} -} diff --git a/internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.go b/internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.go index e53c3721d..25e4f4f59 100644 --- a/internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.go +++ b/internal/plugin/pluginextract/github_com-samcharles93-archie-core-internal-plugin.go @@ -13,30 +13,16 @@ import ( func init() { Symbols["github.com/samcharles93/archie-core/internal/plugin/plugin"] = map[string]reflect.Value{ // function, constant and variable definitions - "AdaptLegacy": reflect.ValueOf(plugin.AdaptLegacy), - "HealthDegraded": reflect.ValueOf(plugin.HealthDegraded), - "HealthHealthy": reflect.ValueOf(plugin.HealthHealthy), - "HealthUnhealthy": reflect.ValueOf(plugin.HealthUnhealthy), - "HealthUnknown": reflect.ValueOf(plugin.HealthUnknown), - "HostAPIVersion": reflect.ValueOf(constant.MakeFromLiteral("\"1.0.0\"", token.STRING, 0)), - "LoadDir": reflect.ValueOf(plugin.LoadDir), - "NewHost": reflect.ValueOf(plugin.NewHost), - "StateFailed": reflect.ValueOf(plugin.StateFailed), - "StateRegistered": reflect.ValueOf(plugin.StateRegistered), - "StateRunning": reflect.ValueOf(plugin.StateRunning), - "StateStarting": reflect.ValueOf(plugin.StateStarting), - "StateStopped": reflect.ValueOf(plugin.StateStopped), - "StateStopping": reflect.ValueOf(plugin.StateStopping), + "AdaptLegacy": reflect.ValueOf(plugin.AdaptLegacy), + "HostAPIVersion": reflect.ValueOf(constant.MakeFromLiteral("\"1.0.0\"", token.STRING, 0)), + "LoadDir": reflect.ValueOf(plugin.LoadDir), + "NewHost": reflect.ValueOf(plugin.NewHost), // type definitions "CapabilityKind": reflect.ValueOf((*plugin.CapabilityKind)(nil)), - "Health": reflect.ValueOf((*plugin.Health)(nil)), - "HealthStatus": reflect.ValueOf((*plugin.HealthStatus)(nil)), "Host": reflect.ValueOf((*plugin.Host)(nil)), - "LifecycleState": reflect.ValueOf((*plugin.LifecycleState)(nil)), "Manifest": reflect.ValueOf((*plugin.Manifest)(nil)), "Module": reflect.ValueOf((*plugin.Module)(nil)), - "ModuleStatus": reflect.ValueOf((*plugin.ModuleStatus)(nil)), "Permission": reflect.ValueOf((*plugin.Permission)(nil)), "Plugin": reflect.ValueOf((*plugin.Plugin)(nil)), "Registry": reflect.ValueOf((*plugin.Registry)(nil)), @@ -50,18 +36,11 @@ func init() { // _github_com_samcharles93_archie_core_internal_plugin_Module is an interface wrapper for Module type type _github_com_samcharles93_archie_core_internal_plugin_Module struct { IValue interface{} - WHealth func(a0 context.Context) plugin.Health WManifest func() plugin.Manifest WStart func(a0 context.Context) error WStop func(a0 context.Context) error } -func (W _github_com_samcharles93_archie_core_internal_plugin_Module) Health(a0 context.Context) plugin.Health { - if W.WHealth == nil { - return plugin.Health{} - } - return W.WHealth(a0) -} func (W _github_com_samcharles93_archie_core_internal_plugin_Module) Manifest() plugin.Manifest { if W.WManifest == nil { return plugin.Manifest{} diff --git a/internal/plugin/pluginextract/reachability_test.go b/internal/plugin/pluginextract/reachability_test.go index e054b43a3..bb4fd9fcc 100644 --- a/internal/plugin/pluginextract/reachability_test.go +++ b/internal/plugin/pluginextract/reachability_test.go @@ -13,11 +13,11 @@ import ( // TestPreviouslyMissingSymbolsReachableFromInterpretedCode is the regression // test for the stale symbol-table drift (e7bo): the committed generated file // predated internal/plugin/host.go (f73b2d1) and was never regenerated, so -// the Host/Module/Manifest/Permission/Health/CapabilityKind/LifecycleState/ -// ModuleStatus types and the NewHost/AdaptLegacy/HostAPIVersion identifiers -// that plugin.go's LoadDir exposes to interpreted daemon plugins were absent -// from the table. A daemon plugin written against the capability-host API -// could not resolve them, silently. +// the Host/Module/Manifest/Permission/CapabilityKind types and the +// NewHost/AdaptLegacy/HostAPIVersion identifiers that plugin.go's LoadDir +// exposes to interpreted daemon plugins were absent from the table. A daemon +// plugin written against the capability-host API could not resolve them, +// silently. // // This test interprets a plugin that references the previously-missing // symbols, resolves it, and calls it -- proving the symbols are wired. @@ -87,10 +87,7 @@ func (testModule) Manifest() plugin.Manifest { } func (testModule) Start(context.Context) error { return nil } -func (testModule) Health(context.Context) plugin.Health { - return plugin.Health{Status: plugin.HealthHealthy} -} -func (testModule) Stop(context.Context) error { return nil } +func (testModule) Stop(context.Context) error { return nil } // TestWrapperNilGuardsPreserved follows the established pattern: yaegi's // fresh wrapper generation omits nil-guards on interface-wrappers, so they @@ -104,9 +101,6 @@ func TestWrapperNilGuardsPreserved(t *testing.T) { if got := mod.Manifest(); got.ID != "" || got.Name != "" || got.APIVersion != "" { t.Errorf("Manifest on nil WManifest = %#v, want empty", got) } - if got := mod.Health(context.Background()); got.Status != "" || got.Message != "" { - t.Errorf("Health on nil WHealth = %#v, want empty", got) - } if err := mod.Stop(context.Background()); err != nil { t.Errorf("Stop on nil WStop = %v, want nil", err) } diff --git a/internal/tools/provider/builtin/provider.go b/internal/tools/provider/builtin/provider.go index 2717037ec..db1f29284 100644 --- a/internal/tools/provider/builtin/provider.go +++ b/internal/tools/provider/builtin/provider.go @@ -119,23 +119,6 @@ func (p *Provider) Discover(ctx context.Context) ([]tools.ToolEntry, error) { return entries, nil } -// Health reports whether the tools were constructed. -func (p *Provider) Health(context.Context) plugin.Health { - if p.workspace == "" { - return plugin.Health{ - Status: plugin.HealthUnhealthy, - Message: "workspace directory is not configured", - } - } - if p.registry == nil { - return plugin.Health{ - Status: plugin.HealthUnhealthy, - Message: "workspace tools are not started", - } - } - return plugin.Health{Status: plugin.HealthHealthy} -} - // Stop releases the constructed tools. func (p *Provider) Stop(context.Context) error { p.registry = nil diff --git a/internal/tools/provider/mcp/provider.go b/internal/tools/provider/mcp/provider.go index a9fab11b3..4f4e4441c 100644 --- a/internal/tools/provider/mcp/provider.go +++ b/internal/tools/provider/mcp/provider.go @@ -155,27 +155,6 @@ func (p *Provider) Discover(ctx context.Context) ([]tools.ToolEntry, error) { return entries, nil } -// Health reports transport state. -func (p *Provider) Health(context.Context) plugin.Health { - if p.name == "" || p.segment == "" { - return plugin.Health{Status: plugin.HealthUnhealthy, Message: "MCP server name is invalid"} - } - if isNilTransport(p.transport) { - return plugin.Health{Status: plugin.HealthUnhealthy, Message: "MCP transport is not configured"} - } - state := p.transport.State() - switch state { - case protocol.StateRunning: - return plugin.Health{Status: plugin.HealthHealthy} - case protocol.StateStarting, protocol.StateStopping: - return plugin.Health{Status: plugin.HealthDegraded, Message: "MCP transport is " + state.String()} - case protocol.StateStopped, protocol.StateError: - return plugin.Health{Status: plugin.HealthUnhealthy, Message: "MCP transport is " + state.String()} - default: - return plugin.Health{Status: plugin.HealthUnhealthy, Message: "MCP transport state is unknown"} - } -} - // Stop stops the MCP transport and removes any media files written during // this provider's lifetime. func (p *Provider) Stop(ctx context.Context) error { diff --git a/internal/tools/provider/mcp/provider_test.go b/internal/tools/provider/mcp/provider_test.go index 31bc7cc4c..74c8dbcbd 100644 --- a/internal/tools/provider/mcp/provider_test.go +++ b/internal/tools/provider/mcp/provider_test.go @@ -9,7 +9,6 @@ import ( "sync" "testing" - "github.com/samcharles93/archie-core/internal/plugin" "github.com/samcharles93/archie-core/internal/tools" protocol "github.com/samcharles93/archie-core/internal/tools/mcp" toolprovider "github.com/samcharles93/archie-core/internal/tools/provider" @@ -242,31 +241,6 @@ func TestProviderRejectsInvalidConfiguration(t *testing.T) { if err := provider.Start(context.Background()); err == nil { t.Fatal("Start() succeeded") } - if provider.Health(context.Background()).Status != plugin.HealthUnhealthy { - t.Fatal("invalid provider health is not unhealthy") - } - }) - } -} - -func TestProviderHealthMapsTransportState(t *testing.T) { - tests := []struct { - state protocol.TransportState - want plugin.HealthStatus - }{ - {state: protocol.StateRunning, want: plugin.HealthHealthy}, - {state: protocol.StateStarting, want: plugin.HealthDegraded}, - {state: protocol.StateStopping, want: plugin.HealthDegraded}, - {state: protocol.StateStopped, want: plugin.HealthUnhealthy}, - {state: protocol.StateError, want: plugin.HealthUnhealthy}, - } - for _, tt := range tests { - t.Run(tt.state.String(), func(t *testing.T) { - transport := newFakeTransport() - transport.state = tt.state - if got := New("health", transport).Health(context.Background()).Status; got != tt.want { - t.Fatalf("Health().Status = %q, want %q", got, tt.want) - } }) } } diff --git a/internal/tools/provider/optional_test.go b/internal/tools/provider/optional_test.go index 51c670bef..37f19775c 100644 --- a/internal/tools/provider/optional_test.go +++ b/internal/tools/provider/optional_test.go @@ -85,16 +85,6 @@ func TestOptionalProviderFailureDoesNotStopTheFamily(t *testing.T) { t.Error("tool \"desktop\" is registered despite its provider failing") } - // Degraded, not healthy: a silent failure is how this went - // unnoticed until the daemon crash-looped. - health := registry.Health(context.Background()) - if health.Status != plugin.HealthDegraded { - t.Errorf("Health = %q, want %q", health.Status, plugin.HealthDegraded) - } - if !strings.Contains(health.Message, "mcp.desktop-commander") { - t.Errorf("Health message %q does not name the failed provider", health.Message) - } - skipped := registry.Skipped() if len(skipped) != 1 { t.Fatalf("Skipped() = %v, want exactly the failed provider", skipped) @@ -225,9 +215,6 @@ func TestEveryOptionalProviderFailing(t *testing.T) { if err := registry.Start(context.Background()); err != nil { t.Fatalf("Start: %v", err) } - if got := registry.Health(context.Background()).Status; got != plugin.HealthDegraded { - t.Errorf("Health = %q, want %q", got, plugin.HealthDegraded) - } if len(registry.Skipped()) != 2 { t.Errorf("Skipped() = %v, want both providers", registry.Skipped()) } @@ -296,13 +283,6 @@ func TestCarinaScenarioThroughCapabilityHost(t *testing.T) { t.Errorf("tool %q was lost to a third-party npm package", name) } } - health := registry.Health(context.Background()) - if health.Status != plugin.HealthDegraded { - t.Errorf("health = %q (%s), want degraded", health.Status, health.Message) - } - if !strings.Contains(health.Message, "unzip") { - t.Errorf("health message %q does not carry the cause", health.Message) - } if err := host.Stop(context.Background()); err != nil { t.Errorf("Stop: %v", err) } diff --git a/internal/tools/provider/provider.go b/internal/tools/provider/provider.go index 7d3f9bd09..127123b06 100644 --- a/internal/tools/provider/provider.go +++ b/internal/tools/provider/provider.go @@ -7,7 +7,6 @@ import ( "fmt" "reflect" "slices" - "strings" "sync" "time" @@ -254,59 +253,6 @@ func (r *Registry) failFamily(ctx context.Context, started []runningProvider, ca return errors.Join(cause, rollbackErr) } -// Health reports aggregate provider health. -func (r *Registry) Health(ctx context.Context) plugin.Health { - r.mu.RLock() - state := r.state - running := append([]runningProvider(nil), r.running...) - skipped := append([]SkippedProvider(nil), r.skipped...) - r.mu.RUnlock() - - switch state { - case stateFailed: - return plugin.Health{Status: plugin.HealthUnhealthy, Message: "tool-provider registry failed"} - case stateRunning: - default: - return plugin.Health{Status: plugin.HealthUnknown, Message: "tool-provider registry is not running"} - } - - aggregate := plugin.Health{Status: plugin.HealthHealthy} - var messages []string - - // An excluded optional provider is a degradation, not a clean start. - // Reporting healthy here is what let one broken npm package go unnoticed - // until the daemon crash-looped. - for _, s := range skipped { - aggregate.Status = plugin.HealthDegraded - message := s.ID + ": unavailable" - if s.Err != nil { - message = s.ID + ": " + s.Err.Error() - } - messages = append(messages, message) - } - - for _, provider := range running { - health := safeHealth(ctx, provider.registration.engine) - switch health.Status { - case plugin.HealthHealthy: - case plugin.HealthDegraded: - if aggregate.Status == plugin.HealthHealthy { - aggregate.Status = plugin.HealthDegraded - } - case plugin.HealthUnhealthy: - aggregate.Status = plugin.HealthUnhealthy - default: - aggregate.Status = plugin.HealthUnhealthy - health.Message = fmt.Sprintf("invalid health status %q", health.Status) - } - if health.Message != "" { - messages = append(messages, provider.registration.manifest.ID+": "+health.Message) - } - } - aggregate.Message = strings.Join(messages, "; ") - return aggregate -} - // Stop removes all provider-owned tools before stopping providers in reverse // startup order. It continues after provider failures and joins their errors. func (r *Registry) Stop(ctx context.Context) error { @@ -580,18 +526,6 @@ func safeDiscover(ctx context.Context, engine Engine) (entries []tools.ToolEntry return engine.Discover(ctx) } -func safeHealth(ctx context.Context, engine Engine) (health plugin.Health) { - defer func() { - if recovered := recover(); recovered != nil { - health = plugin.Health{ - Status: plugin.HealthUnhealthy, - Message: fmt.Sprintf("health panic: %v", recovered), - } - } - }() - return engine.Health(ctx) -} - func safeStop(ctx context.Context, engine Engine) (err error) { defer func() { if recovered := recover(); recovered != nil { diff --git a/internal/tools/provider/provider_test.go b/internal/tools/provider/provider_test.go index 17b36d093..974145f9f 100644 --- a/internal/tools/provider/provider_test.go +++ b/internal/tools/provider/provider_test.go @@ -354,38 +354,6 @@ func TestRegistryStartupRollbackUsesBoundedDetachedContext(t *testing.T) { } } -func TestRegistryHealthAggregatesProviderHealthAndPanics(t *testing.T) { - tests := []struct { - name string - health plugin.Health - panic any - want plugin.HealthStatus - }{ - {name: "healthy", health: plugin.Health{Status: plugin.HealthHealthy}, want: plugin.HealthHealthy}, - {name: "degraded", health: plugin.Health{Status: plugin.HealthDegraded}, want: plugin.HealthDegraded}, - {name: "unhealthy", health: plugin.Health{Status: plugin.HealthUnhealthy}, want: plugin.HealthUnhealthy}, - {name: "panic", panic: "health panic", want: plugin.HealthUnhealthy}, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - registry := NewRegistry(tools.NewRegistry()) - engine := newFakeEngine("health") - engine.health = tt.health - engine.healthPanic = tt.panic - if err := registry.Register(engine); err != nil { - t.Fatal(err) - } - if err := registry.Start(context.Background()); err != nil { - t.Fatal(err) - } - if got := registry.Health(context.Background()).Status; got != tt.want { - t.Fatalf("Health().Status = %q, want %q", got, tt.want) - } - }) - } -} - type fakeEngine struct { manifest plugin.Manifest tools []tools.ToolEntry @@ -396,8 +364,6 @@ type fakeEngine struct { startPanic any discoverPanic any stopPanic any - healthPanic any - health plugin.Health startCount int discoverCount int stopCount int @@ -409,7 +375,6 @@ type fakeEngine struct { func newFakeEngine(id string) *fakeEngine { return &fakeEngine{ manifest: testManifest(id, []plugin.CapabilityKind{"tools"}, nil), - health: plugin.Health{Status: plugin.HealthHealthy}, } } @@ -456,13 +421,6 @@ func (e *fakeEngine) Discover(context.Context) ([]tools.ToolEntry, error) { return e.tools, e.discoverErr } -func (e *fakeEngine) Health(context.Context) plugin.Health { - if e.healthPanic != nil { - panic(e.healthPanic) - } - return e.health -} - func (e *fakeEngine) Stop(ctx context.Context) error { e.stopCount++ e.log("stop")