config: one name-keyed Service definition instead of three hard-coded locations #1600

Closed
opened 2026-10-27 13:41:02 +00:00 by sam · 2 comments
Owner

The same service is already one Go type (config.ServiceConnection). What is
duplicated is its NAME, across three layers:

  • internal/config/services.go:4-14 -- Gateway and State as struct fields
  • internal/infrastructure/configuration/defaults.go:74-82 -- three
    if cfg.Services.X.Y == "" default branches
  • consumers -- internal/app/archied/{bootstrap.go,state_store.go,gateway.go}
    and internal/app/archieui/config.go:80-81 read cfg.Services.State /
    cfg.Services.Gateway by field

Drift this already permits: stateStoreResolvedToken
(internal/app/archied/state_store_client.go:17-23) and gatewayResolvedToken
(internal/app/archied/chat_service.go:20-26) are identical apart from the env
var name; gateway.Target is defaulted while state.Target is a startup error,
with nothing stating that asymmetry in one place.

Design: docs/prds/service-registry.md (decisive, pre-implementation).

Prerequisite, now done: docs/prds/state-store-contract.md section 10 mandated
the opposite ("services.go gains a State ServiceConnection field"). Revised to
rev. 2d in the same commit as the design, so the tree no longer contradicts its
own ratified authority.

The TOML shape does not change, so no deployment profile, config.example.toml,
or install.sh edit is required.

Acceptance criteria

  1. A service is declared once, not in three locations.
  2. Nothing about a service can be stated in one place and contradicted in another.
  3. RegisterService(context, name, target, listen, tokenEnv) is the entry point.
  4. Adding a service requires no new struct field, no new default branch, and no new consumer field access.
  5. The set of services is registry data, not a struct definition.
  6. grep -rn 'Services.(State|Gateway)' --include='*.go' returns nothing.

Close reason

Verified complete on origin/main: tests green


Imported from beads archie-core-u23g · GitHub #862 · type task · priority P1 · created 2026-09-18 · closed 2026-09-18

The same service is already one Go type (config.ServiceConnection). What is duplicated is its NAME, across three layers: - internal/config/services.go:4-14 -- Gateway and State as struct fields - internal/infrastructure/configuration/defaults.go:74-82 -- three `if cfg.Services.X.Y == ""` default branches - consumers -- internal/app/archied/{bootstrap.go,state_store.go,gateway.go} and internal/app/archieui/config.go:80-81 read cfg.Services.State / cfg.Services.Gateway by field Drift this already permits: stateStoreResolvedToken (internal/app/archied/state_store_client.go:17-23) and gatewayResolvedToken (internal/app/archied/chat_service.go:20-26) are identical apart from the env var name; gateway.Target is defaulted while state.Target is a startup error, with nothing stating that asymmetry in one place. Design: docs/prds/service-registry.md (decisive, pre-implementation). Prerequisite, now done: docs/prds/state-store-contract.md section 10 mandated the opposite ("services.go gains a State ServiceConnection field"). Revised to rev. 2d in the same commit as the design, so the tree no longer contradicts its own ratified authority. The TOML shape does not change, so no deployment profile, config.example.toml, or install.sh edit is required. ### Acceptance criteria 1. A service is declared once, not in three locations. 2. Nothing about a service can be stated in one place and contradicted in another. 3. RegisterService(context, name, target, listen, tokenEnv) is the entry point. 4. Adding a service requires no new struct field, no new default branch, and no new consumer field access. 5. The set of services is registry data, not a struct definition. 6. grep -rn 'Services\.\(State\|Gateway\)' --include='*.go' returns nothing. ### Close reason Verified complete on origin/main: tests green --- _Imported from beads `archie-core-u23g` · GitHub #862 · type task · priority P1 · created 2026-09-18 · closed 2026-09-18_
sam added the hightask labels 2026-10-27 13:41:03 +00:00
sam self-assigned this 2026-10-27 13:41:03 +00:00
sam closed this issue 2026-10-27 13:41:03 +00:00
Author
Owner

sam wrote (originally 2026-09-18):

Implemented on branch feat/service-registry, commit 6bdbd5e3. Not pushed, not
merged.

Base correction worth recording: the story and design cite [services.*].listen,
internal/app/archied/listen.go and the listen defaults, and NONE of those exist
on main. They are on feat/attempt-attribution, unmerged. RegisterService's
listen argument has nothing to carry without it, so this work is stacked on
that branch rather than on main. The design doc now states that base.

Shape:

  • config.Services is map[string]ServiceConnection; TOML unchanged.
  • RegisterService(context, name, target, listen, tokenEnv) in
    internal/config/servicespec.go, with the two built-ins registered in init().
  • An empty registered target means operator-supplied, which is how
    services.state.target stays required and the gateway's stays defaulted,
    with no branch naming either service.
  • applyServiceDefaults iterates the registry; no per-service branch remains.
  • stateStoreResolvedToken and gatewayResolvedToken are deleted, replaced by
    Services.ResolvedToken(name, getenv). getenv is a parameter because
    internal/secret imports internal/config.

One thing the design got wrong and the code now handles: a typo'd
[services.gatway] is reported today (measured: UnknownKeys = [services.gatway
services.gatway.target]) because the struct left it in Undecoded(). A map
decodes any section, so it would have loaded silently. unregisteredServiceKeys
asks the registry instead; deleting that call makes the test fail with an empty
UnknownKeys, verified with go test -overlay.

Verification: task check exit 0 (twice, clean tree, go.sum untouched); go test
-race clean on config, configuration, archied, archieui, daemon; the acceptance
grep for Services.State/Services.Gateway returns nothing.

Left open deliberately: it depends on an unmerged branch, so it is not landed.

_sam wrote (originally 2026-09-18):_ Implemented on branch feat/service-registry, commit 6bdbd5e3. Not pushed, not merged. Base correction worth recording: the story and design cite [services.*].listen, internal/app/archied/listen.go and the listen defaults, and NONE of those exist on main. They are on feat/attempt-attribution, unmerged. RegisterService's listen argument has nothing to carry without it, so this work is stacked on that branch rather than on main. The design doc now states that base. Shape: - config.Services is map[string]ServiceConnection; TOML unchanged. - RegisterService(context, name, target, listen, tokenEnv) in internal/config/servicespec.go, with the two built-ins registered in init(). - An empty registered target means operator-supplied, which is how services.state.target stays required and the gateway's stays defaulted, with no branch naming either service. - applyServiceDefaults iterates the registry; no per-service branch remains. - stateStoreResolvedToken and gatewayResolvedToken are deleted, replaced by Services.ResolvedToken(name, getenv). getenv is a parameter because internal/secret imports internal/config. One thing the design got wrong and the code now handles: a typo'd [services.gatway] is reported today (measured: UnknownKeys = [services.gatway services.gatway.target]) because the struct left it in Undecoded(). A map decodes any section, so it would have loaded silently. unregisteredServiceKeys asks the registry instead; deleting that call makes the test fail with an empty UnknownKeys, verified with go test -overlay. Verification: task check exit 0 (twice, clean tree, go.sum untouched); go test -race clean on config, configuration, archied, archieui, daemon; the acceptance grep for Services.State/Services.Gateway returns nothing. Left open deliberately: it depends on an unmerged branch, so it is not landed.
Author
Owner

sam wrote (originally 2026-09-18):

Pushed and raised as PR #872, based on feat/attempt-attribution rather than main because that branch carries the listen field this depends on. Retarget once the base lands. https://github.com/samcharles93/archie-core/pull/872

_sam wrote (originally 2026-09-18):_ Pushed and raised as PR #872, based on feat/attempt-attribution rather than main because that branch carries the listen field this depends on. Retarget once the base lands. https://github.com/samcharles93/archie-core/pull/872
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: sam/archie#1600