From ecf243fc19b9e514f359d58c4c91d6aa70ed99dd Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Thu, 24 Sep 2026 14:47:21 +1000 Subject: [PATCH] feat(config): add state_dir for the daemon's host state The embedded NATS store and endpoint file, the task-log registry and the readiness disk probe resolve from state_dir (default: the data home's archie directory) instead of the directory of db_path. db_path now only locates the legacy SQLite files for the one-time import and its boot gate. --- internal/app/archied/bootstrap.go | 13 ++++---- internal/app/archied/gateway.go | 2 +- internal/app/archied/nats/endpoint.json | 1 + .../$G/streams/ARCHIE_REACTIONS/meta.inf | 1 + .../$G/streams/ARCHIE_REACTIONS/meta.sum | 1 + .../$G/streams/ARCHIE_REACTIONS/msgs/1.blk | Bin 0 -> 51 bytes .../obs/archie-daemon/meta.inf | 1 + .../obs/archie-daemon/meta.sum | 1 + .../ARCHIE_REACTIONS/obs/archie-daemon/o.dat | Bin 0 -> 8 bytes .../ARCHIE_REACTIONS/obs/s3Z87297/meta.inf | 1 + .../ARCHIE_REACTIONS/obs/s3Z87297/meta.sum | 1 + .../ARCHIE_REACTIONS/obs/s3Z87297/o.dat | Bin 0 -> 8 bytes .../ARCHIE_REACTIONS/obs/sg9Gl4th/meta.inf | 1 + .../ARCHIE_REACTIONS/obs/sg9Gl4th/meta.sum | 1 + .../ARCHIE_REACTIONS/obs/sg9Gl4th/o.dat | Bin 0 -> 8 bytes .../$G/streams/ARCHIE_TASKS/meta.inf | 1 + .../$G/streams/ARCHIE_TASKS/meta.sum | 1 + .../$G/streams/ARCHIE_TASKS/msgs/1.blk | 0 .../ARCHIE_TASKS/obs/archie-daemon/meta.inf | 1 + .../ARCHIE_TASKS/obs/archie-daemon/meta.sum | 1 + .../ARCHIE_TASKS/obs/archie-daemon/o.dat | Bin 0 -> 8 bytes internal/app/archied/nats_endpoint.go | 12 ++++---- internal/app/archied/nats_endpoint_test.go | 11 ++++--- internal/app/archied/readiness.go | 9 +++--- internal/app/archied/readiness_test.go | 10 +++---- internal/app/archied/state_store.go | 4 +-- internal/config/config.go | 9 +++++- .../infrastructure/configuration/defaults.go | 4 +++ .../configuration/denied_keys.go | 1 + .../configuration/loader_test.go | 28 ++++++++++++++++++ internal/webui/api_config.go | 2 ++ internal/webui/config_schema.go | 4 ++- internal/webui/config_schema_test.go | 5 ++-- 33 files changed, 92 insertions(+), 35 deletions(-) create mode 100644 internal/app/archied/nats/endpoint.json create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/meta.inf create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/meta.sum create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/msgs/1.blk create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/meta.inf create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/meta.sum create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/o.dat create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/meta.inf create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/meta.sum create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/o.dat create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/meta.inf create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/meta.sum create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/o.dat create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/meta.inf create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/meta.sum create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/msgs/1.blk create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/meta.inf create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/meta.sum create mode 100644 internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/o.dat diff --git a/internal/app/archied/bootstrap.go b/internal/app/archied/bootstrap.go index 5281d21dd..43df551da 100644 --- a/internal/app/archied/bootstrap.go +++ b/internal/app/archied/bootstrap.go @@ -327,11 +327,10 @@ func (b *boot) setupLogging() error { } logFeed := logging.NewFeed(1000) b.logFeed = logFeed - // Task logs live alongside the store rather than under cfg.Log.File's + // Task logs live in the state directory rather than under cfg.Log.File's // directory: cfg.Log.File is optional (file logging can be off), while - // DBPath is required for the daemon to run at all, so it is the more - // reliable anchor for "where archie keeps its state" on this host. - taskLogs := logging.NewTaskRegistry(filepath.Join(filepath.Dir(cfg.DBPath), "logs", "tasks"), logFeed, logging.TaskSinkOptions{}) + // state_dir always resolves. + taskLogs := logging.NewTaskRegistry(filepath.Join(cfg.StateDir, "logs", "tasks"), logFeed, logging.TaskSinkOptions{}) b.taskLogs = taskLogs fileLog, logCloser, logErr := logging.New(logging.Options{ File: cfg.Log.File, @@ -519,7 +518,7 @@ func (b *boot) connectNATS(ctx context.Context) error { //nolint:nestif // embed return err } } else { - endpoint, readErr := readEmbeddedNATSEndpoint(cfg.DBPath) + endpoint, readErr := readEmbeddedNATSEndpoint(cfg.StateDir) if readErr == nil { url, natsToken = endpoint.URL, endpoint.Token if probe, err := nats.Connect(ctx, nats.Config{URL: url, Token: natsToken, Subjects: []string{workintake.SubjectTaskWildcard}, FilterSubject: workintake.SubjectTaskWildcard}, log); err == nil { @@ -603,7 +602,7 @@ func (b *boot) startEmbeddedNATS(ctx context.Context) (string, string, error) { } srv, err := nats.StartEmbedded(ctx, nats.EmbeddedOptions{ Host: host, - StoreDir: filepath.Join(filepath.Dir(cfg.DBPath), "nats"), + StoreDir: filepath.Join(cfg.StateDir, "nats"), }, log) if err != nil { log.Error("embedded nats start failed", "err", err) @@ -611,7 +610,7 @@ func (b *boot) startEmbeddedNATS(ctx context.Context) (string, string, error) { } b.addCleanup(func() { srv.Shutdown() }) log.Info("embedded nats started", "url", srv.ClientURL()) - if err := writeEmbeddedNATSEndpoint(cfg.DBPath, srv.ClientURL(), srv.Token()); err != nil { + if err := writeEmbeddedNATSEndpoint(cfg.StateDir, srv.ClientURL(), srv.Token()); err != nil { srv.Shutdown() return "", "", err } diff --git a/internal/app/archied/gateway.go b/internal/app/archied/gateway.go index d2898457c..7eb8430fd 100644 --- a/internal/app/archied/gateway.go +++ b/internal/app/archied/gateway.go @@ -82,7 +82,7 @@ func RunGateway(ctx context.Context, options GatewayOptions) error { nc, err = natsio.Connect(url, natsio.Token(token)) } else { var endpoint embeddedNATSEndpoint - endpoint, err = readEmbeddedNATSEndpoint(b.cfg.DBPath) + endpoint, err = readEmbeddedNATSEndpoint(b.cfg.StateDir) if err == nil { url, token = endpoint.URL, endpoint.Token nc, err = natsio.Connect(url, natsio.Token(token)) diff --git a/internal/app/archied/nats/endpoint.json b/internal/app/archied/nats/endpoint.json new file mode 100644 index 000000000..34e1c7fcc --- /dev/null +++ b/internal/app/archied/nats/endpoint.json @@ -0,0 +1 @@ +{"url":"nats://127.0.0.1:42009","token":"PXDPQYX3SBCBW6MNZTUSB5LNDW"} \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/meta.inf b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/meta.inf new file mode 100644 index 000000000..ae11187e3 --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/meta.inf @@ -0,0 +1 @@ +{"Created":"2026-09-24T04:45:55.407149438Z","name":"ARCHIE_REACTIONS","subjects":["archie.reaction.\u003e"],"retention":"limits","max_consumers":-1,"max_msgs":-1,"max_bytes":-1,"max_age":86400000000000,"max_msgs_per_subject":-1,"max_msg_size":-1,"discard":"old","storage":"file","num_replicas":1,"duplicate_window":120000000000,"compression":"none","allow_direct":false,"mirror_direct":false,"sealed":false,"deny_delete":false,"deny_purge":false,"allow_rollup_hdrs":false,"consumer_limits":{},"allow_msg_ttl":false,"metadata":{"_nats.req.level":"0"}} \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/meta.sum b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/meta.sum new file mode 100644 index 000000000..37e92299b --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/meta.sum @@ -0,0 +1 @@ +e5007a6989578acf \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/msgs/1.blk b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/msgs/1.blk new file mode 100644 index 0000000000000000000000000000000000000000..422dca8c217b369b5614f87b7f508ce94a0bd6f5 GIT binary patch literal 51 zcmXqJU|?VbVi3?Tc#`I)aYI6cA+abqBQsU6C^a#;Br`uxuOzj&q+)>;Yx}I9FTwyY CXb>a- literal 0 HcmV?d00001 diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/meta.inf b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/meta.inf new file mode 100644 index 000000000..ddd6e649a --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/meta.inf @@ -0,0 +1 @@ +{"Created":"2026-09-24T04:46:09.06756232Z","Name":"archie-daemon","durable_name":"archie-daemon","name":"archie-daemon","deliver_policy":"all","ack_policy":"explicit","ack_wait":300000000000,"max_deliver":3,"filter_subject":"archie.reaction.\u003e","replay_policy":"instant","max_waiting":512,"max_ack_pending":1000,"inactive_threshold":86400000000000,"num_replicas":0,"metadata":{"_nats.req.level":"0"}} \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/meta.sum b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/meta.sum new file mode 100644 index 000000000..7e55c58e9 --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/meta.sum @@ -0,0 +1 @@ +d87c12a35c167265 \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/o.dat b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/archie-daemon/o.dat new file mode 100644 index 0000000000000000000000000000000000000000..055d9019abf53b44fa75492a1b85dcf8996a1f3a GIT binary patch literal 8 LcmWe*VgLgG0LB0r literal 0 HcmV?d00001 diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/meta.inf b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/meta.inf new file mode 100644 index 000000000..3af67b620 --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/meta.inf @@ -0,0 +1 @@ +{"Created":"2026-09-24T04:46:09.078999729Z","Name":"s3Z87297","name":"s3Z87297","deliver_policy":"all","ack_policy":"explicit","ack_wait":30000000000,"max_deliver":-1,"filter_subject":"archie.reaction.\u003e","replay_policy":"instant","max_waiting":512,"max_ack_pending":1000,"num_replicas":0,"metadata":{"_nats.req.level":"0"}} \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/meta.sum b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/meta.sum new file mode 100644 index 000000000..f8024e5e9 --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/meta.sum @@ -0,0 +1 @@ +8f8b6852faee5da4 \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/o.dat b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/s3Z87297/o.dat new file mode 100644 index 0000000000000000000000000000000000000000..f291c5c9aee705825aeb37a04f10452de37894c4 GIT binary patch literal 8 NcmWe*Vgv#P1^@uq0384T literal 0 HcmV?d00001 diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/meta.inf b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/meta.inf new file mode 100644 index 000000000..338606278 --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/meta.inf @@ -0,0 +1 @@ +{"Created":"2026-09-24T04:46:09.079549283Z","Name":"sg9Gl4th","name":"sg9Gl4th","deliver_policy":"all","ack_policy":"explicit","ack_wait":30000000000,"max_deliver":-1,"filter_subject":"archie.reaction.\u003e","replay_policy":"instant","max_waiting":512,"max_ack_pending":1000,"num_replicas":0,"metadata":{"_nats.req.level":"0"}} \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/meta.sum b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/meta.sum new file mode 100644 index 000000000..ffa829155 --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/meta.sum @@ -0,0 +1 @@ +3c91a932fe817389 \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/o.dat b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_REACTIONS/obs/sg9Gl4th/o.dat new file mode 100644 index 0000000000000000000000000000000000000000..f291c5c9aee705825aeb37a04f10452de37894c4 GIT binary patch literal 8 NcmWe*Vgv#P1^@uq0384T literal 0 HcmV?d00001 diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/meta.inf b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/meta.inf new file mode 100644 index 000000000..3f73e54d5 --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/meta.inf @@ -0,0 +1 @@ +{"Created":"2026-09-24T04:45:55.396149543Z","name":"ARCHIE_TASKS","subjects":["archie.task.\u003e"],"retention":"workqueue","max_consumers":-1,"max_msgs":-1,"max_bytes":-1,"max_age":0,"max_msgs_per_subject":-1,"max_msg_size":-1,"discard":"old","storage":"file","num_replicas":1,"duplicate_window":120000000000,"compression":"none","allow_direct":false,"mirror_direct":false,"sealed":false,"deny_delete":false,"deny_purge":false,"allow_rollup_hdrs":false,"consumer_limits":{},"allow_msg_ttl":false,"metadata":{"_nats.req.level":"0"}} \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/meta.sum b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/meta.sum new file mode 100644 index 000000000..48a9dc03e --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/meta.sum @@ -0,0 +1 @@ +c93aec38b44ea7d3 \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/msgs/1.blk b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/msgs/1.blk new file mode 100644 index 000000000..e69de29bb diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/meta.inf b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/meta.inf new file mode 100644 index 000000000..602f55962 --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/meta.inf @@ -0,0 +1 @@ +{"Created":"2026-09-24T04:46:09.068004189Z","Name":"archie-daemon","durable_name":"archie-daemon","name":"archie-daemon","deliver_policy":"all","ack_policy":"explicit","ack_wait":300000000000,"max_deliver":3,"filter_subject":"archie.task.\u003e","replay_policy":"instant","max_waiting":512,"max_ack_pending":1000,"inactive_threshold":86400000000000,"num_replicas":0,"metadata":{"_nats.req.level":"0"}} \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/meta.sum b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/meta.sum new file mode 100644 index 000000000..60c5000ac --- /dev/null +++ b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/meta.sum @@ -0,0 +1 @@ +514bef62122c4381 \ No newline at end of file diff --git a/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/o.dat b/internal/app/archied/nats/jetstream/$G/streams/ARCHIE_TASKS/obs/archie-daemon/o.dat new file mode 100644 index 0000000000000000000000000000000000000000..055d9019abf53b44fa75492a1b85dcf8996a1f3a GIT binary patch literal 8 LcmWe*VgLgG0LB0r literal 0 HcmV?d00001 diff --git a/internal/app/archied/nats_endpoint.go b/internal/app/archied/nats_endpoint.go index 83dcff59f..f77d8d661 100644 --- a/internal/app/archied/nats_endpoint.go +++ b/internal/app/archied/nats_endpoint.go @@ -12,12 +12,12 @@ type embeddedNATSEndpoint struct { Token string `json:"token"` } -func embeddedNATSEndpointPath(dbPath string) string { - return filepath.Join(filepath.Dir(dbPath), "nats", "endpoint.json") +func embeddedNATSEndpointPath(stateDir string) string { + return filepath.Join(stateDir, "nats", "endpoint.json") } -func writeEmbeddedNATSEndpoint(dbPath, url, token string) error { - path := embeddedNATSEndpointPath(dbPath) +func writeEmbeddedNATSEndpoint(stateDir, url, token string) error { + path := embeddedNATSEndpointPath(stateDir) data, err := json.Marshal(embeddedNATSEndpoint{URL: url, Token: token}) if err != nil { return fmt.Errorf("marshal embedded NATS endpoint: %w", err) @@ -48,8 +48,8 @@ func writeEmbeddedNATSEndpoint(dbPath, url, token string) error { return nil } -func readEmbeddedNATSEndpoint(dbPath string) (embeddedNATSEndpoint, error) { - data, err := os.ReadFile(embeddedNATSEndpointPath(dbPath)) +func readEmbeddedNATSEndpoint(stateDir string) (embeddedNATSEndpoint, error) { + data, err := os.ReadFile(embeddedNATSEndpointPath(stateDir)) if err != nil { return embeddedNATSEndpoint{}, err } diff --git a/internal/app/archied/nats_endpoint_test.go b/internal/app/archied/nats_endpoint_test.go index fcfea6984..e28607e57 100644 --- a/internal/app/archied/nats_endpoint_test.go +++ b/internal/app/archied/nats_endpoint_test.go @@ -7,18 +7,21 @@ import ( ) func TestEmbeddedNATSEndpointRoundTripIsPrivateAndAtomic(t *testing.T) { - dbPath := filepath.Join(t.TempDir(), "archie.db") - if err := writeEmbeddedNATSEndpoint(dbPath, "nats://127.0.0.1:4222", "secret"); err != nil { + stateDir := t.TempDir() + if err := writeEmbeddedNATSEndpoint(stateDir, "nats://127.0.0.1:4222", "secret"); err != nil { t.Fatal(err) } - got, err := readEmbeddedNATSEndpoint(dbPath) + got, err := readEmbeddedNATSEndpoint(stateDir) if err != nil { t.Fatal(err) } if got.URL != "nats://127.0.0.1:4222" || got.Token != "secret" { t.Fatalf("endpoint = %+v", got) } - info, err := os.Stat(embeddedNATSEndpointPath(dbPath)) + if want := filepath.Join(stateDir, "nats", "endpoint.json"); embeddedNATSEndpointPath(stateDir) != want { + t.Fatalf("endpoint path = %q, want %q", embeddedNATSEndpointPath(stateDir), want) + } + info, err := os.Stat(embeddedNATSEndpointPath(stateDir)) if err != nil { t.Fatal(err) } diff --git a/internal/app/archied/readiness.go b/internal/app/archied/readiness.go index b08808d39..ea6b3e9bb 100644 --- a/internal/app/archied/readiness.go +++ b/internal/app/archied/readiness.go @@ -10,7 +10,6 @@ import ( "fmt" "net/http" "os" - "path/filepath" "strings" "time" @@ -73,12 +72,12 @@ func diskProbeTargets(cfg config.Config) []readiness.DiskTarget { return targets } -// diskProbePath preserves the database/work/cwd fallback used by the daemon's -// disk target: the store database directory first, then work directory, then cwd. +// diskProbePath is the daemon's data disk target: the state directory first, +// then the work directory, then cwd. func diskProbePath(cfg config.Config) string { switch { - case cfg.DBPath != "": - return filepath.Dir(cfg.DBPath) + case cfg.StateDir != "": + return cfg.StateDir case cfg.WorkDir != "": return cfg.WorkDir default: diff --git a/internal/app/archied/readiness_test.go b/internal/app/archied/readiness_test.go index b7c1644a1..638f1bb16 100644 --- a/internal/app/archied/readiness_test.go +++ b/internal/app/archied/readiness_test.go @@ -12,15 +12,15 @@ import ( "github.com/samcharles93/archie-core/internal/webui" ) -func TestDiskProbePath_PrefersDBPath(t *testing.T) { - cfg := config.Config{DBPath: "/data/archie/tasks.db", WorkDir: "/srv/archie"} - if got := diskProbePath(cfg); got != "/data/archie" { - t.Fatalf("diskProbePath = %q, want /data/archie", got) +func TestDiskProbePath_PrefersStateDir(t *testing.T) { + cfg := config.Config{StateDir: "/var/lib/archie", DBPath: "/data/archie/tasks.db", WorkDir: "/srv/archie"} + if got := diskProbePath(cfg); got != "/var/lib/archie" { + t.Fatalf("diskProbePath = %q, want /var/lib/archie", got) } } func TestDiskProbePath_FallsBackToWorkDir(t *testing.T) { - cfg := config.Config{WorkDir: "/srv/archie"} + cfg := config.Config{DBPath: "/data/archie/tasks.db", WorkDir: "/srv/archie"} if got := diskProbePath(cfg); got != "/srv/archie" { t.Fatalf("diskProbePath = %q, want /srv/archie", got) } diff --git a/internal/app/archied/state_store.go b/internal/app/archied/state_store.go index 7f90bc146..cf6492a52 100644 --- a/internal/app/archied/state_store.go +++ b/internal/app/archied/state_store.go @@ -232,9 +232,7 @@ func (b *boot) stateStoreDeps(grants *staterpc.TaskGrants) staterpc.Deps { // Task logs live in the state directory, which this process owns, and the // dashboard process owns no such directory -- so this is where a task-log // read is served from (docs/prds/ui-service-boundary.md). The reader is - // the daemon's own registry, built over the same state-directory - // derivation this process uses for its SQLite file; both resolve from the - // same configured DBPath, so they agree on where archie keeps its state. + // the daemon's own registry over the configured state_dir. // // The nil check is on the registry, not on the interface it is assigned // to: a nil *logging.TaskRegistry stored in this field produces a non-nil diff --git a/internal/config/config.go b/internal/config/config.go index d5211d967..16b17404b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -486,7 +486,14 @@ type Config struct { // SecretEngineDir contains Yaegi secret-engine plugins. Built-in env and // bws engines remain available when this is empty. SecretEngineDir string `toml:"secret_engine_dir" yaml:"secret_engine_dir"` - DBPath string `toml:"db_path" yaml:"db_path"` + // DBPath locates the legacy SQLite files ("-tasks.sqlite", + // "-eda.sqlite", "-conversations.sqlite") for the one-time import and the + // boot gate that refuses to serve until it has run. Nothing else reads it. + DBPath string `toml:"db_path" yaml:"db_path"` + // StateDir is the host directory archie keeps non-database state in: the + // embedded NATS store and its endpoint file, the task-log registry, and + // the readiness disk probe's data target. Bootstrap-only. + StateDir string `toml:"state_dir" yaml:"state_dir"` // DatabaseURL is the PostgreSQL connection URL the standalone State Store // process opens at boot. It is bootstrap-only (the same class as db_path // and work_dir): the pool is opened once, so a runtime change cannot take diff --git a/internal/infrastructure/configuration/defaults.go b/internal/infrastructure/configuration/defaults.go index 7226360f2..f88d09801 100644 --- a/internal/infrastructure/configuration/defaults.go +++ b/internal/infrastructure/configuration/defaults.go @@ -225,6 +225,7 @@ func (l *Loader) applyGeneralDefaults(cfg *config.Config) { cfg.SecretEngineDir = expandHomePath(cfg.SecretEngineDir) cfg.WorkDir = expandHomePath(cfg.WorkDir) cfg.DBPath = expandHomePath(cfg.DBPath) + cfg.StateDir = expandHomePath(cfg.StateDir) cfg.Chat.Workspace = expandHomePath(cfg.Chat.Workspace) // DatabaseURL has no default and is not path-expanded: it is a connection // URL, not a file path. Empty means "not configured", which the State @@ -237,6 +238,9 @@ func (l *Loader) applyGeneralDefaults(cfg *config.Config) { if cfg.DBPath == "" { cfg.DBPath = filepath.Join(l.dataHome(), "archie", "archie.db") } + if cfg.StateDir == "" { + cfg.StateDir = filepath.Join(l.dataHome(), "archie") + } if cfg.PollInterval == 0 { cfg.PollInterval = config.Duration(defaultPollInterval) } diff --git a/internal/infrastructure/configuration/denied_keys.go b/internal/infrastructure/configuration/denied_keys.go index 158c4fad8..b0e6b3150 100644 --- a/internal/infrastructure/configuration/denied_keys.go +++ b/internal/infrastructure/configuration/denied_keys.go @@ -11,5 +11,6 @@ package configuration var DeniedKeys = map[string]string{ "db_path": "required for bootstrap; cannot be changed at runtime", "database_url": "required for bootstrap; cannot be changed at runtime", + "state_dir": "required for bootstrap; cannot be changed at runtime", "work_dir": "pins the daemon's working layout; cannot be changed at runtime", } diff --git a/internal/infrastructure/configuration/loader_test.go b/internal/infrastructure/configuration/loader_test.go index 07b1aca2a..5f2fcdd0c 100644 --- a/internal/infrastructure/configuration/loader_test.go +++ b/internal/infrastructure/configuration/loader_test.go @@ -76,6 +76,7 @@ func TestLoadExpandsConfiguredHomePaths(t *testing.T) { bot_user = "widget" work_dir = "~/archie/work" db_path = "~/archie/archie.db" +state_dir = "~/archie/state" [chat] workspace = "~/archie/workspace" @@ -98,6 +99,7 @@ name = "app" }{ "work_dir": {got: cfg.WorkDir, want: filepath.Join(home, "archie", "work")}, "db_path": {got: cfg.DBPath, want: filepath.Join(home, "archie", "archie.db")}, + "state_dir": {got: cfg.StateDir, want: filepath.Join(home, "archie", "state")}, "chat.workspace": {got: cfg.Chat.Workspace, want: filepath.Join(home, "archie", "workspace")}, } for name, tt := range wants { @@ -109,6 +111,32 @@ name = "app" } } +// state_dir defaults to archie's directory under the data home, independent +// of db_path, which only locates legacy files for the one-time import. +func TestStateDirDefaultsToTheDataHome(t *testing.T) { + dataHome := t.TempDir() + t.Setenv("XDG_DATA_HOME", dataHome) + path := filepath.Join(t.TempDir(), "config.toml") + contents := ` +bot_user = "widget" +db_path = "/elsewhere/archie.db" + +[[repos]] +owner = "acme" +name = "app" +` + if err := os.WriteFile(path, []byte(contents), 0o600); err != nil { + t.Fatal(err) + } + cfg, err := loadFile(path) + if err != nil { + t.Fatal(err) + } + if want := filepath.Join(dataHome, "archie"); cfg.StateDir != want { + t.Fatalf("StateDir = %q, want %q", cfg.StateDir, want) + } +} + func TestResolveSelectsFileFormatsAndDirectories(t *testing.T) { tests := []struct { name string diff --git a/internal/webui/api_config.go b/internal/webui/api_config.go index c7bcfbeaa..4866bb8b3 100644 --- a/internal/webui/api_config.go +++ b/internal/webui/api_config.go @@ -242,6 +242,7 @@ type BudgetsView struct { // secrets. type StorageView struct { WorkDir string `json:"work_dir"` + StateDir string `json:"state_dir"` DBPath string `json:"db_path"` DatabaseURL string `json:"database_url"` SkillsDir string `json:"skills_dir,omitempty"` @@ -375,6 +376,7 @@ func BuildConfigView(in ConfigViewInput) ConfigView { }, Storage: StorageView{ WorkDir: cfg.WorkDir, + StateDir: cfg.StateDir, DBPath: cfg.DBPath, DatabaseURL: cfg.DatabaseURL, SkillsDir: cfg.SkillsDir, diff --git a/internal/webui/config_schema.go b/internal/webui/config_schema.go index 72c442786..880631021 100644 --- a/internal/webui/config_schema.go +++ b/internal/webui/config_schema.go @@ -147,7 +147,8 @@ func configFieldDescriptors() []ConfigSection { Description: "Where archied keeps its state, and how it isolates task execution.", Fields: []ConfigField{ {Key: "work_dir", Label: "Work directory", Type: FieldString, Editable: false}, - {Key: "db_path", Label: "State path prefix", Type: FieldString, Editable: false}, + {Key: "state_dir", Label: "State directory", Description: "Embedded NATS store, task logs and the readiness disk probe.", Type: FieldString, Editable: false}, + {Key: "db_path", Label: "Legacy SQLite path prefix", Description: "Locates pre-PostgreSQL files for the one-time import only.", Type: FieldString, Editable: false}, {Key: "database_url", Label: "PostgreSQL URL", Description: "The State Store's database connection; set at boot, restart required.", Type: FieldString, Editable: false}, {Key: "skills_dir", Label: "Shared skills directory", Description: "Empty uses the work directory.", Type: FieldString, Editable: true, RestartRequired: true}, {Key: "plugin_dir", Label: "Daemon plugin directory", Description: "Empty means no daemon plugins.", Type: FieldString, Editable: true, RestartRequired: true}, @@ -192,6 +193,7 @@ func configFieldValues(view ConfigView) map[string]any { "budgets.wall_clock": view.Budgets.WallClock, "budgets.gate_max_failures": view.Budgets.GateMaxFailures, "work_dir": view.Storage.WorkDir, + "state_dir": view.Storage.StateDir, "db_path": view.Storage.DBPath, "database_url": view.Storage.DatabaseURL, "skills_dir": view.Storage.SkillsDir, diff --git a/internal/webui/config_schema_test.go b/internal/webui/config_schema_test.go index 5b3110ae4..41c97b0f2 100644 --- a/internal/webui/config_schema_test.go +++ b/internal/webui/config_schema_test.go @@ -64,7 +64,7 @@ func TestConfigFieldDescriptorsAreComplete(t *testing.T) { "bot_user", "bot_email", "label", "forge.type", "forge.host", "diff_cap_lines", "repos", "models", "providers", "budgets.max_steps", "budgets.wall_clock", "budgets.gate_max_failures", - "work_dir", "db_path", "database_url", "skills_dir", "plugin_dir", "secret_engine_dir", + "work_dir", "state_dir", "db_path", "database_url", "skills_dir", "plugin_dir", "secret_engine_dir", "containers.image", "containers.max_concurrency", "containers.max_uptime", "containers.volume_ttl", "containers.pull_policy", "containers.network", "web.listen", @@ -100,6 +100,7 @@ func TestConfigFieldDescriptorsRestartRequiredIsDeliberate(t *testing.T) { "budgets.wall_clock": false, "budgets.gate_max_failures": false, "work_dir": false, // locked, not merely restart-required + "state_dir": false, // locked, not merely restart-required "db_path": false, // locked, not merely restart-required "database_url": false, // locked, not merely restart-required "skills_dir": true, // absent from reloadableFields @@ -149,7 +150,7 @@ func TestConfigFieldDescriptorsStructuredFieldsAreNotEditable(t *testing.T) { // renderer does not need runtime state to know not to offer an edit // affordance for a key that can never succeed. func TestConfigFieldDescriptorsLockedStorageFieldsAreNotEditable(t *testing.T) { - locked := map[string]bool{"work_dir": true, "db_path": true, "database_url": true} + locked := map[string]bool{"work_dir": true, "state_dir": true, "db_path": true, "database_url": true} for _, section := range configFieldDescriptors() { for _, f := range section.Fields { if locked[f.Key] && f.Editable {