From 8ef851117336b2da6219c5c03dc990b1b2c12eb6 Mon Sep 17 00:00:00 2001 From: Ukaykhingmarma28 Date: Mon, 23 Nov 2026 02:36:39 +0600 Subject: [PATCH 1/2] Finish init when the memory model cannot be downloaded On a fresh install the guided init offers the memory search model with Download preselected. When the download failed (offline, a proxy, Hugging Face out of reach) init returned the error before it hooked any agent or set background sync: the folder was bound, nothing was captured, and a second init asked "Bind it again?" with No as the default. The model is an improvement, not a requirement. indexMemory now keeps going on keywords when the download fails and says why in its result, so atlas-cli memory index exits 0 offline with the index built; a cancelled download still stops. Init treats a failed memory search step as a note and goes on to the agents and sync. It also starts the background index when the model is absent (Not now, or a failed download), so the keyword index of the project's documents exists from the start instead of after the first session. The hook's "atlas-cli is not installed" message pointed at tryatlas/atlas-cli; it now names tryatlas/cli. Hooks installed before this report "outdated" until atlas-cli agents add rewrites them. Co-Authored-By: Claude Fable 5.2 --- cmd/atlas-cli/index_cmds.go | 13 ++++++++-- cmd/atlas-cli/index_cmds_test.go | 43 ++++++++++++++++++++++++++++++++ cmd/atlas-cli/init_wizard.go | 12 ++++++--- internal/hooks/wrapper.go | 2 +- 4 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 cmd/atlas-cli/index_cmds_test.go diff --git a/cmd/atlas-cli/index_cmds.go b/cmd/atlas-cli/index_cmds.go index 7907f19..282adbe 100644 --- a/cmd/atlas-cli/index_cmds.go +++ b/cmd/atlas-cli/index_cmds.go @@ -91,6 +91,7 @@ func indexMemory(ctx context.Context, root, scope string, download bool, step tu _ = os.Remove(clistate.Path(root, indexPendingFile)) // this pass covers what asked for it plan := embed.Current() + var downloadErr error if plan.Backend == embed.CPU && download && embed.LoadError() != nil { // Damaged files are kept by a download (it fetches what is missing): // they go first. The app's copy is the same files, as damaged. @@ -106,7 +107,13 @@ func indexMemory(ctx context.Context, root, scope string, download bool, step tu frac(0.8 * float64(done) / float64(total)) } }); err != nil { - return "", fmt.Errorf("download the model: %w", err) + if ctx.Err() != nil { + return "", fmt.Errorf("download the model: %w", ctx.Err()) + } + // The model is an improvement, not a requirement: without it + // the index is still built, on keywords. + downloadErr = err + step("The model could not be downloaded; indexing on keywords") } } vectors := record.Vectors() @@ -148,7 +155,9 @@ func indexMemory(ctx context.Context, root, scope string, download bool, step tu case embed.Off: msg += " Keyword search only (" + plan.Note + ")." case embed.CPU: - if err := embed.LoadError(); err != nil { + if downloadErr != nil { + msg += fmt.Sprintf(" The model could not be downloaded (%v): keyword search only for now (atlas-cli memory index tries again).", downloadErr) + } else if err := embed.LoadError(); err != nil { msg += fmt.Sprintf(" The model files do not load (%v): keyword search only (atlas-cli memory index downloads them again).", err) } else { msg += " No model on this machine: keyword search only (atlas-cli memory index downloads it)." diff --git a/cmd/atlas-cli/index_cmds_test.go b/cmd/atlas-cli/index_cmds_test.go new file mode 100644 index 0000000..b0c0d1c --- /dev/null +++ b/cmd/atlas-cli/index_cmds_test.go @@ -0,0 +1,43 @@ +package main + +import ( + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/tryatlas/cli/internal/embed" +) + +// A model that cannot be downloaded (offline, a proxy, Hugging Face out of +// reach) leaves keyword search: the index is still built and the command +// succeeds, saying why. +func TestIndexFallsBackToKeywordsWhenTheDownloadFails(t *testing.T) { + gitRepo(t) + if code, _, e := runCmd(t, "init", "--local"); code != 0 { + t.Fatal(e) + } + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + http.Error(w, "no route to the model", http.StatusBadGateway) + })) + defer srv.Close() + base := embed.BaseURL + embed.BaseURL = srv.URL + "/" + t.Setenv("ATLAS_MODELS_DIR", t.TempDir()) + t.Setenv("ATLAS_EMBED", "cpu") + embed.Reset() + t.Cleanup(func() { embed.BaseURL = base; embed.Reset() }) + + code, out, e := runCmd(t, "memory", "index") + if code != 0 { + t.Fatalf("exit %d: %s", code, e) + } + for _, want := range []string{"Memory index ready", "could not be downloaded", "502", "keyword search only"} { + if !strings.Contains(out, want) { + t.Errorf("output lacks %q: %s", want, out) + } + } + if embed.Available() { + t.Error("a failed download left a model") + } +} diff --git a/cmd/atlas-cli/init_wizard.go b/cmd/atlas-cli/init_wizard.go index 8b9e012..514f759 100644 --- a/cmd/atlas-cli/init_wizard.go +++ b/cmd/atlas-cli/init_wizard.go @@ -86,10 +86,16 @@ func finishInit(cmd *cobra.Command, root string, local, guided bool, steps initS if err := tui.WorkProgress(out, "Setting up memory search", func(step tui.StepFunc, frac tui.FracFunc) (string, error) { return indexMemory(cmd.Context(), root, scope, true, step, frac) }); err != nil { - return err + if cmd.Context().Err() != nil { + return err + } + // Memory search is the last, optional step: a failed index + // (the bar has shown why) must not leave the agents unhooked. + tui.Note(out, "Memory search uses keywords for now; atlas-cli memory index sets it up later.") + spawnIndex(root) } - } else if embed.Available() { - spawnIndex(root) // the index, in the background + } else { + spawnIndex(root) // the index, in the background (keywords without the model) } if len(agents) > 0 || ask { fmt.Fprintln(out) diff --git a/internal/hooks/wrapper.go b/internal/hooks/wrapper.go index 2443ae7..3aadeee 100644 --- a/internal/hooks/wrapper.go +++ b/internal/hooks/wrapper.go @@ -40,7 +40,7 @@ func shellQuote(s string) string { // MissingMessage is the message a Claude-shaped agent shows when the hook // is installed but atlas-cli is not. -const MissingMessage = `{"systemMessage":"Atlas is enabled here but atlas-cli is not installed or not on PATH. Install: https://github.com/tryatlas/atlas-cli#install"}` +const MissingMessage = `{"systemMessage":"Atlas is enabled here but atlas-cli is not installed or not on PATH. Install: https://github.com/tryatlas/cli#install"}` // Owned reports that a hook command is Atlas's: the bare command, or the // bare command inside a Wrap. From 135a5e34c40590ddec1e41e422640a656dfa84de Mon Sep 17 00:00:00 2001 From: Ukaykhingmarma28 Date: Mon, 23 Nov 2026 02:36:39 +0600 Subject: [PATCH 2/2] Do not take /dev/null for a terminal Interactive() called any character device a terminal, and /dev/null is one. With it as both stdin and stdout (cron, CI, a service) a command with a progress bar started bubbletea and failed: "could not create cancelable reader: add reader to epoll interest list". atlas-cli memory index was the visible case. isTerminal now asks the device (charmbracelet/x/term, already a dependency), so /dev/null and pipes take the plain path. Co-Authored-By: Claude Fable 5.2 --- internal/tui/select.go | 6 ++++-- internal/tui/terminal_test.go | 28 ++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 internal/tui/terminal_test.go diff --git a/internal/tui/select.go b/internal/tui/select.go index 7f3c46b..6aef20b 100644 --- a/internal/tui/select.go +++ b/internal/tui/select.go @@ -8,6 +8,7 @@ import ( "strings" tea "charm.land/bubbletea/v2" + "github.com/charmbracelet/x/term" ) // ErrCancelled is returned when the user leaves a prompt without choosing. @@ -19,9 +20,10 @@ func Interactive() bool { return isTerminal(os.Stdin) && isTerminal(os.Stdout) } +// isTerminal asks the device itself: /dev/null is a character device too, +// and under cron, CI or a service it is both stdin and stdout. func isTerminal(f *os.File) bool { - info, err := f.Stat() - return err == nil && info.Mode()&os.ModeCharDevice != 0 + return term.IsTerminal(f.Fd()) } var ( diff --git a/internal/tui/terminal_test.go b/internal/tui/terminal_test.go new file mode 100644 index 0000000..8e48678 --- /dev/null +++ b/internal/tui/terminal_test.go @@ -0,0 +1,28 @@ +package tui + +import ( + "os" + "testing" +) + +// /dev/null is a character device but no terminal: with it as stdin and +// stdout (cron, CI, a service) a command must not start a prompt or a bar. +func TestDevNullIsNotATerminal(t *testing.T) { + f, err := os.OpenFile(os.DevNull, os.O_RDWR, 0) + if err != nil { + t.Skip(err) + } + defer f.Close() + if isTerminal(f) { + t.Fatal(os.DevNull + " was taken for a terminal") + } + r, w, err := os.Pipe() + if err != nil { + t.Fatal(err) + } + defer r.Close() + defer w.Close() + if isTerminal(r) || isTerminal(w) { + t.Fatal("a pipe was taken for a terminal") + } +}