Operator escape hatch: reload gateway config (notably the sender
allowlist) or recover a wedged adapter from chat, with no shell access to
the host.
Start becomes a supervisor loop that relaunches the bot on request, so a
restart is scoped to the gateway: the daemon keeps running and in-flight
agent tasks are untouched. Exiting the process would also have restarted
under the unless-stopped policy, but would have killed running work.
Two failure modes are handled deliberately:
- The handler runs on the very bot the supervisor is about to stop, so it
hands off over a buffered channel and returns instead of tearing down
inline, which would deadlock the restart it just requested. A duplicate
request while one is in flight is dropped, not queued.
- A failed config reload logs and relaunches on the previous settings, so
a bad config edit cannot take chat down permanently -- which would also
remove the means to fix it.
Authorisation is inherited from authorizedMessage: only allowlisted
senders reach any handler, so /restart is admin-only by construction.
main.go supplies Reload, which re-reads config from disk and refreshes
token and allowlist; other fields still need a full daemon restart, since
they are wired at construction.
The menu still showed ~60 stale hermes commands (/steer, /reload_mcp,
/background) even though SetMyCommands succeeded and logged 8 commands.
Telegram resolves a chat's menu by scope specificity rather than by
recency: a list registered against all_private_chats wins over the
default scope in every DM. We wrote only the default scope, so hermes's
older per-scope registrations kept shadowing ours. getMyCommands confirms
it -- default held our 8, all_private_chats and all_group_chats each held
hermes's ~60.
That state lives on Telegram's side, keyed to the bot token, so it
survived the migration off hermes and would survive any redeploy. Publish
to default, all_private_chats and all_group_chats so the leftovers are
overwritten rather than shadowing us. One failing scope no longer aborts
the rest.
Allowlist (16.33). telegram.New was called with a nil allowlist and
isChatAllowed returned true whenever the list was empty, so any Telegram
user who found the bot could talk to it; AllowedChatIDs was not plumbed
into config, so there was no way to close it. Chat tools run with the
daemon's own authority, so this had to be fixed before wiring any real
tools to the chat agent.
Now chat.telegram.allowed_user_ids configures it and an empty list denies
everyone: a bot handle is public, so failing open is not a safe default.
The check matches the sender (from.id) rather than the chat, so adding
the bot to a group cannot be used to inherit access. Rejections log the
sender id and answer once, so a legitimate user missing from the list can
tell the bot is misconfigured rather than dead. Startup warns when the
gateway is enabled with an empty list.
The previous TestIsChatAllowed asserted 'empty allowlist allows all' --
it encoded the vulnerability -- and is replaced by fail-closed tests.
Command menu (16.34). SetMyCommands was never called, so Telegram showed
no menu and the commands Router implements were undiscoverable; asked
about /commands the LLM confidently answered it had none. The published
list mirrors what Router actually handles. Failure is logged, not fatal:
it costs discoverability, not function.
Upgrades go-telegram/bot v1.18.0 -> v1.22.0 and uses the Bot API's rich
message support instead of hand-rolled formatting.
The previous commit converted LLM Markdown into Telegram's HTML subset,
on the premise that the API could not take Markdown directly and had no
table element. Both are true of v1.18.0 but not of v1.22.0, which adds
sendRichMessage/sendRichMessageDraft taking InputRichMessage{Markdown},
plus RichBlockTableCell for native tables. markdownToHTML and its tests
are deleted: LLM Markdown, tables included, now goes to Telegram as-is.
Replies also stream. runtime.ChatStream already returned a TextStream
and sendRichMessageDraft renders partial output, so the only missing
piece was a gateway seam: gateway.LLMStreamResponder plus Router.
RouteStream, which degrades to the blocking Route when unset so any
adapter can call it unconditionally. Local commands answer from local
state and are not streamed; an unrecognised /command is, since Route
hands it to the LLM. main.go derives both responders from one shared
turn implementation.
Draft updates are throttled to one per 700ms to respect per-chat rate
limits, and every streaming/rich path falls back rather than dropping a
reply: a rejected rich send retries unformatted, and a failed draft
update is skipped since the final message is authoritative.
Two gaps visible in the live heyarchie bot:
1. No typing indicator. A non-command message runs a full LLM turn
(seconds), during which the chat looked dead. defaultHandler now
shows the typing action for the duration, refreshed every 4s since
Telegram clears it after ~5s.
2. ParseMode was never set, so LLM Markdown reached users verbatim:
literal **bold**, backticks, and pipe tables. helpHandler was worse
-- it emitted <b>Archie Gateway</b> with no ParseMode, so the raw
tags were shown.
The SDK has no Markdown->Telegram converter (EscapeMarkdown does the
inverse: it escapes text so it renders literally), and neither native
parse mode helps, since Telegram's Markdown dialects use single-asterisk
*bold* whereas LLMs emit **bold**. So markdownToHTML converts to the
HTML subset Telegram accepts, mapping headings to <b>, bullets to '•',
and tables to <pre> (Telegram has no table element). Send falls back to
unformatted text if Telegram rejects the markup, so a conversion bug can
never swallow a reply.
archied's container-mode agent tasks were all failing with "nats: no
responders available for request" in production. Root cause: pool.go's
selfNetwork() auto-detects the daemon's own Docker network by looking up
a container named after os.Hostname(), then joins spawned agent
containers to that same network so they can resolve "nats" by name.
On carina this detection was silently failing (wrong/stale hostname vs.
actual container ID) and returning "", so every per-task agent container
landed on the default bridge network instead — unable to resolve "nats",
never subscribing, hence "no responders" on every request.
selfNetwork() swallowed every failure silently (only logged on success),
so this had no diagnostic trail.
Fix: added Containers.Network config field (containers.network in
config.toml) so deployments can name the network explicitly instead of
relying on fragile self-detection; selfNetwork() remains as a fallback
but now logs a warning on every failure path so this doesn't silently
recur. Wired through container.Config and cmd/archied/main.go.
Both archied production containers (archie-core-archied-1 and -winter-1)
were crash-looping on carina with "forge token (engine \"env\", key
\"ARCHIE_GITHUB_TOKEN\") is required" despite being configured for gitea.
Root cause: the secrets-engine migration replaced [forge]'s flat
token_env string field with a {engine, key} struct (Forge.Token), but
dropped the old field entirely instead of keeping it as a deprecated
fallback like NATSConfig and TelegramConfig already do. TOML silently
ignores unknown keys, so deployed configs still using token_env had
their token config dropped without any warning, and finalize()
defaulted to demanding ARCHIE_GITHUB_TOKEN.
Fix: re-added Forge.TokenEnv and honor it in finalize() when the new
Token struct is unset, matching the existing NATS/Telegram pattern.
New-style [forge.token] still wins if both are present. Added
regression tests for both cases.
Operationally also fixed the two live configs on carina
(~/.config/archie/config.toml, winter.toml) to the new schema, and
added missing work_dir/db_path to winter.toml (its container had no
config-overlay, so it was defaulting to /root/.local/share/archie
instead of the mounted volume). Both containers verified healthy and
processing real issues after restart.
- daemon.go: real bug — maybeRetryParked resolved fg := d.forgeFor(task)
(matching markDead's pattern) but called d.Forge.SetStateLabel instead
of fg.SetStateLabel, silently using the wrong forge client for
multi-identity/multi-forge task routing. Fixed to use fg throughout.
- telegram.go: updateThreadID existed but was never called anywhere;
wired it into updateLoggingMiddleware so debug logs include thread_id.
- Two SA9003 empty-branch tests (nell adapter_test.go, tools
toolentry_test.go) were dead assertions with no body; implemented the
actual check instead of deleting them.
- memory manager_test.go: mockProvider.lastConfigSchema/lastBackupPaths
were declared but never recorded; wired GetConfigSchema/BackupPaths to
populate them and strengthened the aggregation tests to assert on
per-provider content, not just counts.
- Removed genuinely dead gateway messageevent_test.go helpers (intPtr/
i64Ptr, marked //go:fix inline, already fully superseded by the new()
builtin used throughout the file).
- Remaining errcheck findings (defer Close/Flush/Write, os.Setenv, etc.
in test files) fixed with the existing `_ = ` convention already used
elsewhere in the codebase.
go build ./..., go test ./... (all packages ok), and
golangci-lint run ./... all clean.
Implement the SendTimeout config field (previously silently ignored) via a
timeout-bounded write helper, and close two related races found during
adversarial review: Start()/Stop() could interleave across separate lock
acquisitions, and a subprocess spawned by a fresh Start() or a
crash-triggered restart could clobber a StateStopped already committed and
reported by a concurrent Stop(). Both spawn-commit paths now funnel through
a single guarded commitSpawnedProcess. Closes archie-core-abg.17.16,
archie-core-abg.17.23, archie-core-abg.17.41.
Checkpoint commit covering concurrent work across several archie-core-abg
epics to avoid losing in-progress state:
- Memory manager (18.7-18.16): background sync pipeline, prefetch with
timeout, memory-write notification, threat scanning, shutdown drain
with abandoned-write tracking, frozen snapshot pattern. Wired
ScanContent and NotifyMemoryToolWrite into HandleToolCall so scanning
and notification actually apply to writes, not just exist as unused
primitives.
- Fixed a literal unresolved merge-conflict that had been committed to
internal/memory/scrubber/scrubber.go.
- Tool provider/registry, MCP client/transport (stdio, HTTP, SSE),
multimodal results, disclosure.
- Pairing device auth store, rate limiting.
- Gateway compression, session store, tasks.
- Various workflow, plugin host, and agentexec updates.
Adds internal/secret: a pluggable Engine interface (Name/Version/Resolve)
resolved through a Registry, so secrets backends (sops, Bitwarden Secrets
Manager, Vault/OpenBao) aren't hard-coded into the binary. Only the "env"
engine is compiled in; custom engines are Yaegi-interpreted .go plugins
loaded via Registry.LoadDir, mirroring internal/plugin's conventions
(secretextract provides the generated, nil-guarded symbol table for the
Yaegi/Go interface boundary).
config.Forge.TokenEnv is replaced end-to-end with config.Forge.Token
(secret.SecretRef{Engine, Key}) -- finalize() defaulting, forge token
resolution in cmd/archied/main.go, and per-identity validation that now
requires an explicit token instead of silently resolving to "". No
backwards-compat shim.
Provider.APIKeyEnv, NATSConfig.TokenEnv, and TelegramConfig.TokenEnv are
deliberately not migrated here -- they're forwarded by name to
ai-sdk/runtime and subprocess workers rather than resolved centrally,
which needs its own eager-resolve-then-inject design pass
(archie-core-xec.4). The three shipped engine plugins (sops, bws,
vault/openbao) are tracked separately as archie-core-xec.1-3.
Adversarially reviewed by a fresh agent with no implementation context;
fixed the two findings that survived (missing per-identity token
validation, underdocumented nil-wrapper Resolve edge case).
internal/secret package:
- Engine interface (Name, Version, Resolve) for pluggable secret backends
- SecretRef type replacing TokenEnv/APIKeyEnv string fields
- ResolveOrEnv for backward-compatible env-var fallback
- Built-in env engine registered by default
- Registry with Register/Get/Resolve/LoadDir (yaegi-based)
- DefaultRegistry() singleton for one-off resolution
- 12 tests, race-clean
Scoped to foundation only. Provider/NATS/Telegram migration deferred
to xec.4 (separate bead — those call sites forward env var names to
subprocesses/runtimes and need eager-resolve-then-inject, not a simple
field rename).
40/40 packages pass with -race.
SessionStore extended with SaveMessage, RecentMessages, SearchMessages.
NellDB-backed implementation uses a separate DocDB collection for messages
keyed by session:seq. Conversation history loaded into LLM context for each
Telegram message. Responses persisted. Substring search fallback (vector
search deferred to memory provider embedding integration).
Adapter.Store() exported to share the underlying NellDB engine for session
collections without opening a second log.
Telegram LLMResponder now:
- Saves inbound messages to session store
- Loads 20 most recent messages as chat.Message history
- Sends full conversation context to llm.Chat()
- Persists the assistant response
All 38 packages pass with -race.
Memory:
- MemoryManager created in main.go with built-in file-backed provider
- SystemPromptBlock() injected into every agent stage request via ExtraRules
- memoryPrompt() helper on Daemon, threaded through TaskContext.SystemPrompt
Guardrails:
- GuardrailEngine created from DefaultGuardrailConfig in main.go
- RecordSuccess/RecordFailure called after every agent stage run
- Threaded through TaskContext.Guardrails for per-task guardrail enforcement
Tool registry:
- NewRegistry() created at startup, MCP servers started from config
- Passed to Daemon.ToolRegistry for dynamic tool discovery
Daemon changes:
- Memory, Guardrails, ToolRegistry fields added (nil-safe, backward compat)
- TaskContext gains SystemPrompt + Guardrails fields
- Agent stage injects memory context into ExtraRules
- Agent stage records guardrail state after each run
Telegram LLM routing deferred (TODO comment) — gateway commands work.
All 38 packages pass with -race.
- ToolCallGuardrailConfig + GuardrailEngine with RecordSuccess/RecordFailure
- ToolClassification bitmask (idempotent/mutating) with dispatch gating
- TurnBudget for token/char accounting with spill-to-disk
- AvailabilityCache with TTL + failure grace window
- Progressive disclosure engine for tool schema filtering
- Tool dispatch executor with parallel/serial classification
- RecordSuccess fix: now returns GuardrailDecision (no-progress threshold)
- All tests pass with -race, 58 new test functions across 6 test files
internal/memory/schema.go — normalizes memory-provider-exported
tool schemas between bare and wrapped OpenAI formats. Handles
both function-call wrapper objects and bare name+description+params
shapes. Converges to a consistent internal representation.
Resolve conflict in `.beads/` tracking files and scrubber implementation:
- Accept 8642f40's full implementation of StreamingContextScrubber with io.Writer interface, partial chunk boundary handling, nested tags, zero-alloc fast path, and comprehensive tests.
- Take incoming changes for issues tracking: close multiple verification tasks (18.10–18.13, 18.23–18.26) after adversarial review, update status for in-progress tasks (18.17, 18.18).
Pending bytes buffered while inside a <memory> block were unconditionally
emitted as literal text by Flush, leaking hidden memory-context content
into visible streamed output when a stream cut off mid-tag (e.g. "...secret</mem").
Track pendingInBlock at capture time so Flush discards in-block pending
bytes instead of emitting them. Also corrects stale doc comments claiming
underlying writer errors are surfaced (they're intentionally discarded).
Found by adversarial review of 18.10.
Stateful io.Writer that strips <memory>...</memory> fences from
streaming output, handling partial chunks split across tag
boundaries, nested tags, and missing closing tags.