Skip to content

Commit 99e742d

Browse files
mogulOpenCode Agent
andcommitted
fix(opencode): exclude user overrides from kit-owned role recording
Output equality between the current config value and a new recommendation must not silently reclaim a role that the user explicitly set in the canonical file. Before this fix, when the rendered recommendation happened to match the user's canonical selection, the role was recorded as kit-owned in the embedded state — causing the next recommendation change to tombstone the user's value into removedRoleHistory, which then suppressed it on subsequent renders. The a→b→user-selects-a→a→b sequence overwrote all five user-owned selections. Fix: skip kit-owned role recording (the roles state map) for any role that is already in userRoles (confirmed canonical user override). Kit ownership is only valid when the renderer — not the user — is the authority for that role. Also add two regression tests: - user canonical override survives repeated recommendation cycles across all five roles (render a, render b, user selects a, repeated b preserves, then a then b must not reclaim any role) - new untouched roles still become managed when user has overrides on other roles (user override on X does not block Y becoming managed) Previously passing invariants verified unchanged: - stale lower-file tombstone suppression (removedRoleHistory) - managed role validation - isCanonicalExplicitEdit detection (Finding 7) 53/53 renderer tests pass. Co-authored-by: OpenCode Agent <[email protected]>
1 parent c5ea632 commit 99e742d

2 files changed

Lines changed: 96 additions & 0 deletions

File tree

‎integrations/isolation/acq-kits/opencode/files/home/opencode-config/render-provider-config.mjs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,8 +470,15 @@ function mergeManagedConfig(existing, rendered, state, ownership, canonicalConfi
470470
target[keys.at(-1)] = source[keys.at(-1)]
471471
}
472472
}
473+
// Record kit-owned roles only for roles that are NOT user overrides. A role
474+
// whose output value happens to equal the current recommendation must not be
475+
// reclaimed as kit-owned when the user explicitly selected that value — doing
476+
// so would cause a future recommendation change to tombstone the user's value
477+
// into history and silently suppress it on the next render. Kit ownership is
478+
// only valid when the renderer (not the user) is the authority for that role.
473479
const roles = {}
474480
for (const [role, keys] of Object.entries(ROLE_PATHS)) {
481+
if (Object.prototype.hasOwnProperty.call(userRoles, role)) continue
475482
let source = rendered
476483
for (const key of keys) source = source?.[key]
477484
if (source !== undefined && roleValue(config, keys) === source) roles[role] = source

‎integrations/isolation/acq-kits/opencode/tests/render-provider-config.test.mjs‎

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,95 @@ test("canonical explicit model selection overrides tombstone: render a, render b
728728
assert.equal(finalState.removedRoleHistory?.primary, undefined, "primary tombstone cleared after canonical user override")
729729
})
730730

731+
// ── Finding 8 regression (c5ea632) ───────────────────────────────────────────
732+
// Output equality must not silently reclaim an explicitly user-owned role.
733+
// Scenario: render recommendation a → render recommendation b → user explicitly
734+
// selects a (canonical) → repeated b renders preserve a → render a then b
735+
// must NOT reclaim the five user-owned roles. Provenance must survive across
736+
// full recommendation cycles once the user establishes ownership.
737+
738+
test("user canonical override survives repeated recommendation cycles across all five roles", async () => {
739+
const directory = await mkdtemp(path.join(os.tmpdir(), "opencode-config-"))
740+
const ALL_ROLES = { primary: "large", small: "small-m", compaction: "compact-m", summary: "summary-m", title: "title-m" }
741+
const allModels = Object.values(ALL_ROLES)
742+
743+
// Step 1: Render acme-ai with recommendations = a-suffixed models
744+
const renderedA = renderProviderConfig([{ facts: facts("acme-ai"), catalog: catalog("acme-ai", [...allModels.map(m => m + "-a"), ...allModels.map(m => m + "-b")], Object.fromEntries(Object.entries(ALL_ROLES).map(([role, m]) => [role, m + "-a"]))) }])
745+
await writeConfigAtomically(directory, renderedA, ownershipFromRendered(renderedA))
746+
747+
// Step 2: Render with recommendations = b-suffixed models (a-suffixed enter tombstone history)
748+
const renderedB = renderProviderConfig([{ facts: facts("acme-ai"), catalog: catalog("acme-ai", [...allModels.map(m => m + "-a"), ...allModels.map(m => m + "-b")], Object.fromEntries(Object.entries(ALL_ROLES).map(([role, m]) => [role, m + "-b"]))) }])
749+
await writeConfigAtomically(directory, renderedB, ownershipFromRendered(renderedB))
750+
const afterB1 = parseJsonc(await readFile(path.join(directory, "opencode.jsonc"), "utf8"))
751+
assert.equal(afterB1.model, "acme-ai/large-b", "primary is b after second render")
752+
753+
// Step 3: User explicitly edits canonical to select a-suffixed models for ALL FIVE ROLES,
754+
// preserving the embedded state metadata line (as a real user editor would).
755+
const canonicalRaw = await readFile(path.join(directory, "opencode.jsonc"), "utf8")
756+
const [stateLineU, ...bodyLinesU] = canonicalRaw.split("\n")
757+
const bodyU = parseJsonc(bodyLinesU.join("\n"))
758+
bodyU.model = "acme-ai/large-a"
759+
bodyU.small_model = "acme-ai/small-m-a"
760+
bodyU.agent = { ...bodyU.agent, compaction: { ...bodyU.agent?.compaction, model: "acme-ai/compact-m-a" }, summary: { ...bodyU.agent?.summary, model: "acme-ai/summary-m-a" }, title: { ...bodyU.agent?.title, model: "acme-ai/title-m-a" } }
761+
await writeFile(path.join(directory, "opencode.jsonc"), stateLineU + "\n" + JSON.stringify(bodyU))
762+
763+
// Step 4: Repeated b renders must preserve the user-selected a values for all five roles
764+
for (let i = 0; i < 3; i++) {
765+
await writeConfigAtomically(directory, renderedB, ownershipFromRendered(renderedB))
766+
const after = parseJsonc(await readFile(path.join(directory, "opencode.jsonc"), "utf8"))
767+
assert.equal(after.model, "acme-ai/large-a", `render b #${i + 1}: primary must stay user-selected large-a`)
768+
assert.equal(after.small_model, "acme-ai/small-m-a", `render b #${i + 1}: small must stay user-selected small-m-a`)
769+
assert.equal(after.agent?.compaction?.model, "acme-ai/compact-m-a", `render b #${i + 1}: compaction must stay user-selected`)
770+
assert.equal(after.agent?.summary?.model, "acme-ai/summary-m-a", `render b #${i + 1}: summary must stay user-selected`)
771+
assert.equal(after.agent?.title?.model, "acme-ai/title-m-a", `render b #${i + 1}: title must stay user-selected`)
772+
}
773+
774+
// Step 5: Render a again — output equality (config already contains a-suffixed models) must NOT
775+
// reclaim ownership of any of the five roles. They are user overrides, not kit defaults.
776+
await writeConfigAtomically(directory, renderedA, ownershipFromRendered(renderedA))
777+
const afterA2 = parseJsonc(await readFile(path.join(directory, "opencode.jsonc"), "utf8"))
778+
assert.equal(afterA2.model, "acme-ai/large-a", "render a: primary must stay user-owned")
779+
assert.equal(afterA2.small_model, "acme-ai/small-m-a", "render a: small must stay user-owned")
780+
assert.equal(afterA2.agent?.compaction?.model, "acme-ai/compact-m-a", "render a: compaction must stay user-owned")
781+
assert.equal(afterA2.agent?.summary?.model, "acme-ai/summary-m-a", "render a: summary must stay user-owned")
782+
assert.equal(afterA2.agent?.title?.model, "acme-ai/title-m-a", "render a: title must stay user-owned")
783+
784+
// Step 6: Render b again — must STILL not reclaim any of the five roles (provenance persists)
785+
await writeConfigAtomically(directory, renderedB, ownershipFromRendered(renderedB))
786+
const afterB2 = parseJsonc(await readFile(path.join(directory, "opencode.jsonc"), "utf8"))
787+
assert.equal(afterB2.model, "acme-ai/large-a", "render b after a: primary must remain user-owned")
788+
assert.equal(afterB2.small_model, "acme-ai/small-m-a", "render b after a: small must remain user-owned")
789+
assert.equal(afterB2.agent?.compaction?.model, "acme-ai/compact-m-a", "render b after a: compaction must remain user-owned")
790+
assert.equal(afterB2.agent?.summary?.model, "acme-ai/summary-m-a", "render b after a: summary must remain user-owned")
791+
assert.equal(afterB2.agent?.title?.model, "acme-ai/title-m-a", "render b after a: title must remain user-owned")
792+
})
793+
794+
test("new untouched roles still become managed when user has overrides on other roles", async () => {
795+
// A user override on role X must not prevent role Y (which the user never touched) from
796+
// becoming a kit-managed role when the renderer recommends it for the first time.
797+
const directory = await mkdtemp(path.join(os.tmpdir(), "opencode-config-"))
798+
799+
// Step 1: Render with primary=a only (no small/compaction/summary/title recommendations)
800+
const renderedPrimary = renderProviderConfig([{ facts: facts("acme-ai"), catalog: catalog("acme-ai", ["a", "b"], { primary: "a" }) }])
801+
await writeConfigAtomically(directory, renderedPrimary, ownershipFromRendered(renderedPrimary))
802+
803+
// Step 2: User explicitly selects a different primary model
804+
const rawAfter1 = await readFile(path.join(directory, "opencode.jsonc"), "utf8")
805+
const [sl1, ...bl1] = rawAfter1.split("\n")
806+
const b1 = parseJsonc(bl1.join("\n"))
807+
b1.model = "acme-ai/b"
808+
await writeFile(path.join(directory, "opencode.jsonc"), sl1 + "\n" + JSON.stringify(b1))
809+
810+
// Step 3: Render with primary=a AND small=a for the first time
811+
const renderedBoth = renderProviderConfig([{ facts: facts("acme-ai"), catalog: catalog("acme-ai", ["a", "b"], { primary: "a", small: "a" }) }])
812+
await writeConfigAtomically(directory, renderedBoth, ownershipFromRendered(renderedBoth))
813+
const after3 = parseJsonc(await readFile(path.join(directory, "opencode.jsonc"), "utf8"))
814+
// User's primary override must persist
815+
assert.equal(after3.model, "acme-ai/b", "user primary override must survive")
816+
// New small recommendation (never user-touched) must become managed
817+
assert.equal(after3.small_model, "acme-ai/a", "new small recommendation must become managed")
818+
})
819+
731820
test("stale lower-file historical model is still suppressed when canonical does not hold it", async () => {
732821
const directory = await mkdtemp(path.join(os.tmpdir(), "opencode-config-"))
733822

0 commit comments

Comments
 (0)