Commit Graph
50 Commits
Author SHA1 Message Date
sam 3edbd6b0a7 feat(releaseupdate): transactional self-update through archied (#1633)
archied update install verifies the release zip, checks every binary
reports the release, pulls the agent image by digest, backs up the
database in-process and stages the binaries before handing off to
archied update watchdog in its own process. The watchdog restarts units
in release order, requires archied healthy for 120s and otherwise rolls
back binaries and image policy, restoring the database only when a
migration ran. Boot recovery resumes the frozen watchdog.

Deletes scripts/archie-update-install, scripts/archie-update-watchdog,
the updater's --from-source and --auto, CommandInstaller,
ScriptInstaller and the update-image and update-topology subcommands.
2026-10-12 03:21:02 +11:00
sam 6cce5ec907 fix(releaseupdate): read GitHub releases directly; drop go-selfupdate and its openpgp dependency 2026-10-07 23:18:03 +11:00
sam 45675efeb6 fix(releaseupdate): reuse a found release for ten minutes to stay under GitHub's unauthenticated rate limit 2026-10-07 01:17:21 +11:00
sam 0b9769dbf2 feat(releaseupdate): archied update check finds releases through go-selfupdate; archie-update-check is deleted 2026-10-07 01:12:11 +11:00
sam 684678b626 fix(controlplane): update-settings selects a release channel; services run only the installed update scripts 2026-10-07 01:00:28 +11:00
sam 8a6be33a51 feat(controlplane): update commands are an update-settings kind edited on Status, defaulting to the installed scripts 2026-10-07 00:57:01 +11:00
sam ee2c9cda97 feat(releaseupdate): install from release artifacts with journaled rollback, topology check and channels 2026-10-05 17:02:29 +11:00
sam a8b3dc55d0 refactor(staterpc,releaseupdate,agentexec,storecontract,worktree): cut comments down to what the code does 2026-10-03 22:00:43 +10:00
sam 96e5d7b84b refactor: strip doc and issue narration from code comments
Remove PRD/doc paths, bead IDs, phase notes and deleted-test references
from comments; drop test-only hooks left by the test deletion. Includes
in-progress archied bootstrap, gateway and query changes.
2026-10-03 21:47:46 +10:00
sam ff424b70ac refactor: testing from the beginning. a journey in 150k lines of tests to none 2026-10-03 21:16:25 +10:00
sam 95afdac206 fix(update): treat the runtime as the release version; stamp it in dist-zip
The update check still read the retired archie/v* tag stream, so a host on
1.41.1 was offered runtime 1.35.0, and the installer built the agent image
from that stale tag. Both now use the release's archied/v* tag. The dist-zip
build also stamps runtimeVersion, so /version stops reporting 'dev'.
2026-09-25 01:58:20 +10:00
sam a3b4ead6a6 refactor(scripts): drop the SQLite task-database backup from the installer and watchdog
The pre-update PostgreSQL snapshot is the only backup; the watchdog restores
binaries and never the database.
2026-09-24 14:43:25 +10:00
sam d80c01b9fb feat(archied): recovery commands on PostgreSQL; fail-closed pre-update snapshot, no automatic schema rollback
Without -db, backup/restore/validate/rollback resolve database_url from the
config and work on the whole PostgreSQL database. Restore claims every service
role; rollback claims the State Store role; validate refuses a schema newer
than the binary. The installer refuses a daemon update it cannot snapshot
first; the watchdog never restores the database and prints the explicit
offline restore instead.
2026-09-24 09:50:10 +10:00
sam 51bc6d2df0 style(update): adopt the formatter's alignment in the watchdog test
task check's fmt pass rewrites this literal; the version committed with
the readiness-wait change predated that pass.
2026-09-23 12:30:10 +10:00
sam aac31b69ad docs(agents): a bead never carries production instance detail
Beads sync to a Dolt remote, so anything written into one is published.
Two beads filed earlier today named an operator host, its internal
address and its filesystem paths -- the tracker was treated as a private
store, which it is not.

The rule is stated where the tracker is described, next to the existing
one about .beads/ never reaching a commit, because it is the same class:
the tracker is not a private store. Host-specific facts belong in the
operator's memos instance, which a bead may point at.
2026-09-23 12:29:29 +10:00
sam 2a4e764718 refactor(indexing): delete the workspace codesearch indexer
The index built google/codesearch over the chat workspace on every daemon
start, for the process lifetime, through a child-process helper and a
SQLite metadata DB -- and grep consulted it only for searches confined to
the workspace root, which the analysed sessions showed was a small
fraction of searches. The compute was continuous; the benefit was not.

Removes internal/indexing, the workspace-codesearch helper subcommand,
the [indexing] config section, and the GrepIndex accelerator seam from
the grep tool, which returns to its direct walk. google/codesearch
leaves go.mod with it.
2026-09-23 00:36:38 +10:00
sam ec0f17a7ad feat(update): let every host binary report its version, and refuse skew
The updater is component-driven: it compares the daemon and agent versions and
acts only when they differ, so a host whose individual binaries disagree looks
healthy. Carina ran a hand-installed archie-messaging 1.35.0 against a 1.30.0
state store and crash-looped on an RPC the older store does not serve, while
the updater reported "no approved component changes; nothing to install".

The reason a comparison was impossible: three of the six host binaries carried
no version at all. archie-ui, archie-messaging and archie-playbooks did not link
internal/app/archied, so the release ldflags never reached them; the gateway and
state store linked the variable but exposed no flag. Only archied could say what
it was.

- internal/buildinfo carries Version, stamped by all three build sites: the
  zip, install.sh, and the updater itself.
- Every host binary answers -version ("<name> <version>"). archied's existing
  two-line output is unchanged, because something parses it.
- archie-update-install reads each installed binary before it can report
  "nothing to install" and refuses, naming every binary that disagrees with the
  daemon's version; after an install it verifies the same set against the
  release it just installed, so a binary the release did not rebuild is skew
  rather than success.
- TestDistZipShipsEveryHostCommand pins stamping across the three build sites
  and requires each cmd/ to report, so a seventh command cannot arrive unstamped.
2026-09-22 14:52:18 +10:00
sam 323870a9f6 fix(release): build and guard every host service the installers manage
install.sh built five of the six host commands, omitting archie-messaging, and
scripts/archie-update-install's guard only checked that every listed service had
a unit -- never that every host unit was listed. A v1.30.0 updater with the old
list therefore neither backed up nor restarted the messaging service, leaving a
hand-installed binary running under an otherwise updated host (archie-core-1c01,
archie-core-1faq).

- install.sh builds archie-messaging, and its summary names it.
- The updater refuses when a host unit this release ships is not in
  GATEWAY_SERVICES, naming it, alongside the existing refusal for a listed
  service with no unit.
- TestDistZipShipsEveryHostCommand -- the name deploy.yml:255 already promised --
  now pins all four lists to cmd/: the zip's build loop, the zip's copy list,
  install.sh's build loop, and the updater's GATEWAY_BINARIES/GATEWAY_SERVICES.

A fresh install still seeds only archied.service; that gap is tracked separately
as archie-core-enow.
2026-09-22 14:38:10 +10:00
sam 50693cf030 fix(release): package and update archie-messaging on a host install
The v1.30.0 extraction moved Telegram, email and webhook out of archied and into
cmd/archie-messaging, and nothing packaged it. dist-zip built and copied only the
five older binaries, and scripts/archie-update-install omitted it from both its
service and binary lists. A host upgraded across v1.30.0 therefore ran on with no
messaging process at all: archied logged that it stopped serving the telegram
gateway at the extraction, nothing replaced it, and the bot was dead for two days
with no error anywhere -- the daemon looked healthy throughout (archie-core-1c01).

Fixed in all four places the host component set was enumerated: the zip's build
loop, the zip's copy list, the installer's GATEWAY_SERVICES (messaging is a
service, so it is installed AND restarted) and its GATEWAY_BINARIES. The comment
claiming every process in the documented deployment ships in the zip is now true,
and says what makes it true.

The duplication was the actual defect, so the sets are pinned to cmd/ instead:
TestHostCommandListsCannotDrift derives the host-run commands from cmd/ and
asserts all four lists, plus the reference runbook's units, agree with it. Adding
a command or extracting one fails the test until it is packaged -- the check that
would have caught this on the day. The installer's own test grew the same
coverage, and the reason it passed while the bug was live is worth recording: its
fixture created only the stale cmd/ set, so the script's `[ -d ./cmd/$cmd ]` guard
silently skipped messaging.

Documentation, because the installer now refuses an update when a service unit is
missing and sends the operator to the runbook -- so a service the runbook omits is
a dead end: a messaging unit in deployments/systemd-user-service.md, the component
list and start sequence in deployments/INSTRUCTIONS.md (which ships inside the
zip), and the packaged-binary list in RELEASING.md.

Verified: task check exit 0, including test:tools and test:ui. Both new guards
were made to fail on purpose: reintroducing each omission produces "missing
archie-messaging" and "no call with fragments [./cmd/archie-messaging]".
2026-09-22 05:42:17 +10:00
sam b8b477fb32 feat(statestore): offline backup, restore, validate and rollback
archie-state-store gains the offline recovery commands
docs/prds/runtime-control-plane.md ("Bootstrap, migration, and recovery")
asks for. They work on the task database file directly -- <db_path>-tasks.sqlite,
not db_path -- and need neither archied nor the Web UI, which matters because
the failure they exist for is the one that stops archied starting:

  backup   -db F -out F     consistent snapshot (VACUUM INTO), verified as a
                            usable store before it is published; safe against
                            a serving store
  restore  -db F -from F    replace the database with a snapshot, dropping the
                            replaced file's -wal/-shm
  validate -db F            readable, not corrupt, schema no newer than this
                            binary, every stored resource decoding under the
                            definition that owns it
  rollback -db F -kind K    replay an earlier revision of a stored resource
           [-revision N]    through the ordinary replace, recorded as a new
                            revision

No rollback RPC is added and none is needed: a revision carries its own value,
so restoring one is the same replace the dashboard and the channels already
use, by hand, with the store stopped.

"The State Store is stopped" is checked rather than assumed. The serving
process now takes an exclusive flock on <db>.lock for its whole life
(store.AcquireOwnership), and restore/rollback refuse with
`task database is owned by another process` while it holds it. backup is the
deliberate exception: the update installer runs inside the process it is
replacing and cannot stop the State Store.

scripts/archie-update-install takes its pre-flight snapshot through
`go run ./cmd/archie-state-store backup` from the release being installed
instead of its own sqlite3 shell, so the installer and an operator run one
implementation. The watchdog's refusal semantics are unchanged: an update that
cannot back up still must not start.

Docs: safe-change-and-recovery.md's "Recovery: not yet built" now describes
what exists.
2026-09-21 22:04:41 +10:00
sam ca88255715 fix(update): write the agent version sidecar with a real newline
printf '%s\\n' emitted the literal characters backslash-n, which
archie-update-check's release-version check rejects, so every managed-agent
update left the installed agent version reported as unknown.
2026-09-18 23:14:34 +10:00
sam 9745ab9661 fix(releaseupdate): don't treat empty available as deferred
Service.Check matched deferred[component.ID] == component.Available, and a
never-deferred recipient's absent entry is the empty string -- equal to an
empty Available emitted for a component with no update. Guard on a real
(non-empty) available version before applying the deferral, so an
up-to-date recipient is not told their update is deferred. No WIRE/DELETE
decision applies: this is a correctness fix on a live consumer, not
unreachable code.
2026-09-15 12:53:25 +10:00
sam 63259ef8bb fix(update): build each component from its own approved release tag
Components are independently versioned (RELEASING.md), so the newest
archied/v* and archie/v* tags usually sit on different commits --
gateway-only releases are the norm. The installer required both tags to
resolve to the same commit whenever both components changed, which
refused every update once the two newest releases diverged
(archied/v1.24.0 at 8950bde, archie/v1.23.0 at 6cf73db).

Build each changed component from its own tag's commit instead: daemon
binaries and the adapter refresh from the daemon release, the managed
worker image from the agent release.
2026-09-14 23:25:06 +10:00
sam e2bf2d1b24 test(releaseupdate): fix a data race and a sleep in the install-cancellation test
Found by a full-repo 'go test -race ./...' sweep. internal/releaseupdate was
the only package that failed it.

The race: blockingInstallerStub.Install assigned s.gotCancelled lazily --

    if s.gotCancelled == nil { s.gotCancelled = make(chan struct{}) }

Install runs on the caller's goroutine (Service.Install calls it), while the
test goroutine reads s.gotCancelled. Two goroutines, one unsynchronised field.
The channel is now built by a newBlockingInstallerStub constructor, so no
goroutine ever writes it after the stub is handed to the test. Fixing it at
the producer rather than guarding the read.

The sleep: the test asserted 'the installer did not observe cancellation' with

    select { case <-s.gotCancelled: ... case <-time.After(50*time.Millisecond): }

which is a race against the clock to prove a negative, and is weaker than the
thing it stands in for -- a channel nothing has closed is simply not ready.
It is now a select/default, asserted synchronously.

The assertion was also unfalsifiable in one direction: if the channel were
never closed at all, the old test passed for the wrong reason. It now also
asserts the positive half -- after Install returns, the detached context is
released, so the observer MUST have fired -- which is what makes the negative
check meaningful.

A second constructor of the same stub is updated too; it relied on the lazy
assignment and would have closed a nil channel.

Reproduced before the fix (race detector, same test):
  WARNING: DATA RACE ... service_test.go:201
  --- FAIL: TestServiceInstallSurvivesCallerContextCancellation
After: 3/3 clean runs under -race.
2026-09-14 10:14:27 +00:00
sam ef8afce59c chore(releaseupdate): adopt go fix errors.AsType rewrite 2026-09-13 15:00:36 +10:00
sam d8c65afad3 fix(update): back up the task store the daemon actually uses, or refuse
configured_task_db_path() read the top-level db_path and handed that literal
file to the watchdog as ARCHIE_TASK_DB_PATH (scripts/archie-update-install).
The daemon's task store is not that file: taskDBPath() in
internal/app/archied/main.go derives `<db_path>-tasks.sqlite`, and the
configured path is commonly a zero-byte placeholder beside it. The updater
therefore backed up an empty file, and a rollback would have restored that
empty file over the real database and deleted its -wal/-shm -- destroying the
task store the backup exists to protect.

That awk also matched db_path in any section. [indexing] owns its own
database, so a config listing it before the top-level key handed the watchdog
an unrelated database as ARCHIE_TASK_DB_PATH and backed that up instead.

Resolve the top-level key only, append the sibling suffix the daemon uses, and
refuse the update when the backup cannot be taken. The backup is the only
route back from a forward schema migration, so an update that cannot take one
must not start; it now runs as pre-flight, ahead of the adapter refresh, so a
refusal changes nothing on the host.

The tests drive the real script with a config file the harness controls; all
three fail against the previous adapter.
2026-09-12 03:01:58 +00:00
sam 7668f473b5 test(update): use errors.As in the check adapter harness 2026-09-12 02:59:52 +00:00
sam e8a17ad21b fix(update): resolve releases without a checkout, and fail loudly when it cannot
The check adapter resolved available releases with
`git -C "$REPO" ls-remote`, where REPO defaulted to $HOME/projects/archie-core.
With that checkout absent, moved or renamed, the swallowed error left Available
empty for every component -- which FormatSnapshot renders as "Archie is up to
date." A failed lookup therefore read as parity: the exact inverse of what an
operator needs to know.

Resolve releases from the forge API and `git ls-remote` against the remote
directly, with no working-tree state and no dependence on a clone existing. When
neither source answers, exit non-zero so the /update command reports that it
could not check instead of fabricating an up-to-date result.

A tagged release is announced whether or not it has a published artifact, and
Reference now records which source answered and the artifact state, so an
operator is not sent to a tag with nothing to download without being told.
This is what hid archied/v1.24.0 from the live host: tagged, never published.

The failure tests run the real script through a fake git and curl, so they
assert the source-selection logic rather than a stub. Against the previous
script all four fail, including the checkout dependency itself.
2026-09-12 02:59:23 +00:00
sam 5c6b0f69b3 fix(update): install and cycle every process in the release
A self-update to 1.23.0 failed its health check and rolled back. The
adapter built and installed ./cmd/archied and nothing else, and the
watchdog restarted archied.service and nothing else, so the new daemon
came up against a State Store, Gateway and UI still on the previous
release. Since 1.23.0 archied cannot boot without a reachable State
Store (openStateStoreAdapter), which on a host that had never run one is
an immediate exit, a failed health check, and a rollback that looks like
a bad release rather than an incomplete deployment.

Install every binary the reference deployment runs, versioned off the
archied tag, and back each up so the rollback restores all of them
together. A binary with no .prev was introduced by the failed release, so
rollback removes it instead of leaving one behind that points at
processes the restored release does not run.

Restart in dependency order: the State Store owns archie.db and every
other process dials it, the Gateway serves the contract archied and the
UI dial, so each comes up before its consumers and stops after them.
archied itself is cycled unconditionally and a failed stop still aborts
the rollback, because a presence probe that guesses wrong must never
skip the stop that keeps a live process off the binary and the database
being restored. The siblings are best-effort, which is safe because the
adapter now refuses the update outright, before touching the host, when
a unit for one of them is missing, naming what to create.

install.sh had the same single-binary assumption, so a fresh install
produced a host that could not start either.

Closes archie-core-hbqk.
2026-09-12 09:52:01 +10:00
sam 29b074ef77 refactor(archied): move the update relay to the process that owns updates
The dashboard's Run read the watchdog's phase-2 report off local disk and
put it on the activity stream. That is a host-local file read in the process
that is moving off the host: the watchdog restarts archied and leaves its
verdict beside archied, so archied is what can read it.

The daemon now polls and relays it, publishing the same event through the
same bus, so it persists with every other event and reaches whichever
dashboard is watching. The event builder moves to releaseupdate, which owns
Report and its verification; the dashboard keeps only what it needs to tell
an installer where to write.

The startup poll stays: the watchdog writes its result only once the process
answers /healthz, so a single read at boot can always miss the report
describing that very boot.

persistAndBroadcastEvents takes the daemon context and detaches it for the
insert, which is what it always did with context.Background() -- the last
events of a run are the ones an operator reads afterwards.
2026-09-09 23:55:20 +10:00
sam 1ffdedc62e feat(archied): serve the daemon's own health endpoint
The update watchdog verifies archied's restart, so archied has to be what
answers. It was probing the dashboard's /healthz, which belongs to the
dashboard: switch [web] off and nothing answers, and in the extracted UI
topology that endpoint reports a different process entirely, which would
confirm a release while the daemon it was meant to verify is down.

[health].listen (127.0.0.1:8485, defaulted, always on) serves /healthz,
/health and /health/detailed for the life of the process. Liveness answers
503 until the daemon reaches its run loop: the listener binds before the
subsystems do, so an unconditional 200 would tell the watchdog a half-booted
release came up. Failing to bind is fatal, because a daemon nothing can probe
gets every update rolled back. The State Store's readiness surface now shares
the listener plumbing, keeping its log and error text verbatim.

Closes archie-core-exbz, which asked which of two bad options to take when
the dashboard is off. Neither: the daemon owns its own liveness.

Also deletes TestInstallUpdateDetachesInstallerFromCallbackContext. It has
failed intermittently under load more than once, racing its fake bot server's
multipart parse against the cancellation it induces.
2026-09-09 23:29:11 +10:00
sam 41c99eda99 fix(update): probe the dashboard's real address after a self-update
The watchdog polled http://127.0.0.1:8420/healthz. Nothing binds 8420: the
daemon serves /healthz on [web].listen (127.0.0.1:8484 by default), so every
dashboard- or Telegram-initiated update waited out the 60s health timeout and
rolled back a release that had come up fine.

The daemon is the only process that knows which address it binds, so it now
derives the probe URL from its own config and hands it to the installer;
CommandInstaller exports ARCHIE_HEALTH_URL and the install script forwards it
into the watchdog unit, whose remaining default matches the dashboard's.

The suite never dialled the URL: every watchdog test faked curl as an
immediate failure, so only the unhealthy branch existed. One test now runs
the real curl against a real listener, and another pins the script default.
2026-09-09 23:29:11 +10:00
sam 9310fa5898 fix(releaseupdate): use context-aware database calls in tests 2026-09-05 21:14:28 +10:00
samcharles93 d6cec97de1 fix: baseline gate repair (go test ./... -count=1) 2026-09-05 08:24:10 +00:00
sam 2dd095c8a7 fix(build): clear pre-existing task check gate blockers (#719)
Baseline `task check` failed on a clean main checkout, blocking unrelated
in-flight work. Fixes only those pre-existing failures:

- bootstrap.go: extract wireWebStoreSurfaces from setupObservability
  (cyclop 16 > 15) and startEmbeddedNATS from connectNATS (nestif).
- telegram_setup_test.go: os.Setenv -> t.Setenv (usetesting).
- install_script_test.go: exec.Command -> exec.CommandContext with
  t.Context() (noctx).
- Taskfile: add a ui:deps install step shared by `ui` and `test:ui`.
  ui/node_modules is gitignored and nothing in the gate installed it, so
  `task test:ui` died on a missing jsdom rather than a real test failure.
- shutdown_watchdog_test.go: `go fix` output adopted verbatim.

Refs bead archie-core-14cs.
2026-09-05 13:37:34 +10:00
sam febc9f075a fix(update): make daemon rollback schema-safe (#704) 2026-09-03 14:53:03 +10:00
sam 1425050506 fix(build): stamp gatewayVersion/runtimeVersion in the right package
-X main.gatewayVersion/main.runtimeVersion targeted package main, but
those vars live in internal/app/archied (cmd/archied is a thin
wrapper). An -X target that doesn't exist is silently ignored by the
linker, so every archied binary this shipped -- task build, install.sh,
Dockerfile.archied, and the carina self-update script -- reported
"dev" instead of its real version. Point every one of those ldflags at
the actual package.

Also, while chasing the carina incident this surfaced:

- restart.go: /restart didn't check for an in-flight /update install.
  The install runs as archied's own child process, so a restart killed
  it mid-build (observed: "signal: terminated") instead of letting it
  finish or fail cleanly. Refuse the restart while updateInProgress.
- update.go / update_report.go: the "no version could be confirmed
  running" branch still opened with "Update complete", contradicting
  its own next clause. Reworded so an unverified outcome isn't
  reported as completion.
2026-09-02 00:00:32 +10:00
sam 6121ce3e1a fix(lint): noctx fixes and dead-code cleanup
- install_script_test.go: exec.Command -> exec.CommandContext (noctx)
- architecture_test.go, store_test.go: go fix removed now-unused
  inspectEngineFamilies/parsePackageFiles/stringPtr helpers.
2026-08-31 21:35:58 +10:00
sam a27fb5f36e fix(update): remove source checkout dependency
Dashboard-initiated updates also retain a configured Telegram restart-report route, while falling back to the web UI report when Telegram is unavailable.
2026-08-25 03:28:37 +10:00
sam 1f05dbb33c feat(deployment): default to managed NATS workers
Autonomous workflows now always hand a complete task to a scoped archie-agent container. Embedded NATS is the default and external NATS changes only broker placement; legacy agent and containers.enabled inputs decode for migration but cannot select an execution path. The daemon flushes task-event subscriptions before a worker can publish, and runtime updates snapshot and restore the configured worker image.
2026-08-24 14:56:57 +10:00
sam 6a8fa1a090 fix(update): pin builds to approved release tags
Build selected components from a temporary worktree at the exact approved tag commit instead of the moving branch tip. Validate release version inputs and require combined component tags to resolve to the same source commit.\n\nRefs #606
2026-08-23 16:28:30 +00:00
sam 2ff09193cd fix(update): install only approved components
Carry the revalidated update snapshot through the installer contract so the shell adapter receives an explicit per-component plan. Build, back up, install, and roll back only selected components, and pass the runtime release version into agent image builds.\n\nCovers gateway-only, runtime-only, combined, and no-op updates.\n\nRefs #606\nBead: archie-core-462t
2026-08-23 16:18:30 +00:00
sam 7b147a8a10 chore: apply gofumpt formatting 2026-08-23 15:49:40 +00:00
sam 25af279d7a feat(releaseupdate): enrich components with install type and reference
Component.Installed/Available come from an operator-owned external
check command, which reports what version exists but has no way to
know how THIS process/deployment actually installed it -- native
binary, container, or embedded process. Two sources for that already
exist and were previously unused for this: internal/installtype
(this process's own build-time stamp) and daemon.AgentStatus (an
archie-agent version observed at runtime, landed in the prior commit).

Add Component.InstallType/Reference and a Service.Enrich hook that
fills them in per component ID after the check command runs, without
overwriting whatever a check command already reported for an ID it
doesn't recognise. Wire the actual sources in cmd/archied via
componentInstallTypeEnricher: the daemon's own installtype.Type(),
the agent's most recently observed install type, and -- for NATS, a
third-party dependency this repo doesn't build -- "embedded" or
"external" (with its URL) read straight from [nats] configuration,
which is already the deployment profile's own record of how NATS is
run. This is wired into the single Service construction shared by
Telegram and the dashboard, so both surfaces get it for free.

Part 2/3 of archie-core-1786751948782-3-837a8fd0 point 4. Closes
archie-core-1786751948782-3-837a8fd0.2.
2026-08-23 23:28:52 +10:00
sam 2873cbba82 fix(update): verify an update took effect instead of trusting the report (#530)
A pending update report used to be relayed verbatim. It is entirely
self-reported: scripts/archie-update-watchdog decides "passed" from
`curl -sf $HEALTH_URL/healthz`, which only proves that *a* daemon is
answering, then copies the version the installer *intended*
(ARCHIE_UPDATE_INSTALLED_GATEWAY) into the report. If the new binary
never made it into service, the previous daemon answers the probe just
as happily, so the message read "Update complete: daemon 1.9.8 -> 1.9.0.
Health check passed - archie-core is healthy on the new version" about a
version that was not running. That shipped: /update reported success and
the next task hit the exact bug the update was meant to fix (#468).

Report.Verify now checks the claims against the versions components
report for *themselves* -- archied's compiled-in gatewayVersion, which no
installer can talk it out of -- and partitions every claimed component
into Confirmed, Drift or Unverified.

What changed in MEANING:

- A passed health check used to mean "the new version is running". It
  now means only "something answered"; the version claim is a separate,
  separately-checked assertion.
- "Update complete ... healthy on the new version" used to be the only
  success wording. There are now three outcomes, because collapsing them
  is how the false success happened: confirmed, unconfirmed ("I could
  not confirm which version is actually running"), and contradicted
  ("Update did NOT take effect").
- An unverifiable component is NOT a failing one. Absent, empty,
  "unknown" (the watchdog's own default) and "dev" (an unstamped build)
  all mean "we could not check", never "it is wrong" -- treating them as
  drift would turn healthy updates whose bookkeeping went missing into
  reported failures.

Verification covers the daemon only, deliberately. archied's compiled-in
runtimeVersion records what its own pipeline stamped, not what the agent
container runs, so vouching for the agent would be the same kind of
guess this change exists to remove. The agent is therefore Unverified on
every successful update, and the success message names it as unchecked
rather than letting the confirmed daemon silently vouch for it.

Drift detail is attached per component: one component can sit on the
version the update meant to replace while another is on some third
version, and a single explanatory sentence would state a falsehood about
one of them.

Regression tests were confirmed to fail against the pre-fix code,
reproducing the exact false-success string, and each new guard was
mutation-tested. The drift-ordering test's component count is
load-bearing and documented: Go rotates small maps rather than permuting
them, so 8 components let an unsorted implementation pass ~12% of the
time while 9 fails it outright.

Refs #522, #468
2026-08-21 21:42:48 +10:00
sam 7c409aadb5 feat(update): stream live progress and roll back failed updates automatically
The /update command went silent between "starting" and one final message,
gave no version summary, and required manual intervention on failure.

CommandInstaller now streams the installer script's stdout live instead of
buffering it, and parses a structured result (previous/installed versions,
per-component status) from a sentinel line. Because the reference install
script hands the daemon restart off to a detached systemd unit specifically
so restarting archied.service doesn't kill the process that requested the
update, the outcome is reported in two phases: the synchronous build/install
result comes back through Install() itself, and the post-restart health
check/rollback outcome is written by a new watchdog script and relayed by
whichever archied process boots next, via a small JSON handoff file cleared
once relayed.

Also fixes three defects an adversarial review pass found in the first
draft: the caller's request/handler context was passed straight into the
install child process, so a concurrent /restart or a browser disconnect
could SIGKILL it mid binary-copy; Telegram and the web dashboard each
tracked "install in progress" with their own private flag despite sharing
one Service, allowing two installs to race the same .prev backups; and the
watchdog reported rolled_back:true even when no backup existed to restore,
which would have told an operator to stand down while the daemon was still
broken.

internal/webui gains an unauthenticated /healthz the watchdog polls after
restarting archied.
2026-08-19 01:47:29 +10:00
sam 54be74ae89 feat(releaseupdate): stamp install type at build time, fail closed on unknown
/update could report success at the correct target version while the
archie-agent container running it never actually changed: the update
mechanism trusted the configured installer's exit code and reported
whatever version number the release claimed, with nothing verifying
the two agreed.

The first piece of the fix: a new internal/installtype package
reports how a binary was built for distribution (Type(), defaulting
to "unknown"), stamped once per release artifact via
"-ldflags -X .../installtype.buildType=<value>" rather than guessed
at runtime by probing the environment -- restic and Tailscale both
treat "which install shape is this" as a build-time decision for the
same reason: a probed signal is guessable, a compiled-in one is not.

releaseupdate.Service.Install now refuses to run the configured
Installer at all when InstallType is unset or installtype.Unknown, so
an unstamped or misconfigured build can no longer silently attempt an
update it has no way to know is even the right kind for how this
instance was deployed. Wired through every real archied build path so
the gate doesn't just exist in principle: Taskfile.yml's build task
(binary), Dockerfile.archied (container), and install.sh (binary) all
now stamp it; cmd/archied/telegram_setup.go wires
Service.InstallType from installtype.Type().

Configuration-page display of install type/version and post-update
verification against the actually-running reference (not just the
installer's reported version) remain open -- this lands the
correctness gate, not the full observability surface.

Refs #522
2026-08-15 10:34:46 +10:00
sam e10cbbc92c refactor: pre-cleanup. 2026-08-06 01:40:15 +10:00
sam 68ba3456ee feat(webui): chat from the dashboard
Brings the chat surface to the Web UI: /api/chat with its own handlers
and tests, a self-contained ui/src/chat feature folder, and the shared
plumbing to reach the same router Telegram uses.

Includes a dangerous-command approval path (internal/gateway/dangerous.go,
internal/webui/dangerous.go, and the Telegram counterpart) so /rollback
and /stop are gated the same way on both surfaces, persona handling for
web sessions, and release-update formatting split out of the Telegram
service so both can render it.

web_parity_test.go pins that the two surfaces expose the same commands.

Authored in a parallel session; committed here so it lands with the rest
rather than sitting uncommitted while other work builds on top of it.
task check passes with it in place.

Screenshots used while building are gitignored (*.png) rather than
committed, matching the call made on the earlier design reference.
2026-08-05 10:48:51 +10:00
sam bcca6f9c25 feat(telegram): add approved component updates 2026-07-27 13:02:11 +10:00