From b216e38304eba2b6b57e5fbe4345a1ee73ea25bd Mon Sep 17 00:00:00 2001 From: rcourtman Date: Sun, 7 Jun 2026 12:19:02 +0100 Subject: [PATCH] Surface service + storage facts in the AI context pack MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit filterImportantFacts kept only hardware/dependency/security/version facts, dropping 'service' and 'storage'. But a service fact (e.g. the systemd unit) is exactly how the Assistant restarts/reloads a workload, and a storage fact (the backing dataset/disk) is where its data lives — neither is redundant with the CLI/path sections, and both are what a real question like 'the database is slow, restart it' needs. Add both to the priority categories. Corpus: add a postgresql LXC cell whose required context includes the systemd unit and data filesystem. Teeth-checked — the case fails without the filter change. Build + vet + gofmt clean, full servicediscovery package green. --- internal/servicediscovery/formatters.go | 8 ++++- .../servicediscovery/scenario_corpus_test.go | 34 +++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/internal/servicediscovery/formatters.go b/internal/servicediscovery/formatters.go index 484618763..9eb5f80f2 100644 --- a/internal/servicediscovery/formatters.go +++ b/internal/servicediscovery/formatters.go @@ -122,12 +122,18 @@ func formatSingleDiscovery(d *ResourceDiscovery) string { func filterImportantFacts(facts []DiscoveryFact) []DiscoveryFact { var important []DiscoveryFact - // Priority categories + // Priority categories — facts the assistant needs to understand and act on + // the workload. Service + storage were previously dropped, yet a service + // fact (e.g. the systemd unit) is exactly how you restart/reload a workload, + // and a storage fact (e.g. the backing dataset/disk) is where its data + // physically lives — neither is redundant with the path/CLI sections. priorityCategories := map[FactCategory]bool{ FactCategoryHardware: true, // GPU, TPU FactCategoryDependency: true, // MQTT, database connections FactCategorySecurity: true, // Auth info FactCategoryVersion: true, // Version info + FactCategoryService: true, // how the service is managed (systemd unit, init) + FactCategoryStorage: true, // where data physically lives (pool/dataset/disk) } for _, f := range facts { diff --git a/internal/servicediscovery/scenario_corpus_test.go b/internal/servicediscovery/scenario_corpus_test.go index 260377de3..61a461293 100644 --- a/internal/servicediscovery/scenario_corpus_test.go +++ b/internal/servicediscovery/scenario_corpus_test.go @@ -84,6 +84,40 @@ func contextScenarioCorpus() []contextScenario { "/opt/homeassistant/config -> /config", }, }, + { + name: "postgresql LXC", + userQuestion: "the database is slow and I may need to restart it", + discovery: &ResourceDiscovery{ + ID: MakeResourceID(ResourceTypeSystemContainer, "minipc", "112"), + ResourceType: ResourceTypeSystemContainer, + ResourceID: "112", + TargetID: "minipc", + Hostname: "pg-primary", + ServiceType: "postgresql", + ServiceName: "PostgreSQL", + ServiceVersion: "16.3", + Category: CategoryDatabase, + CLIAccess: "pct exec 112 -- bash", + ConfigPaths: []string{"/etc/postgresql/16/main/postgresql.conf"}, + DataPaths: []string{"/var/lib/postgresql/16/main"}, + LogPaths: []string{"/var/log/postgresql/postgresql-16-main.log"}, + Ports: []PortInfo{{Port: 5432, Protocol: "tcp", Process: "postgres"}}, + Facts: []DiscoveryFact{ + {Category: FactCategoryService, Key: "systemd_unit", Value: "postgresql@16-main.service", Source: "running_services", Confidence: 0.9}, + {Category: FactCategoryStorage, Key: "data_filesystem", Value: "zfs tank/postgres", Source: "disk_usage", Confidence: 0.85}, + }, + }, + // To triage slowness and restart, the Assistant needs how to reach + // the guest, the config + log, AND how the service is managed (the + // systemd unit) and where its data lives (the dataset) — service and + // storage facts the context pack used to drop. + mustContain: []string{ + "pct exec 112", + "postgresql.conf", + "postgresql@16-main.service", + "tank/postgres", + }, + }, } }