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

3.9 KiB

RP23 — Save cross-study findings through the typed research client

Parent E12. Priority P2 / Medium workflow defect. Complexity S. Dependencies A03, RP21. Owner continuation authorizes implementation and commits; all seven conditional tasks remain deferred.

Verified baseline: scripts/research-client.ts:708 requires a truthy finding source although createResearchArtifactSchema accepts omitted/null sources. ResearchService.createArtifact normalizes omission to null; ResearchEvidenceResolver.resolveAll still verifies every completed retained run and strategy-version reference. RP21's cross-variant conclusion therefore used a custom authenticated POST in ignored close-study.mts instead of the typed client. This is a client contract mismatch, not a missing backend capability.

Scope: allow an explicit null or omitted source in ResearchClient.saveFinding; compare the returned source with the backend's null normalization. Keep nonempty canonical, version-specific evidence mandatory. Preserve AI/unvalidated authorship, response identity and availability checks, exact supplied source validation, non-idempotent request behavior and uncertainty reporting. A finding without a single report attachment does not become a sealed report or certify comparability.

Ownership: implementation agent owns scripts/research-client.ts and scripts/test/research-client.test.ts; root owns test/postgres/ai-research-workflow.test.ts, existing usage documentation, manifest and integration. Independent review is required. These disjoint files can be edited in parallel.

Acceptance and mandatory tests:

  • Null and omitted source both save a cross-run, cross-version finding through the typed client; server-returned null is accepted, evidence references/values are retained and authorship stays AI/unvalidated.
  • Request bodies preserve explicit null versus omission. Supplied report/experiment sources retain exact equality checks. Unexpected returned source, changed version/run/metric, malformed availability, wrong project or authorship fail as uncertain accepted-response errors without automatic retry.
  • Empty, legacy, unversioned, duplicate or malformed evidence and malformed supplied sources fail before network access. Notes remain outside this method.
  • Extend the existing disposable PostgreSQL/native AI workflow, reusing its completed runs. Save and reopen a null-source finding referring to both successful candidate versions; compare server-resolved values to retained results and assert no new runs. Failed/missing runs and incorrect strategy versions remain rejected with no artifact persisted. Project authorization remains enforced.
  • Existing sourced-finding and cycle/journal regressions remain green. Run tooling tests, authored-test types, scoped lint/formatting, application types/contracts and the actual PostgreSQL workflow. No new native build is needed for a client-only correction.

Exclusions: new persistence/schema, new financial calculations, generic resume framework, automatic summary generation, new experiments, modifying RP21's saved findings, code isolation changes, paper/live activation or performance optimization. Regression risk: treating absent source as permission to weaken evidence identity/authorization; tests must preserve those checks. Benefit: AI callers can save supported cross-study conclusions using the same validated client, eliminating the demonstrated custom HTTP workaround.

Accepted after independent review: planning 27d2bc96, implementation 8dc8724c. Red baseline demonstrated the client rejection. Client/cycle tests passed 34 / 294 assertions; full tooling passed 149 / 14,250; actual authenticated PostgreSQL/native workflow passed 4 / 215. These focused/tooling counts overlap. Authored/application types, contracts, strict scoped lint, formatting, secrets and diff passed. No full build or full integration rerun; no backend or financial change. Execution evidence.