Skip to content

scanOneTarget is a 188-line pass sequencer with per-target state on session #473

Backlog

Description

@TMHSDigital

Summary

scanOneTarget (188 lines, the top-churn CLI function) sequences every pass of a target and keeps per-target state on the long-lived session struct, reset by hand at the top of the function. The "reset refound, run a pass, subtract refound" step is written three times.

Where

  • internal/cli/session.go:741-929 (scanOneTarget)
  • internal/cli/session.go:56-62 (per-target fields on session: target, targetResults, cands, foundBy, restored, refound), reset at :778-788
  • internal/cli/session.go:969, :896, internal/cli/ptr.go:223 (three copies of the refound step)
  • internal/cli/session.go:891, :914-915 (hand-built gate conjunctions for later passes)

Impact

Each new pass (-permute-only #376, -ptr #436) adds a branch here and a field to session. A field not reset per target leaks between -dL targets; the #408 fix for restored was exactly that. The function can only be tested through a whole session end to end.

Suggested fix

  1. Pin behavior: add a -dL test checking that foundBy and refound are per target (two targets, the second resumed). The existing resume_branches_test.go, permute_only_test.go and ptr_test.go cover the rest.
  2. Introduce type targetRun struct { target; log; cands; foundBy; restored; refound }, created at the top of scanOneTarget, and move the six fields off session.
  3. Extract runPass(ctx, tr, pass, emit) (targetResult, refoundCount), owning the refound reset and subtraction, and use it from the main, permutation and PTR passes.
  4. Extract prepareTarget and restoredTarget, so scanOneTarget reads: prepare, restore or main, permute if allowed, PTR if allowed, record.
  5. Replace the gate conjunctions with one method on targetResult.

Filed by repo-audit/full-audit at a45b999. Severity: medium. Effort: M. audit-key: tech-debt|internal/cli/session.go|scanOneTarget

Activity

  1. added
    area: cli
    tech-debt
    severity: medium
    on Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: cliseverity: mediumtech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions