From 79f84cb2aa64c2362226985250241acb56207dcd Mon Sep 17 00:00:00 2001 From: magisk-k <363574826+magisk-k@users.noreply.github.com> Date: Tue, 1 Dec 2026 15:47:27 +0000 Subject: [PATCH] feat(groups): add switch to keep upstream-hidden Codex automatic modes Codex manifests fetched from upstream carry automatic modes such as codex-auto-review, which upstream already hides from the model picker and Codex uses to review approvals. The gateway removes every automatic mode the group model list does not select, so Codex falls back to the main model for reviews and the forwarded manifest always differs from upstream. Add keep_hidden_auto_modes to the group Codex manifest config. When enabled, automatic modes that upstream marks as hidden are forwarded byte-for-byte; visible ones are still removed unless selected, and explicit selections keep listing them in the picker. The switch is off by default, so existing groups behave as before, and the admin group dialog exposes it next to the pinned accounts settings. --- .../domain/codex_models_manifest_config.go | 7 ++ .../dto/group_mapper_codex_manifest_test.go | 3 + .../service/group_codex_models_manifest.go | 1 + ...penai_codex_models_keep_auto_modes_test.go | 91 +++++++++++++++++++ .../service/openai_codex_models_service.go | 29 +++++- .../group/CodexManifestAccountsField.vue | 18 ++++ .../CodexManifestAccountsField.spec.ts | 14 +++ .../src/i18n/locales/en/admin/overview.ts | 4 +- .../src/i18n/locales/zh/admin/overview.ts | 4 +- frontend/src/types/index.ts | 2 + frontend/src/views/admin/GroupsView.vue | 3 + .../GroupsView.codexManifest.spec.ts | 6 +- .../__tests__/GroupsView.duplicate.spec.ts | 2 +- 13 files changed, 179 insertions(+), 5 deletions(-) create mode 100644 backend/internal/service/openai_codex_models_keep_auto_modes_test.go diff --git a/backend/internal/domain/codex_models_manifest_config.go b/backend/internal/domain/codex_models_manifest_config.go index 22b36d8b46..7d9231ed3b 100644 --- a/backend/internal/domain/codex_models_manifest_config.go +++ b/backend/internal/domain/codex_models_manifest_config.go @@ -12,4 +12,11 @@ type GroupCodexModelsManifestConfig struct { // usable or all upstream fetches fail: fall back to the scheduler loop // (true) or return the upstream error / 503 (false, default). FallbackToScheduler bool `json:"fallback_to_scheduler,omitempty"` + // KeepHiddenAutoModes keeps Codex automatic modes (codex-auto-*) that the + // upstream manifest already hides from the picker, byte-for-byte, instead + // of removing them when the group model list does not select them. Codex + // then reviews approvals with its dedicated reviewer model, and an + // otherwise untouched upstream manifest keeps the upstream ETag. It applies + // to manifests fetched from upstream, with or without pinned accounts. + KeepHiddenAutoModes bool `json:"keep_hidden_auto_modes,omitempty"` } diff --git a/backend/internal/handler/dto/group_mapper_codex_manifest_test.go b/backend/internal/handler/dto/group_mapper_codex_manifest_test.go index d5f550d6e4..e00a05ee28 100644 --- a/backend/internal/handler/dto/group_mapper_codex_manifest_test.go +++ b/backend/internal/handler/dto/group_mapper_codex_manifest_test.go @@ -17,6 +17,7 @@ func TestGroupMapperRoundTripsCodexModelsManifestConfig(t *testing.T) { Enabled: true, AccountIDs: []int64{101, 202}, FallbackToScheduler: true, + KeepHiddenAutoModes: true, }, } @@ -27,6 +28,7 @@ func TestGroupMapperRoundTripsCodexModelsManifestConfig(t *testing.T) { Enabled bool `json:"enabled"` AccountIDs []int64 `json:"account_ids"` FallbackToScheduler bool `json:"fallback_to_scheduler"` + KeepHiddenAutoModes bool `json:"keep_hidden_auto_modes"` } `json:"codex_models_manifest_config"` } require.NoError(t, json.Unmarshal(adminJSON, &adminEnvelope)) @@ -34,6 +36,7 @@ func TestGroupMapperRoundTripsCodexModelsManifestConfig(t *testing.T) { require.True(t, adminEnvelope.CodexModelsManifestConfig.Enabled) require.Equal(t, []int64{101, 202}, adminEnvelope.CodexModelsManifestConfig.AccountIDs) require.True(t, adminEnvelope.CodexModelsManifestConfig.FallbackToScheduler) + require.True(t, adminEnvelope.CodexModelsManifestConfig.KeepHiddenAutoModes) userJSON, err := json.Marshal(GroupFromService(group)) require.NoError(t, err) diff --git a/backend/internal/service/group_codex_models_manifest.go b/backend/internal/service/group_codex_models_manifest.go index 65a12a3cec..6dd670042c 100644 --- a/backend/internal/service/group_codex_models_manifest.go +++ b/backend/internal/service/group_codex_models_manifest.go @@ -25,6 +25,7 @@ func normalizeCodexModelsManifestConfig(platform string, cfg GroupCodexModelsMan out := GroupCodexModelsManifestConfig{ Enabled: cfg.Enabled, FallbackToScheduler: cfg.FallbackToScheduler, + KeepHiddenAutoModes: cfg.KeepHiddenAutoModes, } if len(cfg.AccountIDs) == 0 { return out diff --git a/backend/internal/service/openai_codex_models_keep_auto_modes_test.go b/backend/internal/service/openai_codex_models_keep_auto_modes_test.go new file mode 100644 index 0000000000..ac45b34d44 --- /dev/null +++ b/backend/internal/service/openai_codex_models_keep_auto_modes_test.go @@ -0,0 +1,91 @@ +package service + +import ( + "context" + "testing" + + "github.com/stretchr/testify/require" +) + +func keepHiddenAutoModesGroup(groupID int64, keep bool) *Group { + return &Group{ + ID: groupID, + Platform: PlatformOpenAI, + CodexModelsManifestConfig: GroupCodexModelsManifestConfig{KeepHiddenAutoModes: keep}, + } +} + +// Scenario: with the group switch on, an upstream manifest whose automatic +// mode is hidden by upstream is forwarded byte-for-byte and keeps its ETag. +func TestMergeGroupConfiguredCodexModelsKeepsHiddenAutoModesWhenEnabled(t *testing.T) { + t.Parallel() + + svc := &OpenAIGatewayService{accountRepo: codexModelsVisibilityAccountRepo{}} + upstreamBody := []byte(`{"models":[{"slug":"gpt-5.6","visibility":"list"},{"slug":"codex-auto-review","visibility":"hide","model_messages":{"auto_review":{"enabled":true}}}]}`) + manifest := &OpenAIModelsResponse{ + Body: append([]byte(nil), upstreamBody...), + ETag: `W/"upstream-catalog"`, + } + + require.NoError(t, svc.MergeGroupConfiguredCodexModels(context.Background(), keepHiddenAutoModesGroup(81, true), manifest, "")) + require.Equal(t, upstreamBody, manifest.Body) + require.Equal(t, `W/"upstream-catalog"`, manifest.ETag) +} + +// Scenario: the switch is off by default and hidden automatic modes are still +// removed, matching the existing opt-in behavior. +func TestMergeGroupConfiguredCodexModelsDropsHiddenAutoModesByDefault(t *testing.T) { + t.Parallel() + + svc := &OpenAIGatewayService{accountRepo: codexModelsVisibilityAccountRepo{}} + manifest := &OpenAIModelsResponse{ + Body: []byte(`{"models":[{"slug":"gpt-5.6","visibility":"list"},{"slug":"codex-auto-review","visibility":"hide"}]}`), + ETag: `W/"upstream-catalog"`, + } + + require.NoError(t, svc.MergeGroupConfiguredCodexModels(context.Background(), keepHiddenAutoModesGroup(82, false), manifest, "")) + require.Equal(t, []string{"gpt-5.6"}, codexManifestModelSlugs(t, manifest.Body)) + require.Equal(t, codexModelsManifestBodyETag(manifest.Body), manifest.ETag) +} + +// Scenario: the switch never exposes automatic modes in the picker; entries +// that upstream marks as visible are still removed unless selected. +func TestMergeGroupConfiguredCodexModelsKeepHiddenAutoModesStillDropsVisibleOnes(t *testing.T) { + t.Parallel() + + svc := &OpenAIGatewayService{accountRepo: codexModelsVisibilityAccountRepo{}} + manifest := &OpenAIModelsResponse{ + Body: []byte(`{"models":[{"slug":"codex-auto-review","visibility":"list"},{"slug":"codex-auto-hidden","visibility":"hide"},{"slug":"gpt-5.6","visibility":"list"}]}`), + } + + require.NoError(t, svc.MergeGroupConfiguredCodexModels(context.Background(), keepHiddenAutoModesGroup(83, true), manifest, "")) + require.Equal(t, []string{"codex-auto-hidden", "gpt-5.6"}, codexManifestModelSlugs(t, manifest.Body)) +} + +// Scenario: an explicit model-list selection still lists the automatic mode in +// the picker, with or without the switch. +func TestMergeGroupConfiguredCodexModelsKeepHiddenAutoModesHonorsExplicitSelection(t *testing.T) { + t.Parallel() + + svc := &OpenAIGatewayService{accountRepo: codexModelsVisibilityAccountRepo{}} + group := keepHiddenAutoModesGroup(84, true) + group.ModelAllowlist = GroupModelAllowlist{Enabled: true, Models: []string{"codex-auto-review", "gpt-5.6"}} + manifest := &OpenAIModelsResponse{ + Body: []byte(`{"models":[{"slug":"codex-auto-review","visibility":"hide"},{"slug":"gpt-5.6","visibility":"list"}]}`), + } + + require.NoError(t, svc.MergeGroupConfiguredCodexModels(context.Background(), group, manifest, "")) + models := decodeCodexManifestModels(t, manifest.Body) + require.Equal(t, []string{"codex-auto-review", "gpt-5.6"}, codexManifestModelSlugs(t, manifest.Body)) + require.Equal(t, "list", models[0]["visibility"]) +} + +func TestNormalizeCodexModelsManifestConfigKeepsHiddenAutoModesSwitch(t *testing.T) { + t.Parallel() + + got := normalizeCodexModelsManifestConfig(PlatformOpenAI, GroupCodexModelsManifestConfig{KeepHiddenAutoModes: true}) + require.True(t, got.KeepHiddenAutoModes) + + got = normalizeCodexModelsManifestConfig(PlatformAnthropic, GroupCodexModelsManifestConfig{KeepHiddenAutoModes: true}) + require.False(t, got.KeepHiddenAutoModes, "non-OpenAI groups persist a zero config") +} diff --git a/backend/internal/service/openai_codex_models_service.go b/backend/internal/service/openai_codex_models_service.go index d557500d01..568c60dcd7 100644 --- a/backend/internal/service/openai_codex_models_service.go +++ b/backend/internal/service/openai_codex_models_service.go @@ -156,6 +156,7 @@ func (s *OpenAIGatewayService) BuildGroupConfiguredCodexModelsManifest( nil, group.ModelAllowlist.Models, group.ModelAllowlistEnabled(), + false, ) if err != nil { return nil, false, fmt.Errorf("build group configured Codex models: %w", err) @@ -201,6 +202,7 @@ func (s *OpenAIGatewayService) MergeGroupConfiguredCodexModels( configuredModels, group.ModelAllowlist.Models, group.ModelAllowlistEnabled(), + group.CodexModelsManifestConfig.KeepHiddenAutoModes, ) if err != nil { return fmt.Errorf("merge group configured Codex models: %w", err) @@ -1453,11 +1455,17 @@ func BuildDeepSeekCodexModelsManifest(modelIDs []string) ([]byte, error) { return BuildCodexModelsManifest(modelIDs) } +// mergeConfiguredCodexModelsManifest applies the group's picker policy to a +// Codex manifest. keepHiddenAutoModes keeps automatic modes (codex-auto-*) that +// the group did not explicitly select, provided the source already hides them +// from the picker, byte-for-byte as they appear in body. Visible automatic +// modes are still removed unless selected. func mergeConfiguredCodexModelsManifest( body []byte, configuredModels []string, selectedModels []string, filterBySelection bool, + keepHiddenAutoModes bool, ) ([]byte, bool, error) { var envelope map[string]json.RawMessage if err := json.Unmarshal(body, &envelope); err != nil { @@ -1505,7 +1513,15 @@ func mergeConfiguredCodexModelsManifest( _, explicitlyEnabled := selected[descriptor.Slug] explicitlyEnabled = filterBySelection && explicitlyEnabled if !explicitlyEnabled { - changed = true + if !keepHiddenAutoModes || !codexModelHidden(rawModel) { + changed = true + continue + } + // Codex resolves its approval reviewer from this catalog, and + // upstream already hides the entry from the picker; forward it + // untouched so the manifest can keep the upstream ETag. + seen[descriptor.Slug] = struct{}{} + merged = append(merged, rawModel) continue } visibleModel, visibilityChanged, err := codexModelWithVisibility(rawModel, "list") @@ -1558,6 +1574,17 @@ func mergeConfiguredCodexModelsManifest( return mergedBody, true, nil } +// codexModelHidden reports whether a manifest entry is hidden from the picker. +func codexModelHidden(rawModel json.RawMessage) bool { + var descriptor struct { + Visibility string `json:"visibility"` + } + if err := json.Unmarshal(rawModel, &descriptor); err != nil { + return false + } + return strings.EqualFold(strings.TrimSpace(descriptor.Visibility), "hide") +} + func codexModelWithVisibility(rawModel json.RawMessage, visibility string) (json.RawMessage, bool, error) { var fields map[string]json.RawMessage if err := json.Unmarshal(rawModel, &fields); err != nil { diff --git a/frontend/src/components/admin/group/CodexManifestAccountsField.vue b/frontend/src/components/admin/group/CodexManifestAccountsField.vue index 58c948d75b..8ffc0df4fb 100644 --- a/frontend/src/components/admin/group/CodexManifestAccountsField.vue +++ b/frontend/src/components/admin/group/CodexManifestAccountsField.vue @@ -122,6 +122,24 @@
{{ t("admin.groups.codexModelsManifest.disabledHint") }}
+ + ++ {{ t("admin.groups.codexModelsManifest.keepHiddenAutoModesHint") }} +
+