diff --git a/docs/architecture/agent-system.md b/docs/architecture/agent-system.md index 2b699e5dd..fd37a12bc 100644 --- a/docs/architecture/agent-system.md +++ b/docs/architecture/agent-system.md @@ -2,7 +2,7 @@ **Status:** Current-state investigation in progress **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Domain framing @@ -352,3 +352,32 @@ implemented in different packages: - Record StepExecutions explicitly rather than treating one mutable `stage` field as complete execution history. - Keep Attempt as retry state within the same WorkflowExecution. + +## Curator isolation invariant + +Decided 2026-08-05 +([#435](https://github.com/samcharles93/archie-core/issues/435) epic, +[#98](https://github.com/samcharles93/archie-core/issues/98) runtime). +Recovered 2026-08-09 from the pre-migration issue tracker. + +**Curators are peers, not dependencies.** They must never block, delay, or take +down chat turns, agent runs, or the daemon. + +1. Registry-owned goroutines, one per curator, with per-pass `recover()`, + per-pass budgets (max steps, tokens, timeout), and a configurable maximum of + concurrent passes (default 1) so curators cannot saturate the shared LLM + runtime against chat. +2. Wake events ride the in-process `events.Bus`, which is mutex fan-out with + bounded per-subscriber buffers that **drop** on overflow + (`internal/events/events.go`). A slow curator can never backpressure the chat + publisher. +3. Wake is a best-effort nudge. The trigger is a deterministic read of persisted + primary-input state at pass time, so a dropped wake only delays a run to the + next check-in and never corrupts trigger accounting + ([#22](https://github.com/samcharles93/archie-core/issues/22)). +4. The curator registry lifecycle is independent of the agent loop. Daemon + shutdown cancels in-flight passes and waits bounded. + +Chat turns keep their per-session lanes; agent runs keep their workflow +goroutines and containers. Rule of thumb: **no code path a curator executes may +ever appear on a chat turn's critical path.** diff --git a/docs/architecture/configuration.md b/docs/architecture/configuration.md index 58fc30aa0..82f1975f6 100644 --- a/docs/architecture/configuration.md +++ b/docs/architecture/configuration.md @@ -2,7 +2,7 @@ **Status:** Approved; existing-type assignment is ongoing **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Ownership @@ -290,3 +290,57 @@ The configuration rearchitecture is complete only when: mutability class, owner, and deprecation; - architecture tests prevent a new central runtime configuration model, direct live-setting mutation, and incorrectly fixed behavioural values. + +## Startup policy: missing credential degrades, invalid config is fatal + +Decided 2026-07-30. Recovered 2026-08-09 from the pre-migration issue tracker. + +A missing **credential** disables a capability. Only an **invalid config** stops +the daemon. "Forge is a feature, not a requirement." + +Before `518a1a0`, an unresolvable forge token did `return 1` in +`cmd/archied/main.go`, so a chat-only user who never configured GitHub got no +chat, no gateway, nothing — and under a systemd unit with `Restart=on-failure` +and no start limit it crash-looped every five seconds with the error scrolling +past unread. Forge construction now lives in `resolveForge`, shared by the +primary forge and every configured identity, and degrades to `forge.NewNoop` +with a warning. The identity path had the same defect and was worse: one +identity's missing credential killed all the others. + +Malformed configuration still fails fast in `configuration.Validate`, well +before this point. That distinction is the whole design. + +Apply the same reasoning to any future capability credential, LLM keys +especially: start, report the capability as unavailable, let the operator see it. +Guarded by `TestResolveForgeDegradesInsteadOfFailing`. + +**Known consequence, tracked separately:** `worktree.Manager` still receives the +empty token, so pushes fail late rather than at startup. + +## Config generation belongs to `archied setup`, not `install.sh` + +Decided 2026-07-30 ([#368](https://github.com/samcharles93/archie-core/issues/368)). +Recovered 2026-08-09 from the pre-migration issue tracker. + +`install.sh` must stop generating `config.toml`; `archied setup` owns it. The +installer hand-rolling TOML has already drifted from the schema once: the +generated-config branch hardcoded `key = ARCHIE_GITHUB_TOKEN` and +`host = ${GITEA_URL}` regardless of the answers given, so choosing Gitea produced +a config naming a token the installer never wrote (archied then exited 1), and +choosing GitHub pointed `host` at `gitea.example.com`. `61a5b35` patched this +with a `forge_block` shell helper shared by both config paths — that helper is a +**workaround**, deleted by +[#72](https://github.com/samcharles93/archie-core/issues/72). The durable fix is +that the code writing the config is the code that reads it. + +Why Go and not Python: the installer must run where nothing is installed yet, and +`python3` with `tomllib` means 3.11+, which is not safe on LTS distros. `archied` +is already being built two steps earlier. + +**Key constraint for the port:** `BurntSushi/toml` does **not** survive a +decode/encode round trip with comments intact, and `config.example.toml` carries +documentation users are meant to hand-edit. Decide the write strategy +([#412](https://github.com/samcharles93/archie-core/issues/412)) before writing +any prompting code. Do not port a separate `config.yaml`/`auth.yaml` secret +split — Archie already has `secret.SecretRef{engine,key}`, so setup writes the +reference to TOML and the value to the secret engine. diff --git a/docs/architecture/dependencies-and-contracts.md b/docs/architecture/dependencies-and-contracts.md index 505d2727b..1039ebb16 100644 --- a/docs/architecture/dependencies-and-contracts.md +++ b/docs/architecture/dependencies-and-contracts.md @@ -2,7 +2,7 @@ **Status:** Approved foundation **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Dependency direction diff --git a/docs/architecture/generated-documentation.md b/docs/architecture/generated-documentation.md index 34961988b..bc143a46d 100644 --- a/docs/architecture/generated-documentation.md +++ b/docs/architecture/generated-documentation.md @@ -2,7 +2,7 @@ **Status:** Initial generator and site scaffold in progress **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Purpose diff --git a/docs/architecture/identity.md b/docs/architecture/identity.md index 3da1c9789..9b29a5713 100644 --- a/docs/architecture/identity.md +++ b/docs/architecture/identity.md @@ -2,7 +2,7 @@ **Status:** Approved foundation; lifecycle details are deferred **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Purpose @@ -291,3 +291,28 @@ Focused tests verify that: The focused identity tests pass. Broader daemon and NATS suites could not open embedded listener ports in the current sandbox; their failures occurred before identity behaviour executed. + +## Three-layer identity model + +Agreed 2026-07-30; the frame for SOUL +([#68](https://github.com/samcharles93/archie-core/issues/68)) and the curator +([#435](https://github.com/samcharles93/archie-core/issues/435)). +Recovered 2026-08-09 from the pre-migration issue tracker. + +**Layer 1 — invariants.** Instruction precedence, core rules, and the `` +and `` blocks live in `internal/gateway/templates/archie.md.tpl` and are +unreachable at runtime by anyone. + +**Layer 2 — SOUL.** User-authored identity: agent name, register, warmth. +Editable without a rebuild. + +**Layer 3 — representation.** Curator-derived knowledge about the user. It may +only **propose** changes to SOUL and never apply them. If derived conclusions can +silently rewrite tone, personality drifts and the user loses the control SOUL +exists to give them. A proposal queue also makes the visibility requirement fall +out for free, since pending conclusions are inherently reviewable. + +**Why SOUL comes first:** tone currently lives in Go string constants +(`DefaultPersonas` in `internal/gateway/persona.go`), so fixing a rude reply on +2026-07-29 required editing Go and rebuilding. SOUL is small, fixes a real +defect, and defines the boundary the curator must respect. diff --git a/docs/architecture/messaging-and-work-intake.md b/docs/architecture/messaging-and-work-intake.md index 07ad09c69..c571b1ba7 100644 --- a/docs/architecture/messaging-and-work-intake.md +++ b/docs/architecture/messaging-and-work-intake.md @@ -2,7 +2,7 @@ **Status:** Current state researched; foundation decisions in progress **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Purpose @@ -284,3 +284,37 @@ Current intake is fragmented: - the smallest accepted-work-request contract consumed by the Agent System; - migration of forge polling, replies, chat commands, email, webhook, Telegram, and Jira integrations. + +## Non-goal: semantic search over chat messages + +Decided 2026-08-03 while migrating `internal/gateway` to NellDB v0.3.0. +Recovered 2026-08-09 from the pre-migration issue tracker. + +Semantic/vector search over chat messages is an **explicit non-goal** until usage +data shows a real need. + +Message search is lexical only: collection-scoped `sdk.DocDB.TextSearch` over +per-session collections, paged via `MessageQuery{Query,Limit,Offset}` → +`MessagePage`. Do not add embeddings config, do not call +`sdk.DocDB.SearchSimilar`, and do not write `nell.Record.Vector` on message +records. + +The rationale is cost without a demonstrated use case. Measured 2026-08-03 with +`embeddinggemma:300m` — note this was never an infrastructure problem, the model +was already pulled and `ai-sdk/provider/ollama` already has `embed.go`: + +- 121 ms median warm per message on the write path, 12.5 s cold; +- 768 dims = 3072 bytes per vector, roughly 15× a typical message payload; +- the NellDB v0.3.0 store contract requires `Record.Clone` to deep-copy + `Vector`, so vectors on message records are cloned by **every** chronological + read — `RecentMessages(200)` would copy 600 KB of vectors it discards, on the + hot path of every turn; +- `SearchSimilar` is a linear cosine scan (parallel only above 1000 records), + with no ANN index; +- `LogStore` is append-only and v0.3.0 retains tombstones indefinitely, so the + growth does not compact away. + +If this is ever revisited: NellDB gates vector search on +`Type == TypeVector && len(Vector) > 0`, so partial vectorisation is natively +supported, and vectors belong in a sibling collection (`vectors:`) so +chronological reads never clone them. diff --git a/docs/architecture/migration-decisions.md b/docs/architecture/migration-decisions.md index 1c8fe3359..8e143d7e2 100644 --- a/docs/architecture/migration-decisions.md +++ b/docs/architecture/migration-decisions.md @@ -2,7 +2,7 @@ **Status:** Active migration inventory **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Purpose @@ -238,3 +238,35 @@ Migration design is complete when: Exact Go APIs, SQL statements, and mechanical refactoring steps MAY be finalized during implementation when they do not change these semantics. + +## Recorded migration position (2026-07-29) + +Recovered 2026-08-09 from the pre-migration issue tracker. This section records +decisions the maintainer approved that the repository did not otherwise capture. + +**Completed:** `internal/infrastructure/eventbus/nats` (rebuilt, not relocated); +`internal/infrastructure/configuration` (loading moved out of `internal/config`, +which is now types-only and does no I/O); `internal/eventbus` (broker-neutral +contract); `internal/domain/workintake` (the first `internal/domain/` package, +owning `TaskEnvelope`, the routing `Kind`, the label vocabulary, and task +subjects). + +**DECISION — private input DTO deferred (approved).** +`configuration.Document.Config` is still `internal/config.Config` rather than the +private per-domain input DTO this document mandates. Building an ~800-line +parallel type tree while every consumer still reads `config.Config` would mean +two shapes kept in sync by hand, with no consumer for the new one. It is named as +a field so the compromise is visible at each use site, with the deletion +condition recorded in that package's `doc.go`. Do this **with** the +`internal/config` dissolution, not ahead of it. + +**Agreed next: `internal/app/{archied,agentworker}`.** `run()` in +`cmd/archied/main.go` is ~460 lines, against `organisation.md`'s rule that +`cmd/*` must not contain substantive wiring or act as a service locator. It is +also the last non-infrastructure holder of the NATS SDK, and it is where the +config DTO translation will land, so it unblocks the dissolution above. + +**Method constraint.** Do not write a separate recorded package-review document +per area when the decisions are already dictated by +`dependencies-and-contracts.md`. That is the ceremony pattern this project +deliberately avoids. diff --git a/docs/architecture/organisation.md b/docs/architecture/organisation.md index 555f39056..591ed0d96 100644 --- a/docs/architecture/organisation.md +++ b/docs/architecture/organisation.md @@ -2,7 +2,7 @@ **Status:** Approved **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Target structure diff --git a/docs/architecture/package-review.md b/docs/architecture/package-review.md index dd384779a..713522674 100644 --- a/docs/architecture/package-review.md +++ b/docs/architecture/package-review.md @@ -2,7 +2,7 @@ **Status:** Active **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Purpose diff --git a/docs/architecture/plugins-and-extensions.md b/docs/architecture/plugins-and-extensions.md index ad6e647e3..bfff80c18 100644 --- a/docs/architecture/plugins-and-extensions.md +++ b/docs/architecture/plugins-and-extensions.md @@ -2,7 +2,7 @@ **Status:** Approved foundation **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Plugin framework @@ -43,7 +43,13 @@ network services without a concrete security or operational reason. ## Curator surprisal sampling (deferred) -The curator engine family (epic `archie-core-yp9`) selects which memories +**Deferred by decision, 2026-08-05** — Archie has no embedding capability, and +wave 1 ships the strategy seam without one. Pick the deferred work up in order: +[#436](https://github.com/samcharles93/archie-core/issues/436) first, then +[#437](https://github.com/samcharles93/archie-core/issues/437) which depends on it +and on [#407](https://github.com/samcharles93/archie-core/issues/407). + +The curator engine family (epic [#435](https://github.com/samcharles93/archie-core/issues/435)) selects which memories deserve agentic attention via surprisal-based sampling: score memories by how surprising they are and spend the sampled reasoner's agentic budget on the most surprising items. Wave 1 of the epic ships the `Sampler` strategy seam in @@ -53,8 +59,8 @@ extension point and is gated behind an embedding capability Archie does not yet have — **any surprisal-style sampling is gated behind adding one**. Requirements for the deferred work, so it can be picked up without -re-deriving the design (tracked as `archie-core-yp9.1` embeddings capability, -then `archie-core-yp9.2` surprisal strategies): +re-deriving the design (tracked as [#436](https://github.com/samcharles93/archie-core/issues/436) embeddings capability, +then [#437](https://github.com/samcharles93/archie-core/issues/437) surprisal strategies): - A `Sampler` implementation behind the same interface as the cheap strategies; selection deterministic given fixed inputs. diff --git a/docs/architecture/policy.md b/docs/architecture/policy.md index acd839c0a..4835c866d 100644 --- a/docs/architecture/policy.md +++ b/docs/architecture/policy.md @@ -2,7 +2,7 @@ **Status:** Approved foundation; exact API is deferred **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Purpose diff --git a/docs/architecture/safe-change-and-recovery.md b/docs/architecture/safe-change-and-recovery.md index 29f524ea2..38f3320f8 100644 --- a/docs/architecture/safe-change-and-recovery.md +++ b/docs/architecture/safe-change-and-recovery.md @@ -2,7 +2,7 @@ **Status:** Requirements approved; mechanics are under design **Date:** 2026-07-28 -**Beads issue:** `archie-core-5d7` +**Tracking issue:** [#73](https://github.com/samcharles93/archie-core/issues/73) ## Purpose @@ -99,3 +99,32 @@ capabilities continue operating. Remediation MUST be bounded, observable, and policy-driven. Recovery MUST NOT silently oscillate between versions or retry forever. + +## Gateway restart: two constraints learned the hard way + +Telegram `/restart` (`internal/channels/telegram/restart.go` plus the `Start` +supervisor loop). Recovered 2026-08-09 from the pre-migration issue tracker. +Both constraints must survive any refactor. + +**1. Deadlock.** The `/restart` handler runs *on* the bot instance the supervisor +is about to stop. Tearing down inline from the handler deadlocks the restart it +just asked for. So the handler sends on a **buffered** channel (`restartCh`, +capacity 1) and returns immediately; the supervisor loop in `Start` does the +teardown. Duplicate requests hit the default branch and are dropped, not queued. + +**2. Lockout.** A failed config reload must **not** be fatal. It logs and +relaunches with the previous in-memory settings. If a bad config edit killed the +gateway, it would also destroy the only means of fixing it remotely — which is +the entire reason `/restart` exists. + +**Scope is gateway-only by design.** The daemon keeps running so in-flight agent +tasks survive. Exiting the process would also restart under a `unless-stopped` +policy, but would kill running work. `Reload` (supplied by `cmd/archied/main.go`) +re-reads config from disk and refreshes **only** the token and `AllowedUserIDs`; +everything else is wired into the daemon at construction and still needs a full +restart. + +**Authorisation is inherited:** `authorizedMessage` rejects non-allowlisted +senders before any handler runs, so all gateway commands are admin-only by +construction. Do not add per-command auth without checking that invariant still +holds.