26 KiB
status, system, requirements, created, owners
| status | system | requirements | created | owners | ||
|---|---|---|---|---|---|---|
| draft | executors |
|
2026-08-17 |
|
Executor-Profile Environment Precedence System Design Part 3
Purpose and boundaries
This design preserves the technical source detail for REQ-EXECUTORS-EXECUTOR-PROFILE-ENV-PRECEDENCE-001 during migration.
Requirement mapping
| Requirement | Design section |
|---|---|
REQ-EXECUTORS-EXECUTOR-PROFILE-ENV-PRECEDENCE-001 |
Migrated source detail |
Migrated source detail
Acceptance criteria
Observable behaviour. Each criterion is pass/fail against the resolver's return value, the emitted override records, or the resulting environment map.
Precedence
- AC-1 WHEN a key has one literal definition from origin
executor profileand one literal definition from originagent profilewith a different value, THE SYSTEM SHALL resolve that key to theexecutor profilevalue and SHALL NOT return an error. - AC-2 WHEN a key has one literal definition from origin
managed runtimeand one literal definition from originagent profilewith a different value, THE SYSTEM SHALL resolve that key to themanaged runtimevalue and SHALL NOT return an error. - AC-3 WHEN a key has one literal definition from origin
managed credentialsand one literal definition from originagent profilewith a different value, THE SYSTEM SHALL resolve that key to themanaged credentialsvalue and SHALL NOT return an error. - AC-4 WHEN the resolver receives one literal definition from origin
agent profileand one literal definition from originmanaged agent defaultsfor the same key with different values, THE SYSTEM SHALL resolve that key to theagent profilevalue and SHALL NOT return an error. This is a resolver-level criterion. In the assembled launch path the pair cannot occur, becauseappendAgentRuntimeDefaultsdrops the agent-runtime default before resolution (AC-17). Tier 3 exists so the resolver's table is total and the assembly-time skip is a redundant optimisation rather than the only thing preventing a conflict. - AC-4a WHEN a definition is dropped at assembly time by
appendAgentRuntimeDefaults, THE SYSTEM SHALL NOT emit an override record for that key. Assembly-time filtering is not an override; only a resolver tier decision is. - AC-5 WHEN a key has literal definitions from two different Tier 1 origins with different
values, THE SYSTEM SHALL return a
*ConflictErrorwhoseOriginslists every participating Tier 1 origin sorted ascending, and SHALL NOT resolve the key. - AC-5a WHEN a key has an
executor profileliteral and anagent profileliteral carrying THE SAME value, plus amanaged runtimeliteral carrying a DIFFERENT value, THE SYSTEM SHALL return a*ConflictErrornaming all three origins sorted ascending, and SHALL NOT resolve the key. The mergedexecutor profile/agent profileidentity classifies as Tier 1 via its strongest contributing origin (procedure step 6), so the top tier holds two identities and AC-5 applies. THE SYSTEM SHALL NOT classify that merged identity by the survivingDefinition.Originfield alone, which would rank it Tier 2 and silently discard theexecutor profilevalue. This case is production-reachable and is the reason step 6 says "strongest":AGENT_MODELis emitted asmanaged runtimefromprofileInfo.Model(environment_resolution.go:65) and is not a reserved key (profile_crud.go:867-868reserve onlyTASK_DESCRIPTIONandKANDEV_*), so a user who duplicated it onto both profiles — the workaround this feature replaces — hits it. - AC-5b WHEN a key has an
executor profileliteral and anagent profileliteral carrying THE SAME value, plus a differing literal from a Tier 3 origin, THE SYSTEM SHALL resolve the key to the merged value and emit ONEOverrideRecordwhoseWinningOriginsholds BOTHagent profileandexecutor profilesorted ascending and whoseWinningTierisTierAuthoritative. This pins thatWinningOriginsmay span tiers whileWinningTierrecords only the strongest. This is a resolver-level criterion; in the assembled launch pathappendAgentRuntimeDefaultsdrops the Tier 3 definition first (AC-17). - AC-6 WHEN a key has two definitions carrying the same
Originstring and differentdefinitionIdentityvalues, AND no definition for that key sits in a STRONGER tier than that origin, THE SYSTEM SHALL return a*ConflictError. Where a stronger tier does hold exactly one surviving identity, procedure step 6 governs instead: the stronger tier wins and the ambiguous weaker-tier origins are discarded intoLosingOrigins, because a set of definitions that is being thrown away wholesale need not be self-consistent first. That discarded origin appears inLosingOriginsEXACTLY ONCE even though it contributed two identities, because both origin lists are de-duplicated sets ("The override record"); AC-8d observes this case directly. Same-origin ambiguity WITHIN the winning tier still conflicts, which is the case that matters: two differingexecutor profiledefinitions, or two differingmanaged runtimedefinitions, block the launch exactly as today (AC-5). REACHABILITY IS PER-ORIGIN, AND ONE ORIGIN REACHES THIS IN PRODUCTION. An earlier draft claimed the assembled launch path "cannot produce two same-origin definitions that disagree, because duplicate keys within one profile are rejected at save time (profile_crud.go:908)". That is true foragent profileand false forexecutor profile: the duplicate-key check is agent-profile-only (see "The two profile kinds are NOT validated the same way"), so one executor profile may legitimately hold two entries with the same key and different values. Per origin:agent profile— NOT reachable; duplicate keys rejected at save time (profile_crud.go:908).managed agent defaults— NOT reachable; built from a map.managed runtime— reachable in principle, sincereq.EnvandappendStandardDefinitionsboth emit this origin, though a collision there is a managed-value bug rather than user input.executor profile— REACHABLE from ordinary user input, with no validation preventing it. The behaviour is nonetheless unchanged from today: every one of those origins is Tier 1, so with no stronger tier present the key returns*ConflictErrorexactly as it does now. AC-6a requires the test for the reachable case.
- AC-6a WHEN one executor profile holds TWO entries with the same key and different non-empty
values, and no definition for that key sits in a stronger tier, THE SYSTEM SHALL return a
*ConflictErrornamingexecutor profile, and SHALL NOT resolve the key by picking either value. This is the ASSEMBLED-PATH case AC-6 says is reachable, and it SHALL be tested throughExecutor.taskEnvironmentSourcesrather than only against the resolver, because the claim being pinned is that a real executor profile can produce the pair.executor profileis Tier 1, so this is AC-5's same-tier behaviour and is unchanged from today; the AC exists so the reachable case has a test rather than resting on a false save-time guarantee. - AC-7 WHEN a key is defined only by origin
agent profileand no executor profile is selected for the session, THE SYSTEM SHALL resolve that key to theagent profilevalue. - AC-8 WHEN a key is defined only by origin
agent profileand the selected executor profile declares no environment variables, THE SYSTEM SHALL resolve that key to theagent profilevalue. - AC-8a WHEN a key has two Tier 1 definitions that share one
definitionIdentityand one differing literal Tier 2 definition, THE SYSTEM SHALL merge the Tier 1 pair first, then apply tier precedence, resolving the key to the merged Tier 1 value and emitting a singleOverrideRecordwhoseWinningOriginsholds BOTH contributing Tier 1 origins sorted ascending, whoseWinningTierisTierAuthoritative, and whoseLosingOriginsholds the one Tier 2 origin. Merging precedes tier comparison (procedure step 3 before step 6). This is the case that makesWinningOriginsa slice rather than a string. - AC-8b WHEN a key has two differing literal Tier 1 definitions and one differing literal
Tier 2 definition, THE SYSTEM SHALL return a
*ConflictErrorwhoseOriginsnames all three origins, sorted ascending. An ambiguous top tier is not resolved by falling through to a lower tier. - AC-8c WHEN a key has one literal Tier 1 definition and differing literal definitions in both
Tier 2 and Tier 3, THE SYSTEM SHALL resolve the key to the Tier 1 value and emit ONE
OverrideRecordwhoseLosingOriginsholds both the Tier 2 and the Tier 3 origin, each paired with its own tier, sorted byOriginascending. Per AC-24 this one record produces TWO counter increments, one per losing origin. - AC-8d WHEN a key has ONE literal Tier 1 definition and TWO literal definitions that carry
THE SAME lower-tier
Originstring as each other but DIFFERENTdefinitionIdentityvalues, THE SYSTEM SHALL resolve the key to the Tier 1 value and emit ONEOverrideRecordwhoseLosingOriginshaslen(LosingOrigins) == 1— a single entry for that origin paired with its own tier — and which produces EXACTLY ONE counter increment. This is the losing-side de-duplication pin, and it is the case AC-6's stronger-tier carve-out creates: one origin contributing two discarded identities is ONE loser, not two. A test assertinglen(LosingOrigins) == 2or two increments is asserting the rejected bag reading. This one IS genuinely resolver-level, and unlike AC-6 the reason survives the per-origin check in AC-6a. The ambiguous origin here is a LOSING origin, so it necessarily sits in Tier 2 or Tier 3 — a Tier 1 origin can never lose, and an ambiguity inside Tier 1 conflicts instead (AC-5, AC-6a). The only Tier 2 origin isagent profile, whose duplicate keys ARE rejected at save time (profile_crud.go:908), and the only Tier 3 origin ismanaged agent defaults, which is built from a map.executor profile, the one origin that can produce disagreeing duplicates, is Tier 1 and therefore cannot appear inLosingOriginsat all. - AC-8e WHEN a key has ONE Tier 1 value contributed by TWO definitions that share BOTH an
Originstring and adefinitionIdentity, plus a differing literal definition in a lower tier, THE SYSTEM SHALL emit ONEOverrideRecordwhoseWinningOriginshaslen(WinningOrigins) == 1— that origin listed once, not twice. This is the winning-side de-duplication pin. It matters beyond symmetry: today'sselectDefinitionsalready accumulates contributing origins into amap[string]struct{}, so the bag reading would be a silent behaviour change to existing merge-origin reporting. Contrast with AC-8a, where two DISTINCT origins contribute one identity and both are listed.
Secret veto
- AC-9 IF a key has definitions with different
definitionIdentityvalues and at least one of them has a non-emptySecretID, THEN THE SYSTEM SHALL return a*ConflictErrorand SHALL NOT apply tier precedence, even when the definitions sit in different tiers. - AC-10 WHEN a key has a secret-backed
executor profiledefinition and a literalagent profiledefinition, THE SYSTEM SHALL return a*ConflictError. - AC-11 WHEN a key has a literal
executor profiledefinition and a secret-backedagent profiledefinition, THE SYSTEM SHALL return a*ConflictError. - AC-12 WHEN a key has a secret-backed
repository <name>definition and any differing definition from any other origin, THE SYSTEM SHALL return a*ConflictError, preserving ADR-2026-08-03. - AC-12a WHEN a key has a secret-backed
repository appdefinition and a secret-backedexecutor profiledefinition that carry THE SAMESecretID, plus a differing literalagent profiledefinition, THE SYSTEM SHALL return a*ConflictErrorwhoseOriginsnames ALL THREE origins —agent profile,executor profile,repository app— de-duplicated and sorted ascending, and SHALL NOT resolve the key. The two secret-backed definitions share the identity"secret:<id>"and MERGE at procedure step 3, so a single survivingDefinitioncarries oneOriginfield between them. THE SYSTEM SHALL NOT enumerateDefinition.Originper surviving identity, which would report only two origins and hide from the user one of the two places the secret is bound. This is the veto-path counterpart of AC-5a, and it is the MORE production-reachable of the two: ADR-2026-08-03 makes every repository binding secret-only, so real secret disagreements arrive at step 5 rather than step 6. It preserves today's behaviour —selectDefinitionsalready folds the merged identity's accumulated origin set into the conflict set — andTestResolveEnvironmentSources_ReportsEveryConflictingOriginalready asserts against this field. - AC-13 WHEN a
*ConflictErroris returned, its message andOriginsSHALL contain no secret value, noSecretID, and no literal value.
No regression for currently-succeeding tasks
- AC-14 WHEN a key has exactly one definition, THE SYSTEM SHALL resolve it to that definition's value, unchanged from today.
- AC-15 WHEN a key has multiple definitions that all share one
definitionIdentity, THE SYSTEM SHALL merge them, resolve the key to that shared value, record every origin as it does today, and SHALL NOT emit an override record. Nothing was overridden. - AC-16 WHEN a definition set produced no error before this change AND its result was
DETERMINISTIC under the current three-column sort — that is, its outcome did not depend on input
slice order — THE SYSTEM SHALL produce the same environment map after this change.
The determinism qualifier is not a hedge; it is required, and AC-29a states the same bound for
the sort. Two changes land together, and only one of them is precedence:
- PRECEDENCE re-routes only sets that previously returned
*ConflictError, so it cannot alter any set that already succeeded. - THE FIVE-COLUMN SORT (AC-29) additionally settles ties the three-column sort left to input
order. One such tie already succeeds today: a same-
Key/Origin/SecretIDpair differing only inWorkspaceIDmerges (identity is"secret:" + SecretID), and whichever definition happens to come first supplies theWorkspaceIDthatresolveEnvironmentDefinitionbranches on to chooseRevealForWorkspaceover a global reveal (environment_resolution.go:188-195). Its revealed VALUE is therefore input-order-dependent today, and AC-29b now pins it. For such a set the post-change map may differ from one of its pre-change orderings, deliberately. A differential test against the currentselectDefinitionsas oracle MUST therefore restrict its generator to conflict-free sets that are order-INDEPENDENT today, or assert per-ordering agreement only for sets with noWorkspaceIDtie. Generating the tie class and demanding equality would be testing a promise this AC does not make.
- PRECEDENCE re-routes only sets that previously returned
- AC-17 WHEN
appendAgentRuntimeDefaultsruns, it SHALL continue to skip any key already defined by an earlier definition, preservingTestAppendAgentRuntimeDefaultsFillsOnlyMissingKeys.
Preflight consistency
- AC-18 THE shape-only preflight at
task_environment.go:118SHALL apply the same tier and secret-veto rules as the final resolve, so it never rejects a definition set that the final resolve would accept. - AC-19 WHILE the preflight definition set contains no
agent profiledefinitions, its accept/reject verdict SHALL be identical to today's for every input. - AC-19a BOTH assembly sites SHALL derive their origin strings from one shared set of exported
constants declared in the
environmentpackage, and the tier table SHALL be defined once, in that same package. The orchestrator site currently hardcodes"managed runtime"and"executor profile"(task_environment.go:63,:67) while the lifecycle site uses unexported constants (environment_resolution.go:17-21); a rule keyed on origin cannot depend on two independent spellings staying in sync. - AC-19c THE
environmentpackage SHALL export exactly two classification functions,TierForOrigin(origin string) TierandIsRepositoryOrigin(origin string) bool, and SHALL NOT export the tier table itself.TierForOriginSHALL be the only reader of that table.IsRepositoryOriginSHALL be the only implementation of the normative repository-origin rule ("What counts as a repository origin"), and BOTHTierForOriginandNormalizeOriginLabel(AC-25) SHALL call it rather than re-deriving it — one spelling, per AC-19a. A test SHALL assertIsRepositoryOriginagainst the worked boundary table in that section: true forrepository,repository app,repository app(two spaces) andrepository\tapp; false forrepositoryappand the empty string. A test SHALL also assert thatTierForOriginreturnsTierAuthoritativefor an origin the table does not name (AC-35). Keeping the table unexported is observable at compile time and is the point: an exported map could be mutated by any importer, which would defeat the single-source-of-truth guarantee AC-19a asks for. - AC-19b
ValidateSHALL keep the signaturefunc Validate([]Definition) errorand SHALL emit no override record, no override log, and no counter increment. A test SHALL assert that a definition set which WOULD produce an override when passed toResolveproduces no observable override side effect when passed toValidate.
Observability
-
AC-20 WHEN tier precedence resolves a key that would previously have produced a
*ConflictError, THE SYSTEM SHALL produce exactly oneOverrideRecordfor that key, populated as declared in "The override record":Key,WinningOrigins(every DISTINCT origin that contributed to the merged winning identity, each listed ONCE, sorted ascending, at least one),WinningTier, andLosingOrigins(every DISTINCT origin appearing among the discarded identities, each listed ONCE with its tier, sorted byOriginascending, at least one). BOTH lists are DE-DUPLICATED SETS: no origin string appears twice in either. One entry per ORIGIN, never one per contributing or discarded identity. AC-8d and AC-8e observe the two de-duplication cases directly. -
AC-20a WHEN
Resolvereturns a non-nil error, it SHALL return a nil map and a nil[]OverrideRecord, even if tier precedence had already resolved other keys before the failing key was reached, AND the caller SHALL emit no override log record and SHALL NOT increment the counter for that resolve. A test SHALL cover both error paths: (a) one key resolved by tier precedence plus a second key that conflicts, and (b) one key resolved by tier precedence plus a secret that fails to reveal, which is the more reachable case because step 7 reveals only after every key is conflict-free. Nothing was applied, so nothing is reported. -
AC-21 An
OverrideRecordSHALL NOT contain any literal value, anySecretID, or any decrypted secret. The type has no field capable of carrying one. -
AC-22 THE resolver SHALL return override records to its caller rather than logging them itself. The
environmentpackage holds no logger and must stay a pure function of its inputs. Records reach the caller asResolve's new third return value. -
AC-23 WHEN a launch applies one or more overrides,
Manager.resolveStrictEnvironmentSHALL emit one structured log record at Info level perOverrideRecord, with the messageenvironment override appliedand these fields:Field Type Source env_keystring OverrideRecord.Keywinning_origins[]string WinningOrigins, in record orderwinning_tierint WinningTierlosing_origins[]string LosingOrigins[].Origin, in record orderlosing_tiers[]int LosingOrigins[].Tier, index-aligned withlosing_originstask_idstring LaunchRequest.TaskIDsession_idstring LaunchRequest.SessionIDOrigins are logged UNNORMALISED, so a reader sees which repository was involved. Normalisation (AC-25) applies to the metric label only, where cardinality matters.
-
AC-24 THE SYSTEM SHALL increment an expvar counter map named
environment_override_applied_totalonce per entry inLosingOrigins, so the number of increments for one record equalslen(LosingOrigins)exactly. Counting is POST-MERGE and strictly per-ORIGIN, never per input definition and never per discarded identity: ALL discarded definitions sharing one origin collapse into a singleLosingOriginsentry and are counted ONCE, whether or not they share adefinitionIdentity. Two differingagent profileliterals discarded together are ONE increment, not two (AC-8d). The earlier wording conditioned that collapse on sharing "one origin AND onedefinitionIdentity", which read as one entry per identity and contradicted this AC's own per-ORIGIN rule; the condition is the ORIGIN alone, becauseLosingOriginsis a de-duplicated set (AC-20, "The override record"). One key overriding one origin increments its label pair exactly once, so the counter measures overrides rather than internal identity groupings. The record and the log record remain one per key (AC-20, AC-23); only the counter fans out per losing origin, because one label pair cannot represent several losers. -
AC-24a THE counter SHALL live in a new neutral package
apps/backend/internal/agent/runtime/envmetrics, following the existing convention inapps/backend/internal/workflow/signalmetrics: anexpvar.NewMapat package scope, incremented through an exportedRecordOverrideApplied(winningOrigin, losingOrigin string)helper, with the label key built ask1=v1;k2=v2so a downstream Prometheus translation splits on the same delimiters. The label key names SHALL be exactlywinning_originandlosing_origin, giving map keys of the formwinning_origin=executor profile;losing_origin=agent profile.RecordOverrideAppliedSHALL receive values that are ALREADY NORMALISED per AC-25 and SHALL perform no normalisation of its own.envmetricsstays a neutral recorder with no dependency onenvironment, exactly assignalmetricsis neutral today. -
AC-24b THE counter SHALL be incremented by the lifecycle caller, in the same place as the AC-23 log, and SHALL NOT be incremented inside
selectDefinitions,Resolve, orValidate. Theenvironmentpackage must not importenvmetrics; keeping the resolver pure is what makes AC-27's repeatability testable. -
AC-25 THE normalised origin used as a metric label SHALL be derived as follows, and this normalisation applies to BOTH label values:
- an origin for which
IsRepositoryOriginreports true collapses to the single valuerepository, so repository names cannot make metric cardinality unbounded; - every other origin, INCLUDING an origin the tier table does not recognise, is used verbatim, with no case folding and no whitespace substitution. Origins are produced by code constants, so the value set is bounded without further processing.
- WHEN
WinningOriginsholds more than one origin, thewinning_originlabel value SHALL be each origin normalised, de-duplicated, sorted ascending, and joined with+(for exampleexecutor profile+managed runtime). The join's de-duplication is a POST-NORMALISATION step and is separate from the set rule onWinningOriginsitself: AC-20 already guarantees no origin appears twice in the field, but two DISTINCT repository origins (repository app,repository web) both normalise torepository, so the collapse can still produce a duplicate that the join must remove. That specific pair is resolver-level only, exactly as AC-4 and AC-6 are: repository definitions are secret-only by ADR construction, and the veto (AC-9) bars any secret-backed definition from reachingWinningOriginsbeside a differing definition. The join is de-duplicated anyway so the label rule is total and cannot depend on that reachability argument staying true.
THE normalisation SHALL be owned by the
environmentpackage and exposed as two exported functions beside the tier table:NormalizeOriginLabel(origin string) stringfor a single origin, andJoinOriginLabels(origins []string) stringfor the collapse-dedupe-sort-join overWinningOrigins.NormalizeOriginLabelSHALL make its repository decision by callingIsRepositoryOrigin(AC-19c), never by re-deriving the rule. The lifecycle caller calls these two and passes the results toRecordOverrideApplied; because AC-24 fans the counter out per losing origin, thelosing_originvalue is always a single origin andNormalizeOriginLabelalone produces it.environmentowns this because the repository rule is the same knowledge the tier table already consults (AC-19a): two independent spellings of "what counts as a repository origin" is precisely the drift AC-19a exists to prevent, which is why exactly one predicate exists and both callers share it. - an origin for which
-
AC-26 WHEN no override is applied during a launch, THE SYSTEM SHALL emit no override log record and SHALL NOT increment the counter. THE RETURN CONVENTION IS PINNED: when no override is applied,
ResolveSHALL returnnilfor[]OverrideRecord, never a non-nil empty slice.niland[]OverrideRecord{}are notreflect.DeepEqual, so leaving the choice open would make the AC-27 and AC-30 determinism tests fail or pass on an irrelevant detail. Callers SHALL nonetheless treat an empty slice andnilidentically —len(records) == 0is the correct caller-side test, so a future change to the convention cannot silently start emitting logs.