Commit Graph
212 Commits
Author SHA1 Message Date
sam 50d96b4d28 fix(eda): tie module results to checker and tighten action ids 2026-09-22 09:22:45 +10:00
sam d26ba54e77 feat(eda): wire action playbooks through loader and module schemas
Pass 2 of archie-core-nx30. Pass 1 typed each prior action's result in
the CEL env; this pass wires that typing through the loader, module
schemas, and daemon, and removes the now-redundant id classifier.

Loader shape (D2): one playbook is exactly one workflow action
(unchanged) OR one or more module actions; the shapes never mix. Mixed,
unsupported, or zero actions fail the load naming the playbook.
playbook.Load now takes a KindSchemas source (a small interface this
package defines, satisfied by *module.ModuleRegistry) so playbook grows
no module import. Callers: bootstrap.loadEDAPlaybooks passes b.modules;
daemon and playbook tests pass module.New().

Per-playbook env (D3): each action's when and args values compile against
an env built from the PRIOR actions' ids typed by their kinds' Result
structs (expr.NewEnv(DeclaredResult{ID,Type})). event stays dyn. An
undeclared id, a forward reference, or a field the kind's Result lacks is
a compile-time undefined-field error.

Args schema (D4): an args key the kind's Args struct does not define
fails the load. An args VALUE whose compiled type mismatches the field
type is left as a named gap (not cheap without leaking cel-go type kinds
into playbook and handling dyn reads); a wrong-typed value still surfaces
at module invoke, not load.

D1: Store.Dispatch routes workflow playbooks only, so an action playbook
cannot hijack the definition pin. bootstrap.loadEDAPlaybooks logs a
visible Warn (not debug) for each loaded action playbook naming it and
stating it does not execute yet.

D5: ModuleRegistry.Invoke is deliberately schema-agnostic (the stored
invoker is type-erased and returns map[string]any). The map-to-Result
marshalling belongs in the coordinator named by the doc, which is the
t2db.31 run path and out of scope here.

Classifier enumeration (E) and verdict, all proven for a typed action
playbook via CEL (expr.NewEnv with a declared log.Result id):

  unknown id                        CEL compile (undefined field)       -> delete unknownActionReference
  literal map index actions["x"]    CEL compile (no _[_] overload)      -> covered
  computed index actions[key]       CEL compile (undeclared 'key')      -> covered
  dynamic index actions[event.name] CEL compile (no _[_] overload)      -> covered
  "x" in actions                    CEL compile (no @in overload)       -> covered
  size(actions)                     CEL compile (no size overload)      -> covered
  actions.all(...)                  CEL compile (not a range)           -> covered
  actions == {}                     CEL compile (no _==_ overload)      -> covered
  bare actions                      compiles; KEPT classifier           -> retained resolvable check

unknownActionReference is deleted; actionReferences/ActionReferences are
kept solely for the bare-actions spelling CEL does not reject.
2026-09-22 09:02:33 +10:00
sam 3fd9b4f353 feat(messaging): route a channel reload, and refuse one that cannot reload
archie-core-np7l's service half -- the reload action and its truthful refusal. The
request surface that carries the instruction from the dashboard is its own change,
because it is its own object with its own lifetime (the reasoning is recorded in
docs/architecture/migration-decisions.md).

Service.ReloadChannel routes to the channel's own seam rather than reimplementing
it: the telegram front-end re-reads its token and allowlist, which is what its own
/restart path calls. A channel that cannot reload is refused with a reason instead
of accepted and ignored, because the dashboard offers the action on the strength of
the capability the descriptor declares, and an accepted-then-nothing reload is a
lie the operator cannot see through.

The capability and the action now come from one source. Before this a descriptor
declared ReloadSupported by NAME, so a channel could announce reload support and
have nothing behind it; reloadable() decides both, and the descriptor test builds
a real gateway with a seam rather than a fake named "telegram".

Verified: task check exit 0. Coverage: the refusal names the reason for a channel
that declares no support and for an unknown channel; the service reaches telegram's
own reload seam and the re-read config lands; and the declaration and the action
cannot drift, which is asserted by reloading every composed channel and requiring
the refusal specifically to be "does not support reload" -- a declared reload may
still fail on the configuration it re-reads, and that is a different fact.
2026-09-22 08:15:32 +10:00
sam aa300d7631 fix(archieui): let the boundary guard permit a contract-backed channel reader
The UI boundary test forbade wiring Server.Channels, and it was right about what
the field used to hold: a live *status.Manager is a runtime handle this process has
no business owning. It now holds a reader over the State Store's channel-status
contract, which is the same shape as the Mappings, Bindings and ApplyStatus fields
the guard already expects to be wired. The distinction it draws is the handle, not
the name, so the assertion moves with the field and says why.

Also adopts task fmt's rewrite of the reader's status construction: go fix drops
the explicit embedded Descriptor, and formatter output is law here.
2026-09-22 08:10:01 +10:00
sam bf0627dbdf feat(state): carry channel lifecycle from the Messaging Service to the dashboard
archie-core-8cda.6.8's carrier. The service now records channel lifecycle and has
nowhere to put it: /api/channels answered with nothing because
webui.Server.Channels had no production source, and reload answered 501 for the
same reason. This adds the surface the register decided on, following the split
archie-core-ymut established for config snapshots -- a pair of administrative RPCs
whose writer is one process and whose reader is the UI -- and wires both ends.

Wire and store: PutChannelStatus / ListChannelStatus, with ChannelStatus carrying
id, name, state, detail, configured, reload_supported and observed_at. The store
holds one row per channel and replaces the reported set, so a channel the reporter
no longer mentions is deleted rather than left standing as a stale "running"; an
empty report clears the table, because hosting no channels is a fact worth
reporting. A row without an id is refused: it could never be replaced or removed
by a later report.

Writer: the service publishes on every lifecycle transition through a coalescing
signal -- a burst of transitions is one write, since a reader only wants the latest
state of every channel -- plus a start-up report and a final report after shutdown,
so a stopped service leaves the store honest. A failed write is logged and retried
on the next signal; the dashboard losing channel state is worth a warning and never
worth failing a channel start over.

Reader: webui.Server.Channels becomes a source rather than a concrete manager, and
webui.RemoteChannelStatus reads the store the way RemoteConfigView reads the config
snapshot. A store it cannot reach reports nothing rather than a stale "running",
and a state the reader does not recognise is carried through rather than dropped.

The contract's own index gains the group in the same change that adds the RPCs --
a surface the grouped table does not list is one nobody finds -- and the count moves
to 51. The register records why the surface is the State Store rather than a
resource kind, and why reload gets its own surface rather than a field here: reading
status must not be able to retrigger an action, a transient request is not
distinguishable from state once anything polls it, and it would invert the
writer/reader relationship the precedent establishes.

Verified: task check exit 0. New coverage: the store's replace-the-set semantics
and its refusal of an id-less row, the reader's mapping including an unknown state,
and the publisher's start-up, transition and final reports.
2026-09-22 08:04:44 +10:00
sam 4f9e446ad6 feat(messaging): record channel lifecycle, and decide its surface
archie-core-8cda.6.8's producer half. The service handed every channel an empty
channels.Lifecycle{}, so starting, running, failed and stopped were recorded
nowhere and internal/channels/status.Manager -- which has had MarkStarting,
MarkRunning, MarkDegraded, MarkFailed, MarkStopped and Snapshot all along -- had no
production writer at all. The channels have always reported: all three call
ReportStarting and ReportRunning on whichever lifecycle they are given.

Each composed channel now gets its own report into a manager keyed by channel, so
one channel's failure marks only itself; a channel that cannot start is marked
failed with its reason rather than only logged, and a channel that returns is
marked stopped. Service.ChannelStatus is the producer a dashboard surface reads.

Left open deliberately: the cross-process carrier, and reload's direction.
docs/architecture/migration-decisions.md records the shape by the precedent the
contract already establishes -- archie-core-ymut's config snapshot is "the one
surface whose writer is the daemon and whose reader is the UI process", a pair of
administrative RPCs deny-by-default under authorizesTaskScopedCall -- and names
what that settles: channel state is runtime state rather than a settings document,
so it does not belong among the ControlPlaneService's validated resource kinds; the
UI already dials the State Store and pumps its cursor, so no new transport is
needed; and the contract PRD's grouped table gains a group in the same change that
adds the RPCs. Reload runs the other way and is left as a named open question
rather than decided by analogy with a status report, because a request queue and a
status report do not have the same lifetime. It also records that 8cda.6.9's
component self-report is the same shape, so the two do not become two homes for
"what a component reports about itself".

Red-proofed: restoring the empty lifecycle fails TestServiceRecordsChannelLifecycle
with "channel webhook never reached running; last report State:configured", so the
test pins the fix rather than the manager's existence.

Verified: task check exit 0.
2026-09-22 07:57:29 +10:00
sam 012ccc7d98 test(messaging): add the end-to-end channel smoke verification
archie-core-8cda.6.5's remaining half. The gate landed in b4358c53; what was
missing is the verification that the extracted service actually carries a message.

It drives the deployed path -- compose, the real webhook adapter, a real listener,
a real signed HTTP request -- and asserts on what crossed the chat contract as well
as on the reply the caller receives back, which DeliverTo=origin routes through
that contract. The envelope assertions are the three transport facts this channel
must carry, each of which has a reason recorded elsewhere: platform "webhook" is
how the Gateway learns which channel it serves (archie-core-c1qx); SenderID stays
empty because a route path is a source and never a person (archie-core-oyna); and
the route survives as the budget key, so the inbound limit still applies.

Webhook is the only channel a test can own. Telegram needs a bot token and the
Telegram API, email needs SMTP, so neither can be exercised here. The PRD's fourth
criterion asks for a live Telegram round trip "or equivalent channel smoke test",
and this is that equivalent: every step between the POST and the contract is the
deployed code path. The gRPC hop beyond the contract is covered by
internal/infrastructure/gatewayrpc's conformance tests, which run the same client
and server in both local and remote mode.

Red-proofed rather than assumed: signing the request with the wrong secret fails it
with "status = 401, want 200", so the signed path is genuinely exercised rather
than bypassed.

Also carries 1513b0a2, the migration register's correction, which was committed
unpushed on purpose so it would ride a code change rather than re-stamp :latest on
its own.

Verified: task check exit 0.
2026-09-22 07:50:26 +10:00
sam b4358c5324 refactor(messaging): sever the Messaging Service from the store and workflow runtime
The PRD's deletion gate for the Messaging Service could not pass: go list -deps
./cmd/archie-messaging linked modernc.org/sqlite, internal/store,
internal/domain/workflow and internal/agentexec -- all through one import,
archiemessaging/run.go -> internal/app/controlplane, from which the service used
three symbols. The decision was to sever rather than amend the gate, because a
boundary you whitelist around is no longer a boundary (archie-core-1ng1, recorded
in docs/architecture/migration-decisions.md).

Measured before touching anything: internal/app/controlplane was the ONLY direct
import of the service that dragged those runtimes -- every other one was clean --
so severing this one dependency is sufficient for the gate.

Moved into the new internal/infrastructure/controlplanerpc: the generic resource
client (NewRPCClient, Query), the RuntimeChatConfig projection, the reader
interface (now the exported ResourceReader), the wire sentinels, the status
mapping (now ClientError), and the channel-settings document with its decode --
ChannelSettings, TelegramSettings, WebhookChannelSettings, EmailSettings,
RateLimitSettings, ChannelDuration, DecodeRenamingLegacyKeys.

internal/app/controlplane keeps the store-backed server, the Definition registry,
every kind's seed/validator/Normalize, the schema derivation, and its
resource-specific reads and watches. Its Client embeds the new one, so the read
path has one implementation while the workflow, persona and cronstore reads stay
with the processes that already link those engines. The documents are type-aliased
back into this package so the store-backed side reads them by the names it has
always used: one definition, not a copy on each side of the boundary.

The gate is now enforced by cmd/archie-messaging/architecture_test.go, measuring
the linked binary against the PRD's banned list, with one exception checked in
both directions: internal/domain/workflow/task, the Task status and view
vocabulary whose own dependency set holds none of the banned runtimes. The UI gate
carries the same entry for the same reason, and the fleet skill names it as the
precedent.

Verified: task check exit 0. The gate was red-proofed twice -- banning
internal/channels fails it, and removing the workflow/task exception fails it --
so neither the loop nor the exception is decorative.
2026-09-22 07:26:55 +10:00
sam 8395605d0b feat(eda): evaluate action args as CEL expressions (J2) 2026-09-22 05:56:26 +10:00
sam f31481e594 test(eda): pin playbook dispatch ledger docs and regression gaps 2026-09-22 04:51:17 +10:00
sam 49b6f708da fix(eda): wire playbook dispatch ledger and validate its key 2026-09-22 04:36:28 +10:00
sam c8dbeebe83 fix(gateway): stamp the session platform from the channel that carried the message
One Router serves every channel and named itself "web", so Source.Platform -- the
FIRST component of the session natural key, and the platform GetByChannel filters
on -- was a constant, true of no channel but the dashboard. Two consequences
followed: the per-user identity policy was real code that no production call site
reached with a real channel name, and a curator pass's write to agent-user memory
could not be read back by the turn that wrote it, because that turn resolved no
UserID.

The channel now travels with the message. Frontends name the channel they carry
(pb.Message.platform: telegram, email, webhook, web), and the Gateway stamps the
session from it, falling back to its own name when a sender names none -- which is
what every existing row holds and what a frontend that does not participate keeps
doing.

Identity resolution reads the platform off the inbound rather than closing over a
channel name, so carriesPersonIdentity finally decides something in production:
telegram and email resolve a person, the dashboard and a webhook resolve nothing,
and an unknown platform fails closed.

Deliberately NOT changed, because it is where this could quietly widen scope:
TurnRunnerConfig.Channel still keys tool availability, so no channel gains or
loses a tool here. Only session lookup and identity follow the message's platform.

Consequence the maintainer accepted: a chat whose active session came from /new or
/branch re-resolves once, since GetByChannel now filters on the channel's name. A
chat with no /new re-resolves onto the same deterministic session id and heals
silently.

Verified: gateway, archied, gatewayrpc, messaging, webui, channels and cmd suites,
go vet ./..., go build ./..., golangci-lint run ./... (0 issues), docs:check.
New contracts: TestResolveSessionKeyStampsTheMessagesPlatform, the per-platform
identity table, and the transport-context wire round trip.
2026-09-22 04:30:15 +10:00
sam f29169c2cf fix(cronstore): write a schedule interval as a duration, not nanoseconds
The schedules document stored interval as a bare time.Duration, so its JSON was
the nanosecond count -- 1800000000000 for thirty minutes -- and the Web UI, which
now derives field metadata from the document type, correctly rendered a number
input. Same defect 02rm fixed for rate_limit.window, in the second stored time
this tree has. Nobody should be asked for a count of nanoseconds to configure a
schedule.

cronstore.Duration writes the string time.ParseDuration reads and reads that, a
nanosecond count, and nothing else: every schedule stored before this shape
existed carries a count, in both the control plane's schedules resource and this
package's own jobs table, which persists the spec as JSON. A value that parses as
neither is refused rather than decoding as zero, because a zero interval is a job
that never fires.

The derived schema needed no change and gets it for free -- which exposed a fix
the derivation itself needed: it classified durations by NAME, so cronstore.Duration
derived as an integer. durationLike now asks the type instead -- does it expose the
standard duration, and does it marshal as a quoted string -- so the next duration
type is classified correctly rather than silently rendering as a number box. That
failure mode was invisible until a live daemon showed it.

normalizeSchedules already re-marshals, so a stored document converges on its next
write while reads keep tolerating the count.

Verified: cronstore, crondelivery, controlplane, scheduling, webui and archied
suites, go vet ./..., go build ./..., golangci-lint run ./... (0 issues),
docs:check. Against a live daemon (8484): the catalog serves schedule.interval as
{type: string, format: duration}.
2026-09-22 04:22:46 +10:00
sam 55ea071092 docs: drop one host's service names from port guidance
Five files named a specific host's service and the port it holds as the
reason a deployment might move the state store's listen address, including
config.example.toml, which ships to every operator. The guidance keeps its
point -- move the listen/target pair together when a port is already taken
on the host -- without naming a service the reader may not run, or have
heard of.

Also corrects the Taskfile's dev-stack summary, which still described the
state store as binding 127.0.0.1:9090. deployments/dev.toml pairs it with
9091, and has since the pair became configurable, so the comment described
a stack that does not start.
2026-09-22 04:09:16 +10:00
sam 4225036afa test(controlplane): pin a bare time.Duration as an integer, not a duration
schemaFixture covered config.Duration and channelDuration, both of which marshal
as the string time.ParseDuration reads, but not a bare time.Duration, which
marshals as its nanosecond count. The derivation already distinguishes them by
named type rather than by kind; this pins it, because the failure mode is a
client rendering a text box for a number, and the schedules document has exactly
that field (cronstore.Schedule.Interval).
2026-09-22 03:56:19 +10:00
sam 89d2d0e1ba chore(controlplane): adopt go fix's rewrites in schema.go
task fmt is not a formatter: it runs go fix to a fixpoint and then
golangci-lint's formatters, so a package can be gofmt-clean and still
go-fix-dirty. The merge train's full gate on 6ba10c0b caught exactly that and
rewrote this file -- reflect.TypeFor[T]() in place of reflect.TypeOf(T(0)), the
t.Fields() iterator, and maps.Copy over a manual key-by-key copy.

Adopted verbatim; formatter output is law here. The remaining stages of that
gate ran against this content, so it arrives verified rather than merely
formatted. The author's scoped gate could not have caught it: gofumpt and
golangci-lint fmt agree with the original text, and only go fix disagrees.
2026-09-22 03:55:12 +10:00
sam 6ba10c0b6e feat(controlplane): derive resource schemas from the documents they describe
Twelve definitions each advertised a bare {"type":"object"} or {"type":"array"},
so no resource descriptor carried a single field: the Web UI had nothing to
label, describe or format a field with, and the one component that parsed a
schema was dead code. The constants could not be kept honest either -- a schema
written beside a struct drifts the moment a field is added, and nothing compares
the two.

Definition now names its document type and Descriptor derives the schema from it.
json tags give the keys, falling back to the Go field name because that is what
encoding/json stores; the Go type gives type and format; and a field's own
title, format and doc tags override. A duration is a string with format
"duration", which is how every duration field in the catalogue -- poll_interval,
max_uptime, rate_limit.window -- gets a client-side affordance from one rule
instead of twelve hand-written ones.

Deliberately structural: it emits no prose of its own. Field descriptions already
have one home (internal/webui/config_schema.go, keyed by dotted config path), and
a second would be two places to keep the same fact true. It also never emits
"required", because an empty string is legitimate for nearly every field here --
a blank workspace, a disabled rate limit -- so requiring most of them would
invite a client to enforce something the document does not mean.

Guarded by TestEveryResourceDescriptorDerivesProperties, which walks the catalogue
the production constructor builds and fails if any kind describes no fields --
the assertion that would have caught all twelve. It accepts a keyed collection's
additionalProperties as described, because a map document has no fixed keys.

Verified: controlplane, workflow, webui, archieui and staterpc suites, go vet,
go build ./..., golangci-lint run ./... (0 issues), docs:check.
2026-09-22 03:50:53 +10:00
sam 7fd01992d3 fix(archied): build the Gateway's worktree manager so it serves review_pr
boot.prReviewer returns nil without a worktree manager, and a nil reviewer
omits review_pr from every channel's tool set. RunGateway never called
buildTreesAndIdentities, so the Gateway resolved a nil reviewer and no
channel could review a PR.

Extract the manager's construction into boot.buildWorktreeManager, called
by buildTreesAndIdentities (daemon, unchanged field-for-field) and by
startGatewayRuntime before setupGatewayChat. The Gateway does not call
buildTreesAndIdentities: that also registers daemon identity runners the
Gateway must not own, and PR review only needs a clone of the PR head,
which worktree.Manager.CheckoutPR does from the forge.

Pin the ordering by source position in composition_order_test.go, alongside
the memory-engine ordering the same function already carries, and pin both
compositions behaviourally in worktree_manager_composition_test.go: the
Gateway's step must yield a reviewer that advertises review_pr, and the
daemon must still build its root manager plus one runner per identity with
a distinct WorkDir.

Correct docs/prds/operator-pr-review.md, which still asserted the daemon
supplies ChatPRReviewer and holds the review in-flight set.
2026-09-22 03:44:45 +10:00
sam a45aebcf14 fix(controlplane): give the channel document its own shape
The channel-settings resource embedded internal/config types directly, so the
document the Web UI edits was a JSON projection of TOML-tagged structs:
encoding/json fell back to Go field names, and rate_limit.window was a bare
time.Duration. An operator saw "Window" over a field expecting a nanosecond
count -- 60000000000 for the window = "1m" the file example writes -- and
"ListenAddr" over the email addresses, while every sibling resource in the same
registry is snake_case.

Define the shape here instead: emailSettings and rateLimitSettings with explicit
tags, and channelDuration, which writes the string the file accepts and reads
that, a nanosecond count, and the Go-cased keys an existing store holds.

Reading a legacy document is deliberate, so it stays strict about everything
else. decodeRenamingLegacyKeys renames the four known legacy keys and keeps
DisallowUnknownFields, because swallowing an unknown key decodes as "unset", and
an unset rate limit is off -- the failure this shape exists to end. A
misspelling is refused.

normalizeChannels, through the Definition.Normalize hook schedules already uses,
rewrites a legacy document into the current shape on write, so a stored document
converges the next time it is saved. Reads tolerate it until then, so no
deployment has to re-save before the document can be read.

Verified: the controlplane, messaging and configuration suites, archied (the
loadRuntimeConfig consumer), go vet, go build ./..., golangci-lint run ./..., and
docs:check. The full task check is the merge train's, on this tip.

The same audit found container-runtime-policies embedding config.ContainerConfig
(seven fields, no json tags); tracked separately rather than folded in here.
2026-09-22 03:43:46 +10:00
sam 0be664300b feat(archied): report systemd readiness and loop-driven watchdog heartbeats
archied now speaks sd_notify(3): READY=1 at the moment the process declares
itself serving, and WATCHDOG=1 heartbeats while the run loop's own progress
marker is fresh. The heartbeat is licensed by that marker (daemon.LastPollAt,
stamped at the start of every poll pass) rather than by an independent ticker,
so a loop wedged inside a pass stops being reported as alive and trips the
unit's watchdog.

The protocol is three environment variables and one datagram per state, so it
is spoken directly with net.DialUnix instead of through a new dependency.
Without NOTIFY_SOCKET nothing is sent, nothing is logged, and startup is
unaffected.
2026-09-22 03:35:55 +10:00
sam 708233a538 fix(webhook): keep a route path out of the sender identity
A webhook set SenderID to its configured route path. The turn path reads that
field through a per-channel resolver which refuses webhook, but the session
curator derives its participant from the raw field with no channel filter, so a
webhook session with exactly one distinct sender and one extracted fact wrote
agent-user memory addressed to User: "/hooks/...". Nothing reads it, and every
pass added more, because the facts are identical strings with no dedup.
docs/prds/memory-engine-unification.md criterion 7 requires that a route path
never become a user identity.

Clear it at the producer rather than teaching every consumer which channels are
lying: a route path is a source, not a person, so it no longer enters SenderID.
It still keys the inbound rate limit, where it is the documented per-source
budget for webhooks (config.RateLimitConfig), so it travels in the new
transport-only Inbound.BudgetKey -- carried on the wire beside Page, never
persisted, and never read as an identity.

pb.Message gains budget_key (field 9) for the same reason page (field 7) exists:
transport context that rides with an inbound message and is deliberately absent
from storedProto's rendering of a canonical record.

The curator needs no change. An empty SenderID already fails closed as an
unidentified user message, which is the path a dashboard session takes, and
sessionParticipant's existing skip covers it; the test name now says so.
2026-09-22 03:18:59 +10:00
sam 0d5705a532 docs(archied): correct the watch loop's claims and pin the boundaries
Three claims the reconnect loop records were false, and one boundary was
unpinned either way.

The claim that a store which "stalls until its read times out" is charged and
climbs the ladder described a timeout this code does not impose: nextUpdate
waits on the stream and the loop's context, and never on a clock, so a peer
that accepts the stream and then never answers it ends nothing here and is
charged by nothing here -- a probe held the read open for 2s with no retry
logged at all, and the attempt that finally ended was read as healthy. What
ends that stream is the transport's client keepalive on
internal/infrastructure/staterpc/dial.go (Time 10s, Timeout 5s), which the
watch rides because bootstrap takes its control-plane client off the
*staterpc.Client that dial returned. The comment now states that, names the
file, and states this loop's own boundary: it charges only attempts that END.

"The rule reaches every shape" was false for the shape it was argued from. The
window is derived from the delay the attempt would be charged (four times the
minimum at the minimum rung), so a stall at or past it -- 1s and 1.1s were
measured -- is read as a store that answered on every attempt and pins the
ladder at 250ms, against [250ms 500ms 1s 2s] at a 500ms stall. The comment now
says the reach stops at the window, and why that is deliberate rather than a
gap to close: the stalled attempt lasts the window, so those reopens are under
one a second against the four a second the rule exists to charge.
TestKeepWatchTreatsAStallPastTheWindowAsAStoreThatAnswered pins it, at a
five-minimum stall against the four-minimum window (widening the window past
the stall fails it).

The rule's sentence said "outlived a window", which the operator (>=) does not
mean, and a verification pass confirmed >= -> > survived the whole package. The
comparison stays inclusive and the sentence now says so: an attempt still open
when the window closes is a store that answered. The load-bearing inequality is
the other one -- the window is a strictly wider multiple of the charge, so a
store that fails as slowly as the charge is still charged -- and
TestAttemptHealthyAtTheWindowBoundary pins both edges at every rung: equal to
the window is healthy, a nanosecond inside it is charged.

TestKeepWatchChargesAnAttemptThatEndedWithNothing's window case now stands open
past the window rather than for exactly it: its sleep starts before the loop's
attempt does, so an attempt measured against it could be judged a hair early,
and the exact edge is pinned without a clock by the new unit test.

TestBothWatchStreamsRunThroughTheReconnectLoop asserted only that the name
keepWatch appeared, so a launch site handing the loop a wait of its own was
invisible -- the persona site's wait has no behavioural test at all. It now
reads the wait argument of each keepWatch call (changing it fails the test, and
nothing else in the package does).

No upper bound was added for the wait itself: the injection seam replaces the
wait in every test that drives the loop, so a bound on waitFor's own duration
would have to be a wall-clock one, and the correct code overshot a 25ms timer
to 65ms on a saturated 16-CPU box (169/200 samples over 1.5x, 8/200 over 2x),
which is exactly the flake a bound tight enough to catch the 2x mutation buys.
The wait doc states what the injected wait can and cannot show.
2026-09-22 01:58:03 +10:00
sam 4c77a20fa8 fix(archied): re-establish the control-plane watch streams after they end
The settings and persona watches were launched once, at boot, and ended on the
first stream failure: the goroutine returned, so every later stored change for
that kind was silently never applied and the process recovered only by
restarting (archie-core-yrmr).

Both watches now run one keepWatch goroutine per kind, which re-establishes the
stream in place after a bounded backoff, resuming after the last version an
update carried and stopping on ctx cancellation -- which the loop watches for
itself, so a stream that never closes cannot hold up shutdown. A first open that
fails still fails the boot that asked for it.

The reconnect delay is decided by the attempt that just ended, and only by that
(attemptHealthy, retryDelay): an attempt is healthy iff it delivered an update
this watch had not handled, or it outlived a window that is a strict multiple of
the delay it would otherwise be charged. A healthy attempt returns the delay to
the minimum, a failed one doubles it up to the cap, and the window moves with
the ladder instead of sitting at its floor. The acceptance of a reopen is the
wrong unit: gRPC takes the stream before the handler reads anything, and
controlplane.Server.Watch answers a store it cannot read by ending the stream,
so during the outage this reconnect exists for every reopen is accepted and
every stream ends carrying nothing -- measured with the real server and client
over bufconn, 4.0 watch RPCs a second across 2s of store outage with retry_in
pinned at 250ms when that acceptance is read as health. A window fixed at the
minimum is the same defect for the likelier shape of outage: a store that has
stopped answering does not error at once, it stalls until its read times out,
and an attempt that takes longer to fail than the minimum outlives that window
on every attempt -- measured in the end-to-end outage test before the change, a
300ms stall left the ladder flat at 250ms/250ms/250ms/250ms while the store
never answered a read. Both shapes are charged now, and the outage test drives
three of them (an immediate error, a 300ms stall, and a stall as long as the
delay that rung would be charged) up four rungs of the ladder, each logged retry
held to the delay actually waited.

The wait is injected (wait, production passes waitFor), because the ladder was
only ever asserted through the retry_in attribute: a loop that logged one delay
and waited another would have reported a growing ladder and reopened on a
schedule of its own. TestKeepWatchWaitsTheDelayItCharged reads the delays back
as values and asserts the ladder, and the outage test's gaps catch a wait that
returns without waiting. The retargeted reset test is joined by
TestKeepWatchChargesAReopenTheStoreMerelyAccepted: a delay reset by the
acceptance of a reopen charges every attempt of the outage from the minimum, and
nothing pinned that before.

The watch returns on cancellation without draining what the producer left for
it, so controlplane.Client's producers stop on the same context instead of
parking on a send no reader will ever take -- reproduced 40/40 times as a
goroutine still blocked on an undelivered send after keepWatch returned, one
goroutine and one channel leaked per kind at every exit. That cross-package
coupling is load-bearing in both directions and is stated as such; the two
producers now share the one stream reader that carries it.

A Recv failure is the store being unreachable, not a document this process
refused, and docs/prds/control-plane-apply-status.md ("What can be reported, and
what cannot") is what forbids reporting it as a failure of the process it
affected. The record is now written only for an update that carries a version,
which is what controlplane.Client emits for a document that would not validate
and never for a transport failure. Reporting the transport failure would also
overwrite the text of a standing refusal, replacing the one message that says
what to fix with "control-plane unavailable". The record is not un-clearable of
itself -- Report overwrites it on the next applied version -- but a store that
never changes again leaves the one stamp standing, and the process must not
write it at all. That emission is the whole of the failure path and now has the
test it lacked, from the producer's side:
TestWatchClientsDeliverARecvFailureAsAVersionlessUpdate pins that a Recv failure
is handed over carrying the mapped error and no version, and that a stream the
server closed and one that ended with the watch's context are not updates at all.

The refused version is deliberately not re-offered: the resume point moves past
it, so an edit only a newer build can decode cannot become a hot loop. Both ends
of that contract are pinned now: the watch stub filters its scripted stream by
AfterVersion as the server does, and controlplane.Server.Watch's own filter has
a test for the first time. The apply-status reporter's 30s re-stamp is unchanged
(TestRestampKeepsAReportedFailure).
2026-09-22 01:58:03 +10:00
sam 8b27037641 fix(archied): serve only the health facts a /status reply can carry
setupGatewayChat is the only production constructor of a Router and it runs
in the Gateway, which owns no container pool, no poll loop and no channel
manager. The producers wired to those three built report sections no reply
could carry, and /status' own description of itself claimed all five fields.
The health source now carries the broker connection and the chat-model
outcome, the two facts the answering process holds.

The tests for the deleted producers go with them, replaced by one that pins
the served shape with a pool and a daemon present in the boot.

Corrects docs/prds/status-health-surface.md, where the intro, the Phase 2
summary and the rendering bullet all claimed the five-line surface.
2026-09-22 01:58:00 +10:00
sam c579f6f021 fix(controlplane): carry parallel_tool_calls through the tool-settings projection
mcpServerSettings mirrors config.MCPServer field by field, and
runtimeToolConfigFrom rebuilds cfg.Tools from that mirror wholesale. The
parallel-tool-calls flag had no home in it, so on any deployment with a
control plane the file document's parallel_tool_calls = true was dropped and
every MCP server stayed serialized. The field is now carried through both
conversions -- the seed that writes the resource and the layering that reads
it back -- and the resource accepts it, so an operator can set it there too.

The field-by-field mirror is what let the field fall through, so the test
populates every MCPServer field by reflection and requires each one to be
projected and handed back, with an explicit allowlist for the fields the
projection deliberately leaves to the file document.
2026-09-22 01:57:58 +10:00
sam 22ed337c20 feat(tools): add per-server parallel_tool_calls to the MCP client
MCPServer gains ParallelToolCalls (default false). The client's
per-server callMu is now nil for a server that opted in, so CallTool
stops serializing that server's calls and the caller's own concurrency
decides; every other server keeps exactly one tools/call in flight.

The flag is threaded from config through the provider constructor -
the only place MCPServer configs become Client instances - into
NewClient, in both the daemon and the agent worker.
2026-09-22 01:57:58 +10:00
sam 2de6fe7ed9 test(archied): fail a state store keepalive revert in milliseconds
The keepalive agreement was guarded only by the 50s stream case, whose control
tears down 41s in: a revert of the server policy cost the whole window to
detect. stateStoreServerOpts's options are now checked in microseconds -- a
loopback listener installs exactly one option, the enforcement policy, and that
policy is 5s with PermitWithoutStream false, strictly below the dialer's ping
interval and at least a factor of two under it.

staterpc exports ServerKeepalivePolicy and ClientKeepaliveParams so both halves
of the agreement are read from the package that owns them rather than restated
in the test: changing either side alone (the floor, or the dialer's interval)
fails it. ServerKeepaliveOption is now the policy wrapped in an option.

The stream pair is unchanged and still proves the tear-down and the survival end
to end; its two cases already run concurrently (t.Parallel, 214f9bd9), so the
package pays the longer case (50s) rather than the sum (91s).
2026-09-22 01:57:56 +10:00
sam cf33b000fa fix(staterpc): make the state store's server policy accept the dialer's pings
The dialer's keepalive pings a server running grpc's default enforcement policy (MinTime 5m), which counts every ping arriving less than five minutes after the previous one as a strike and answers the third with GOAWAY too_many_pings. The dialer pings every 10s, so a connection that carries no write for ~40s -- a watch while the watched resource's version is unchanged -- was torn down, where before the client keepalive it stayed up.

ServerKeepaliveOption returns MinTime 5s, half the client's ping interval, so every ping lands 5s clear of a strike; stateStoreServerOpts installs it on the loopback and token listeners alike.
2026-09-22 01:57:56 +10:00
sam 4877e16379 fix(sessioncurator): address curator memory by the deployment's bot user
The curator derived the agent half of its agent-user scope from the
session record's BotUser, which is the router's session-resolution match
key: empty when no [[identities]] are configured (the shipped default),
identities[0].Name when they are. The engine validates the scope and
refuses an empty agent, so every pass in a single-identity deployment
failed on its first session and wrote nothing, forever; in a
multi-identity deployment the write landed at an agent no chat turn
reads.

A turn addresses its own memory with cfg.BotUser, so the composition now
hands the curator that same value through NewAdapter. The record's
BotUser stays exactly what it is, the match key resolution compares
against.

A session the pass cannot address is now skipped with a memory.skipped
action naming why, at the point the scope is produced, instead of
aborting the pass and dropping the actions already collected: one
session with no address must not starve the rest. Real infrastructure
failures -- an unregistered engine, an unreadable store -- remain pass
errors.
2026-09-22 01:57:54 +10:00
sam 856e2eef71 fix(configuration): resolve the default config path in one place
Four binaries derived the default with os.UserConfigDir while the daemon
resolved it from its own config home. The two agree on Linux with an
absolute XDG_CONFIG_HOME and diverge everywhere else, so one deployment
booted from a different config file depending on which binary started.

Move the rule into the package that owns configuration resolution
(internal/infrastructure/configuration, which already owns xdgDataHome and
DefaultWorkDir) as DefaultConfigDir/DefaultConfigPath, and have every
-config default take it from there: archie-gateway, archie-messaging,
archie-state-store (serve and recovery) and archie-ui, plus the daemon's
own parseArgs, setup generator and drain-marker path.

Fence the claim at the source, since the resolved value is only observable
by starting a process: no source under cmd/ or internal/app/archied may
call os.UserConfigDir, and every -config registration must default to the
helper.
2026-09-22 01:57:49 +10:00
sam de98260765 fix(controlplane): make the scheduling policy carry the label its trigger pairs with
The scheduling-policy resource carried the dispatch trigger but not the
trigger-matching label, so validateScheduling could judge only half of
the pairing the file layer's validateDispatch enforces on the effective
document (a label-requiring trigger with no label matches every open
issue -- the GH#445 guard). The write path therefore stored trigger
label/either with no label whenever the file's own label was unset, and
boot then refused the layered document: a value the store blessed,
archied unstartable, the operator left with the offline rollback as the
only remedy (archie-core-7pyj).

The resource now carries the label: the seed copies the file document's
label, RuntimeConfig layers it with the trigger (a policy stored before
the field existed decodes nil and leaves the file's label in force, the
same absence-means-inherited shape a kind with no stored value has),
and validateScheduling refuses a label-requiring trigger with no label,
the pairing judged on the data the store actually holds. Once the store
carries a label it owns it, so a file that later loses the label can no
longer break a stored policy that depends on one. The parity test
gains both directions, and a legacy policy without the field is pinned
as an absence, not an erasure.
2026-09-22 00:32:30 +10:00
sam 921cd1d559 fix(statestore): skip the legacy cron jobs the schedules resource cannot hold
migrateLegacySchedules replaced the whole legacy cron/jobs.json list into
the schedules resource, whose validator refuses every job whose kind is
not 'workflow' -- and chat is the legacy default (an empty kind on
schema-v1 jobs means chat). One chat job therefore failed the replace,
the migration returned the error and RunStateStore aborted before the
server ever listened. The failure was permanent: the seed had already
landed at version 1, so every restart re-ran the migration and refused
again, until an operator renamed cron/jobs.json by hand -- a remedy no
recovery doc mentions (archie-core-q6vw).

The migration now moves only the jobs the schedules resource can hold
and reports the rest instead of refusing them: chat and unrecognised
kinds were already dead deliveries in the old engine (the delivery
router maps KindWorkflow alone). An unreadable or corrupt sidecar is
logged and left in place for the next start, the way ImportConfig skips
a seed the resource validator refuses -- a value this process cannot
use must not stop the one process every other process dials. A
successful replace is marked by renaming the file to jobs.json.migrated
(the skipped jobs stay readable in it); until the rename lands, the
replaying request ID keeps the replace idempotent across restarts.
2026-09-22 00:14:08 +10:00
sam d4d10faa9f feat(eda): wire the playbook coordinator into production workflow selection
A loaded playbook now decides a real task's workflow. The wiring point is the
daemon's definition pin (Daemon.resolveWorkflowID, consumed by
pinWorkflowFromCollection), not pollNATS/publishTask as the design doc
assumed: routing moved out of the agent process when workflow definitions
became database rows pinned before dispatch, so the pin is the one place a
task's workflow is chosen.

Precedence: an explicit Task.Workflow (the waiting_human -> approved requeue)
still wins, then a matching playbook, then workflow.ResolveWorkflowID's
existing label/kind bindings. A playbook naming an undefined workflow is a
reported failure that parks the task rather than a silent fall-through to the
binding's choice -- the operator bound that trigger deliberately.

Store.Dispatch returns the selected workflow name plus the matching playbook's
id and version, instead of a compiled workflow.Workflow: the production caller
decides against the active definition collection, and the id/version are the
first two components of the resolved gap-2 idempotency key. The playbook
package no longer imports internal/domain/workflow.

The shipped example's `when` read event.priority, a field no intake supplies,
so it could never have fired once wired. Both examples now read the event
surface playbookInput really builds, and label-trigger.yaml documents the axis
an instance defines for itself: trigger.kind is the closed workintake
vocabulary because a kind addresses a NATS subject, while trigger.labels is
free-form and binds an operator's own taxonomy to a workflow.

Module/Channel/Forge positions stay rejected at load; they need the
playbook_dispatches ledger first (archie-core-t2db.24).

Closes archie-core-t2db.23
2026-09-21 23:47:06 +10:00
sam 84256e2d75 test(archied): supersede the restart test with the broader one, staleness window made mutation-proof
Takes the wider of the two independently-written archie-core-eju6 tests: it also
covers the queried half of boot.runtimeConfig (plugin_dir, not just the watched
budgets), the SIGHUP reload re-applying the database layer, a task-scoped grant
denied on PutApplyStatus/ListApplyStatus, and a real gRPC transport over bufconn
behind TaskGrants.

Its staleness leg had the same defect the narrower test did: the aged fixture was
derived from applystatus.StaleAfter, the constant the reader honours, so the
fixture moved with any mutation and the assertion held for a window measured in
hours. The aged row now uses a documented-window literal (90s, the operator-facing
contract) so the reader is constrained from both sides.
2026-09-21 23:19:48 +10:00
sam ac5aa317a8 test(archied): age the apply-status fixture by the documented window
The clause-5 staleness reading aged its fixture by applystatus.StaleAfter, so
the fixture moved with the very constant the reader is supposed to honour and
the reading agreed with the reader by construction: mutating StaleAfter to
1000h left the test passing, which is a staleness assertion that never went
stale.

Age the row by the documented 90-second window (three 30-second re-stamps,
docs/prds/control-plane-apply-status.md) held as a fixture literal instead, so
a window that stopped expiring fails the reading, and say in the fresh half's
assertion that it is the other end of that age pair.

archie-core-eju6.
2026-09-21 23:12:24 +10:00
sam 3bbad40738 test(archied): end-to-end restart test for a database-backed settings change
archie-core-eju6: docs/prds/runtime-control-plane.md ("First implementation")
lists an end-to-end restart test as a deliverable and there was none.

One test drives the whole path against a real State Store: the dashboard's own
HTTP adapter writes a task-limit change (attributed by the adapter to the System
identity), the audit trail records it as an ordinary edit above the migration
seed, the process that consumes it stops and starts again against the same
store and the same file document, and the restarted process is running the
stored limits rather than the file's. The apply-status row for that process
reports the version it applied, and the settings page reads an aged record as
not reporting instead of current.
2026-09-21 23:09:23 +10:00
sam 67ebeb8d52 fix(controlplane): a kind with no stored value leaves the file's value in force
The fix-closure review found the previous pass moved the failure instead of
ending it. A seed the resource validator refuses leaves the kind ABSENT, and
RuntimeConfig treated an absent kind as fatal, so archied and the Gateway
refused to start with "control-plane resource not found" -- a database-named
error that editing config.toml cannot clear. Reproduced before the fix: every
kind in the new table failed that way.

Two changes, one on each side of the seam:

- Client.RuntimeConfig (and RuntimeChatConfig) now treat a kind with no stored
  value as "the file document's value stays in effect", which is what the
  skip-and-report comment already claimed. The version map records no version
  for such a kind, so nothing is reported as applied. A value the file layer
  also refuses still fails closed, at configuration.Validate, with a message
  naming the file's own field -- and the file is the fix.

- Which repository lists are valid can no longer differ between the layers.
  configuration.ValidateRepositories is now the single rule set (owner and name
  present, no duplicates, compilable test glob) and the repository-policies
  resource validator delegates to it. The file layer had no duplicate rule
  while the resource layer did, so a duplicate [[repos]] entry passed the loader
  and then vanished into a skipped seed.

Also, from the same review: the scheduling validator's "0s" carve-out is gone,
so a zero poll interval is refused at write time as configuration.Validate
refuses it (there is no defaulting behind a stored value); applyOverlayFile's
doc now says which overlay forms fold (a conf.d extra does not, and nothing
reads cfg.Extra); and plugin-settings' no-op validator is a named function with
the reason it accepts everything.
2026-09-21 22:12:32 +10:00
sam 042a86ce4a fix(config): judge a database-owned setting at the layer that owns it
Review of the two previous commits found the split was incomplete in both
directions: the checks moved off the file load path were still enforced
anywhere the value could enter the system, and the fold reached only one of the
three overlay paths.

A stale database-owned TOML value could still stop archie-state-store. The
process seeds every control-plane resource from the same file config on a fresh
database, and the seed runs the resource's own validator; three of the five
values the loader now accepts aborted the boot there (verified by booting
RunStateStore before the fix). A seed that does not validate is now SKIPPED and
reported instead of fatal: the resource stays absent, so the file's value is the
one in effect and editing config.toml is still the fix -- the daemon and the
Gateway are where it fails closed, at boot.runtimeConfig.

The resource validators were weaker than configuration.Validate for exactly the
fields the split reclassified, so a value the file path used to refuse at load
became storable in the database, and then un-fixable by editing config.toml.
The trigger enum and the test-glob rule now come from the configuration package
rather than being restated, the container image is required there as it is in the
file, and a table test ties the two layers together value by value.

The directory form of -config-overlay kept the archie-core-e2e2 failure: it
decoded each overlay file straight into the populated config, so a map-valued
entry it only partly addressed still cleared the fields it did not name. Both
the overlay layer's main file and its feature files now fold, which is what
Loader.Dir's documented parity with Loader.Overlay has always claimed.

The overlay file's key report is derived from the apply's own view of the file as
well as the file decode's, because TOML matches keys case-insensitively and the
fold's yaml decode does not: a key only the file decode matched was consumed by
the report and dropped by the apply, a silent no-op that worked in the base file.

Tests: the state-store boot is asserted against the real process, the directory
overlay and the case-mismatched key each have one, and ImportConfig pins that a
refused seed is not stored.
2026-09-21 22:12:32 +10:00
sam 13efe4fd1a fix(config): stop judging database-owned settings on the file load path
Loader.finalize ran the whole validation over the file document, so a stale
TOML value in a setting the control plane owns failed startup -- including
archie-state-store, which resolves its file config and opens the store without
ever layering a database resource over it. docs/prds/runtime-control-plane.md,
"Bootstrap, migration, and recovery": after migration, settings in TOML are
ignored and cannot block State Store startup.

The checks over the settings a control plane resource is seeded from and
replaces wholesale now run only on the effective document: providers
(provider-settings), poll_interval and dispatch (scheduling-policy), containers
(container-runtime-policies) and the repository lists (repository-policies).
They moved from validate to validateDatabaseOwned; validateBootstrap keeps the
checks over settings no resource carries (forge intake, identities, nats,
memory, image, capture). File sources pass validateBootstrap and
Loader.ApplyOverlay, which layers overrides onto an effective document, passes
Validate.

Nothing stops being judged: the daemon and the Gateway both run the full
Validate in boot.runtimeConfig, the one place database resources are layered
in, before any capability starts -- so a stored value that will not validate
still stops the process rather than being published. Cases that asserted the
load path rejects a database-owned value now assert both layers, and
TestRuntimeConfigFailsClosedOnAnInvalidDatabaseValue pins the second.
2026-09-21 22:09:06 +10:00
sam 21c6aca513 fix(statestore): build the recovery control-plane server on the shared step vocabulary
After the rebase onto main, controlplane.NewServer takes the step vocabulary
it resolves definitions against (controlplane.ResourceStore, *workflow.Manager)
and returns (Server, error). Both offline call sites still passed the store
alone, so internal/app/archied stopped compiling -- and with it
cmd/archie-state-store, cmd/archied and cmd/archie-gateway.

validate and rollback now build their server through
openStateStoreControlPlane, the root helper the served path already uses, so
the offline checks resolve the same shared provider set
(internal/infrastructure/workflowsteps) as the process whose verdict they
predict, and the constructor's error is returned as a refusal rather than
dropped. No second vocabulary call site: the fwmp pin on
openStateStoreControlPlane covers these paths unchanged.

The test's seeding helper builds its server from the same shared set
(workflowsteps.NewManager) because it cannot call the unexported root helper;
an empty manager there would seed values the served path never validates
against. That is not merely a claim: with an empty manager the three
validate tests fail with `workflow "bootstrap" step 1: unknown type
"bootstrap.prepare"`, so they already pin that the offline path resolves a
live, shared vocabulary.
2026-09-21 22:07:41 +10:00
sam b5b58c370a fix(statestore): read a kind the store does not hold as its seed, and stop validate touching the daemon's log
Four defects from the re-run contract review, all in the recovery path.

A store missing a control-plane kind was refused while a store with no
resources table at all was accepted -- two stances inside validateStore for
states the daemon cannot tell apart. The State Store seeds every kind from
its own config before it serves (RunStateStore -> ImportConfig), so a kind
the file does not hold yet is one archied reads the seed for: an upgrade that
adds a kind, and a validate before the State Store has started again, exited
1 with "read provider-settings: resource not found" for a store the daemon
boots on fine. StoredRuntimeConfig now reads a missing kind as the seed the
State Store would write for it (Definition.seededValue, shared with
ImportConfig so the two cannot drift), and the missing-table branch is the
same stance taken to its extreme.

defaultConfigPath() derived the daemon's config with os.UserConfigDir, which
disagrees with archied's configHome on darwin and rejects a relative
XDG_CONFIG_HOME outright -- leaving validate with an empty path and no
verdict, on a host where archied boots from relative-dir/archie/config.toml.
It is now the daemon's own rule, exported as archied.DefaultConfigPath and
used by the daemon's own -config default too, with a test pinning the
equality.

-h exited 2, the code documented as "the command line was wrong", while the
serve path in the same binary exits 0 and main.go advertises -h for these
subcommands. ErrHelp now returns 0.

validate resolved the boot config through loadConfig -> setupLogging, which
created cfg.Log.File's directory, opened the log, and wrote a line stamped
component="daemon" -- a diagnostic editing the deployment it inspects, and
rotating a log the daemon is writing. boot.stderrLog keeps setupLogging on
the stderr logger for the recovery path: no feed, no task-log registry, no
durable copy.

Tests: TestRecoveryValidateRunsTheGateBootRuns now asserts the unseeded and
the missing-kind stores are accepted (both exited 1 before), while the
bogus-policy case still refuses; TestRecoveryHelpExitsZero,
TestRecoveryValidateLeavesTheDaemonLogAlone and
TestRecoveryDefaultConfigFollowsTheDaemonsConfigHome are new. Each was run
red first, and the seed fallback and stderrLog were mutation-checked.
2026-09-21 22:04:42 +10:00
sam 8d015db7c1 fix(statestore): make validate run boot's gate, and stop backup replacing the database
Two P1 findings from review, both about a claim outrunning the code.

validate answered a different question from boot's. Boot refuses on
configuration.Validate over the file config with every stored resource
layered onto it (internal/app/archied/control_plane.go:27), which is a
stricter check than the write path's per-resource Decode: validateScheduling
never inspects dispatch.trigger and explicitly permits "0s", while boot
rejects an unknown trigger and a non-positive poll interval. A store holding
such a value printed "is a valid store ... N stored resources validate" and
exited 0 while archied exited 1 on it -- a false green pushing an operator
toward the blunt restore instead of the surgical rollback.

validate now runs both layers and reports both, in boot's order:
store.ValidateFile, then the write path's ValidateStored, then the config
gate. The layering itself is now one implementation: controlplane's
runtimeConfigFrom takes a resourceReader, which the gRPC client and a new
Server.StoredRuntimeConfig (reading its own store) both provide, so the
offline check cannot drift from the daemon's. validate takes -config /
-config-overlay (default: the path the serve subcommand uses), because the
question is about the stored values layered onto that document.

backup had no guard against -out naming the database. It renames its
snapshot over the target, so `backup -db F -out F` replaced a database a
serving State Store may still have open and orphaned the WAL of the file it
just unlinked -- the state Restore refuses up front and maintenance.go's own
comment calls unrecoverable. backup now refuses with the same message
Restore uses, which is what makes its exemption from the ownership lock
sound.

Claims corrected where they ran ahead of the code: ValidateStored now says it
is the write path's check and not boot's, the Restore comment no longer
promises "never a mixture" for the sidecars it removes first, the usage text
advertises validate's -config, and the architecture table drops "must be
stopped" for validate (nothing enforces it; read-only opens skip the lock by
design) and states which two layers validate reports.

Tests: TestRecoveryValidateRunsTheGateBootRuns fails on the pre-fix code
("validate accepted a stored policy the daemon refuses to boot with") and
covers a store the State Store never seeded; TestRecoveryBackupRefuses-
TheDatabaseAsItsOwnSnapshot fails on the pre-fix code ("backup over the
database itself succeeded"). The validate-accept test now seeds the store
through ImportConfig and asserts the reported count is non-zero, and the
stored-resource case uses a value both gates refuse instead of one only the
write path does.
2026-09-21 22:04:42 +10:00
sam 014868eda8 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 66ea2937a9 fix(workflow): make gate.diff-rules fail closed on a change it never read
The step's contract said it diffs "the worktree". It does not: Trees.Diff
reports the merge base against HEAD, so only committed work is visible.
A stored definition that placed gate.diff-rules before the step that
commits therefore ran every rule against an empty diff, found nothing and
returned nil, letting the run proceed -- the "load and check nothing"
failure the same file's settings validation exists to prevent, and
indistinguishable in the run's events from a change that passed.

The rules now read the committed change, and a run that read no committed
change while the worktree still holds uncommitted work fails on the spot,
naming the step it must follow. The count of added lines read is logged on
every run, so "checked nothing" is visible rather than silent.

Telling those two apart needs a fact Trees does not carry, so it arrives as
the same shape of optional capability changeStatsReader is: an unexported
interface in the domain, implemented where git is actually read
(worktree.Manager.HasUncommittedChanges, which excludes ignored files the
way CommitAll's own status check does) and forwarded by hybridTrees, the
Trees every production run uses. A Trees implementation that cannot answer
is refused rather than assumed clean: for a gate, silence about the change
is a failure, not a pass.

The four remaining review findings are recorded, not fixed, in
archie-core-ze7y (the escalated .archie/stages/*.go decision, P1, which now
blocks archie-core-8szi), archie-core-4kbg (discoverability),
archie-core-s1jz (hunk-header and threshold hardening) and archie-core-vof9
(retry keeps the pinned definition, so a rule cannot be unblocked by
editing it).
2026-09-21 20:43:48 +10:00
sam 6354cda6b1 feat(archied): check a live settings replacement before switching to it
Resolves archie-core-nwa0. The live apply path builds and probes a replacement
before promoting it and retains the previous component when the probe fails,
reporting the outcome through the apply-status surface instead of a hard-coded
nil.
2026-09-21 20:33:41 +10:00
sam e8558f6c36 fix(archied): probe what the live settings update would actually run
Review of d7f3d0da found the build-and-probe step shape-only: the check it
added re-ran workflow.ExecutionSettings.Validate, which the store runs before
writing the document and controlplane.Client runs again on the way out, so no
producer could trip it. That review was right; this corrects it.

- The probe is now this process's own runnability check on the candidate it
  would switch to: configuration.Validate over the configuration snapshot the
  new limits would be published as, the same gate runtimeConfig applies before
  publishing a layered config and the readiness probe applies to the published
  one. The duplicated schema check is gone.
- The refusal the daemon really meets arrives as a watch error, because the
  client decodes every document before the apply path sees it. That branch
  logged and returned without writing an apply-status record, so the settings
  page showed a live resource as healthy while nothing was being applied. It
  now reports the refusal, against the version the reporter last applied.
  Whether the stream is re-established afterwards stays archie-core-yrmr.
- `Closes archie-core-nwa0` in d7f3d0da is withdrawn: the item stays open. For
  a limits-only kind no producer can make the owned check fail today, so the
  refusal path is exercised by test, not by traffic; the live kind whose
  candidate check has content is personas (archie-core-nw7t). Both callers are
  covered by tests now, through the client seam, instead of by calling the
  apply function directly.
- The comments no longer claim behaviour the code lacks: the boot abort is the
  fail-closed direction of a rule whose branch boot cannot reach, and the
  carried-forward version is the reporter's property, not this call's.

Out of scope and recorded instead: the live apply still publishes with
cfgHolder.Set rather than publishConfig, leaving the dashboard's config
snapshot stale after a live change (archie-core-75cc). workflow-definitions
gets no check because nothing swaps a running definition: the daemon reads the
collection per task pin (daemon.go:1479, pinWorkflowFromCollection) and the
only other reader is the dashboard's stream, so there is no live replacement to
probe.
2026-09-21 20:32:04 +10:00
sam 83974b6847 feat(archied): check a live settings replacement before switching to it
docs/prds/runtime-control-plane.md ("API") requires a live change to start
and check the new component before switching to it, keeping the old one
running when the check fails. The live workflow-execution-settings apply
stored whatever arrived on the watch, republished the configuration snapshot
new tasks are built from, and reported success unconditionally.

Stage the update as a candidate first: validate the limits and build the
snapshot they produce without touching anything running, then switch both in
only if the check passes. A refused update leaves the running limits and the
snapshot in place and reports the failure through the apply-status surface,
which keeps the version that is still live and carries the error. Boot
propagates the same rejection, so a process is never started on limits it
cannot run.

personas is the other live-watched kind and gets no check or report here;
filed as archie-core-nw7t rather than half-wired.

Closes archie-core-nwa0.
2026-09-21 20:32:04 +10:00
sam cfe393e9ea refactor(archied): fold the daemon's state surfaces into one boot step
Run's added openDaemonWorkflowDefinitions guard pushed it to gocyclo 21
(.golangci.yml's budget is 20). openDaemonStateSurfaces owns the pair --
adapter, then the definitions client on its transport -- so Run keeps one
branch for the whole sequence and no suppression is added.

step_vocabulary_test.go's pin moves with the sequence: it still asserts
adapter before client, client before buildDaemon, and now also that Run
opens neither half directly, so the ordering has exactly one call site.

Behaviour is unchanged; the gateway root still calls openStateStoreAdapter
alone and resolves no step vocabulary.
2026-09-21 20:29:20 +10:00
sam 1b4289ed0c fix(archied): register the step vocabulary only where a root resolves it
Review pass on the step-vocabulary shape. The gateway root shared
openStateStoreAdapter with the daemon, so it registered a step vocabulary and
built a workflow-definitions client it never read: the same dead vocabulary the
previous commit removed from internal/app/archiemessaging, reintroduced through
the shared adapter, and able to fail the gateway's boot the day a provider set
can fail to load. The vocabulary and the client now belong to the daemon root
alone (openDaemonWorkflowDefinitions, called by Run before buildDaemon captures
it), which is what Client's "a process that never reads or writes a workflow
definition needs no provider set and cannot be failed by one" already claimed.

The root guard was weaker than its own comment: it asserted that a root calls
stepVocabulary(), not that the manager returned is the one handed to
NewServer/NewWorkflowDefinitionsClient, so a root could call it and inject an
empty manager and keep every test green. The pin now asserts the data flow (both
halves mutation-checked), plus Run's ordering -- after openStateStoreAdapter,
before buildDaemon.

Three root guards asserted exact equality with workflow.BuiltinStepRegistry(),
which contradicted the extension path they guard: adding a provider to
workflowsteps.Providers() -- the documented way a step type arrives -- failed
all three, and the expectation could not be satisfied by editing it. They now
assert what their doc says (every shipped stage present) plus provenance (every
name resolved is declared by the shared provider set), and the workflowsteps
guard derives its expectation from Providers() so both sides move together.

New guard on the defect class the bead exists for: TestNoProductionSiteReaches-
ForTheBuiltinStepRegistry scans the module and fails if any non-test file outside
the domain declaration and the shipped provider names BuiltinStepRegistry, which
the agreement test cannot see for a sixth resolution site added later.

Claim-vs-code corrections: openStateStoreAdapter "reads and replaces" -> the
daemon only reads, and ReplaceWorkflowDefinitions has no production caller yet;
workflowsteps' package/Providers docs no longer claim every Archie binary
registers the set (archie-gateway, archie-messaging, archie-playbooks and
archie-ui do not); the shipped-provider test no longer says production does not
call BuiltinStepRegistry, which is false -- production calls it only there.
2026-09-21 20:22:44 +10:00
sam c0ec3f6b8e fix(workflow): pin the roots, drop the dead vocabulary, guard the nil manager
Third review pass on the step-vocabulary shape, one fix per finding.

P1, roots unpinned. The agreement test built its own manager and injected it, so
it pinned the resolution sites and not the roots that decide the provider set; a
root regressed to workflow.NewManager() (no shipped stages) left go test green.
archied now resolves through one unit, stepVocabulary (step_vocabulary.go), and
agentworker's productionWorkerDependencies is exercised directly:
internal/app/agentworker/step_vocabulary_test.go and
internal/app/archied/step_vocabulary_test.go assert each root's manager resolves
the shared provider set's shipped stages and accepts a provider registered
through it. RunStateStore and openStateStoreAdapter own a SQLite file and a gRPC
dial, so their calls are pinned by source position, the way
composition_order_test.go pins the memory-engine ordering.

P2-B, dead vocabulary. archie-messaging registered a step vocabulary it never
resolved (its only control-plane call is RuntimeChatConfig) and could fail
startup on it before the State Store target guard. The workflow-definitions
surface is now its own type, controlplane.WorkflowDefinitionsClient, so the
vocabulary is a constructor dependency of the one surface that resolves step
types and of nothing else. The messaging root no longer imports workflowsteps.

P2-C, nil manager. A nil *workflow.Manager dereferenced on every resolution path.
stepRegistry and CompilePinnedWorkflow now refuse with an error naming the wiring
mistake; TestNilStepVocabularyFailsClosedAtEveryResolutionSite pins the refusal.

Claim-vs-code corrections: agreement is stated as within one build (vocabulary.go,
stepRegistry, openStateStoreControlPlane, openStateStoreAdapter); the Yaegi claim
now says no bridge to StepFactory has been built and cites
internal/secret/secretextract; the provider set names its three roots;
Manager.Register's ordering is documented as a constraint with its consequence,
and the shape rule no longer claims to reserve shipped stage names; the
shipped-stage test compares against the builtin factory's own stage.
2026-09-21 20:00:37 +10:00