configtemplate's package comment explained the module-root placement by
naming the embed directive in prose, which staticcheck reads as a
malformed directive (SA9009). Reworded, with a note saying why.
Found by running golangci-lint repo-wide while auditing 6108fc5, which
also showed that archie-core-qa4 reports 4/4 phases complete and offers
to close while 56 findings remain. Filed as archie-core-qa4.5 so the
epic's completion count reflects the gate rather than the phase list;
qa4.5 depends on archie-core-ts9, because the nilerr findings in grep.go
are the same swallowed-error bug and fixing them mechanically would
change tool behaviour.
Groundwork for archied setup owning config generation (archie-core-ewk),
so install.sh stops emitting a second copy of the config that drifts from
the example operators actually read.
configtemplate lives at the module root because go:embed cannot reach
outside its own directory and config.example.toml is kept at the root
where it is easy to hand-edit. tomlwrite applies setup answers to that
template in place, preserving the comments that make the generated file
readable - BurntSushi/toml round-trips values but not comments, so
re-encoding a decoded document would strip them.
The nestif extraction in 712388d pulled --provider handling out of
parseModelRest into a helper that took modelParts by pointer and
appended every surviving field to it. The caller's own loop appended
the same fields again, so every model name was doubled: /model gpt-5.6
asked the router for "gpt-5.6 gpt-5.6" and SetActiveModel rejected it
as unknown. The index loop becoming a range loop also stopped the
space-separated "--provider openai" value being consumed with its flag,
so it landed in the name too. Direct model switching over Telegram was
broken for everything but --refresh and provider-only switches.
splitProviderFlag is now the sole accumulator and returns the surviving
fields, so the shared-slice shape that allowed the double append cannot
recur (archie-core-0d6).
Found while auditing the remaining hunks of 6108fc5 (archie-core-ifi):
the naked return in the same function could not be regression-tested
until the function produced correct values. That audit is complete and
the other seven hunks are behaviour-neutral. Notably shell.go's
errorlint rewrite is not a repeat of the grep failure - it had no
companion exit-code condition to drop, and the ctx.Err() timeout check
already runs first - and find.go's errors.Is rewrite is safe because
errors.Is(err, nil) is false for any non-nil err.
Tests cover the return order of parseModelRest (two strings and three
bools, so a transposed pair compiles silently), the field count of the
model name, and shell's exit-code branch, which had no coverage at all.
The find fallback's habit of reporting a cancelled walk as "no matches
found" is filed as archie-core-ts9.
An unresolvable forge token aborted startup with exit 1, denying the
operator chat, the gateway and every other subsystem over a capability
they may not use -- and under the installed unit (Restart=on-failure,
RestartSec=5s) it crash-looped where the error was never read.
Forge setup moves into resolveForge, shared by the primary forge and
each configured identity, and degrades to NoopForge with a warning.
Malformed config still fails fast in validation. The systemd unit gains
StartLimitIntervalSec/StartLimitBurst as a backstop for other failures.
- Render [forge] from the answers given: the generated-config path
hardcoded the GitHub token key and the Gitea host, so a Gitea install
read a key the installer never wrote and a GitHub install pointed at
gitea.example.com. Both config paths now share one renderer.
- Read tokens with -rs so they stay out of terminal scrollback, and
replace rather than append env keys so a re-run does not leave the
revoked token in the file.
- Exit early on non-Linux instead of failing later in a heredoc.
- Never abort the install because the shipped source tree has local
changes; build what is on disk.
An errorlint autofix rewrote the ExitError check to match any exit
code, so a search that never ran (bad pattern, unreadable path) was
reported as "no matches found". Keep errors.As, restore the exit-code
check, and add a regression test.
The communication rules were entirely prohibitions, with nothing
licensing warmth. On a social turn there is no answer to lead with, so
"lead with the answer, keep it short" collapsed into a demand that the
user justify getting in touch: "are you there?" drew "I'm here. What do
you need?"
/stop cancelled the chat turn but could not touch a task the daemon was
executing, and /cancel refused outright:
case statusRunning:
return fmt.Errorf("task is actively running; cannot cancel
until it reaches a waiting state")
So the one case worth interrupting was the one case neither command
would touch.
The daemon now holds a cancel function for every executing task,
registered in process() -- the single point every dispatch path reaches
-- so a task is stoppable for its whole life, including the slow clone,
worktree prepare and image pull that is exactly when someone realises
they asked for the wrong thing.
- /cancel <id> interrupts the work first, then records the terminal
state. That order matters: writing the state while the task still runs
invites it to write its own afterwards and win. A task the store calls
running that nothing is executing (crashed daemon) still gets its state
recorded, which is what unsticks it.
- bare /stop now stops the reply, the queue behind it, and every running
task for the identity, reporting which of those it actually did.
Nobody reaching for the brake should have to look up a task ID first.
- StopRunning deliberately writes no terminal state: a stopped task
unwinds to parked, which is resumable. Forcing rejected would discard
work worth keeping.
- Without a runtime wired, cancelling a running task is still refused --
recording it as cancelled while it carries on would be a lie.
Container teardown detaches from the task context. Release runs on the
way out, and the main reason a task is on its way out is cancellation --
at which point the graceful ContainerStop failed instantly and the
container was left to the forced remove. Cleanup gets its own deadline.
process() gained two statements and crossed the funlen limit, so the
container setup block is extracted rather than suppressed.
Add internal/tools/command: an always-on floor under the shell tool,
enforced in the provider adapter so the lifted tau files stay diffable.
This is not a security boundary and does not pretend to be one. Anything
with a shell has countless ways past a rule list. What it buys is that
the failures with no recovery -- where you cannot intervene afterwards
because the machine, the filesystem, or the gateway itself is gone --
are not reachable by an ordinary mistake.
Rules: recursive delete of / and system directories, mkfs, raw block
device writes, fork bombs, kill -1, shutdown/reboot/init/systemctl
power, and sudo -S with no SUDO_PASSWORD configured. Two more are
archie's own: an agent must not stop the daemon that hosts /stop
(pkill/systemctl/docker), nor start a second one outside the supervisor.
The parsing is the actual work. Patterns are anchored to command
position, so `git commit -m "revert the rm -rf / change"` and
`echo "rm -rf /"` are ordinary commands, while `echo x; rm -rf /` and
`$(rm -rf /)` are not. Quoting, separators, ${VAR} braces, environment
assignments and privilege wrappers are all parsed rather than matched.
Probing the first version found two bypasses that made every rule
optional, both of which a model writes unprompted rather than only an
attacker: `bash -c "rm -rf /"` and `xargs rm -rf /` hide the command in
an argument. Segments are now followed into shell -c payloads, eval, and
command wrappers (xargs, timeout, nice, env, nohup, ...), bounded by a
nesting limit. Tests cover both directions -- the refusals and, at equal
length, the ordinary commands that must not trip them.
shell.go relied on exec.CommandContext's default cancellation, which
kills only the process it started. A shell's real work is a child of
that shell, so cancelling `go test ./...` reaped the shell and left the
test binary running, and `nohup x &` was never touched at all.
That made /stop a lie for the case it exists to cover: the turn
unwound, the user was told it stopped, and the command carried on.
Worse than expected, and caught by writing the test first: without a
process group the tool does not merely fail to kill the command, it
hangs. The backgrounded grandchild inherits stdout, so cmd.Wait blocks
until the shell timeout regardless of cancellation. Verified by
reverting the fix -- the new test fails on a 30s hang, not on the
survival assertion.
Run the command as its own process group, signal the group on
cancellation, and bound Wait with WaitDelay so an inherited pipe cannot
hold the turn open. setProcessGroup/signalProcessGroup were already
present in the lifted set, used by tau's agent.go but not its shell
tool; this extends them to the shell and clears the unused-code lint
that was flagging them.
Recorded as a mutation in shell.go's provenance header.
/stop could not reach a running turn, and the reason was worse than a
missing cancel. go-telegram/bot runs one update worker that calls
handlers synchronously (defaultWorkers = 1, never overridden), and the
chat turn ran on it. While a turn streamed -- or sat in a shell tool --
the worker was blocked and /stop sat unread in the update channel until
the turn it was meant to kill had already finished.
Add gateway.Turns: a per-session serial lane that turns are submitted to
and that the event loop never waits on. The worker is free again in
microseconds, so /stop is serviced immediately; ordering comes from the
lane being serial rather than from the loop being blocked.
- Bare /stop cancels the running turn and clears the backlog behind it,
with no approval step. Approval guards destructive commands, and
gating the brake behind a confirmation defeats it. /stop <name> keeps
the existing process-termination behaviour and its approval.
- Cancellation propagates through the turn context, so it reaches the
model stream and any tool underneath -- a shell command built with
exec.CommandContext dies with the turn.
- Queues are unbounded and never shed. A dropped message is a silent
failure that surfaces later as an agent that ignored something.
- Turns are recovered per-lane: the channel's panic middleware wraps the
event-loop goroutine, which no longer runs the turn.
Also raise the chat step budget. It was hardcoded at 8 -- roughly one
read, one grep and two edits -- so turns hit the cap and stopped
mid-task with no indication they had been cut off. It is now
chat.max_steps, defaulting to 100. Interruption is /stop's job.
The chat agent had two tools -- memory_edit and skill_activate -- so it
could not read a file, search a tree or run a command. ai-sdk's runtime
already drives a tool loop for it (MaxSteps 8, toolExecute wired as the
executor), so the loop was never the missing piece: the registry was empty
of anything useful.
Lifted from tau internal/agent/tools at commit f5289ea, per the recorded
copy-and-mutate strategy: every file carries a provenance header naming its
tau source path, the commit, and the mutations made, so refreshing from
upstream is a diff rather than archaeology.
internal/tools/builtin/ the lifted tools, ~3.1k lines
internal/tools/provider/builtin/ the adapter to tools.ToolEntry
Six tools: read, write, edit, shell, grep, find. Tau's own tests came with
them and pass unmodified, which is the evidence that the lift is faithful.
Deliberately not lifted:
- agent.go (1214 lines): subagent spawning, and the only real coupling in
the package -- 10 tau packages including chat, sessions, store and
registry. Nothing the chat agent needs to do work.
- skill.go: depends on tau's skills package; archie has internal/skill and
already exposes skill_activate.
- docs.go: serves tau's own embedded documentation via tau/docs.
Not lifting the coordinator either. It is tau's agent loop (6.4k lines over
ten packages) and archie already has one in the ai-sdk runtime; porting it
would leave two loops competing. Its cancellation and tool events are worth
having, but they are a few hundred lines built against the existing path
rather than six thousand lifted onto a second one.
The adapter bridges two shape differences: archie hands handlers decoded
arguments where tau's executor takes raw JSON, and tau reports tool-level
failure in Result.IsError rather than as an error -- surfaced as a real
error so the runtime and the guardrail engine both see it. Tools are
classified idempotent or mutating for guardrails and budgets; that is
categorisation, not a jail.
chat.workspace roots the tools and defaults to empty, which registers none
of them. They read, write and execute, so the directory has to be a
deliberate choice rather than whatever the daemon started in -- in the
container that is /.
Verified: go build, go vet, gofmt clean; full suite passes.
Three defects found from a real Telegram transcript.
1. The operator's name was compiled into the prompt.
internal/gateway/persona.go and prompt.go both hardcoded "Sam's" into the
default persona and the fallback prompt. The persona renders first into
every system prompt, so a personal name was sent to the model provider on
every turn, and any other deployment got an assistant that believed it
worked for someone else. There was nowhere to put it: Repo.Owner is a repo
owner and config.Config had no operator concept.
ChatConfig.Operator now carries it, rendered in the prompt's <env> block as
runtime metadata and omitted entirely when unset. config.example.toml
documents that setting it sends the name to the model provider.
2. /new claimed to clear history that it had not cleared.
The chat responder keyed history by channel id through a local sessionKey
helper, while the session commands operate on tracked session ids.
sessionTracker.resolve mints deterministic ids so the two agree -- until
/new, /branch or /resume assigns a generated id, after which they address
different histories permanently. /new reported "Conversation history has
been cleared" while the next turn still saw everything, and /undo,
/compress, /resume and /sessions acted on a namespace the conversation
never read.
gateway.Router.ResolveSessionKey already existed for this, and
session_commands.go:104 said outright that main.go should call it instead of
its inline helper. It never got wired. The responder now resolves through
the router and the dead helper is deleted so it cannot come back.
buildTelegramRouter constructs the router before the responder so the
dependency is visible rather than captured by reference.
3. Prompt rules for two behaviours the transcript showed.
The agent offered to accept shell access it has no tool to use, which is
both unhonourable and a request for the user's secrets. It also opened
mid-conversation replies with a greeting, and described its own manner
("no fluff") in stock phrasing. Added core rule 7 and three communication
rules covering greetings, self-description and register.
Note the memory claim in that transcript was NOT a fabrication: the
memory_edit tool's own description names MEMORY.md and USER.md, and tool
descriptions are part of the prompt.
Also added chat-turn logging (session id, channel, thread, history depth).
Chat turns were entirely unlogged, so a report of lost context had no
evidence to check: 76 log lines covered two days and none of them was a
conversation. A separate report of mid-conversation amnesia remains
undiagnosed -- single process, 43h uptime, compression untriggered at three
messages -- and this is what makes it diagnosable next time.
Regression tests: prompt renders/omits the operator and carries no personal
name; the responder resolves via ResolveSessionKey and defines no local
session key helper.
Verified: go build, go vet, gofmt clean; full suite passes.
dependencies-and-contracts.md rule 1 says domains must not import
internal/infrastructure. internal/daemon and internal/agentexec both did,
and for exactly the thing the doc carves out: "internal/eventbus is an
approved shared application contract ... it MUST remain broker-neutral."
The Publisher/Consumer/Requester interfaces existed but lived inside the
NATS package, so a caller could depend on the behaviour yet still had to
import the implementation to name it. They now live in internal/eventbus,
and nats.Client asserts against eventbus.Bus.
The larger violation was ownership of meaning. The doc says "message schemas
stay with their owning domains; the event bus transports messages, it does
not own their meaning." The bus exported TaskEnvelope and a PublishTask
method, so the transport knew what a unit of work was, and it exported the
archie.agent.* subject helpers, so it also owned the agent protocol.
- TaskEnvelope, its routing Kind, the label vocabulary and the task
subjects move to internal/domain/workintake, which encodes and decodes
its own bytes. This starts internal/domain/ per organisation.md.
- The agent request/response/system subjects move to internal/agentexec,
which defines what those messages mean.
- internal/workflow keeps only the kind-to-registry mapping; the label
table stays single and lives with the domain that reads forge issues.
- The bus now carries opaque payloads on plain-string subjects.
Consumers declare the smallest interface they need rather than taking the
whole Bus: daemon.TaskBus is publish-unique/fetch/request, agentexec.
RequestBus is publish-request/reply-inbox, and archie-agent's stageBus is
fetch/respond. None can reach what it does not use.
Two defects this surfaced:
- archie-agent declared its own JetStream stream with a second copy of the
name, subjects, retention, dedup window, MaxDeliver and TTLs that
nats.Connect already sets -- two definitions of one stream, free to
diverge. Config now takes Subjects and FilterSubject from composition,
which is what let the agent use the shared client and delete its
hand-rolled setup.
- Replying to a request needs core NATS, not the JetStream publish path:
a reply inbox is ephemeral and belongs to no stream, so a durable
publish to it fails. The old code hid this by using the raw connection.
The contract now distinguishes Respond from Publish. The agentexec
round-trip test caught it after I had made the same mistake in
archie-agent.
Also translated the SDK's ErrNoResponders into eventbus.ErrNoResponders, so
the daemon's taskrun retry no longer imports the NATS SDK to name a
transient condition. The SDK is now confined to the nats package, the *rpc
packages (themselves NATS infrastructure), and cmd/*.
The agentexec test fake previously hand-rolled a JetStream consumer; it now
drains the client's own consumer, which is both closer to production and
avoids conflicting consumers on a work-queue stream.
Verified: go build, go vet, gofmt clean; full test suite passes.
The gateway work added /whoami, /profile, /sessions, /resume and /agents as
executable commands; TestPublishedCommandsMatchExecutableCommandSurface
correctly caught that they were undiscoverable. Two workers touching a
coupled surface -- the test is the thing that noticed.
These five command handlers were dropped during parallel merges of the
Telegram workers; the Router fields they depend on (Identity, Models,
Sessions, Agents) were already in place.
/new, /reset, /topic, /retry, /undo, /title, /branch, /fork, /compress,
and /compact are executable via the gateway router but were missing
from gatewayCommandSpecs, making them undiscoverable in Telegram's
command menu and /help output.
internal/config both defined the types every package imports and performed
the file I/O to produce them. Importing a settings struct therefore pulled
in a TOML decoder and a YAML decoder, and the shared model owned discovery,
decoding, overlays, defaulting and validation all at once. See
docs/architecture/configuration.md, which requires loading to move out and
internal/config to be dissolved.
internal/config is now types only -- no os, no filepath, no toml. The new
package owns loading, one concern per file:
features.go the closed set of recognised feature files
discovery.go directory scan and classification
decode.go TOML/YAML decoding, format dispatch
defaults.go filling absent values, no errors
validate.go judging supplied values, no mutation
provenance.go which file contributed what
loader.go Loader wiring the above; File/Overlay/Dir
Beyond relocating, this fixes what the old code conflated:
- Defaulting and validation were interleaved. applyAgentDefaults and
applyDispatchDefaults returned validation errors; validateContainers and
validateSingleIdentity quietly mutated the config. There was no point at
which you could see what the operator actually supplied. They are now
separate passes: applyDefaults never fails, validate never writes.
- Errors were fmt.Errorf strings prefixed "config: ", so a caller could not
distinguish operator-fixable input from an unreadable file without
matching message text. Five sentinels now carry that distinction.
- dataHome() read XDG_DATA_HOME directly and discarded the error from
os.UserHomeDir, so defaulting could not be tested without the
environment. It is injectable on Loader and no longer swallows the error.
- Nothing recorded where a value came from. With overlays, feature files
and conf.d/ all able to set the same field, "which file set this?" was
answerable only by re-deriving precedence by hand. Provenance records it.
- Feature files were applied in map iteration order, making load order and
any resulting error arbitrary. Discovery now returns them sorted.
- loadMainConfig reported "no config.yaml or config.toml found in %s" with
an empty string: the directory was lost when it was extracted from
loadDirInto, so the error named no directory.
- Unreadable or malformed conf.d/ extras were skipped silently, which
presents as a setting the operator wrote simply not taking effect.
- Decode errors from the main config were returned bare, without naming
the file that failed to parse.
The 40 loader tests moved with the code and their assertions are unchanged,
so the defaulting and validation rewrite is behaviour-preserving.
Document.Config is the temporary seam: still internal/config.Config, named
as a field so the compromise is visible at each use site, with its deletion
condition recorded in doc.go. Building typed per-domain sections now, while
every consumer still reads config.Config, would mean two shapes kept in sync
by hand with no consumer for the new one; that belongs with the dissolution
work, not ahead of it.
No consumer outside cmd/archied changed.
Verified: go build, go vet, gofmt clean; go test ./internal/config/... and
./internal/infrastructure/configuration/... pass. Pre-existing gateway and
telegram failures are unchanged.
RegisterAll returned as soon as nc.Subscribe had queued each SUB frame on
the client. Delivery to the server is asynchronous, so a caller that
registered a responder and immediately issued a request could beat its own
subscription and get nats.ErrNoResponders from a responder that was, by
then, listening.
This made TestRunTaskExecutesBootstrapWorkflowEndToEnd flaky in CI: it
passed in isolation and failed under full-suite load, when the scheduler
was contended enough for the request to win the race.
Flushing after subscribing gives Register a real guarantee -- a nil error
now means the subjects are reachable. That applies to production startup
too, not just tests: archied registers storerpc, forgerpc and worktreerpc
the same way.
The duplicated rollback loop is now a single unsubscribeAll closure, which
also becomes the returned unsubscribe func.
Verified: three consecutive full-suite runs with no archie-agent failure,
plus five targeted runs of the rpc packages. Remaining gateway and
telegram failures are pre-existing and unrelated.
The event bus was inspecting forge issue labels ("bug", "feature",
"bootstrap") to pick a subject. That put a forge vocabulary inside
infrastructure and duplicated the label table already owned by
workflow.Route -- adding a label meant remembering both places, and
nothing would have caught it if you forgot.
The label table now lives once, in internal/workflow, which already owns
label semantics:
- workflow.Kind names the routing category, with labelKinds as the
single label vocabulary and kindWorkflows mapping kind to registry
entry. Route consumes the ordered kind list so a "bug,feature" task
still falls through to feasibility when no tdd workflow is
registered, exactly as the switch did.
- nats.TaskKind is a closed, validated set of subject tokens.
PublishTask rejects an unknown kind rather than silently delivering
it to the default queue; the zero kind means default, so messages
queued before this field decode unchanged.
- The daemon classifies at the publish site and sets TaskEnvelope.Kind.
Also fixes two defects this exposed:
- drainNATS never reached its SQLite fallback. Replacing the old
(nil, nil) no-message signal with ErrNoMessage in 492ca20 made that
case continue at the top of the loop, but no-message is precisely
when the fallback must run -- requeued tasks (waiting_human approval,
retry-parked) never go through a NATS publish, so nothing would ever
arrive to trigger them. go vet caught it as unreachable code.
- config.classifyFeatureFile silently overwrote duplicate feature
files, so config.gateway.yaml and conf.d/gateway.yaml together
applied one at random. Its own doc comment recorded the bug
("or "" on success/duplicate"). The known-feature list in the error
message is now derived from knownFeatureNames instead of being
spelled out a second time beside it.
A test also called t.Fatalf from a non-test goroutine, where it does not
stop the test.
Verified: go build, go vet, gofmt clean. Pre-existing gateway (18) and
telegram (1) failures are unchanged in count -- they are lost routing
wiring from the parallel telegram merges, tracked separately.
Relocating internal/nats as-is would have cemented its problems into the
approved layout, so this is a rewrite rather than a move.
What was wrong:
- Conn() *nats.Conn, PublishMsg(*nats.Msg) and Fetch() jetstream.Msg pushed
SDK types into all four consumers, so the broker was not replaceable --
the opposite of what dependencies-and-contracts.md requires.
- PublishTask took seven positional parameters, six of them strings, where a
transposed argument was a silent bug.
- Labels travelled as a comma-separated string and were re-split on every
publish.
- Fetch returned (nil, nil) for 'no message', which every caller had to
remember to special-case.
- The logger field was stored and never used.
- Stream name, consumer name and every timeout were hardcoded constants.
- Errors were inconsistently wrapped; several paths returned bare errors.
- Connect repeated nc.Close() on each failure branch.
What replaces it:
- One concern per file: config, errors, subjects, message, client,
publisher, consumer.
- Publisher/Consumer/Requester interfaces with compile-time assertions, so
callers depend on behaviour and can be faked without a broker.
- A Message wrapper keeps jetstream types behind the boundary; consumers no
longer import the NATS SDK at all.
- TaskEnvelope with []string labels and JSON methods preserving the
comma-separated wire form for already-queued messages.
- Sentinel errors (ErrNoMessage, ErrNotConnected, ErrNoReplyAddress,
ErrInvalidConfig) and %w wrapping with operation context throughout.
- Config with validation and defaults; a single deferred cleanup in Connect.
- CoreConn() as the one documented escape hatch, for the *rpc packages that
are themselves NATS infrastructure.
Consumers migrated: cmd/archied, cmd/archie-agent, internal/daemon,
internal/agentexec. Behaviour, subjects and wire format unchanged.
- bodyclose: add deferred resp.Body.Close() in storage_test.go Docker test handler
- contextcheck: thread context through email handleSMTP/processMessage; replace
context.Background() with context.WithoutCancel(ctx) in telegram, webhook, webui
shutdown paths and container pool cleanup; add ctx parameter to Pool.Release
- containedctx: replace ctx context.Context struct field with stopCh chan struct{}
in StdioTransport and SSETransport; thread lifecycle context through goroutine
chains instead of storing it in structs
- fatcontext: lift context deadline derivation out of PrefetchContext loop