Skip to content

refactor(combo): god-file split pilot — types + validateQuality + predicates (QG v2 Fase 9 T5 D1-D3) - #4162

Merged
diegosouzapw merged 3 commits into
release/v3.8.29from
refactor/combo-split-pilot
Jun 18, 2026
Merged

diegosouzapw merged 3 commits into
release/v3.8.29from
refactor/combo-split-pilot

Conversation

@diegosouzapw

Copy link
Copy Markdown
Collaborator

Contexto (QG v2 Fase 9 — Onda 3 Task 5, PILOTO)

Primeiro de ~15 PRs do split dos god-files. Prova o padrão extract + re-export byte-idêntico em open-sse/services/combo.ts (5297 LOC). 3 extrações de risco BAIXO, 1 commit cada. Plano: docs/superpowers/plans/2026-06-18-godfiles-split.md (local).

O que mudou

Módulo novo Conteúdo LOC
combo/types.ts tipos/interfaces compartilhados (+ aliases de tipo p/ evitar ciclo) 138
combo/validateQuality.ts validateResponseQuality + toRetryAfterDisplayValue 339
combo/comboPredicates.ts 11 predicados puros + 7 constantes 164

combo.ts: 5297 → 4739 LOC. Cada símbolo originalmente público segue exportado via re-export barrel (export { ... } from "./combo/..."); internos importados de volta onde combo.ts os usa. Nenhum consumidor externo muda.

Validação (auditada pelo controlador, trust-but-verify)

  • Byte-idêntico: diff de combo.ts = só remoções + re-exports/imports (zero lógica editada); validateResponseQuality e os 11 predicados diffados função-a-função vs origem = IDÊNTICOS.
  • typecheck:core rc=0 (todos os símbolos resolvem; getTargetProvider interno importado de volta).
  • 113 testes unit (validate-response-quality / skip-provider-breaker / combo-max-depth / combo-strategies / combo-routing-engine) + 1 integração round-robin sticky-3 = 0 fail (estado de roteamento preservado).
  • lint 0/0 nos 4 arquivos · check:cycles OK (sem ciclo novo; combo↔chatCore pré-existente não piorou) · build rc=0 (o ERR_FS_CP_EINVAL local é artefato do node_modules symlinkado da worktree, na cópia de native-assets pós-compile — não afeta CI).
  • file-size baseline: só a linha do combo.ts (5298→4740; +1 = trailing-newline do gate). Drift pré-existente de 22 arquivos NÃO tocado (escopo separado).
  • Sem conflito de merge (nenhum commit recente tocou combo.ts).

Próximo (após sua revisão do piloto): D4-D8 (combo) + C1-C7 (chatCore), terminando em D7 (estado RR/quota, alto risco). Fase 3 = re-add ao stryker.conf.json:mutate + expandir batches.

🤖 Generated with Claude Code

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors the large combo.ts file by extracting types, predicates, and validation logic into dedicated files under open-sse/services/combo/ (types.ts, comboPredicates.ts, and validateQuality.ts) while preserving backward compatibility via re-exports. The review feedback identifies two potential runtime TypeError vulnerabilities: one during SSE data parsing in validateQuality.ts if the parsed JSON is not an object, and another in comboPredicates.ts if isProviderCircuitOpenResult is invoked with a nullish result argument.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +107 to +112
let parsed: Record<string, unknown>;
try {
parsed = JSON.parse(data);
} catch {
continue;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When parsing the SSE data payload, JSON.parse(data) can return null or primitive values (such as booleans or numbers) if the payload is malformed or contains unexpected content. Accessing properties like parsed.type or passing parsed directly to isKnownNonClaudeStreamPayload without a non-null object check can lead to runtime TypeError exceptions. Adding a defensive check to ensure parsed is a non-null object prevents potential crashes during stream peeking.

Suggested change
let parsed: Record<string, unknown>;
try {
parsed = JSON.parse(data);
} catch {
continue;
}
let parsed: Record<string, unknown>;
try {
const val = JSON.parse(data);
if (!val || typeof val !== "object") continue;
parsed = val as Record<string, unknown>;
} catch {
continue;
}

Comment on lines +39 to +43
export function isProviderCircuitOpenResult(
result: { headers?: Headers | null; status?: number },
errorText: string
): boolean {
const breakerHeader = result.headers?.get?.("x-omniroute-provider-breaker");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The isProviderCircuitOpenResult function accepts a result object, but does not check if result itself is null or undefined before accessing result.headers. To prevent potential runtime TypeError exceptions if the function is called with a nullish value (e.g., in test environments or edge cases), use optional chaining on result as well.

Suggested change
export function isProviderCircuitOpenResult(
result: { headers?: Headers | null; status?: number },
errorText: string
): boolean {
const breakerHeader = result.headers?.get?.("x-omniroute-provider-breaker");
export function isProviderCircuitOpenResult(
result: { headers?: Headers | null; status?: number } | null | undefined,
errorText: string
): boolean {
const breakerHeader = result?.headers?.get?.("x-omniroute-provider-breaker");

@diegosouzapw
diegosouzapw merged commit 0e33b2b into release/v3.8.29 Jun 18, 2026
4 checks passed
@diegosouzapw
diegosouzapw deleted the refactor/combo-split-pilot branch June 19, 2026 12:07
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…dicates (QG v2 Fase 9 T5 D1-D3) (cheaper-inference#4162)

Integrated into release/v3.8.29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant