Skip to content

refactor(ai-review): runWorkersOpinion takes 12 positional params, ending in two adjacent same-typed booleans #10253

Description

@JSONbored

Split out of #10170, as the direct successor to #10210. See the AST re-baseline — measured properly, runWorkersOpinion is the worst real offender in the codebase at 12 positional parameters, and persistDecisionRecord (the one #10170 originally named) turns out to have 6 and is not an offender at all.

The signature

src/services/ai-review.ts:1613

async function runWorkersOpinion(
  env: Env,
  primary: string,
  fallback: string,
  system: string,
  user: string,
  maxTokens: number,
  diagnostics: AiReviewDiagnostic[] = [],
  systemAppend = "",
  correlation?: AiRunCorrelation,
  images?: readonly AiContentBlock[] | undefined,   // #4111
  bodyTruncated = false,                            // #8961
  prHasTestEvidence = false,                        // #8833
): Promise<ReviewerOpinionOutcome>

Why this one, and why now

Two adjacent same-typed booleans at the tail. bodyTruncated and prHasTestEvidence are both boolean, both default false, and sit next to each other. Swap them at a call site and nothing fails to compile, nothing fails a type check, and no test necessarily catches it — but the evidence-absence demotion (#8961) and the test-absence demotion (#8833) both fire on the wrong condition. This is exactly the failure mode #10210 was accepted to prevent, in the function that has it worst.

images? has no caller. Its own comment says so: "Absent for every existing caller — wiring a real caller is a deliberately deferred follow-up." So every call site that wants either trailing boolean must thread an undefined placeholder past it. #10170 recorded "call sites already pass undefined placeholders positionally" as the smell justifying an options object; it was wrong about persistDecisionRecord, and right about this one.

It grows by one per signal. The last three parameters were appended by three separate issues (#4111, #8961, #8833). The next reviewer signal appends a thirteenth, and the two-boolean hazard becomes a three-boolean one.

Scope

Convert the accidental tail to a single options object, keeping the genuinely positional head. env through maxTokens are the real arguments and should stay positional; everything from diagnostics onward is the accidental part.

There are 4+ call sites, all within src/services/ai-review.ts (~lines 3234, 3265, 3280, 3349) — this does not cross a package or twin boundary, so unlike #10210 there is no parity suite to keep in step.

Guardrails

  • Pure refactor. No behaviour change, no signal added or removed, no prompt or demotion rule touched. The existing ai-review suites are the regression proof — if an assertion needs editing, that is a signal the refactor changed behaviour and should be re-examined rather than the test adjusted.
  • Worth confirming while in here whether images? should simply be dropped rather than carried into the options object, given it has been dead since feat(review): advisory-only AI-vision analysis of before/after visual captures #4111. That is a separate call — flag it, do not decide it silently.

Deliberately narrow: this issue is runWorkersOpinion only. The other 25 functions at 8+ parameters from the re-baseline are not in scope.

Metadata

Metadata

Assignees

Labels

maintainer-onlyOwner-only work — yields no Gittensor points.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions