Skip to content

M2-12: Implement preflight orchestrator and fail-closed API #33

Closed

Description

@pillowtalk-Qy
Type: App/Core Integration
Priority: P0 / trust boundary
Initial status: Blocked
Owner: App/API
Depends on: M2-05, M2-06, M2-07, M2-10, M2-11
Blocks: M2-13, M3 integration
Writable: API orchestrator/service, API integration tests

唯一目标

在一个请求中完成 validate -> quote -> action -> simulate -> map -> align -> decide -> report,返回不依赖 Clear402 的 Mini-Demo 结果。

验收

[ ] total hard timeout 25s;quote timeout 8s
[ ] late work ignored/aborted where supported
[ ] LIVE 绝不静默切换 FIXTURE
[ ] unavailable evidence 尽力形成合法 failed evidence/STOP
[ ] schema/programming invariant error = structured 500,不伪装 STOP
[ ] contract error 不伪装安全判断
[ ] raw response size limited
[ ] logs redact RPC/sensitive request data
[ ] response 包含 report/presentation,无 credential
[ ] 无 clear402-profile import
[ ] FakeMossPort integration tests 离线

验证

pnpm vitest run apps/web/test/api
pnpm vitest run tests/integration
pnpm --filter @moss-mini-demo/web build
pnpm check

Codex 指令

按固定顺序编排 public ports/API。区分 domain STOP、acquisition failure 和 500 invariant;
不得 catch-all 后伪造 STOP,不得引入 Clear402。加入 timeout/cancellation/redaction tests。

Activity

  1. 1 remaining item

  2. self-assigned this
    on Aug 8, 2026
  3. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    BUILDER_CLAIM / PLANNING_STARTED

    Qy has claimed #33 as the sole active implementation issue.

    • exact planning baseline: main@42637ff3e152e44de3c88848e30f1d2c666d0863
    • workflow state: Project In Progress
    • next artifact: closed Work Plan covering writable paths, contracts, timeout/cancellation behavior, domain STOP versus acquisition failure versus structured 500, redaction, raw-size limits, offline FakeMossPort tests, and exact verification
    • no implementation branch/worktree will be created until the Work Plan is published and passes SINGLE_OPERATOR_SCOPE_REVIEW

    This is single-operator execution; it does not claim independent review.

  4. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    Work Plan - M2-12 preflight orchestrator and fail-closed API

    Planning control

    Unique objective and fixed sequence

    Implement one server request path that uses only public package contracts in this order:

    validate -> quote/select -> action/capability -> simulate/map -> project -> align -> decide/report -> presentation.

    The handler remains the validation/HTTP boundary. PreflightOrchestrator is the mode-aware service: explicit FIXTURE requests delegate only to the reviewed Fixture service; LIVE requests require an explicit server-side session resolver. Missing LIVE configuration returns structured LIVE_UNAVAILABLE; it never invokes Fixture behavior. A supplied LIVE session contains a public MossPort, catalog, candidate protocols, policy factory, provenance/network, and limitations. Monad/RPC source construction and live evidence remain #29 scope.

    Closed writable path list

    Exactly these 13 paths are writable:

    1. apps/web/package.json - add public adapter/core workspace dependencies and clean standalone build/typecheck ordering.
    2. pnpm-lock.yaml - update only the apps/web importer for those workspace dependencies.
    3. apps/web/src/contracts/preflight.ts - add strict presentation success fields and a fixed timeout error code without weakening request/provenance contracts or byte limits.
    4. apps/web/src/server/preflight-service.ts - extend the stable service result only for a structured hard-timeout classification.
    5. apps/web/src/server/preflight-handler.ts - derive/validate presentation, reject sensitive response material, preserve byte limiting, and emit only fixed redacted log events.
    6. apps/web/src/server/preflight-orchestrator.ts - new mode-aware public-port orchestration, deadlines, cancellation and error classification.
    7. apps/web/src/server/preflight-projection.ts - new deterministic projection from public quote/capability/simulation evidence into legal report/alignment inputs.
    8. apps/web/app/api/preflight/route.ts - compose the orchestrator, explicit Fixture service and currently unconfigured LIVE resolver.
    9. apps/web/test/contracts.test.ts - strict presentation and timeout contract assertions.
    10. apps/web/test/routes.test.ts - response presentation, 4xx/5xx distinction, redaction, sensitive-output rejection and no-fallback assertions.
    11. apps/web/test/api/fake-moss.ts - offline public createFakeMossPort bindings/configurations only.
    12. apps/web/test/api/preflight-orchestrator.test.ts - ordered happy/STOP/acquisition/timeout/cancellation/invariant tests.
    13. tests/integration/preflight-api.test.ts - minimal HTTP-to-report/presentation proof using the offline FakeMossPort; no M2-13: Pass non-UI end-to-end integration gate #34 gate report or request-fixture matrix.

    No wildcard path is authorized. Package-internal source, schemas, Decision Engine, workflows, docs, Clear402, vendor/Moss, secrets, wallets, signing and transaction submission are unchanged.

    Trust and error boundaries

    • Total hard deadline is 25,000 ms from service entry. Quote collection has an 8,000 ms stage deadline. A total/quote deadline aborts quote work through a merged AbortSignal where supported; action/simulation have no public AbortSignal and are raced, terminally ignored if late.
    • Quote-stage acquisition timeout/failure becomes explicit failed Quote evidence and NOT_SELECTED, then a legal STOP when sufficient source input can be assembled.
    • Action acquisition failure/timeout becomes capability: FAILED plus simulation: MISSING, then a legal STOP.
    • Simulation acquisition failure/timeout becomes simulation: FAILED, then a legal STOP.
    • Adapter input/source-contract violations, projection/schema failures, impossible associations and presentation/report invariants throw through the service boundary and become fixed structured 500 responses with no report or fake STOP.
    • A hard deadline before legal failed evidence can be assembled returns fixed structured timeout HTTP error with no Decision.
    • Request-contract failures remain 4xx and never reach the service.
    • Logs contain only runId, fixed event/stage and allowlisted safe codes; never request bodies, RPC data, arbitrary Error messages/stacks, URLs, environment values or credentials.
    • Success serialization is rejected rather than truncated when it exceeds 2,097,152 bytes or contains credential-shaped keys. Response schema remains strict.
    • No import path may contain clear402-profile or any Clear402 runtime package.

    Evidence projection

    • Quote and selection records are deterministically ordered and linked to source evidence.
    • Capability projection uses the verified public construction result, immutable snapshot/integrity result and observed transaction targets.
    • Simulation projection uses the public mapped RawSimulationEvidence, including block/Moss context, receipts, outcomes, warnings, coverage, ordering, state continuity and retained raw artifacts.
    • Alignment observations point to resolving public report evidence paths. Evidence gaps remain explicit FAILED | MISSING | UNPROVABLE; they are never filled with favorable guesses.
    • evaluateAlignmentV0_1, assemblePreflightReportV0_1 and derivePreflightPresentationV0_1 are called only through @moss-mini-demo/preflight-core public exports.
    • LIVE report provenance is only LIVE_SOURCE | LOCAL_FORK; Fake integration evidence uses explicit synthetic configuration and is never exposed as LIVE by the production route.

    Tests and verification

    Focused tests must cover:

    • exact stage order and one invocation per stage;
    • public FakeMossPort offline happy path yielding a schema-valid report and matching presentation;
    • no valid selection, action failure, simulation failure, warnings and evidence gaps yielding domain STOP;
    • invariant/source-contract failures yielding structured 500 with no report;
    • malformed request yielding 4xx before any port call;
    • 8 s quote deadline, 25 s total deadline, cancellation where supported, and ignored late fulfillment;
    • LIVE unavailable with no Fixture fallback;
    • response byte limit, credential-shaped output rejection and log redaction;
    • no Clear402 import.

    Required commands under Node 22.23.1 / pnpm 11.16.0:

    pnpm vitest run apps/web/test/api
    pnpm vitest run tests/integration
    pnpm vitest run apps/web/test/contracts.test.ts apps/web/test/fake-preflight-service.test.ts apps/web/test/routes.test.ts
    pnpm --filter @moss-mini-demo/web build
    pnpm check

    Then inspect the exact 13-path diff, run zero-artifact and clean-worktree QA in a separate worktree, freeze the accepted head/tree, require exact-head quality-gate, publish Implementation Report and SINGLE_OPERATOR_QA_PASS, mark READY_TO_MERGE, protected squash merge, and complete merged-main audit.

    Stop conditions

    Stop for a Scope Amendment before touching any fourteenth path, changing a public package API, adding a non-workspace dependency, changing the request contract, weakening strict schemas/limits/provenance, introducing a live endpoint or credential, importing package-private source, requiring Clear402, or representing a programming/contract failure as STOP.

  5. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    SINGLE_OPERATOR_SCOPE_REVIEW / PASS

    This is Qy's same-controller review, not an independent reviewer claim.

    Reviewed immutable planning object:

    Review result: PASS.

    The objective, 13 writable paths, public package boundaries, service/route composition, no-fallback rule, evidence-gap behavior, domain STOP versus acquisition/timeout HTTP failure versus invariant 500, 25 s/8 s deadlines, cancellation/late-result handling, redacted logging, credential-shaped output rejection, response byte limit, offline FakeMossPort tests, #29/#34 non-goals, exact verification and amendment stop conditions are internally coherent and cover every #33 acceptance item.

    Implementation is authorized only against this frozen Work Plan and exact baseline. Any fourteenth path or public package/API change requires a separately published Scope Amendment before editing.

  6. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    SCOPE_AMENDMENT_1 / REQUESTED

    The first exact-head clean CI run exposed one dependency-order path missing from Work Plan v1.

    Evidence:

    Cause: root typecheck builds report-schema, decision-engine and preflight-core before root tsc, but #33's new root integration test imports the Web orchestrator and therefore requires the public moss-adapter build output before that root tsc. Local focused/Web checks had already built moss-adapter dist, masking the missing clean dependency order.

    Requested fourteenth writable path:
    14. package.json

    The only authorized edit is to insert:
    pnpm --filter @moss-mini-demo/moss-adapter build
    after the decision-engine build and before preflight-core/root tsc in the root typecheck script. This matches the existing root build and test:package-import dependency order.

    No other root script, dependency, source, test, workflow, package, lockfile, API, report shape, Decision rule, presentation behavior, or path changes. The failed head/run are retained as evidence and are invalid for QA/merge. After authorization, implementation returns to IMPLEMENT, creates a new commit/head, removes generated package/Web build artifacts, runs frozen install and the complete local matrix, and requires a new exact-head CI before QA handoff.

    SCOPE_AMENDMENT_1_SUBMITTED / AWAITING_SINGLE_OPERATOR_SCOPE_REVIEW

  7. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    SINGLE_OPERATOR_SCOPE_REVIEW / AMENDMENT_1 / PASS

    This is a same-controller scope review by Qy, not an independent reviewer claim.

    Reviewed amendment: #33 (comment)

    • exact body SHA-256, no added newline: 774b833952bff59bf04aa3f43bd8c79e684cb09458d69f19c973fb099fcc95bf
    • exact clean CI reproduction: run 31243546763 / job 93068299223 at invalidated head 70fe41aa3437de2a6c35fed6564f7e43192f9528

    Findings:

    • PASS: the failure is a clean-check dependency-order defect, not a source-contract or assertion bypass.
    • PASS: @moss-mini-demo/moss-adapter is a new direct public dependency of the Web orchestrator and its package entry requires built declarations.
    • PASS: report-schema -> decision-engine -> moss-adapter/preflight-core -> root tsc is the actual dependency order and matches existing root build/package-import conventions.
    • PASS: package.json is the only additional path required.
    • PASS: the exact edit is one command insertion in root typecheck; no dependency, workflow, test, API or runtime code changes.
    • PASS: all original timeout, cancellation, STOP/500, presentation correlation, raw-size, redaction, no-fallback, no-Clear402 and offline FakeMossPort constraints remain unchanged.
    • PASS: prior head/CI is explicitly invalidated; a no-dist local gate and new exact-head CI are mandatory.

    No amendment finding remains open.

    Qy authorizes the reviewed amendment as sole controller. The closed writable set is now the original 13 paths plus exactly:
    14. package.json

    Within package.json, only the root typecheck dependency-order insertion described above is authorized. Any other edit requires another prior amendment.

    SINGLE_OPERATOR_SCOPE_REVIEW_PASS / SCOPE_AMENDMENT_1_AUTHORIZED / RETURN_TO_IMPLEMENT

  8. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    IMPLEMENTATION_FROZEN

    Draft PR #78 is frozen at accepted head c3c8d7570cf68c5a49950ff4e6ef5be1b3f0ccbd, tree 0ee1852379381bfe35fb460a4ee4f484f9048896.

    • exact-head quality-gate: success, run 31243778070 / job 93068915956
    • Implementation Report: feat(web): orchestrate fail-closed preflight API #78 (comment)
    • reviewed scope including Amendment 1: exactly 14 paths, 2,215 additions / 12 deletions
    • clean/no-dist local pnpm check: passed, 33 files / 1,108 tests
    • focused API/integration: 15 + 1 passed
    • preflight-core coverage: 100% statements/branches/functions/lines, 200 tests
    • implementation worktree clean; local, remote and PR head identical

    The initial failing head/run is retained transparently in the report and is not accepted. The current head now leaves IMPLEMENT and enters clean same-operator QA. No independent reviewer is claimed.

    IMPLEMENTATION_FROZEN / CLEAN_SINGLE_OPERATOR_QA_PENDING

  9. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    SINGLE_OPERATOR_QA_HANDOFF

    This is same-operator QA, not an independent reviewer claim.

    QA starts with no dependencies, package dist or Web build artifacts. It will perform frozen install, inspect the exact amended 14-path diff, reproduce timeout/cancellation/late-result, STOP versus invariant 500, redaction/credential, no-fallback/no-Clear402 and offline public-port boundaries, run the exact Issue commands and a full no-dist gate, then recheck PR/protection state. Any head movement invalidates this handoff.

    SINGLE_OPERATOR_QA_HANDOFF / CLEAN_QA_START

  10. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    SINGLE_OPERATOR_QA_PASS

    This is same-operator QA from a separate clean detached worktree; no independent reviewer is claimed.

    Accepted/frozen head c3c8d7570cf68c5a49950ff4e6ef5be1b3f0ccbd passed:

    • exact-head CI run 31243778070 / job 93068915956
    • frozen install on Node 22.23.1 / pnpm 11.16.0
    • API orchestrator 15 tests, offline HTTP integration 1 test, contracts/Fake service/routes 38 tests
    • preflight-core 200-test coverage at 100% statements/branches/functions/lines
    • explicit no-dist root pnpm check: 33 files / 1,108 tests plus all build/import/browser/production gates
    • exact 14-path scope and Amendment 1 audit, timeout/cancellation/late result, acquisition STOP versus invariant 500, presentation correlation, response bounds, credential/log redaction, no-fallback, no-Clear402 and secret scans
    • clean worktree, unchanged head, PR MERGEABLE/CLEAN, 0 review threads, protected squash-only policy

    The unchanged 6 pre-existing Web audit advisories are recorded in the QA report and were not introduced by #33. Full QA record: #78 (comment)

    PASS. Any head movement invalidates this result.

    SINGLE_OPERATOR_QA_PASS / READY_FOR_MERGE_GATE_ASSESSMENT

  11. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    READY_TO_MERGE

    PR #78 is ready at immutable head c3c8d7570cf68c5a49950ff4e6ef5be1b3f0ccbd.

    Work Plan/Amendment, Implementation Report, separate clean SINGLE_OPERATOR_QA_PASS, exact-head quality-gate run 31243778070/job 93068915956, 0 unresolved threads, mergeable/CLEAN status, exact 14-path scope, and protected-main/squash-only policy have all been rechecked with no head movement.

    Authorized next state: leave Draft and use protected squash merge only. No independent reviewer or pre-merge completion claim.

    READY_TO_MERGE / PROTECTED_SQUASH_ONLY

  12. pillowtalk-Qy commented on Aug 8, 2026

    @pillowtalk-Qy
    ContributorAuthor

    POST_MERGE_AUDIT - PASS

    • PR feat(web): orchestrate fail-closed preflight API #78 protected squash merge: 95c4aac532cdc2231054c431f3a175f9c223e1f5
    • accepted head: c3c8d7570cf68c5a49950ff4e6ef5be1b3f0ccbd
    • parent: baseline 42637ff3e152e44de3c88848e30f1d2c666d0863; single-parent linear history verified
    • accepted/merged tree equality: 0ee1852379381bfe35fb460a4ee4f484f9048896
    • merged-main quality-gate: run 31244317834 / job 93070284632, success
    • local/remote main synchronized; remote/local branch and both Issue worktrees cleaned
    • exact 14-path reviewed scope retained; protection and squash-only policy unchanged
    • Issue Closed and Project Done
    • PR audit record: feat(web): orchestrate fail-closed preflight API #78 (comment)

    All implementation, clean QA, merge and post-merge gates have passed.

    POST_MERGE_AUDIT_PASS / ISSUE_COMPLETE

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions