Repository navigation
Description
This issue was written by an AI agent (OpenHands) on behalf of @jpshackelford, from the manual testing of #818.
Summary
After #818, one POST /outcomes cannot report a total key and an increment key together. Let an item in values carry its own period, effective_at, dedupe_key and dimensions, so a run can report both kinds, and later several dimension sets, in one call.
Background
#818 puts period, effective_at, dedupe_key and dimensions on the whole submission. The service checks each fact against its own key:
| Key | period |
effective_at / dedupe_key |
|---|---|---|
| total | required | refused |
| increment | refused | allowed |
A submission that holds both kinds cannot satisfy both rows. With period, the increment is refused. Without it, the total is refused. I confirmed on the head of #818 that both forms answer 422 and store nothing. A run that reports "PRs merged this week" (a total) and "lines changed" (an increment) has to make two calls. The two calls are not atomic.
This is a deliberate strictness in #818 and not a defect. The 422 is loud and names the expected format. This issue is about removing the limit without losing the strictness.
Proposal
Each of the four fields is set either at the top level or on the items, never both.
- The top level is shorthand for "set this field on every fact". That is what it means in feat: add periods and dedupe keys to outcomes #818, so nothing changes for existing clients.
- An item in
valuesmay set any of the four fields itself. - If any item sets a field, the top level may not set the same field. The request answers 422 as ambiguous.
- The per-key rules in the table above stay as they are.
A mixed request needs no top-level period and nothing to opt out of:
{"values": [
{"key": "merged", "type": "number", "value": 3, "period": "2026-W48"},
{"key": "lines", "type": "number", "value": 412, "dedupe_key": "run-123"}
]}An all-totals or all-increments request keeps the single top-level field and stays short.
Why this rule
- There is no precedence question, because a field cannot be set in both places.
- There is no sentinel value. An earlier sketch let an item override an inherited field with
null. That is awkward to read and to document. - Mistakes stay loud. A top-level field that does not fit a key still answers 422.
Alternatives considered
- Top-level fields as defaults that apply only to keys that accept them. A mixed request would just work, but a
periodmeant for a key that turns out to be an increment would be ignored without an error. - Default a total's
periodto the current period. This removes the conflict, but it brings back the problem feat: add periods and dedupe keys to outcomes #818 fixes: a run at 02:00 that reports yesterday's total would land in today's bucket. Requiringperiodis deliberate.
Open points
- The flat
payloadform cannot carry per-item fields. A mixed submission would have to use the typedvaluesform. Agents mostly use the flat form, so the mixed case stays slightly awkward for them, but it becomes possible. - A key can appear only once per submission today ("Outcome keys must be unique within a submission"). That blocks the most useful use of per-item
dimensions: one call that reports a total for several repositories, as twomergeditems with differentdimensions. It would have to relax to "unique key and dimensions together". That needs its own decision, including how it interacts withdedupe_key. - Error messages should name the failing item (its index and key), as they name the key today.
- Atomicity stays as it is. Any invalid item rejects the whole submission, and nothing is stored.
Compatibility
Additive. A request that uses only top-level fields behaves exactly as in #818. The one thing to preserve in #818 is that top-level fields keep meaning "applies to every fact".
Acceptance criteria
- A submission with a total item carrying
periodand an increment item carryingdedupe_keyanswers 201 and stores both. - A field set both at the top level and on an item answers 422.
- A total item with no
periodanywhere, and an increment item with aperiod, still answer 422, naming the item. - Existing top-level-only requests are unchanged.
- Tests cover PostgreSQL and SQLite.
OpenHands AI triage
The following comments and acceptance criteria were added by the OpenHands AI agent.
Triage
Evidence: the outcomes contract on #818's head (a7b5e9e) keeps period, effective_at, dedupe_key and dimensions top-level only (SubmitOutcomeRequest; typed items in outcome_schemas.py are extra="forbid") and resolve_effective_at() (outcome_periods.py) enforces the per-key rules, so one submission cannot mix a total and an increment; the author's manual API test recorded on #818 reproduces this on the real service on both backends. This issue is the deliberate follow-up, not a defect.
Scope: in POST /outcomes, an item in values may carry its own period, effective_at, dedupe_key and dimensions, validated like the top-level fields (grain-format period, dedupe_key length, dimension limits). Top-level fields keep their #818 meaning, shorthand for "applies to every fact". Setting the same field in both places answers 422; there is no precedence and no null override. The #818 per-key rules still apply item by item, the 422 responses name the failing item's index and key, atomicity is unchanged (any invalid item stores nothing), and dedupe conflict handling honors the item's own dedupe_key. Implementation targets the head of the stacked outcome-time-and-totals branch (#818).
Non-goals: the flat payload form gains no per-item fields (mixed submissions must use typed values); "Outcome keys must be unique within a submission" stays, so per-item dimensions still cannot split one key across dimension sets (issue open point 2, needs its own decision including how it interacts with dedupe_key); no defaulting a total's period; no change to key registration (semantics/grain), aggregation, run row limits, or authentication.
Acceptance Criteria
- A typed
valuessubmission with a total item carrying its ownperiodand an increment item carrying its owndedupe_keyanswers 201, stores both facts (readable viaGET /factories/{factory_id}/outcomes/valuesand the aggregate route), and repeats of the increment item with the samededupe_keyanswerstored: 0, duplicates: 1without adding rows. - A field set at both the top level and on an item - each of
period,effective_at,dedupe_key,dimensions- answers 422 and stores no facts. - A total item with no
periodanywhere, and an increment item that receives aperiod(its own or the top level's), answers 422 naming that item's index and key; feat: add periods and dedupe keys to outcomes #818's per-key refusals still hold item by item (for exampleeffective_atordedupe_keyrefused on a total item, malformed or futureperiod422). - A
valuessubmission in which any single item is invalid answers 422 and persists none of its valid items (atomicity unchanged). - Top-level-only requests are unchanged from feat: add periods and dedupe keys to outcomes #818: all-total submissions with a top-level
period, all-increment submissions with top-leveleffective_at/dedupe_key, and flatpayloadsubmissions all behave exactly as before. - New and updated tests cover the new paths under the repository's PostgreSQL and SQLite parametrized fixtures and pass on both backends.
-
.agents/skills/verify-automation/references/feature-map/F20-outcomes.mddocuments per-item fields and the "top level or item, never both" rule.
Activity