fix/cfe-inputs
needs attentiond1ec070 · incrementalPR #287reviewed 2026-07-24 00:31 UTC1H · 3M · 4L- Purpose
- BAT-272 — CFE collector was silently reporting a failed Mi Espacio registration as a successful job with zero bills. This branch fixes the silent-success path and adds comprehensive grading tests.
- Goal
- Ensure a transient Mi Espacio registration failure retries via SFN and grades 'failed', not 'completed'. A genuinely empty account still grades 'completed' (no false positives).
- Sub-goals
- SG-1: Repair the recoverable gate + make registration-failure distinguishable (decideMiEspacioFailureAction)
- SG-2: Pin the finalize grading with regression tests (decideFinalizeJob 3-row truth table)
- SG-3: Rework strategy label — gobierno_fallback distinct from gobierno_only
- SG-4: Preview e2e on manually-deployed cfe-silent estate (ALL PASS)
- SG-N: Framework improvements (MAX_BRANCH_NAME_LEN 16, doc fixes)
- What
- This incremental commit: simplifies latestTotal derivation (removes isBillTotalTrustworthy staleness check); removes 200-char service_name guard; wires latest_only into parseFilesListQuery; adds BAT-272 grading regression tests; adds .describe() to public schemas; updates API doc strings.
- Why
- The latestTotal staleness check was preventing registration attempts on RPUs with old stored bills — the new approach always tries the stored total and lets CFE return LATEST_TOTAL_REQUIRED if it rejects it, which is a cleaner user-facing error. The service_name update behavior is removed from the public API (existing-contract names immutable via this route).
- Areas
- domains/utility/src/cfe-job+80−75apps/platform/src/api/utils+25−20apps/platform/src/api/contracts/public-v1+12−8packages/api/src/schemas/public+10−10
- Blast
- 6 files in incremental diff; 9 branch-own files total. Touches public-v1 validator (API-facing), CFE job decisions (pure core), public schemas. No shell changes, no DB migrations, no CDK/infra.
Findings · 9
correctness1
service_name 200-char guard removed; new-RPU contracts accept unbounded names
apps/platform/src/api/utils/public-v1-validation.ts:427
MAX_SERVICE_NAME_LENGTH and its guard were the only length check on the public-v1 path. For new RPUs, an oversized service_name now stores in the DB without error (text column, no constraint).
security1
Unbounded service_name may hit SFN/EventBridge 256KB payload caps
apps/platform/src/api/utils/public-v1-validation.ts:426
No length validation between the HTTP body and the DB insert. A megabyte-scale service_name could push SFN StartExecution or EventBridge events over the 256KB hard cap.
conventions3
MCP batu_collect_bills missing latest_total param
packages/mcp-server/src/index.ts:221
Per .claude/rules/mcp-server.md: every public-v1 route's MCP tool must match the endpoint's validator. parseJobCreateBody now accepts latest_total, but batu_collect_bills has no latest_total field and doesn't forward it. An agent cannot supply latest_total to break the CFE registration deadlock — the primary purpose of this commit.
MCP README not updated for latest_total
packages/mcp-server/README.md
mcp-server.md rule: update the tools table for any new filter. batu_collect_bills entry omits latest_total.
latest_total fail() omits error code; period_count includes one
apps/platform/src/api/utils/public-v1-validation.ts:414
Inconsistent with the adjacent period_count pattern in the same function.
tests3
latest_only in parseFilesListQuery has zero test coverage
apps/platform/src/api/utils/__tests__/public-v1-validation.test.ts
latest_only was added but no test covers it, including the mutual-exclusion guard with bill_id.
toCfeJobConfig: latest_total → latestTotal not tested for zero value
apps/platform/src/api/mappers/public-v1/__tests__/jobs.mapper.test.ts
latest_total: 0 is a valid bill total; the !== undefined guard is correct but untested.
Collect SFN: latestTotal only tested as null
apps/platform/src/api/utils/__tests__/cfe-job-dispatch.test.ts:173
No test asserts non-null latestTotal propagates into the SFN collect payload.
improvement1
No comment explaining absence of service_name length cap
apps/platform/src/api/utils/public-v1-validation.ts
Future maintainer may re-add the cap without understanding the deliberate removal.