feat(secrets): re-land ADR-0031 Phase 3 stack onto main — environments registry + per-context LLM keys + credentials registry - #87
Merged
Conversation
…n (ADR-0031 Phase 3) Make "environment" a per-execution scoping dimension instead of a single server-wide config string baked into the secret resolver at DI time. - workflow.New gains an environment field + getter; the WorkflowHandler builds a per-workflow secrets.Resolver scoped to that environment. New executions take the environment from the trigger (default FUSE_ENVIRONMENT); replay reads it from the reconstructed workflow so resolution stays deterministic across restart/recovery/retry. - Thread environment trigger -> message -> workflow_sup spawn -> instance supervisor -> WorkflowHandlerInitArgs. Sub-workflows inherit the parent's environment. TriggerWorkflowRequest/Response gain an optional environment field; CLI `fuse workflow` gains -e/--environment. - Persist environment on the workflows row (migration 000009, NOT NULL DEFAULT 'default' backfill) and read it back in Get; excluded from the upsert UPDATE clause so state-change saves never clobber it. - Drop the now-orphaned process-wide secret resolver DI provider. Tests: unit coverage for New/Environment(); functional contract subtest asserts Save/Get preserves environment (memory + postgres). Strict environments registry and trigger validation follow in a separate PR. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…R-0031 Phase 3)
Provider API keys / base-URLs may now be {{secret:NAME}} references resolved
from the SecretStore against the running workflow's environment, so different
workflows in one process can use different provider credentials.
- pkg/llm: Registry is now factory-based — Get/Default take (ctx, environment);
NewRegistry(map[string]ProviderFactory); NewStaticRegistry shim for the
static fast path and tests.
- di/llm: provideLLMRegistry builds per-provider factories. Fully-static config
is built once (singleton fast path, unchanged behavior); a config with
{{secret:}} refs resolves via SecretStore + ReplaceSecretRefs per call and
builds a fresh provider. Resolved keys are Reveal()'d only into the SDK
client, never logged.
- Thread the workflow environment to functions: ExecutionInfo.Environment
(carried on ExecuteFunctionMessage, set from a.workflow.Environment() at the
3 handler dispatch sites). ai/chat & ai/agent resolve the provider inside
their async goroutine (off the pool worker) using execInfo.Environment;
agent resolves once and reuses it across the loop. Sub/tool ExecutionInfo
inherits the environment.
Backward compatible: all-literal config with the memory store behaves exactly
as before. Tests: registry factory dispatch, chat env-routing, di per-env
resolution + singleton fast path. ADR-0031 + .env.example updated.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…idation (ADR-0031 Phase 3) (#84) Make environments declarable and validated, completing the explicit environments model on top of per-execution scoping. - Environment domain (pkg/workflow) with name-format validation and the DefaultEnvironmentName constant. - EnvironmentRepository (memory seeds 'default'; postgres + migration 000010 seeding 'default'), EnvironmentService with IsValid, DTOs, and CRUD HTTP API: GET /v1/environments, GET/PUT/DELETE /v1/environments/{name} (the default environment cannot be deleted). - Trigger validation: the trigger handler rejects an unknown environment with HTTP 400 (default is always valid). DI wires the repo/service/handlers. Tests: domain Validate, memory repo, service (IsValid + CRUD), and a memory+postgres functional contract test asserting the seeded default. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… values (ADR-0031 Phase 2)
Introduce typed, centrally-managed credential objects (ADR-0031 Option B),
referenced by id. A credential is metadata (id, free-form type, description,
field names); its field VALUES live in the existing SecretStore under the
reserved name cred/<id>/<field>, per environment — one custody point, reusing
Phase-1 encryption + scoping.
This PR is the registry/management layer only (no engine wiring yet):
- pkg/workflow/credential.go: Credential domain + validation (lowercase id,
mixed-case dot-free field names).
- pkg/secrets/credential.go: CredentialSecretName + {{credential:id.field}}
token helpers. The "/" separator is outside the {{secret:NAME}} charset, so
credential values can never collide with secret references (tested).
- CredentialRepository (memory + postgres TEXT[] fields) + migration 000011.
- CredentialService: values written to the SecretStore via ManagedSecretStore
per environment (read-only backends rejected with ErrReadOnlySecretStore);
Fields merged across saves; reads return metadata only, never values.
- CRUD API GET /v1/credentials, GET/PUT/DELETE /v1/credentials/{id}
(?environment= selects the value scope; values never returned on GET).
- `fuse credentials set/list/delete` CLI.
Consumption wiring (source:"credential", {{credential:}} token, LLM
provider-by-id) follows in a separate PR. Migration 000011 must land after the
environments migration 000010.
Tests: domain/helper/namespace-collision, memory repo, service (value→store,
per-env isolation, read-only fallback, field merge), memory+postgres contract.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…scope' into feat/per-context-llm-keys # Conflicts: # docs/adr/0031-settings-secrets-and-environments.md
…feat/credentials-registry # Conflicts: # internal/actors/mux_worker.go # internal/app/di/actors.go # internal/app/di/repos.go # internal/app/di/services.go # tests/functional/postgres_test.go
…stry # Conflicts: # internal/handlers/trigger_workflow.go
The fields TEXT[] column is NOT NULL; a nil []string encodes as SQL NULL and
violated the constraint when saving a credential with no fields (caught by the
functional postgres contract test). Coerce nil -> []string{}.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jun 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this PR
Only #83 (per-execution environment threading) actually landed on
main. PRs #84(environments registry + strict validation), #85 (per-context LLM provider keys), and #86
(credentials registry) were each merged into their stacked feature-branch base rather than
main, so their code never reachedmain. This PR re-lands all three together ontomainfromthe tip of the stack. Nothing in here is new code — it's the already-reviewed content of
#84 + #85 + #86, merged.
Contents (all ADR-0031)
Environmentdomain, memory + PostgresEnvironmentRepository(migration
000010, seedsdefault),EnvironmentService.IsValid, CRUD/v1/environments,and strict trigger validation (unknown env → HTTP 400).
llm.Registry;provideLLMRegistryresolvesprovider
{{secret:NAME}}API key/base-URL per workflow environment (static config = build-oncefast path);
ExecutionInfo.Environmentcarries scope to ai/chat & ai/agent.Credentialdomain, memory + PostgresCredentialRepository(migration
000011),CredentialService(values stored in the SecretStore atcred/<id>/<field>per environment; read-only backends rejected), CRUD/v1/credentials,fuse credentialsCLI. Field values never returned on reads.Migrations
000010/000011follow main's000009sequentially.Verification
make lint0 issues ·make buildok ·make test697 pass ·make swaggerclean (verifiedon the branch tip before this PR).
Follow-ups (not in this PR)
source:"credential",{{credential:id.field}},LLM_<PROVIDER>_CREDENTIAL).SecretStorebackend.🤖 Generated with Claude Code