Skip to content

fix(cli): escape routed pair diagnostics - #408

Merged
barbatdev merged 1 commit into
mainfrom
fix/qa-route-escaping
Oct 31, 2026
Merged

barbatdev merged 1 commit into
mainfrom
fix/qa-route-escaping

Conversation

@barbatdev

Copy link
Copy Markdown
Contributor

Linked Issue

Refs #374

Umbrella: #401

PR Type

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

Summary

Bound and escape caller-owned provider/model identities before rendering the model-probe diagnostic, including backslash to prevent escape forging.

Changes

This is slice 7/8, 70 authored changed lines. Code, focused tests and applicable operating documentation stay together. Exact reviewed source commit: 0fa63eed9b26e67358ff64c0927d4d19f9ed2537. Delivery head 520e70abe46da9b776316e088355b901eb776ade has the identical complete source tree.

Focused Tests

Each cumulative prepared slice passed go test ./internal/cli ./internal/qapi ./internal/qaroute ./internal/installobserve -count=1, go vet ./... and whitespace checks. Final candidate additionally passed go test ./... -count=1, go vet ./..., go test -race ./... and all 15 repository Python policy tests on a byte-verified canonical clean snapshot. Independent source-agreement, typed-admission and final security verification passed with no severe blockers; final verification observed 19 named tests plus four package suites/vet.

Native assessment of this exact slice: medium native tier, reviewDue=false (under_budget); no new native review started. Security-affecting slices retained explicit high-risk escalation and independent verification rather than treating assessment as proof. Parser's separately requested native review completed approved and acknowledged.

Runtime Harness

Disposable public CLI fixtures, no real provider calls. Rejections pin no launch/write effects, route identity and safe profile tokens. macOS /tmp is a symlink and intentionally refused: canonical snapshot cwd passed unchanged guards. No credentials changed.

Rollback

Revert this slice. Revert any dependent later slice first; no stored-data migration.

Chain Dependencies / Out of Scope

Sequential verified-main strategy: merged #407 -> [current slice 7/8] -> remaining slices. This PR targets main only after its predecessor lands, so its diff contains only this work unit. Do not close the umbrella from this intermediate slice.

Known acceptance limit: #329's literal transient/persistent causal distinction is NOT established by stage reporting and remains open. Defensive untyped branches, a currently unreachable non_nan_route mapping and a brittle wording assertion were disclosed as nonblocking verifier advisories, not silently fixed. Provider transport #345 and lifecycle #373 are out of scope.

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 barbatdev added the type:bug Bug fix label Oct 30, 2026
@barbatdev

Copy link
Copy Markdown
Contributor Author

Fleet review (glm)

Lens: requirements + adversarial. Slice 7/8 of #401 adds sanitizeRouteIdentity and applies it to the single routed-pair render site (internal/cli/doctor.go:408), with table-driven unit tests plus an end-to-end refusal test staging a hostile model token in a disposable catalog copy. The escaping itself is correct: printable ASCII (minus backslash) passes through, backslash is escaped first so escape forging is impossible, DEL and all non-ASCII bytes become \xNN, and values over the 128-byte bound are withheld. I verified BackendUnavailableError.Error() is a constant string, so the preceding raw err.Error() line cannot leak the pair, and no other render site of unavailable.Provider/Model exists at this head. The stage-classification and note lines required by #374 already landed in earlier slices of the chain, so this slice neither contradicts nor duplicates them. Three non-blocking observations: the equally caller-owned --catalog path is still rendered raw in the same refusal output; an empty route identity renders as , conflating a common misconfiguration with a withheld over-long value; and the body's claimed source commit is not resolvable in this repository, so its identical-tree claim is unverifiable from the repo alone.

Suggestion (1)

  • Empty route identity renders as , hiding a common misconfiguration (internal/cli/doctor.go:466): sanitizeRouteIdentity maps both empty and over-long values to . An empty model (or provider) in a profile is a plausible authoring mistake, and the pre-change output (route_model= with an empty value) told the operator exactly that; suggests the value was withheld for size, pointing the operator at the wrong remedy. A distinct token such as for the empty case would preserve the diagnostic fidelity the issue asks for.

Question (2)

  • Caller-owned --catalog path is still rendered raw in the same refusal output (internal/cli/doctor.go:412): This slice hardens the routed provider/model pair because 'a profile is a caller-owned file'. The --catalog argument is equally caller-owned, and catalogRoot flows raw into qaRouteSetupNote (Sprintf %s), the route_missing_backend line (line 418), and qaProfileDiagnostic's route_setup field (line 567). A catalog path containing ESC or other control bytes reaches the operator's terminal unescaped. This is pre-existing behavior not introduced by the diff, so it is not blocking here, but it is the same trust surface this slice's rationale names; if a later slice in the chain covers it, confirming which one would close the gap.
  • Claimed source commit 0fa63eed is not resolvable in refactor-ia/cortex (PR body (#408)): The body states 'Exact reviewed source commit: 0fa63eed... Delivery head 520e70a... has the identical complete source tree.' The GitHub API returns 422 (No commit found for SHA) for 0fa63eed in this repository, so the identical-tree claim cannot be verified from the repo. If the source commit lives in a fork or was rewritten, noting where it can be resolved would make the claim auditable.

Verdict: ready to merge

@barbatdev
barbatdev merged commit 69c75ca into main Oct 31, 2026
3 checks passed
@barbatdev

Copy link
Copy Markdown
Contributor Author

Fleet review (qwen38)

Lens: evidence. Slice 7/8 for #374: the routed provider/model pair from BackendUnavailableError now passes through sanitizeRouteIdentity before reaching the operator terminal (doctor.go:408), which escapes every byte outside printable ASCII (including backslash, so a literal \xNN cannot be forged) and withholds empty or >128-byte values. The escape property is backed by real, PR-contained evidence: the unit test pins ESC, newline, backslash-forgery, UTF-8, empty and over-long cases, and the CLI-level test stages a hostile profile in a disposable catalog copy, asserts no raw 0x1b byte appears in stderr and asserts the escaped form route_model=evil\x1b[2Jmodel. Both tests are reproducible from the diff alone, not just asserted in the body. The sanitizer logic itself has no blocking defect found. Open evidence items: the only production call site patched is the runQA stderr path, and the PR shows no scan proving no other path prints caller-owned provider/model identities; the delivery-head source-equivalence claim is an assertion with no reproducible check; and the comment's claim that the 128-byte bound matches qaroute is not evidenced in the diff.

Suggestion (1)

  • Length bound is applied pre-escape and its 'same as qaroute' claim is unevidenced (internal/cli/doctor.go:464): The bound len(value) > 128 is checked before escaping, so a maximal accepted value can expand up to 4x (512 bytes) in output — harmless for terminal safety, but the comment asserts this is 'the same one qaroute applies' without evidence in the diff. If qaroute's bound differs, a legitimate (if unusual) long identity would be silently replaced by in the diagnostic, defeating the stated purpose that operators can compare the value against the runtime's model table. Consider citing the qaroute bound (file:line) or adding a cross-check test that pins both bounds.

Question (2)

  • Only one call site is sanitized; no evidence other identity print sites were surveyed (internal/cli/doctor.go:408): The diff adds sanitizeRouteIdentity and wires it at exactly one production call site (the BackendUnavailableError stderr line in runQA). Issue qa run refusals do not identify the failing stage and the route note misreports the resolved route #374 S5's premise is that caller-owned profile tokens must not reach the terminal unescaped. The PR contains no test or statement showing that no other location (e.g. other error wrappers, note paths in qaadmission/qaroute, or doctor's own probe reporting) prints the same Provider/Model fields raw. Evidence: grep over the diff shows a single invocation of the new function outside its own test. Please confirm the other print sites were checked and are either already escaped or cannot carry caller-owned tokens.
  • Delivery-head source equivalence is asserted, not evidenced (PR body): The body claims 'Delivery head 520e70a has the identical complete source tree' as the reviewed source commit 0fa63eed9b26e67358ff64c0927d4d19f9ed2537. Nothing in the PR makes that reproducible (no tree hash comparison, no commands). Under the evidence lens this is an assertion rather than evidence: the verification narrative (go test suites, race runs, 19 named tests) was performed on the source commit, and the reviewed head is only as trustworthy as that unverified equivalence. A tree-hash line in the body would close this.

Verdict: ready to merge

@barbatdev

Copy link
Copy Markdown
Contributor Author

Post-merge QA (glm)

Slice 7/8: sanitizeRouteIdentity bounds (128 chars) and escapes caller-owned provider/model tokens, including backslash so an escape cannot be forged, and the runQA routed-pair diagnostic now goes through it. The test table covers plain ids, ESC sequences, newlines, backslash forging, non-ASCII, empty and over-long values, and the CLI-level test pins a hostile routed model never reaching the terminal raw. The escaping choice (escape rather than flatten) is right for values operators must compare against the runtime's model table. Nothing found that breaks what landed.

No findings.

Verdict: clean

@barbatdev

Copy link
Copy Markdown
Contributor Author

Post-merge QA (deepseek)

Lens: evidence + test design. The escaping is the right shape: printable ASCII passes through, every other byte becomes a bounded hex escape, backslash is escaped so a caller-owned profile cannot forge an escape sequence, and empty or over-long values are withheld. The unit table covers the dangerous classes (ESC, newline, backslash, non-ASCII, empty, 129 bytes). Two evidence gaps: the end-to-end refusal test exercises only the model field, and the "same bound qaroute applies" claim lives in a comment with nothing in the diff tying the two bounds together.

Suggestion (1)

  • The integration test escapes the routed model but never the provider (internal/cli/doctor.go): TestQARunModelProbeEscapesTheRoutedPair pins route_model against a hostile profile value and asserts no raw ESC reaches stderr. The provider goes through the same sanitizeRouteIdentity call in runQA's BackendUnavailableError branch but is never driven with a hostile value. Test condition: profile with provider "e\u001bvil" and the model-unavailable scenario, asserting route_provider=e\x1bvil and no raw ESC byte.

Question (1)

  • The 128-byte bound is claimed to match qaroute, and nothing asserts it (internal/cli/doctor.go:466): The comment says the length bound "is the same one qaroute applies" without naming the constant, and no test relates the two. If qaroute's bound moves, this diagnostic silently accepts an identity the router would have refused, or withholds a pair the router accepted as . Which bound is authoritative, and is the coupling meant to be enforced rather than documented?

Verdict: clean

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.

1 participant