Skip to content

Corrección: feat(cli): name preflight refusal stages and selected profiles (#407) #409

In review

Description

@barbatdev

Source PR: #407
Branch: fix/qa-refusal-profile
Head reviewed: 569ea98

Push the fixes to the branch above; do not open a new pull request. Comment on the PR and on this issue when done.

Blocking findings

  • Pre-launch refusals that return before the stage block still print no stage (internal/cli/doctor.go:387): qaRefusalStage is only consulted in the block that runs after qapi.RunLocalReportOn returns (doctor.go:386-389). Every earlier pre-launch refusal returns through qaFailure before reaching it: the --evidence read failure at doctor.go:352-363 (which prints evidence_field=/evidence_reason= and no stage) and the install-root failure at doctor.go:373 (error=actor_unavailable, reachable because qaInstallRoot fails when os.UserHomeDir fails, e.g. HOME unset). The new docs/operating.md:219 says "A qa run refusal names the preflight question that refused it (qa run refusals do not identify the failing stage and the route note misreports the resolved route #374)", and docs/operating.md:232 says an evidence refusal prints stage=evidence_admission with evidence_field/evidence_reason — the word order describes exactly the branch that prints the two fields without the stage. This is the ambiguity qa run refusals do not identify the failing stage and the route note misreports the resolved route #374 was filed for, still present in the two paths the doc promises to cover.
    • Failure scenario: cortex qa run --role requirements-analyst --request requirements.txt --catalog /abs/catalog --evidence missing.json prints error=invalid_request, the note=prerequisites line, then evidence_field=path evidence_reason=file_not_found, and exits failure with no stage= line, so the operator cannot tell this from any other pre-launch refusal; env -u HOME cortex qa run --role requirements-analyst --request requirements.txt --catalog /abs/catalog likewise prints error=actor_unavailable with no stage=actor_admission.
  • route_provider/route_model are written raw while the new doc claims they are escaped (internal/cli/doctor.go:408): fmt.Fprintf(stderr, "route_provider=%s route_model=%s\n", unavailable.Provider, unavailable.Model) writes the routed pair verbatim. That pair is the profile's own text: qaroute.routeText accepts any JSON string of up to 128 bytes with no charset restriction, resolve.go copies it into ResolvedRoute.Provider/Model, and qapi carries it into BackendUnavailableError (backend.go:70-83, report.go:172). The section this PR adds says the pair is "escaped for the terminal" (docs/operating.md:230), and the same PR sanitizes the caller-supplied --profile id through sanitizeProfileToken, so the escaping contract exists in the new surface but is not applied to the values the profile file controls. The model-probe test only feeds a benign pair (openai-codex/gpt-5.6-terra), so nothing catches it.
    • Failure scenario: A catalog whose cortex/qa-profiles.json routes the role to {"provider":"\u001b]52;c;SGVsbG8=\u0007","model":"m","effort":"low"} and a run whose availability probe answers model_unavailable writes the raw OSC 52 sequence into stderr on the route_provider= line (clipboard write / title rewrite in the operator's terminal), contradicting the documented escaping.

Acceptance criteria

  • Fixed: Pre-launch refusals that return before the stage block still print no stage (internal/cli/doctor.go:387). The scenario below no longer reproduces: cortex qa run --role requirements-analyst --request requirements.txt --catalog /abs/catalog --evidence missing.json prints error=invalid_request, the note=prerequisites line, then evidence_field=path evidence_reason=file_not_found, and exits failure with no stage= line, so the operator cannot tell this from any other pre-launch refusal; env -u HOME cortex qa run --role requirements-analyst --request requirements.txt --catalog /abs/catalog likewise prints error=actor_unavailable with no stage=actor_admission.
  • Fixed: route_provider/route_model are written raw while the new doc claims they are escaped (internal/cli/doctor.go:408). The scenario below no longer reproduces: A catalog whose cortex/qa-profiles.json routes the role to {"provider":"\u001b]52;c;SGVsbG8=\u0007","model":"m","effort":"low"} and a run whose availability probe answers model_unavailable writes the raw OSC 52 sequence into stderr on the route_provider= line (clipboard write / title rewrite in the operator's terminal), contradicting the documented escaping.

Activity

  1. added
    status:approved
    on Oct 31, 2026
  2. added
    fleet
    on Nov 24, 2026
  3. barbatdev commented on Nov 24, 2026

    @barbatdev
    ContributorAuthor

    Implemented in #446 at d9d6743. Early evidence-file refusals emit stage=evidence_admission; unset-HOME install-root refusal emits stage=actor_admission. Existing terminal-safe provider/model rendering is covered with hostile profile regressions. Current main reports missing evidence as file_unavailable (the bounded reader drops the underlying stat error); that existing reason remains unchanged. Focused tests, full Go suite, vet, all 16 local Python policy tests and independent review passed. Exact-head GitHub CI also passed the full race suite and all policy checks: https://github.com/refactor-ia/cortex/actions/runs/45307126360. Ready for review; not merged.

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

    fleetfleet-qastatus:approved

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions