stock-bot/docs/development/backlog/tasks/RP27.md

3.8 KiB

RP27 — Inspect complete canonical run results through the AI client

Parent E12. Priority P2 / Medium workflow gap. Complexity M. Dependencies A03, F08, RP25. Owner continuation authorizes implementation and commits. All seven conditional tasks remain deferred.

Verified baseline: ResearchClient reads experiment summaries and evidence-linked findings but exposes no full run-result read. The authenticated API already serves GET /runs/:id/results. BacktestResults.getRunResults validates canonical financial/reporting facts, analytics and the trusted SQL request inline; the AI workflow inspects full results through its privileged test service instead of the actual research credential.

Scope: add ResearchClient.canonicalRunResult(runId, signal?). Reuse one pure canonical-result decoder in libs/research/src/results.ts, extracted from the current backend validation. It checks result/request/run/backtest identities, execution kind, completion/time fields, the existing native report parser and existing statistical projection. Return the original validated payload without rounding or replacing financial strings. The backend retains its separate comparison against the trusted SQL request/backtest. Legacy reads remain supported by the current backend reader; the explicitly canonical client method rejects legacy/malformed results.

Affected modules: shared research results, backend services/backtests/results.ts, research client/tests, a shared actual-native result fixture and contract tests, existing PostgreSQL AI/reproduction/canonical tests and README. No new endpoint, permission, schema, accounting/fill semantics, strategy execution, engine build, UI or generic client framework.

Acceptance/tests:

  • An authorized AI client retrieves the complete saved request, native fills/positions/risk, analytics and provenance using GET only. Values/nulls/decimal strings and the input object are unchanged. Client reads never submit or retry jobs.
  • Corrupt/mismatched run/backtest/request identity, execution kind, native identity/policy, analytics or metadata are rejected. Backend SQL snapshot binding remains mandatory, including missing/corrupt snapshots; no fallback to embedded request or legacy economics.
  • Unit/contract tests use actual Rust-produced fixture finances. Existing AI workflow reads actual isolated-candidate results through the new authenticated method, compares them with retained records, and verifies unchanged run counts plus 401 after revocation. Missing/failed runs return existing read errors. Abort/deadline and invalid-ID behavior use the existing client transport.
  • Run shared contract/native reporting, client/cycle and complete tooling tests; full integration; actual PostgreSQL AI/canonical/reproduction suites; application/authored types, contracts, scoped lint/formatting and secrets. No performance claim or optimization work.

Definition of done: demonstrate the missing client capability, extract existing validation without changing economics, review embedded versus trusted-SQL identity checks, pass relevant gates, document usage, update task state and commit. No new architecture decision is needed.

Accepted after root review: plan 65c65948, implementation 66af201d. The new client capability failed before implementation. Permitted focused contract/native-report/client/cycle checks passed 47 tests / 494 assertions. Full integration passed 1,403 with 14 existing conditional skips / 10,592 assertions; tooling passed 158 / 14,394; actual PostgreSQL AI/canonical/reproduction suites passed 20 / 409. Authored/application types, contracts, strict scoped lint, formatting, secrets and diff passed. Trusted SQL snapshot binding, actual research credential reads, revocation and unchanged run counts were verified. The disposable database was stopped. Execution evidence.