diff --git a/.beads/interactions.jsonl b/.beads/interactions.jsonl index 9087f0bc9..177b87103 100644 --- a/.beads/interactions.jsonl +++ b/.beads/interactions.jsonl @@ -155,3 +155,4 @@ {"id":"int-21fc57e924a09c3e2cc06dad0b9fc341","kind":"field_change","created_at":"2026-07-27T03:02:11.029169675Z","actor":"Sam Catlow","issue_id":"archie-core-rqp","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Shipped: deployment-neutral /update with configured argv check/install adapters, gateway/runtime release sections, per-user exact-version persisted deferrals, recipient-bound expiring single-use callback actions, global install serialization, callback authorization, and truthful progress/failure. Webhook callback queries enabled. task check and scoped lint clean; adversarial review findings remediated."}} {"id":"int-0515875f328056cbb0888785d35497c9","kind":"field_change","created_at":"2026-07-27T12:11:14.316202683Z","actor":"Sam Catlow","issue_id":"archie-core-5dn","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Investigated local Hermes CLI and current Archie implementation; added the requested parity TODO checklist."}} {"id":"int-e2b07b5c81dd19cabd9e2a18ff94f7f7","kind":"field_change","created_at":"2026-07-27T12:20:51.572157777Z","actor":"Sam Catlow","issue_id":"archie-core-sc5","extra":{"field":"status","new_value":"closed","old_value":"open","reason":"Implemented gateway.BuildSystemPrompt rendering internal/gateway/templates/archie.md.tpl: instruction precedence, core rules, communication rules, and blocks, with PersonaRegistry kept as the style layer on top. Tool inventory is derived from the same core.ToolSet passed to the model (cmd/archied/toolSummaries) so prompt and reality cannot drift; empty toolset renders an explicit 'no tools are available'. Tool metadata is markup-escaped and whitespace-flattened against forged tags and forged list entries. task check clean: vet, full go test ./... , golangci-lint 0 issues on changed packages, gofumpt clean. Commit 7fde716. NOT yet deployed - not pushed."}} +{"id":"int-c52b1ab5add5f30c8a63b5f03e5faff7","kind":"field_change","created_at":"2026-07-27T13:47:42.515040687Z","actor":"Sam Catlow","issue_id":"archie-core-4we","extra":{"field":"status","new_value":"closed","old_value":"in_progress","reason":"Ported tau internal/indexing/codesearch.go @ 4893818d0c76 into archie-core internal/indexing. Mutations: global config path helpers replaced by explicit indexing.Config + DefaultConfig(workDir) (two archied instances share carina and must not share an index); child-process helper is archied's own 'workspace-codesearch' subcommand in cmd/archied/codesearch.go, dispatched from main() before flag parsing so it touches no config/store/NATS; deferred db.Close explicitly discarded for errcheck. Added dep github.com/google/codesearch v1.3.0-rc.1 (uuid and modernc sqlite already present). Verified E2E against the real repo: 2.2MB indexed in 0.05s, correct hits, [] for no match, corrupt index -> clean error exit 1 rather than process death. task check clean; golangci-lint 0 issues on both packages. Commit c924281. NOT pushed. Follow-up: nothing calls indexing.NewManager yet -- it is ported and proven but not wired into the agent's grep path."}} diff --git a/.beads/issues.jsonl b/.beads/issues.jsonl index 1ab7d80eb..0391c2ffd 100644 --- a/.beads/issues.jsonl +++ b/.beads/issues.jsonl @@ -53,7 +53,7 @@ {"_type":"issue","id":"archie-core-abg.18","title":"[EPIC] Memory: pluggable provider architecture with file-backed persistence","description":"Pluggable memory system to match Hermes parity:\\n\\n1. **MemoryProvider interface**: Abstract interface with methods for initialize(), get_tool_schemas(), prefetch(), sync_turn(), and optional lifecycle hooks (on_session_end, on_session_switch, on_pre_compress, on_memory_write).\\n\\n2. **Built-in file-backed memory**: MEMORY.md and USER.md stored per-session/profile. LLM-callable memory tool with add/replace/remove actions. Frozen snapshot at session start (preserves prefix cache), immediate disk write on updates. Section-sign delimited entries with substring matching.\\n\\n3. **MemoryManager**: Orchestrates built-in + at most one external provider. Background serialized write executor. Prefetch with timeout (8s). Streaming context scrubber that strips injected memory spans from model output.\\n\\nRef: docs/prds/hermes-gap-analysis.md section 4","acceptance_criteria":"An external memory provider (e.g. Honcho, Mem0) can be plugged in via config. The built-in memory tool persists across sessions. Conversation context is recalled on session resume.","status":"open","priority":0,"issue_type":"epic","owner":"sam@catlow.tech","created_at":"2026-07-25T14:02:22Z","created_by":"Sam Catlow","updated_at":"2026-07-25T14:02:22Z","dependencies":[{"issue_id":"archie-core-abg.18","depends_on_id":"archie-core-abg","type":"parent-child","created_at":"2026-07-26T00:02:22Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-abg.16","title":"[EPIC] Gateway: rich message model, adapter lifecycle, session management","description":"Foundational gateway infrastructure to match Hermes parity. Three interdependent pieces:\\n\\n1. **Message model**: Replace the 3-field Message struct with a rich MessageEvent (MessageType enum: text/photo/video/audio/voice/document/sticker/command, media_urls, reply_to context, metadata dict, source). This is the wire type every adapter produces.\\n\\n2. **Adapter lifecycle**: Replace the 3-method Gateway interface with a BasePlatformAdapter interface: connect()/disconnect()/send() as required methods, plus optional overrides for typing indicators, edit/delete, image/voice/video/document send, interactive UX (clarify buttons, approval dialogs). Capability flags (supports_code_blocks, splits_long_messages, supports_async_delivery).\\n\\n3. **Session management**: SessionSource struct (platform, chat_id, chat_type, user_id, thread_id, guild_id, profile), AsyncSessionStore for persistent session storage, SessionContext for system prompt injection.\\n\\nAll three blocks together enable adding new platforms as plugins without touching core gateway code.\\n\\nRef: docs/prds/hermes-gap-analysis.md sections 1-2","acceptance_criteria":"New adapters can be added by implementing a Go interface with connect/disconnect/send + optional media methods. Messages carry full metadata through the pipeline. Sessions persist across gateway restarts.","status":"open","priority":0,"issue_type":"epic","owner":"sam@catlow.tech","created_at":"2026-07-25T14:02:21Z","created_by":"Sam Catlow","updated_at":"2026-07-25T14:02:21Z","dependencies":[{"issue_id":"archie-core-abg.16","depends_on_id":"archie-core-abg","type":"parent-child","created_at":"2026-07-26T00:02:21Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-jfg","title":"Spawned archie-agent containers not on daemon's docker network — can't reach NATS","description":"Root cause of 'agent still failing on the server': archied's container.Pool.Acquire creates archie-agent containers via the Docker SDK with no NetworkMode set, so Docker attaches them to the default bridge network. archied and nats run on the compose-created 'archie-core_default' network instead, so the spawned container's hostname resolution for 'nats' (from NATS_URL=nats://nats:4222) fails and archie-agent can't connect. Confirmed on carina host logs: archied logs show repeating 'taskrun request failed err=\"nats: no responders available for request\"' for every task, containers created and destroyed within ~1.5s (consistent with archie-agent's NATS client failing fast). Fixed by detecting the daemon's own container's network in NewPool (selfNetwork, via ContainerInspect on os.Hostname()) and setting HostConfig.NetworkMode on spawned containers to match.","status":"closed","priority":0,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-07-24T03:10:26Z","created_by":"Sam Catlow","updated_at":"2026-07-25T13:04:34Z","closed_at":"2026-07-25T13:04:34Z","close_reason":"Fix already implemented and verified: selfNetwork() in internal/container/pool.go detects the daemon's own container network via ContainerInspect(os.Hostname()) and Acquire() sets HostConfig.NetworkMode to match, so spawned archie-agent containers join the same compose network as nats. Build and internal/container tests pass.","dependency_count":0,"dependent_count":0,"comment_count":0} -{"_type":"issue","id":"archie-core-4we","title":"Port tau internal/indexing (codesearch) into archie-core","description":"First slice of the tau cherry-pick strategy. Copy-and-mutate (NOT extract to pkg/ - Sam's decision: exporting would force designing metrics/session/logger seams upfront before archie-core knows which it wants differently).\n\ntau/internal/indexing is the cheapest high-value lift: 512 LoC, one file, and its only tau coupling is 3 calls to config.WorkspaceIndexDir()/WorkspaceIndexDBPath(). Nothing else in tau imports it.\n\nMutations: replace the global config path helpers with explicit constructor params (archie-core passes config, no globals); add the workspace-codesearch helper subcommand to archied since the manager deliberately runs google/codesearch in a child process (upstream fatal exits + mmap leaks must not kill the daemon).\n\nEach lifted file carries a provenance header (source path + tau commit) so a future refresh is a diff, not archaeology.","status":"open","priority":1,"issue_type":"feature","owner":"sam@catlow.tech","created_at":"2026-07-27T13:41:58Z","created_by":"Sam Catlow","updated_at":"2026-07-27T13:41:58Z","dependency_count":0,"dependent_count":0,"comment_count":0} +{"_type":"issue","id":"archie-core-4we","title":"Port tau internal/indexing (codesearch) into archie-core","description":"First slice of the tau cherry-pick strategy. Copy-and-mutate (NOT extract to pkg/ - Sam's decision: exporting would force designing metrics/session/logger seams upfront before archie-core knows which it wants differently).\n\ntau/internal/indexing is the cheapest high-value lift: 512 LoC, one file, and its only tau coupling is 3 calls to config.WorkspaceIndexDir()/WorkspaceIndexDBPath(). Nothing else in tau imports it.\n\nMutations: replace the global config path helpers with explicit constructor params (archie-core passes config, no globals); add the workspace-codesearch helper subcommand to archied since the manager deliberately runs google/codesearch in a child process (upstream fatal exits + mmap leaks must not kill the daemon).\n\nEach lifted file carries a provenance header (source path + tau commit) so a future refresh is a diff, not archaeology.","status":"closed","priority":1,"issue_type":"feature","assignee":"Sam Catlow","owner":"sam@catlow.tech","created_at":"2026-07-27T13:41:58Z","created_by":"Sam Catlow","updated_at":"2026-07-27T13:47:42Z","started_at":"2026-07-27T13:42:57Z","closed_at":"2026-07-27T13:47:42Z","close_reason":"Ported tau internal/indexing/codesearch.go @ 4893818d0c76 into archie-core internal/indexing. Mutations: global config path helpers replaced by explicit indexing.Config + DefaultConfig(workDir) (two archied instances share carina and must not share an index); child-process helper is archied's own 'workspace-codesearch' subcommand in cmd/archied/codesearch.go, dispatched from main() before flag parsing so it touches no config/store/NATS; deferred db.Close explicitly discarded for errcheck. Added dep github.com/google/codesearch v1.3.0-rc.1 (uuid and modernc sqlite already present). Verified E2E against the real repo: 2.2MB indexed in 0.05s, correct hits, [] for no match, corrupt index -\u003e clean error exit 1 rather than process death. task check clean; golangci-lint 0 issues on both packages. Commit c924281. NOT pushed. Follow-up: nothing calls indexing.NewManager yet -- it is ported and proven but not wired into the agent's grep path.","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-sc5","title":"Chat: real system prompt template for Archie (identity, tools, env)","description":"The chat agent's system prompt is the four-sentence static string in gateway.DefaultPersonas(). It carries no tool inventory, no environment/date block, and no instruction precedence, so the model invents its own capabilities -- it told Sam it 'only has the memory editing tool' and then offered to walk him through installing software it cannot install.\n\nTake the shape from tau: /work/apps/tau/internal/agent/templates/agent.md.tpl renders an agent body plus \u003ctools\u003e, \u003cguidelines\u003e, \u003cproject_context\u003e and \u003cenv\u003e blocks, and /work/apps/tau/internal/agent/spec/templates/tau.agent.md supplies identity, instruction precedence, core rules, communication rules and confirmation boundaries.\n\nKeep the existing PersonaRegistry as the style layer; the template is the substrate it renders into.","status":"closed","priority":1,"issue_type":"feature","owner":"sam@catlow.tech","created_at":"2026-07-27T12:14:08Z","created_by":"Sam Catlow","updated_at":"2026-07-27T12:20:52Z","closed_at":"2026-07-27T12:20:52Z","close_reason":"Implemented gateway.BuildSystemPrompt rendering internal/gateway/templates/archie.md.tpl: instruction precedence, core rules, communication rules, \u003ctools\u003e and \u003cenv\u003e blocks, with PersonaRegistry kept as the style layer on top. Tool inventory is derived from the same core.ToolSet passed to the model (cmd/archied/toolSummaries) so prompt and reality cannot drift; empty toolset renders an explicit 'no tools are available'. Tool metadata is markup-escaped and whitespace-flattened against forged tags and forged list entries. task check clean: vet, full go test ./... , golangci-lint 0 issues on changed packages, gofumpt clean. Commit 7fde716. NOT yet deployed - not pushed.","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-qnm","title":"Telegram: remove task approval from the public command surface","description":"Existing /approve [identity=name] \u003ctask-id\u003e was inherited as chat-task lifecycle control, but Sam explicitly states task approvals are not a product requirement. Reserve /approve exclusively for dangerous-command approval. Remove task approval from Telegram command menu/help/router/public UX; retain or remove internal waiting_human task mechanics only after verifying workflow callers. Do not repurpose the command until the dangerous-command approval model (archie-core-alm.6) exists.","acceptance_criteria":"Telegram no longer advertises or accepts task approval via /approve; no documentation/help describes task approvals; task lifecycle code is not broken for existing non-Telegram workflow paths; /approve remains unclaimed or is implemented only for the approved dangerous-command design.","status":"open","priority":1,"issue_type":"bug","owner":"sam@catlow.tech","created_at":"2026-07-27T09:00:56Z","created_by":"Sam Catlow","updated_at":"2026-07-27T09:00:56Z","dependency_count":0,"dependent_count":0,"comment_count":0} {"_type":"issue","id":"archie-core-alm.6","title":"Telegram: controlled execution and checkpoint commands","description":"Design /rollback [number] filesystem checkpoints, /stop background process termination, /approve and /deny for dangerous commands. /approve is RESERVED exclusively for dangerous-command approval; it must not be interpreted as task approval. The pending-command UX is inline selection buttons: Approve this time, Approve Permanently, Deny. Define the exact policy scope/lifetime for permanent approval, callback authorization, expiry, audit persistence, and cancellation. Requires a real sandbox/process/checkpoint authority; do not create commands that claim control over host processes or filesystem state Archie does not own.","acceptance_criteria":"For every pending dangerous command, Telegram renders authorized inline buttons exactly representing Approve this time, Approve Permanently, and Deny. Callbacks are recipient-bound, expiring, single-use, auditable, and cannot authorize a changed command. Permanent approval scope/lifetime is explicit. /approve exclusively controls this policy; /deny controls the same policy. Authority boundaries match actual sandbox/process ownership; tests cover authorization, expiry, replay, denial, and failure.","status":"open","priority":1,"issue_type":"feature","owner":"sam@catlow.tech","created_at":"2026-07-27T08:59:54Z","created_by":"Sam Catlow","updated_at":"2026-07-27T09:01:52Z","dependencies":[{"issue_id":"archie-core-alm.6","depends_on_id":"archie-core-alm","type":"parent-child","created_at":"2026-07-27T18:59:53Z","created_by":"Sam Catlow","metadata":"{}"}],"dependency_count":0,"dependent_count":0,"comment_count":0} diff --git a/config.example.toml b/config.example.toml index cda3cba17..017dd3eed 100644 --- a/config.example.toml +++ b/config.example.toml @@ -73,6 +73,10 @@ command = "archie-agent" # executable path for subprocess mode (not used in n # The worker still runs as the daemon user until the Docker sandbox phase lands. # env = ["GOCACHE"] # extra environment variable names forwarded to the worker +[indexing] # workspace codesearch index; both paths default under work_dir +# index_dir = "/var/lib/archie/indexes" # codesearch sidecar files +# db_path = "/var/lib/archie/workspace-indexes.db" # index lifecycle metadata + [web] # observability dashboard (read-only, no auth -- keep it local/tailnet) listen = "127.0.0.1:8484" # "off" disables diff --git a/internal/config/config.go b/internal/config/config.go index 8c100d877..558edd189 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -333,6 +333,8 @@ type Config struct { // Tools holds MCP server and tool policy configuration (from config.tools.yaml). Tools ToolsConfig `toml:"tools" yaml:"tools"` + // Indexing locates the workspace codesearch index. + Indexing IndexingConfig `toml:"indexing" yaml:"indexing"` // Identities declares multi-identity configurations. When non-empty, // each identity runs its own poll loop with its own forge client, @@ -564,6 +566,7 @@ func finalize(cfg Config) (Config, error) { if cfg.DBPath == "" { cfg.DBPath = filepath.Join(dataHome(), "archie", "archie.db") } + cfg.Indexing = cfg.Indexing.withDefaults(cfg.WorkDir) if cfg.PollInterval == 0 { cfg.PollInterval = Duration(60 * time.Second) } diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 00f0f8d1d..9dd2f451e 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -833,3 +833,52 @@ func LoadBytes(data []byte) (Config, error) { _ = tmp.Close() return Load(tmp.Name()) } + +func TestFinalizeIndexingDefaults(t *testing.T) { + tests := []struct { + name string + extra string + wantIndex string + wantDBIsSet bool + }{ + { + name: "defaults derive from work_dir", + // Both paths must land under the daemon's own work_dir so two + // archied instances on one host cannot share an index. + extra: "\nwork_dir = \"/srv/archie/work\"\n", + wantIndex: filepath.Join("/srv/archie/work", "indexes"), + wantDBIsSet: true, + }, + { + name: "explicit index_dir is preserved", + extra: "\nwork_dir = \"/srv/archie/work\"\n" + + "[indexing]\nindex_dir = \"/mnt/fast/idx\"\n", + wantIndex: "/mnt/fast/idx", + wantDBIsSet: true, + }, + } + + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + path := filepath.Join(t.TempDir(), "config.toml") + // tc.extra precedes the table sections: a top-level key written + // after [[repos]] would be parsed as a member of that table. + contents := "bot_user = \"widget\"\n" + tc.extra + + "[forge]\ntype = \"gitea\"\nhost = \"https://git.example.test\"\ntoken_env = \"T\"\n" + + "[[repos]]\nowner = \"acme\"\nname = \"app\"\n" + if err := os.WriteFile(path, []byte(contents), 0o600); err != nil { + t.Fatal(err) + } + cfg, err := Load(path) + if err != nil { + t.Fatal(err) + } + if cfg.Indexing.IndexDir != tc.wantIndex { + t.Errorf("Indexing.IndexDir = %q, want %q", cfg.Indexing.IndexDir, tc.wantIndex) + } + if tc.wantDBIsSet && cfg.Indexing.DBPath == "" { + t.Error("Indexing.DBPath is empty; want a default derived from work_dir") + } + }) + } +} diff --git a/internal/config/indexer.go b/internal/config/indexer.go new file mode 100644 index 000000000..c57463a10 --- /dev/null +++ b/internal/config/indexer.go @@ -0,0 +1,29 @@ +package config + +import "path/filepath" + +// IndexingConfig locates the workspace codesearch index. +// +// The index is a large, fully rebuildable artifact, so both paths are +// settable to allow putting it on different storage from the task work tree. +type IndexingConfig struct { + // IndexDir holds the codesearch sidecar files. + IndexDir string `toml:"index_dir" yaml:"index_dir" json:"index_dir,omitempty"` + // DBPath is the SQLite database holding index lifecycle metadata. + DBPath string `toml:"db_path" yaml:"db_path" json:"db_path,omitempty"` +} + +// withDefaults fills unset paths from the daemon's work directory. +// +// Deriving from workDir rather than a shared data home is deliberate: two +// archied instances run on one host, each with its own work_dir, so this +// keeps their indexes separate without either having to configure anything. +func (c IndexingConfig) withDefaults(workDir string) IndexingConfig { + if c.IndexDir == "" { + c.IndexDir = filepath.Join(workDir, "indexes") + } + if c.DBPath == "" { + c.DBPath = filepath.Join(workDir, "workspace-indexes.db") + } + return c +} diff --git a/internal/indexing/codesearch.go b/internal/indexing/codesearch.go index b244863e7..1db9c0335 100644 --- a/internal/indexing/codesearch.go +++ b/internal/indexing/codesearch.go @@ -21,6 +21,7 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "os" "os/exec" "path/filepath" @@ -58,6 +59,17 @@ type Manager struct { indexPath string dbPath string runner helperRunner + log *slog.Logger +} + +// logger is nil-safe: a Manager may be constructed as a struct literal +// (the tests do), so defaulting at the point of use rather than in the +// constructor is what actually holds. +func (m *Manager) logger() *slog.Logger { + if m == nil || m.log == nil { + return slog.Default() + } + return m.log } type helperRunner interface { @@ -69,22 +81,20 @@ type processRunner struct{} // Config locates the index storage for a Manager. // -// tau derived these from process-global helpers. archied owns its paths in -// daemon config and passes them down, so they are parameters here: two -// daemons on one host (archie and winter) must not share one index. +// tau derived these from process-global helpers. archied resolves them in +// its own config layer ([indexing] in config.toml, defaulted off work_dir by +// config.finalize) and passes them down. Defaulting deliberately does NOT +// live here: this package stays free of archie-core's config so it remains +// a straight diff against its tau original. type Config struct { // IndexDir holds the mmap-friendly codesearch sidecar files. IndexDir string // DBPath is the SQLite database holding index lifecycle metadata. DBPath string -} - -// DefaultConfig derives index paths from a daemon work directory. -func DefaultConfig(workDir string) Config { - return Config{ - IndexDir: filepath.Join(workDir, "indexes"), - DBPath: filepath.Join(workDir, "workspace-indexes.db"), - } + // Log receives index build failures. Without it a failed build is + // invisible: the manager degrades to unindexed search and the reason + // is only ever written to a database column nobody reads. + Log *slog.Logger } // NewManager prepares lifecycle storage and starts an asynchronous atomic @@ -108,6 +118,7 @@ func NewManager(ctx context.Context, cfg Config, root string) (*Manager, error) indexPath: filepath.Join(cfg.IndexDir, workspaceKey(absRoot)+".csearch"), dbPath: cfg.DBPath, runner: processRunner{}, + log: cfg.Log, } if err := m.ensureSchema(ctx); err != nil { return nil, err @@ -205,7 +216,15 @@ func (m *Manager) refreshAsync(parent context.Context) { buildID := uuid.NewString() previous, _ := m.state(ctx) claimed, err := m.claimBuild(ctx, startedAt, buildID) - if err != nil || !claimed { + if err != nil { + // Degrading to unindexed search is safe but slow, and until + // this is logged the only record of why is a database column + // with no reader. + m.logger().Warn("workspace index build not claimed", "root", m.root, "error", err) + return + } + if !claimed { + // Another process holds the build claim; not an error. return } finalPath := m.indexPath + "." + buildID @@ -213,18 +232,24 @@ func (m *Manager) refreshAsync(parent context.Context) { _ = os.Remove(tmp) if err := m.runner.Build(ctx, m.root, tmp); err != nil { _ = os.Remove(tmp) + m.logger().Warn("workspace index build failed; falling back to unindexed search", + "root", m.root, "error", err) m.finishBuild(parent, buildID, "error", time.Time{}, "", err.Error()) return } if err := os.Rename(tmp, finalPath); err != nil { _ = os.Remove(tmp) + m.logger().Warn("workspace index could not be published", + "root", m.root, "error", err) m.finishBuild(parent, buildID, "error", time.Time{}, "", err.Error()) return } if !m.finishBuild(parent, buildID, "ready", startedAt, finalPath, "") { _ = os.Remove(finalPath) + m.logger().Warn("workspace index build superseded before publication", "root", m.root) return } + m.logger().Info("workspace index ready", "root", m.root, "index", finalPath) if previous.IndexPath != "" && previous.IndexPath != finalPath && (previous.IndexPath == m.indexPath || strings.HasPrefix(previous.IndexPath, m.indexPath+".")) { _ = os.Remove(previous.IndexPath) diff --git a/internal/indexing/codesearch_test.go b/internal/indexing/codesearch_test.go index 8a2d2b7dc..56cec3d28 100644 --- a/internal/indexing/codesearch_test.go +++ b/internal/indexing/codesearch_test.go @@ -248,3 +248,24 @@ func runGit(t *testing.T, dir string, args ...string) { t.Fatalf("git %v: %v: %s", args, err, out) } } + +// A Manager built as a struct literal has no logger. Logging on the build +// path must not panic, since that path runs in a background goroutine where +// a panic takes the whole daemon down. +func TestManagerLoggerIsNilSafe(t *testing.T) { + tests := []struct { + name string + m *Manager + }{ + {name: "zero manager", m: &Manager{}}, + {name: "nil manager", m: nil}, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + if got := tc.m.logger(); got == nil { + t.Fatal("logger() returned nil") + } + tc.m.logger().Warn("must not panic") + }) + } +}