← Back to Pull requests

fix(contract): read every text file a directory boundary scan selects #9422

Closed
unknown closed this pull request without merging on Nov 26, 2026 07:15 UTC
View on GitHub
unknown unknown commented on Nov 25, 2026 04:32 UTC
Author

Goal And Delivered Outcome

  • Outcome basis / optional anchor: Self-contained ordinary contribution: the reproduced defect and its regression tests are in this PR; the linked issue is the report for the same defect.
  • Goal/source and gap: loopx check --scan-path <directory> is the documented pre-publication boundary gate (CONTRIBUTING.md, AGENTS.md, docs/public-private-boundary.md), but _resolve_scannable_file in loopx/contract.py selected directory candidates with a seven-entry suffix allow-list. Every other file was dropped before it was opened: 2,745 of 8,647 tracked files (31.7%, including 1,564 TypeScript sources) are UTF-8 text that the gate never read, while it still printed public boundary scan clean.

  • Observable before → after, with the validation row that proves it: a synthetic token in notes.txt inside a scanned directory produced ok: true / public boundary scan clean: 1 files before, and produces ok: false / notes.txt:1: credential after. The documented four-root scan reads 4,485 files before and 5,567 after, with zero blocking hits in both. Proven by the real_entrypoint row below.

  • Issue/task and intended base: Closes #9421; intended base upstream/main 216757852.
  • Author Declaration

  • Written by: model_agent (Doubao, via Doubao Work agent mode).

  • AI disclosure: drafted and validated by an AI agent under the account owner's direction, with an independent local AI review before submission; no human maintainer reviewed the change before publication.
  • Implemented against

  • Specification and revision: docs/public-private-boundary.md at 216757852 (§ "loopx check treats that as a file-state boundary") and the linked issue.

  • Criteria:
  • | Criterion (spec clause) | Disposition | Symbol / path | Test or command |
    | --- | --- | --- | --- |
    | A git-tracked file "enters the public boundary and is scanned like any other publishable file" (docs/public-private-boundary.md:257-261) | implemented | _resolve_scannable_file, BINARY_MEDIA_SUFFIXES in loopx/contract.py | tests/test_contract_scan_text_coverage.py, tests/test_contract_public_boundary_prefilter.py |
    | A --scan-path directory is reviewed for outgoing private material (loopx check --help) | implemented | same | CLI reproduction below and tests/test_contract_scan_text_coverage.py |
    | Binary media stays skipped so a mixed tree still scans | implemented | BINARY_MEDIA_SUFFIXES, _is_binary_media_path | test_directory_scan_skips_binary_media_without_failing |
    | Untracked OS metadata is skipped only when its own header proves the format; a text lookalike and a tracked file stay scanned (docs/public-private-boundary.md:263-267) | implemented | LOCAL_METADATA_HEADERS, _has_local_metadata_header, tracked_paths in loopx/contract.py | tests/test_contract_scan_text_coverage.py (gitignored .DS_Store/AppleDouble clean; git add -f .DS_Store still fails closed; no-Git staging text lookalike scanned) |
    | BOM-marked UTF-16 text is decoded before content rules; other undecodable input still fails closed (docs/public-private-boundary.md:263-269) | implemented | _decode_bom_utf16, _read_utf8 in loopx/control_plane/runtime/file_reads.py | tests/test_contract_scan_text_coverage.py (UTF-16 desktop.ini clean; direct/directory parity; malformed UTF-16 rejected) |
    | Unreadable input fails closed instead of passing silently | implemented | existing strict UTF-8 read | test_undecodable_file_with_an_unknown_suffix_stays_unexamined; tests/control_plane/test_public_boundary_parallel_reads.py |
    | Symlink eligibility follows the resolved target, not the alias name | implemented | _resolve_scannable_file | tests/test_contract_public_boundary_prefilter.py::test_scan_enumeration_follows_the_resolved_target_and_binary_media (POSIX run) |

  • Self-check before submission: reproduced the false clean receipt at the base commit through the real CLI and with an isolated runtime home; wrote the four new regression tests and saw three fail before the fix; ran the documented four-root scan (5,567 files, zero blocking hits) and the bare default scan (0 errors); ran the semantic-coinage advisory against the base commit (--changed-from 216757852), which flags BINARY_MEDIA_SUFFIXES as a new local closed set — kept local deliberately because it is file-format classification for this one scanner, and the closest existing list (public_safe_outbound.scan_cli.BINARY_SUFFIXES) answers a different question by also pruning build output and opaque packages; the intermediate name-based metadata set is replaced at the exact head by a header table in the same local scope. The credential blocking rules are unchanged; the reference classifier additionally recognizes a bare ${ interpolation template (a runtime expression cannot be a literal). Two workbench fixtures the wider scan now reaches were normalized: the fake-Codex payload emits null for an agent-approved review (matching the inProgress event; no workbench code reads the field), and the calendar fixture uses a reserved example app-link host (https://applink.example.com/...); neither fixture value is read by product code. The modified enumeration test still pins resolved-target and alias-name behavior after its suffix cases moved from .ts to binary media. Review follow-up: reproduced the reported .DS_Store failure at ab45c7113 (ok: false, unreadable_files: [".DS_Store: invalid UTF-8"]) and fixed it in 73aab878b by skipping known OS metadata names only while Git does not track them; the tracked case still fails closed. Second review follow-up: a Git-less staging directory lost a valid Markdown file named ._README.md because the name alone decided; 8eda65fc3 requires the Finder \x00\x00\x00\x01Bud1 or AppleDouble \x00\x05\x16\x07 header before skipping, so text lookalikes stay in the scan. Covered by no-Git-index, read-only-directory and text-lookalike cases. Third review follow-up: a BOM-marked UTF-16LE desktop.ini was reported as invalid UTF-8; 5b79cb162 retries an explicit UTF-16 BOM as strict UTF-16 in the existing reader, while bare, UTF-32 and malformed BOM payloads stay undecodable. Covered by clean-directory, direct-file, content-rule and malformed cases.
  • Scope And Continuation

  • Completed scope and remaining work: Directory text selection in loopx check, its regression coverage, and the expectations that encoded pyvenv.cfg as unscannable; plus the two fixture normalizations and the ${ reference precision needed to keep the repository's own default scan green after it starts reading those files. A known OS metadata file is skipped only when Git does not track it and its own header proves the Finder or AppleDouble format, so a normal macOS checkout stays clean without dropping text lookalikes; tracked content remains verified. Directory text is decoded as UTF-8, with an explicit UTF-16 BOM decoded as strict UTF-16 (Windows desktop.ini); other undecodable input stays fail-closed. No remaining work in this gate.

  • Slice boundary / successor: N/A. The sibling suffix allow-list in static-site packaging is a different owner and is tracked separately (#9405/#9406); it is not extended or changed here.
  • Validation

  • Tested revision: 89fbe0e5f109a8ac8793735582a3c18d604be249 on codex/boundary-scan-text-coverage-m5k2, merged onto current main 81ff83a0193a93e737862e1adf3bcebdf104a953

  • Exact-head refresh: focused contract suites 244 passed; broader boundary suites 514 passed / 6 skipped with one unrelated temporary-venv Python SIGABRT; TZ=UTC workbench daemon checks 89 passed; real directory and direct-file CLI checks both reject the same synthetic token; standard premerge passed 6 direct checks, 19 catalog/risk/public-boundary checks, 0 failures.

  • Run state: finished

  • Input classes: synthetic, public_fixture
  • | Check kind | Result | Public-safe evidence / limitation |
    | --- | --- | --- |
    | real_entrypoint | passed | loopx check --scan-path <tmp>: base ok: true, public boundary scan clean: 1 files; head ok: false, notes.txt:1: credential. Direct file scan rejects the same bytes in both. |
    | real_entrypoint | passed | Review finding re-run with an isolated runtime home: untracked gitignored .DS_Store (b"\x00\x00\x00\x01Bud1\xff\xfe...") beside a tracked README.md → exit 0, public boundary scan clean: 2 files, no unreadable files; the same bytes committed with git add -f → exit 1, scan file could not be read: .DS_Store: invalid UTF-8. |
    | real_entrypoint | passed | Second review finding re-run: a Git-less staging directory with README.md and a valid text ._README.md → exit 0, public boundary scan clean: 2 files (before 8eda65fc3: 1 file); binary-format .DS_Store and AppleDouble files in the same Git-less shape are still skipped by their header. |
    | real_entrypoint | passed | Third review finding re-run (isolated runtime home): UTF-16LE-with-BOM desktop.ini beside README.md → exit 0, public boundary scan clean: 2 files; direct desktop.ini scan → exit 0, 1 file; a malformed UTF-16LE BOM fixture → exit 1, scan file could not be read: desktop.ini. |
    | real_entrypoint | passed | Bare loopx check (default --scan-root ., isolated runtime home): base ok: true, 0 errors, 122 warnings, 5,306 files; head ok: true, 0 errors, 309 warnings, 8,056 files. The three source constructs first surfaced at the widened head are now reference warnings (index.ts:321 ${...}, fake-codex.mjs:361 null) or absent (personal-plan.test.ts:67 reserved example host). |
    | regression_parity | passed | Same four-root command at base and head: 4,485 → 5,567 scanned files, zero blocking hits in both; 55 → 67 non-blocking boundary warnings (summary 57 → 69 with registry warnings), all pre-existing references. |
    | static | passed | python -m ruff check (5 changed Python files), python -m py_compile, and python scripts/generate_semantic_inventory.py --changed-from 216757852 (advisory disposition above). mypy reports 16 Windows-only platform-stub errors, identical at base. |
    | integration | passed | loopx canary premerge --from-git-diff --git-diff-base 216757852, re-run at 5b79cb162: all direct checks, the public-boundary check over the changed paths, risk-profile smokes 8/8, and 10/10 catalog canaries passed. |
    | unit | passed | New tests/test_contract_scan_text_coverage.py 13 passed, 1 skipped on Windows: the four text-coverage cases, header-proven .DS_Store/AppleDouble (gitignored and Git-less staging), a text ._README.md staging lookalike with a credential, a tracked git add -f .DS_Store that still fails, a BOM-marked UTF-16 desktop.ini clean case with direct/directory content-rule parity, a malformed UTF-16 rejection, and a POSIX-only read-only-directory case. tests/test_contract_credential_pattern_precision.py + the coverage file 171/171 on Windows. The existing blocking cases for literal Authorization: values are unchanged; the new reference cases cover ${(await ...)} and a named runtime value. |
    | unit | passed | Workbench fixtures: personal-plan.test.ts 7/7 and adapters.test.ts 82/82 under npx tsx --test in apps/workbench/packages/daemon. |
    | integration | passed | Linux boundary suites: tests/test_contract_.py, tests/test_public_.py, tests/control_plane/test_public_boundary_parallel_reads.py, tests/control_plane/test_contract_health.py, tests/canary/test_premerge_public_boundary_run.py, tests/canary/test_git_path_display.py — 511 passed; focused boundary set 275 passed. |
    | unit | passed | Windows focused runs: 62 passed with the known base-identical CRLF failure; contract set re-run after the UTF-16 fix: 255 passed, 12 skipped, the same 7 host-only failures (os.symlink privilege — WinError 1314 — and one CRLF line-number case, identical at base); control-plane boundary suite failed only on the same os.symlink privilege; tests/canary/test_git_path_display.py 8 failures identical at base (unrelated byte-path tests). |
    | integration | not_run | GitHub required checks run only after this PR exists; verification is deferred to the published CI run. |

  • Coverage and gaps: The changed selector is covered by direct CLI reproduction, synthetic fixtures for .txt/.ts/.html/extensionless files, binary media, undecodable input, header-proven versus text OS metadata (.DS_Store, AppleDouble) in Git and Git-less staging shapes, BOM-marked UTF-16 desktop.ini (directory and direct input, content-rule parity, malformed payload), a read-only directory on POSIX, and POSIX resolved-symlink cases. The bare-scan disposition is covered by the repository's own tree at base and head plus the two workbench test files. Not covered locally: Windows symlink creation (host privilege, base-identical), and the slow delegation suites that hang on this Windows host both at base and head; neither exercises the selector. The credential patterns and literal-blocking cases are unchanged; only the reference classifier recognizes bare ${ templates.
  • Frontend / Visual Evidence

  • UI impact: none

  • Before: N/A

  • After: N/A

  • First viewport and preview: N/A (CLI-only change)

  • States and viewports shown: N/A

  • Source data: none

  • Attention review: N/A

  • Craft review: N/A
  • Type of Change

  • Bug fix

  • New feature

  • Breaking change

  • Refactoring (no functional changes)

  • Documentation update

  • Test update
  • LoopX Area

  • Control plane (goals, todos, quota, scheduler, registry, runtime)

  • Benchmark boundary (adapters, runners, verifiers, scoring, evidence)

  • Capability or extension (providers, adapters, skills)

  • Public docs or presentation surface (README, protocols, dashboard)

  • Build, packaging, installer, or CI

  • Host or runtime integration
  • Technical Direction

  • Direction / acceptance reference, when applicable: Core control-plane hardening (public-boundary gate correctness).
  • Shared-authority RFC fixture impact

  • Production-scale fixture schema: N/A

  • Semantic dimensions changed, or reviewed no-impact rationale: N/A (no TypeScript control-plane migration or Goal Authority surface changed)

  • Provider conformance arms run: N/A

  • Read-only legacy/file/PostgreSQL three-arm rehearsal (required for promotion, runtime-routing, or compatibility-projection changes): N/A
  • Boundary Checklist

  • Neither the diff nor this PR body/comments/attachments disclose private state, credentials, raw traces or verifier output, internal links, or local machine paths (including .loopx/, .codex/goals/, and live ACTIVE_GOAL_STATE.md).

  • I did not duplicate maintainer-owned benchmark work unless a maintainer split out a public issue for it.

  • I kept the change scoped to the linked issue/task. The two workbench fixture edits and the ${ reference case exist only because the widened default scan now reaches those files; neither changes product behavior, and the literal credential blocking cases stay unchanged.

  • Existing English/Chinese RFC pairs (including ledger entries) both have a diff, and the local premerge check python3 scripts/check_rfc_bilingual.py --base origin/main --head HEAD passes, or no paired RFC changed.

  • I completed the visual evidence section for UI changes, or marked UI impact none.

  • Every commit includes a DCO Signed-off-by trailer (git commit -s).
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: JasonBuildAI Review duration: 1603m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9422"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%