Skip to content

fix(cli): name early QA preflight refusal stages - #446

Open
barbatdev wants to merge 1 commit into
mainfrom
fix/409-preflight-refusals
Open

barbatdev wants to merge 1 commit into
mainfrom
fix/409-preflight-refusals

Conversation

@barbatdev

@barbatdev barbatdev commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Linked Issue

Closes #409

PR Type

  • type:feature Feature
  • type:bug Bug fix
  • type:docs Documentation
  • type:refactor Refactoring
  • type:chore Maintenance
  • type:breaking-change Breaking change

Summary

Name the preflight stage on evidence-file read failures and install-root resolution failures, which return before the report pipeline can classify them.

The source PR #407 is already merged, so this correction uses a new feature branch rather than updating a closed review.

Changes

  • Emit stage=evidence_admission before early evidence diagnostics.
  • Emit stage=actor_admission when the selected runtime's install root cannot be resolved.
  • Add public CLI regressions for missing, directory and oversized evidence, unset HOME, and hostile profile-controlled provider/model values.
  • Clarify the existing operating documentation. Preserve error codes, evidence reasons, normal success and post-launch output.

Route identity escaping is already present on the current base; its hostile-input regression passes without any additional production change. Missing evidence currently reports file_unavailable, not the issue example's file_not_found, because the existing bounded file reader discards the underlying stat error. This correction preserves that existing reason and fixes the missing stage.

Focused Tests

  • Observed RED for early evidence/install-root stage assertions before the production fix; the hostile-route test already passed on base.
  • go test ./internal/cli -run 'TestQARun(Early|ModelRefusalEscapes|NamesThePreflightRefusalStage|WithoutAProfile|ProfileFlag)' -count=1 — passed, including final parent spot check.
  • go test ./... -count=1 — passed.
  • go vet ./... — passed.
  • /usr/bin/python3 -m unittest tests.test_community_policy tests.test_github_policy tests.test_runtime_adapter_contract — all 16 tests passed.
  • git diff --check — passed.
  • Independent scratch-snapshot review: no blockers; focused tests, full CLI package and CLI vet passed.
  • Exact-head GitHub CI passed at d9d6743fc77d3044097194e9ebfbf5f7752164d4: full Go suite, vet, full race detector suite, all Python policy contracts, and PR metadata validation. CI run: https://github.com/refactor-ia/cortex/actions/runs/45307126360.
  • Local full-race attempts exceeded foreground runner limits; the redundant background run was stopped once exact-head CI independently passed the complete race suite. No local race pass is claimed.

The initial Python run exposed the repository's exact publication inventory; the new tests were moved into the existing QA test file rather than changing policy. The default managed Python lacked PyYAML; the system interpreter passed all policy tests.

Runtime Harness

Public Run entry point with disposable catalog/runtime fixtures, no real provider calls. Assertions cover failure exit status, empty stdout, stage attribution, retained evidence fields/reasons, terminal escaping of both route fields, and no report-execution frame after refusals. Existing success and post-launch tests remain passing.

Rollback

Revert this commit to remove the two diagnostic stage lines, their regression tests and documentation clarifications. No stored-data or configuration migration.

Chain Dependencies / Out of Scope

Standalone correction on current main; 83 changed lines. No new route sanitizer, file-reader behavior change, request-validation policy, or runtime configuration changes.

Risk: item 3 (user-visible CLI diagnostic contract); hostile-route security behavior is regression-tested. Independently verified.

Checklist

  • Linked issue is open and status:approved.
  • Exactly one matching type:* label is applied.
  • Focused tests and runtime harness evidence are recorded.
  • Rollback and out-of-scope boundaries are documented.

@barbatdev

Copy link
Copy Markdown
Contributor Author

Fleet review (deepseek)

Lens: evidence + test design. Reviewed #446 at head d9d6743 and verified each claim against the source at that head, not only against the diff. Both blocking findings of #409 are addressed: an evidence-file read failure now prints stage=evidence_admission before its evidence_field/evidence_reason line (internal/cli/doctor.go:360-373), and an install-root resolution failure prints stage=actor_admission (doctor.go:381-386). The routed pair was already escaped on the base and doctor.go:419-421 passes Provider and Model through sanitizeRouteIdentity -> escapeDiagnosticText, which renders every byte outside printable ASCII (and the backslash itself) as \xNN; that matches the new hostile-route expectation byte for byte, so the PR correctly adds only a regression test for it. The new tests are consistent with the implementation rather than merely written to it: readQAFile (doctor.go:624-643) returns a bare fmt.Errorf and never wraps os.ErrNotExist, so a missing path lands in the file_unavailable branch, a directory in not_a_file, and an oversized file in exceeds_size; qaInstallRoot fails when HOME is unset because skillroot.ResolveSystemUninstallRoots calls os.UserHomeDir (internal/skillroot/resolve.go:157-162), which is exactly what the install-root test unsets; and qaReportNote contains no stage= token, so the Count(stderr, "stage=") == 1 assertion is meaningful. No blocking finding. The remaining notes are about the one quoted reason that differs from #409's example, two earlier refusals that still print no stage, and one unasserted detail line in the oversized case.

Suggestion (2)

  • Two earlier refusals still return without a stage (internal/cli/doctor.go:353): The correction covers the two paths Corrección: feat(cli): name preflight refusal stages and selected profiles (#407) #409 named, but the doc sentence the PR edits still reads "A qa run refusal names the preflight question that refused it" (docs/operating.md), and two refusals before the evidence block still print only error= plus note=: the unreadable --request file at doctor.go:353-355 (cortex qa run --role requirements-analyst --request missing.txt --catalog /abs/catalog prints error=invalid_request, the note=prerequisites line, and no stage=), and the os.Getwd/filepath.Abs failure at doctor.go:376-380. Not in the correction's acceptance criteria and not new behaviour, so not blocking: either name stage=evidence_admission-style vocabulary for the request-file refusal or state the exception in the same doc section.
  • The oversized case asserts only the prefix, so evidence_detail is untested (internal/cli/qa_test.go:872): TestQARunEarlyEvidenceRefusalNamesStage checks a prefix ending at the evidence_field line plus Count(stderr, "stage=") == 1. For the oversized subtest the implementation also emits evidence_detail=file size %d exceeds %d bytes (doctor.go:367), which no assertion covers, so a regression that dropped or duplicated that line would pass. Add one assertion for the oversized case that the detail line is present with the created size and that no second stage token appears.

Question (1)

Verdict: ready to merge

@barbatdev

Copy link
Copy Markdown
Contributor Author

Fleet review (glmflash)

Lens: adversarial. The PR fixes both blocking findings of correction issue #409 against the diff at head d9d6743. Criterion 1 (early refusals print no stage): verified in the head's internal/cli/doctor.go — the evidence read failure prints stage=evidence_admission before the evidence_field/evidence_reason lines (doctor.go:362) and the install-root failure prints stage=actor_admission before returning (doctor.go:384); new regressions in qa_test.go cover missing, directory, oversized evidence and the unset-HOME install-root path, each asserting exactly one stage line, failure exit, empty stdout, and no backend launch. Criterion 2 (raw route identity vs documented escaping): verified that doctor.go:420 at the head writes route_provider/route_model through sanitizeRouteIdentity (which delegates to escapeDiagnosticText, doctor.go:481-487), so the documented escaping holds on the current base without a production change, exactly as the PR body claims, and the new TestQARunModelRefusalEscapesProfileRouteIdentity pins the hostile OSC-52/newline/backslash cases with an assertion that no raw control byte reaches stderr. Docs changes in docs/operating.md accurately describe both newly named paths. Exact-head CI (run 45307126360) passed, including the full race suite. One residual gap found adversarially, filed as a question because the correction criteria do not name it and the four-stage vocabulary has no entry that fits: the request-file read failure path still returns before the stage block without a stage.

Suggestion (1)

  • Install-root test only exercises the HOME-driven path (internal/cli/qa_test.go:903): TestQARunEarlyInstallRootRefusalNamesStage combines t.Setenv("HOME", "") with os.Unsetenv("HOME"). On Linux os.UserHomeDir fails when HOME is unset, which is what the test pins; on platforms where the underlying lookup consults other variables the fixture would not reproduce the refusal. Fine for the current Linux-only fleet; worth remembering if the harness ever runs on another platform.

Question (1)

  • Request-file read failure is the one remaining pre-stage-block return with no stage (internal/cli/doctor.go:355): readRequestTask failure returns qaFailure(stderr, "invalid_request") before the stage block and prints no stage. The correction criteria only named the evidence read (now fixed at doctor.go:362) and install-root (now fixed at doctor.go:384) paths, so this is not a criterion contradiction, but it is the same ambiguity class issue qa run refusals do not identify the failing stage and the route note misreports the resolved route #374 was filed for. None of the four documented stages (route_resolution, actor_admission, model_probe, evidence_admission) describes a missing/unreadable --request file, so the stage vocabulary cannot classify it as-is.

Verdict: ready to merge

@barbatdev

Copy link
Copy Markdown
Contributor Author

Fleet review (qwen38)

Lens: evidence. Reviewed #446 at head d9d6743 (83 changed lines: docs/operating.md, internal/cli/doctor.go, internal/cli/qa_test.go) against correction issue #409. Both blocking criteria are met with verifiable evidence. AC1 (early refusals print a stage): the head source emits stage=evidence_admission before the evidence field lines and stage=actor_admission on the install-root failure, and regression tests pin the exact stderr prefix, exit status, empty stdout, single stage line, and no backend launch for missing, directory, oversized evidence and unset HOME. AC2 (escaped route identity): confirmed against the base itself — sanitizeRouteIdentity already wraps route_provider/route_model at base f84fb20 (doctor.go:417), so the #409 finding against the older head is resolved; the PR adds an honest regression test that feeds an OSC 52 / newline / title-rewrite route pair and asserts no raw control bytes remain, and the PR body correctly states this test passed on base rather than claiming a production fix. The CI claim was verified by inspecting the exact-head runs: CI run 45307126360 (success) contains go vet, go test ./..., go test -race ./... and all three Python policy suites in its single job, plus three successful PR validation runs. One evidence gap noted below: the file_not_found reason branch is unreachable and the issued acceptance-criterion text quotes a reason the shipped behavior does not produce, which the PR acknowledges and explains but leaves as a definitional ambiguity rather than a defect.

Suggestion (1)

  • Positive evidence for both refusal shapes; add a note-assertion for the actor branch only if the note vocabulary evolves (internal/cli/qa_test.go:872): The early-evidence test asserts the full stderr prefix (error line, note=prerequisites, stage line, then the field/reason line) plus strings.Count(stderr, "stage=") == 1 and absence of the qa-report-frame marker — strong, order-pinned evidence for AC1. The install-root test asserts exact equality of stderr instead of a prefix, which is stricter, so no change is required; noted only as the rationale for why the two siblings use different assertion shapes, in case a future step adds a remedy line to one of them and the exact-equality assertion needs to be relaxed deliberately rather than accidentally.

Question (1)

  • file_not_found reason is unreachable; acceptance criterion text quotes a reason the code cannot emit (internal/cli/doctor.go:363): Issue Corrección: feat(cli): name preflight refusal stages and selected profiles (#407) #409's acceptance criterion describes the missing-evidence refusal as printing evidence_reason=file_not_found. The shipped path prints file_unavailable instead, because readQAFile (doctor.go:624-627) collapses the stat error into fmt.Errorf("request is not a bounded regular file") without %w, so the os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) branch at doctor.go:363 can never match for an evidence file that does not exist. The PR body openly documents this deviation ('Missing evidence currently reports file_unavailable, not the issue example's file_not_found') and the new test pins file_unavailable, so the stage fix itself is correctly evidenced — but the file_not_found branch is now dead code with no test that can exercise it, and the correction issue's checklist wording stays permanently unsatisfiable as literally written. Please confirm which reason string is the contract for a missing evidence file: either close the branch in Corrección: feat(cli): name preflight refusal stages and selected profiles (#407) #409 with the file_unavailable outcome (and later remove the dead branch or wrap the stat error so it is reachable), or treat the divergence as out of scope for this PR and record the resolution on the issue.

Verdict: ready to merge

@barbatdev

Copy link
Copy Markdown
Contributor Author

Fleet review (glm)

Lens: requirements + adversarial. Both blocking scenarios from issue #409 are fixed at this head: the early evidence read failure now prints stage=evidence_admission before the evidence_field/evidence_reason lines (internal/cli/doctor.go:362), and the install-root resolution failure now prints stage=actor_admission (internal/cli/doctor.go:384); error codes, note line, and ordering match the pipeline-classified path, and the new tests assert exact prefixes, single stage occurrence, empty stdout, failure exit, and no backend launch. The route-identity escaping required by the second criterion is present at head (internal/cli/doctor.go:420 routes Provider/Model through sanitizeRouteIdentity -> escapeDiagnosticText) and the new regression genuinely injects raw OSC-52/ESC/BEL/CR/backslash bytes through a caller-owned profile and asserts the escaped rendering plus absence of raw control bytes, so that criterion no longer reproduces either. Doc updates at docs/operating.md:255-264 match the implemented behavior, including the install-root extension of actor_admission and read-failure coverage of evidence_admission. Remaining findings are non-blocking: the criterion-1 example output names evidence_reason=file_not_found, but a missing evidence file actually reports file_unavailable because the bounded reader discards the stat error (documented in the PR body, with the file-reader change declared out of scope); the os.IsNotExist branch that would print file_not_found is unreachable dead code; and request-task/cwd/catalog resolution failures still refuse with no stage, which is the same ambiguity class but outside the issue's two named scenarios and the fixed four-stage vocabulary. Process note: issue #409 asked for fixes on branch fix/qa-refusal-profile, but source PR #407 was already merged, so a new branch/PR is a reasonable delivery; the PR closes the correction issue.

Suggestion (1)

  • Unreachable file_not_found branch (internal/cli/doctor.go:363): readQAFile (internal/cli/doctor.go:624-643) returns only freshly constructed fmt.Errorf values, never an error wrapping os.ErrNotExist, so the branch at doctor.go:363-364 that prints evidence_reason=file_not_found is dead code for every reachable input, including missing files. It misleads readers into expecting file_not_found in the reason vocabulary. Not required for merge; consider wiring the stat error through or removing the branch in a follow-up so the code and the reason vocabulary agree.

Question (2)

  • Missing evidence reports file_unavailable, not the criterion example's file_not_found (internal/cli/doctor.go:363): Acceptance criterion 1 of issue Corrección: feat(cli): name preflight refusal stages and selected profiles (#407) #409 quotes the refusal output as evidence_field=path evidence_reason=file_not_found, but a missing evidence file reports evidence_reason=file_unavailable: readQAFile (internal/cli/doctor.go:624-643) discards the underlying os.Stat error into a generic constructed error, so the os.IsNotExist check at doctor.go:363 never matches a missing file and control falls to the file_unavailable branch at doctor.go:371. The PR body documents this divergence and explicitly declares the file-reader behavior change out of scope; the new test pins file_unavailable. The core defect of the criterion (no stage= line) is fixed, so this is not blocking, but the divergence from the criterion's literal example should be confirmed as accepted when the correction issue checkbox is ticked.
  • Request-task and cwd/catalog resolution failures still print no stage (internal/cli/doctor.go:353): Two further pre-launch refusals return through qaFailure before any stage attribution: the request-task read failure at internal/cli/doctor.go:353-356 (e.g. --request missing.txt prints error=invalid_request with no stage and no field, since readRequestTask uses the same discarding readQAFile) and the os.Getwd/filepath.Abs failure at internal/cli/doctor.go:376-380. docs/operating.md:248 states 'A qa run refusal names the preflight question that refused it', and these refusals name none. They are outside issue Corrección: feat(cli): name preflight refusal stages and selected profiles (#407) #409's two named scenarios and outside the fixed four-stage vocabulary of qa run refusals do not identify the failing stage and the route note misreports the resolved route #374 S4, so they are not blocking here; confirm whether request-file admission is intentionally excluded from the stage vocabulary or deserves its own follow-up.

Verdict: ready to merge

@barbatdev

Copy link
Copy Markdown
Contributor Author

Fleet review (mimo)

Lens: requirements. Both acceptance criteria of issue #409 are satisfied at head d9d6743: (1) the two early refusals now print their stage before returning (internal/cli/doctor.go:362 evidence_admission, doctor.go:384 actor_admission) and both new regression tests assert exactly the stage-plus-fields output; (2) route_provider/route_model are escaped on this head via sanitizeRouteIdentity (doctor.go:420, helper at doctor.go:477), which I verified against the reviewed head's file content, and the new hostile-route test asserts no raw ESC/BEL/CR reaches stderr. The diff does not contradict any explicit criterion, so no blocking findings. Remaining items are an ambiguity in the criterion's quoted reason token and two out-of-scope refusals worth clarifying.

Suggestion (1)

  • Dead file_not_found branch misleads future readers (internal/cli/doctor.go:362): Because readQAFile never wraps its underlying stat/open errors, the os.IsNotExist(err) || errors.Is(err, os.ErrNotExist) branch at doctor.go:362-363 can never execute. It documents a file_not_found reason that no input can produce, which is exactly the mismatch that made the issue's scenario quote confusing. Either wire the real error through or drop the branch so the code matches the observed vocabulary.

Question (2)

  • Criterion scenario quotes evidence_reason=file_not_found, head produces file_unavailable (internal/cli/doctor.go:371): Acceptance criterion 1 quotes the failing scenario as printing evidence_field=path evidence_reason=file_not_found. At this head, readQAFile (doctor.go:624-629) swallows the os.Stat error and returns fmt.Errorf without %w, so a missing evidence file always lands in the final else branch and prints evidence_reason=file_unavailable (doctor.go:371); the os.IsNotExist branch at doctor.go:362 is unreachable. The stage defect the criterion targets IS fixed, and the PR body discloses this discrepancy, but the criterion's quoted token and the actual output still differ. Please confirm whether the criterion text should be corrected or the reason token is a separate expected fix.
  • Two other early refusals still print no stage while docs claim every refusal names one (docs/operating.md:248): docs/operating.md:248 states '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)'. Two pre-launch refusals at this head still return qaFailure with no stage line: readRequestTask failure (internal/cli/doctor.go:355, error=invalid_request) and the Getwd/catalog-abs failure (internal/cli/doctor.go:379, error=invalid_request). Neither is named by issue Corrección: feat(cli): name preflight refusal stages and selected profiles (#407) #409's acceptance criteria, so they are out of this correction's scope, but confirm they are intentionally outside the fixed stage vocabulary rather than a remaining gap of the same ambiguity qa run refusals do not identify the failing stage and the route note misreports the resolved route #374 filed for.

Verdict: ready to merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type:bug Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants