Skip to content

feat(campaign): failures by code with a cursor, and the outcomes aggregate (admin-contract R4.2 + R4.3, #296) - #575

Open
omercelikdev wants to merge 8 commits into
mainfrom
agent/296-live-governor
Open

omercelikdev wants to merge 8 commits into
mainfrom
agent/296-live-governor

Conversation

@omercelikdev

@omercelikdev omercelikdev commented Nov 11, 2026 •

Copy link
Copy Markdown
Collaborator

What and why

This is #296's server half: admin-contract R4 slices R4-S3 (R4.2) and R4-S4 (R4.3), built to the text accepted on main. Before this, the governor could not answer "what is failing, and why". /failures stopped at 500 rows with no cursor, its rows left out the error code the store has kept since R2.1, and nothing counted failures by code.

  • R4.2: GET /goldpath/admin/campaign/{id}/failures?afterSeq=&take=
    • It walks every failed item by keyset on Seq. afterSeq is exclusive; absent or 0 gives the first page, as before.
    • Each row carries errorCode.
    • take keeps its [1, 500] clamp.
    • API: GoldpathCampaignFailedItem.ErrorCode is init-only, because the record is shipped and positional. The new overload is GetFailedItemsAsync(id, afterSeq, take, ct), and the shipped (id, take, ct) calls it with afterSeq: 0.
  • R4.3: GET /goldpath/admin/campaign/{id}/outcomes
    • byState: items per state, in state order, with empty states omitted.
    • failedByCode: at most 20 entries, ordered by count descending, then code ordinal, with no code last among equal counts.
    • failedCodesTruncated: true when more codes exist.
    • An unknown id answers 404 with no body. The route counts and derives nothing.
    • The database ranks by count, breaks ties under the provider's bytewise collation (PostgreSQL C, Oracle BINARY; SQLite is bytewise by default), and returns one code more than the page holds. So the rows it returns are the contract's first 21, including when equal counts straddle the twentieth place. The final order is applied by the service, because providers disagree on where NULL sorts.
    • API: GetOutcomesAsync, GoldpathCampaignOutcomes and GoldpathCampaignCodeCount, as the RFC lists them, plus the members records synthesize. The cap and the collation helper are internal, so no public line was added that the RFC does not list.
  • Measured: /outcomes on a 1M-item campaign takes a 104 ms and 118 ms median of 5, over two runs. Profile: the agent's sandbox (4 vCPU Xeon, 15 GB), PostgreSQL 17, Testcontainers, commit abbd4c9, 2026-11-11 21:00 UTC, local run, recorded in ops/campaign-benchmarks.md. That is well under the 5 s poll, so R4.3's "poll it less often" fallback is not needed. (The tie-break collation added in 2804f21 was not re-benched.)

Not in this PR: the console half (R4-S7). It covers #296's criteria 1, 2 and 4: the 5-second poll, the binding constraint and outcomes on screen, and the vitest/axe floors. The RFC's slice table files it separately, so it is now #574, labelled needs-owner. It needs one decision first: the binding constraint (#294) exists only in the leader's memory as a metric, and no admin route or field can return it on every replica. The question and my recommendation (a pacer-written column, on the next train) are in #574 and open-threads T69. This PR therefore does not close #296; the owner closes it when #574 lands or replaces those criteria.

Reproduce

git fetch origin agent/296-live-governor && git checkout agent/296-live-governor
dotnet build Goldpath.sln -c Release                                    # 0 warnings
U="FullyQualifiedName~R4FailuresAndOutcomesTests|FullyQualifiedName~RouteContractTests"
dotnet test tests/Goldpath.Campaign.Tests -c Release --no-build --filter "$U"   # green 18/18
S=packages/Goldpath.Campaign/GoldpathCampaignAdminService.cs

# RED A: the code is not projected -> 4 red (both code facts, the 1,203 walk, the HTTP fact)
sed -i 's/ { ErrorCode = i.ErrorCode })/)/' $S
dotnet build tests/Goldpath.Campaign.Tests -c Release -v q && dotnet test tests/Goldpath.Campaign.Tests -c Release --no-build --filter "$U"; git checkout $S

# RED B: the cursor is ignored -> 2 red (the walk answers 500,500,500,500,500; the HTTP page)
sed -i 's/ \&\& i.Seq > afterSeq)/)/' $S
dotnet build tests/Goldpath.Campaign.Tests -c Release -v q && dotnet test tests/Goldpath.Campaign.Tests -c Release --no-build --filter "$U"; git checkout $S

# RED C: truncation off by one -> ExactlyTwentyCodes_AreNotTruncated red
sed -i 's/codes.Count > MaxFailedCodes)/codes.Count >= MaxFailedCodes)/' $S   # (build + test as above); git checkout $S
# RED D: case-insensitive order -> TwentyFiveCodes_… red
sed -i 's/ThenBy(c => c.Code, StringComparer.Ordinal)/ThenBy(c => c.Code, StringComparer.OrdinalIgnoreCase)/' $S   # (build + test); git checkout $S
# RED E: null-last removed in memory -> Outcomes_CountByState_AndFailuresByCode red
sed -i '/ThenBy(c => c.Code is null ? 1 : 0)/d' $S   # (build + test); git checkout $S
# RED F: route renamed -> RouteContractTests + the HTTP fact red
sed -i 's|"/{id:guid}/outcomes"|"/{id:guid}/outcome"|' packages/Goldpath.Campaign/GoldpathCampaignAdminEndpoints.cs   # (build + test); git checkout packages/

# Real databases (Docker)
I="FullyQualifiedName~CampaignOutcomes"
dotnet test tests/Goldpath.IntegrationTests -c Release --no-build --filter "$I"     # green 2/2; PostgreSQL with ICU en-US, Oracle with NLS_SORT=GENERIC_M
# RED G: leave the order to the database (drop the in-memory sort) -> red on PostgreSQL:
#   Expected ["ACK_TIMEOUT","B-UPPER","a-lower",null,…]  Actual ["ACK_TIMEOUT","a-lower","B-UPPER",null,…]
# RED H: the tie-break under the database's own collation (the verifier's finding 1) -> red on BOTH databases:
#   Expected { Code = B-UPPER, Count = 1 }  Actual { Code = a-lower, Count = 1 }
sed -i 's/var collation = BinaryCollation(db.Database.ProviderName);/string? collation = null;/' $S
dotnet build tests/Goldpath.IntegrationTests -c Release -v q && dotnet test tests/Goldpath.IntegrationTests -c Release --no-build --filter "$I"; git checkout $S
# The bench (Category=Bench): prints BENCH-CAMPAIGN outcomes: … median … ms
dotnet test tests/Goldpath.IntegrationTests -c Release --no-build --filter "FullyQualifiedName~CampaignBenchTests.Outcomes_on_a_one_million_item_campaign" --logger "console;verbosity=detailed"

I ran every plant (A–H) and saw each one go red as described. With the code restored, all are green.

Acceptance criteria (#296), with evidence

Pre-PR self-check

  • Every criterion is either met with its evidence or stated plainly as not met (above).

  • Ledgers and docs:

    Not touched, because nothing in them changed: ga-gate-status.md, ai-sdlc-status.md and coverage-matrix.md. api-review-gate.sh is green with the 34 new lines.

  • XML docs: the new members are new, and ErrorCode sits in a new record body. No member is inserted between an existing /// and its declaration.

  • Honesty:

    • "linguistic collation" is claimed only where it is set up: postgres:17-alpine's default en_US.utf8 sorts bytewise (checked), so the proof runs with ICU en-US; the Oracle proof sets NLS_SORT = GENERIC_M on every connection.
    • The limits are stated wherever the feature is described:
      • the two counts are two statements, not one snapshot;
      • the boundary tie is ordinal on PostgreSQL, Oracle and SQLite; on a provider with no proof (SQL Server) the database's collation still breaks it, and a bytewise collation orders by code point where ordinal orders UTF-16 units (differs only between U+E000–U+FFFF and characters above U+FFFF) — both in T69;
      • no 30M figure is claimed.
  • Wired: the HTTP fact runs through MapGoldpathCampaignAdmin on a TestServer (afterSeq, /outcomes, 404, and a 400 for afterSeq=abc). AdminReadRoleSurfaceTests (which enumerates every admin route) is green, so /outcomes reads under goldpath-ops-read.

  • Contracts: the field names, the defaults (afterSeq = 0, take = 100), the 404 and the 20-code cap match R4.2/R4.3.

  • Bench: the new fact is in CampaignBenchTests (Category=Bench), serial with that class's other facts, and never in CI's integration job. Its numbers carry profile, date, commit and run.

  • Deep self-review:

    • Security: two new reads only. Both sit behind the guarded group (goldpath-ops-read, plus R1's all-tenants filter on multi-tenant apps), with no new input beyond a long and a Guid that model binding types. Bad input answers 400 (tested). The collation name is a constant chosen by provider, never input. Nothing is logged, there are no secrets, and there is no new dependency.
    • Edge cases: afterSeq negative, 0 and past the end; take 0 and 1,000 (clamped); no items; an unknown id; R1 rows with no code; another campaign's failures excluded; a code on a non-failed item not counted; exactly 20 codes not truncated, 25 truncated; mixed case; a collation-divergent tie across the 20th place.
      • Oracle's 1000-item IN-list limit does not apply: there is no IN list.
      • tr-TR: the R4 suite is green under DOTNET_CULTURE=tr-TR LANG=tr_TR.UTF-8 (16/16); the comparisons are StringComparer.Ordinal, and the provider match is ordinal.
    • Concurrency: read-only. The no-snapshot drift is documented.
    • Migrations: none. This uses the existing (CampaignId, State, …) indexes, as R4 requires.
    • Performance: two grouped counts, measured at 1M. The failures page is bounded by the clamp.
    • Compatibility: additive. An R3 client gets the same first page. No shipped signature changed.
    • Code quality:
      • The scoped mutation run on the new lines first scored 83.87%. Its 4 survivors exposed a redundant database-side NULL clause, which was removed and explained, and 1 exposed the byState key order, which is now asserted. The re-run is 27/27, 100% (before 2804f21; the collation lines are covered by RED H and the provider-mapping theory).
      • No suppression, no dead code.

Gates run (at 2804f21)

Gate Result
dotnet build (Campaign + test projects) -c Release 0 warnings, 0 errors
Goldpath.Campaign.Tests 522/522
CampaignOutcomesPostgresTests, CampaignOutcomesOracleTests 2/2 (PostgreSQL 17 with ICU, Oracle Free 23.26.3 in a linguistic session)
docs-freshness.sh, ledger-check.sh, schema-honesty.sh, skills-parity.sh, template-pins.sh, api-review-gate.sh rc 0 ×6
dotnet format whitespace --verify-no-changes on the touched files clean

What I could not verify

  • The full Campaign mutation run (a package score). It is hours long and ran out of memory on this sandbox before. The nightly matrix will give the package score.
  • SQL Server. The suite has no SQL Server lane for Campaign; the tie-break there uses the database's collation (T69).

Part of #296 (the console half is #574)

…egate (admin-contract R4.2 + R4.3, #296)

R4.2 (R4-S3): GET /campaign/{id}/failures?afterSeq= walks the whole failed set
by keyset on the item's own key, and each row carries its errorCode (an
init-only property on the shipped positional record). The shipped
GetFailedItemsAsync(id, take, ct) is the overload with afterSeq: 0, so an R3
client gets today's first page. take keeps its [1, 500] clamp.

R4.3 (R4-S4): GET /campaign/{id}/outcomes answers the items counted by state
and the failures counted by error code - at most 20 codes, count descending,
code ordinal, no code last among equal counts, with failedCodesTruncated; 404
for an unknown id. The database ranks by count and brings one code more than
the page; the final order is the service's, because providers disagree on
NULL placement and on collation. It derives nothing (no ratio, no ETA).

Proof: R4FailuresAndOutcomesTests (unit, SQLite) - codes from a handler's
Failed(code) and from a callback, the 1,203-row walk in three pages, the
counts, the 25-code truncation in ordinal order, the routes over HTTP. Red
with each fault planted (code not projected, cursor ignored, null-last rule
removed, truncation off by one, case-insensitive order, route renamed).
CampaignOutcomesProof on PostgreSQL (ICU en-US collation, where the
database's own order disagrees - red with the order left to the database) and
on Oracle. RouteContractTests gains the outcomes line. A bench fact measures
the call on a 1M-item campaign.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018AFdNcUHVZCtRVq4DLoW71
…atabase; byState order pinned (#296)

The scoped mutation run on the new lines (Goldpath.Campaign config, the
outcomes and failures members only) scored 83.87%: four survivors were the
database-side NULL-placement clause, which cannot change the answer (one
NULL group, and the extra row it may take is the row the page drops), and
one was byState's key order, which no test pinned. The clause is gone, the
comment says why, and the unit test asserts the keys in state order. Re-run:
27 of 27 killed, 100%.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018AFdNcUHVZCtRVq4DLoW71
… the upgrade guide, the bench and the ledgers (#296)

- admin contract: the campaign inventory gains afterSeq and /{id}/outcomes.
- ops: runbooks §5 reads /outcomes first, then walks /failures; the bench page
  records /outcomes on a 1M-item campaign at abbd4c9 (104 and 118 ms median).
- upgrade guide preview.10: additive, nothing to do; CHANGELOG [Unreleased].
- README: the R4 reads.
- stryker/README: the scoped run on the new lines, 83.87% then 100%.
- open-threads T69: the console half (R4-S7) and the binding constraint,
  which only the leader's meter holds today; and the tie at the twentieth
  code, whose membership is the database collation's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018AFdNcUHVZCtRVq4DLoW71
…snapshot (#296)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018AFdNcUHVZCtRVq4DLoW71
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018AFdNcUHVZCtRVq4DLoW71
@omercelikdev omercelikdev added the agent-pr PR opened by the overnight agent label Nov 11, 2026
@github-actions github-actions Bot added the tier:C ADR-0014 Tier C: decisions, releases, gates, policy, agent layer; the owner merges label Nov 11, 2026
@omercelikdev

Copy link
Copy Markdown
Collaborator Author

CI, as observed after opening:

  • Green: every gm / * shape, kit, review, alert-rules, golden manifests (PR subset) and CodeQL. merge-policy waits for the owner.
  • oracle is red on 1 test of 74: NotificationOracleTests.The_renewal_mail_actually_lands_and_the_evidence_stamps failed after 38 ms with ORA-12537: TNS:connection closed.
    • This PR does not touch that test.
    • main's own oracle job is red on its last three runs (c9d23ae, 440f4a0, 9311ccd), on CampaignOracleTests.Thousands_release_paced_….
    • This run had 74 tests against main's 73. The extra one is this PR's CampaignOutcomesOracleTests, and it passed.
  • Not re-run: the rules do not allow an empty commit to re-trigger CI.
  • Still running when I checked: gates and integration.

Generated by Claude Code

@omercelikdev

Copy link
Copy Markdown
Collaborator Author

Verifier verdict (run 2026-11-12)

Head verified: 29649a1831b2b5bff0570e95c9ac8aa640d75089 · Base: main @ c9d23ae5020cbd4a87540dd58e9c20253764d52b · Verdict: changes requested (1 MAJOR, 1 MINOR), plus one question for the owner.

Steps 1–6

# Step Result
1 Scope R4.2 and R4.3 are built as the RFC describes: afterSeq, errorCode, the overload, /outcomes, the two records, and the route-freeze line. There are no workflow, permission, dependency or pin changes, no test is weakened and no suppression is added. #296's criteria 1, 2 (the panel) and 4 are not met, but Closes #296 is still in the body. See finding 2.
2 Rules PublicAPI.Unshipped has 34 lines and matches the code. api-review-gate.sh rc 0. XML docs are on every new public member, and none is inserted between an existing /// and its declaration. CHANGELOG [Unreleased], the preview.10 upgrade guide, the RFC inventory rows, runbook §5, the README, the benchmarks page and the stryker README are all updated. T69 does not collide: main ends at T67 and open PR #560 holds T68 (I checked every open PR's open-threads patch).
3 Confidentiality I grepped the diff and the commit messages for the listed names, \bBTK\b, tokens and hostnames: no hits.
4 Reproduce dotnet build Goldpath.sln -c Release: 0 warnings, 0 errors. Goldpath.Campaign.Tests: 516/516. The R4 tests and RouteContract tests: 12/12, and also 12/12 under LANG=tr_TR.UTF-8. Plants A–F each went red exactly as the PR states (A 4 red, B 2, C 1, D 1, E 1, F 2). Plant G (database order) went red on PostgreSQL with ICU: Expected ["ACK_TIMEOUT","B-UPPER","a-lower",null,…] Actual ["ACK_TIMEOUT","a-lower","B-UPPER",null,…]. Everything was green again after restoring. CampaignOutcomesPostgresTests, AdminReadRoleSurfaceTests (PostgreSQL) and CampaignOutcomesOracleTests (Oracle Free 23.26.3): green. Gates: docs-freshness, ledger-check, schema-honesty, skills-parity, template-pins and api-review-gate all rc 0.
5 CI Required checks (gates, integration, kit, golden manifests (PR subset)): green. merge-policy is red, which is by design on Tier C. oracle (not required) is red: 73/74, NotificationOracleTests.The_renewal_mail_actually_lands…, ORA-12537. The worker's claim is half right. Main's oracle job is red on its last four pushes (c9d23ae, 440f4a0, 9311ccd, 86ab2df), but on a different test: CampaignOracleTests.Thousands_release_paced_across_leader_handovers…. That test passed on this PR's run. For the Notification test, I ran it locally on origin/main and it fails the same way it fails on the PR head (TaskCanceledException in NotificationFacts.WaitForStateAsync, NotificationTests.cs:130). The PR touches no Notification file, so the red does not come from this PR.
6 Charter n.a.

Deep review

Area Result
a Security ✓ Both routes sit in the guarded group (AdminSurfaceGuard.Apply → goldpath-ops-read, with no verb floor), and AdminReadRoleSurfaceTests enumerates every route's metadata, including /{id:guid}/outcomes. R1's all-tenants filter covers the group. The cursor is a typed long, used as a parameterised Seq > @p inside the same campaign. A forged or tampered value can only move the start of the caller's own authorised set; overflow and non-numeric values answer 400 (probe P5). take is clamped to [1, 500], including int.MinValue and int.MaxValue. The bench uses ExecuteSqlInterpolatedAsync, which is parameterised, and it is test-only. Nothing is logged, and there is no new dependency.
b Correctness Finding 1 (which codes are listed when equal counts straddle 20th place). The rest ✓: NULL placement in a tie at the boundary is correct even where SQLite sorts NULL first (probe P2); negative, zero and past-the-end cursors; an unknown id; an empty campaign; other campaigns are excluded; tr-TR green.
c Concurrency ✓ Read-only. The two-statement drift is documented.
d Data / dialects ✓ No migration. PostgreSQL and Oracle translate and are proven. SQL Server is n.a.: the repo has no EF SQL Server provider or lane for Campaign (only Locking.SqlServer), and the PR says so honestly.
e Performance ✓ /outcomes measured by the PR (2 × ~110 ms at 1M). I did not re-run the 1M bench. NIT: the /failures walk is not measured at scale. Each page is State = Failed AND Seq > x ORDER BY Seq LIMIT n, served either by the PK (CampaignId, Seq) walking past successes or by (CampaignId, State, …) plus a top-N sort over every failed row. The first page had the same shape before this PR.
f Compatibility ✓ Additive. The shipped overload keeps its signature, an R3 client gets the same first page, and the RFC table matches the routes.
g Tests ✓ Strong. Plants A–G plus three mutations of my own all went red: Take(21→20) → the 25-code test, the State == Failed filter dropped → the counts test, the AnyAsync check broken → the 404 tests. The one gap is the boundary tie with collation-divergent codes (finding 1): TwentyFiveCodes… and the PostgreSQL proof put their case-divergent ties above the cut, and the straddling ties (C00…, Z00…) sort the same under every collation.
h Code quality ✓ Clean and idiomatic. Comments explain why. No dead code.
i Operability ✓ Runbook §5 leads with /outcomes. No new config.
j Honesty Finding 1 (the README, CHANGELOG and upgrade guide state the ordinal top-20 without the limit) and finding 2. Wiring is proven through MapGoldpathCampaignAdmin on a TestServer.

Edge-case probes (throwaway, not pushed)

Probe Result
P1 (PostgreSQL 17, ICU en-US): 19 codes × 10, then a-lower, a-second and B-UPPER × 1 each. The contract (count desc, then ordinal) makes B-UPPER the 20th entry. RED: Expected "B-UPPER" Actual "a-lower"
P2 (SQLite): 19 × 10, then null, B and A × 1, so NULL sits in the boundary tie green (20th is A, truncated)
P3: afterSeq = long.MaxValue / long.MinValue, take = int.MinValue / int.MaxValue, an unknown id green
P5 (HTTP): afterSeq=99999999999999999999 → 400, afterSeq=1;DROP → 400, negative take → 200 clamped, a non-GUID id → 404 green
tr-TR: the R4, RouteContract and probe suites under LANG=tr_TR.UTF-8 green (15/15)

Findings

  1. MAJOR: failedByCode does not always list the 20 codes R4.3 defines; at a tie across 20th place the database's collation decides. packages/Goldpath.Campaign/GoldpathCampaignAdminService.cs:330-346. The database runs ORDER BY Count DESC, Code under its own collation and keeps 21 rows. The ordinal re-sort can only reorder those 21, so a code that is ordinal-earlier but collation-later is never fetched.
    • Why it matters: R4.3 (accepted text) says the list is ordered "by count (descending), then by code (ordinal) … The order is fixed in the query, not left to the database". The README says "not left to the database's collation". The CHANGELOG and the upgrade guide say "the 20 most frequent … code ordinal". On a PostgreSQL with a linguistic collation, the same data answers a different list than on SQLite or Oracle (BINARY). The limit is written down only in T69 and a code comment. The PR's claim that the limits are "stated wherever the feature is described" does not hold for the README, the CHANGELOG or the upgrade guide.
    • Evidence: probe P1 above.
    • Expected fix, one of:
      • (a) Make the database's tie-break agree with ordinal, so its top 21 is the contract's. One way is a binary collation on the tie-break key per provider (PostgreSQL COLLATE "C"; Oracle and SQLite are already BINARY by default). Another is a second bounded query for the boundary count's tie group. Then add P1 (codes that diverge under collation, tied across the cut) to CampaignOutcomesProof.
      • (b) The owner amends R4.3 to say that which equal-count codes fill the last places is the provider's collation. In that case the README, CHANGELOG, upgrade guide and runbook must say so too.
  2. MINOR: Closes qorpe/goldpath#296 would auto-close an issue with 3 of 4 acceptance criteria unmet. The PR body says the 5-second poll, the panel, and vitest/axe are moved to R4-S7: the live campaign governor in the console — 5-second poll, outcomes by code, the failures walk, the binding constraint (#296's console half) #574. The RFC's slice table lists R4-S3 as "A live campaign governor: auto-refresh, binding constraint, failures by code with a cursor #296 (part 1)". Fix: change it to Part of #296 (or Refs), and let the owner close A live campaign governor: auto-refresh, binding constraint, failures by code with a cursor #296 when R4-S7: the live campaign governor in the console — 5-second poll, outcomes by code, the failures walk, the binding constraint (#296's console half) #574 lands, or when they decide R4-S7: the live campaign governor in the console — 5-second poll, outcomes by code, the failures walk, the binding constraint (#296's console half) #574 replaces those criteria.

NITs (optional): measure one /failures?afterSeq= page on the 1M bench campaign (see e).

Question for the owner (needs-owner)

For finding 1: should R4.3's "top 20, count desc then code ordinal" hold on every provider, which means fix (a) in this PR, or should R4.3 be amended so the boundary tie is provider-defined (fix (b))?
My recommendation is (a). The contract already promises ordinal, and a governor that names different codes on PostgreSQL and on Oracle for the same data is the provider dependence R4.3 was written to rule out. The cost is one provider-aware tie-break, or one extra bounded query.

Labels: changes-requested, needs-owner. Tier C: the owner merges.


Generated by Claude Code

@omercelikdev omercelikdev added changes-requested Verifier found problems; the worker fixes these first needs-owner Needs an owner decision; the question is in the last comment labels Nov 12, 2026
… chosen ordinally on every proven provider (#296)

The outcomes query broke count ties under the database's own collation, so on an ICU
PostgreSQL or a linguistic Oracle session a code that is ordinal-earlier but collation-later
was never fetched, and the service's ordinal re-sort could not bring it back. The tie-break
now runs under the provider's bytewise collation (PostgreSQL "C", Oracle BINARY; SQLite is
bytewise by default). A boundary-tie campaign joins CampaignOutcomesProof on both databases
(red without the fix on each: B-UPPER expected, a-lower answered), with a SQLite twin and
the provider mapping in the unit suite. T69 drops the closed limit and keeps its residuals.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018AFdNchYxTtB7tJ7kURQXf
@omercelikdev

Copy link
Copy Markdown
Collaborator Author

Addressed verifier findings: 1 (MAJOR, the boundary tie), 2 (MINOR, the closing keyword). Head: 2804f21.

Finding 1: fix (a), the one that keeps R4.3's accepted text. The owner question still stands: if the owner prefers (b), revert 2804f21.

  • The fix: the outcomes query breaks equal counts under the provider's bytewise collation: EF.Functions.Collate(code, "C") on PostgreSQL and "BINARY" on Oracle. SQLite is already bytewise, and other providers are left unchanged. So the 21 rows the database fetches are the contract's 21. The service's ordinal re-sort is unchanged.
  • New proofs:
    • CampaignOutcomesProof has a second campaign, your P1: 19 codes ×10, then a-lower, a-second and B-UPPER ×1. The proof asserts that the 20th entry is B-UPPER and that the list is truncated.
    • The Oracle half now runs in a linguistic session. A connection interceptor sets NLS_SORT = GENERIC_M, because Oracle's ORDER BY follows the session's NLS_SORT and a client's language settings can change it.
    • Unit suite: a SQLite version of the same case, and a theory that pins which collation each provider gets.
  • Red without the fix (collation forced to null): both databases fail with Expected { Code = B-UPPER, Count = 1 } / Actual { Code = a-lower, Count = 1 }. Green after restoring.
  • Docs: README, CHANGELOG (the R4.3 bullet and the proof bullet) and the upgrade guide now state that the tie is broken ordinally. T69's tie limit is closed. T69 keeps two residuals, each with a trigger and a proof:
    • a provider with no proof, such as SQL Server;
    • code-point order versus UTF-16 ordinal, which differ only between U+E000–U+FFFF and characters above U+FFFF.

Finding 2: the body now ends Part of qorpe/goldpath#296 instead of Closes. The body is also refreshed for this head: plant RED H, 522 tests, and the Oracle session.

Pre-PR self-check (whole PR at 2804f21):

Gates:

  • Build (Release): 0 warnings, 0 errors.
  • Goldpath.Campaign.Tests: 522/522.
  • CampaignOutcomes{Postgres,Oracle}Tests: 2/2.
  • docs-freshness, ledger-check, schema-honesty, skills-parity, template-pins, api-review-gate: rc 0 for all.
  • dotnet format whitespace: clean.

Generated by Claude Code

@omercelikdev

Copy link
Copy Markdown
Collaborator Author

Owner decision (2026-11-12): option (a)

The owner chose option (a) for the verifier's question. R4.3's accepted text stands: failedByCode is the top 20 by count (descending), then by code (ordinal), on every provider, the 20th place included. The RFC is not amended. Keep 2804f21; it is the fix (a) asked for.

Why:

  • The contract already promises ordinal order.
  • A governor that names different codes on PostgreSQL and on Oracle for the same data is the provider dependence R4.3 was written to rule out.
  • The cost is one bytewise collation on the tie-break key. It sorts the grouped codes, not the item rows.

This answers the needs-owner question. The next verifier run checks 2804f21 as usual.

Recorded by the owner's session (Claude Code), on the owner's instruction.

@omercelikdev omercelikdev removed the needs-owner Needs an owner decision; the question is in the last comment label Nov 12, 2026
omercelikdev and others added 2 commits November 12, 2026 12:05
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s no closed claim (#296)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@omercelikdev

Copy link
Copy Markdown
Collaborator Author

Synced with main@90f78d3 (#560) in c0fdbd7, plus one ledger wording fix in 56f1878.

The merge. #560 conflicted in two ledgers, both side-by-side additions:

For each ledger, the merge's diff against main has exactly this PR's added and removed lines, and its diff against 2804f21 has exactly #560's. Nothing was reworded in the merge.

gates was red on 2804f21 itself. ledger-check reads any T69 line with "closed" as a claim that #296 and #574 are closed, and both are open. The words were "The tie limit this row first recorded is closed in the same PR". 56f1878 changes "closed" to "settled". This is the only change outside the merge.

Local, on 56f1878:

  • dotnet build Goldpath.sln: 0 warnings, 0 errors. dotnet format --verify-no-changes: clean.
  • Goldpath.Campaign.Tests: 522/522.
  • The gates job's other script steps give rc 0: corpus-check, specanchor-freshness, skills-parity, ledger-check, schema-honesty, docs-freshness, corpay-feed --selftest, merge-tier.py selftest, template-pins, train-freshness samples/corpay, product-guard samples/corpay and license-gate.

The merge-policy red is the Tier C rule: this PR needs owner-approved before it can merge. changes-requested stays until the next verifier run checks 2804f21.

Owner's session (Claude Code), on the owner's instruction.

@omercelikdev

Copy link
Copy Markdown
Collaborator Author

Verifier verdict (run 2026-11-12, daytime)

Head verified: 56f1878ecf0641411c6e59ed00f3e7f74f0c2dd1. Base: main @ 90f78d3.

My last verdict was on 29649a1. The delta since then is three commits:

Verdict: no blocking findings. 0 BLOCKER, 0 MAJOR, 0 MINOR, 1 NIT. Tier C: the owner merges; this is never an auto-merge.

Previous findings

  • MAJOR 1 (the boundary tie): fixed by option (a), as the owner decided on 2026-11-12. The tie-break now uses EF.Functions.Collate(code, "C") on Npgsql and "BINARY" on Oracle. On SQLite and on providers without a proof there is no collate clause.
  • MINOR 2: fixed. The body says Part of qorpe/goldpath#296.

Steps 1–6

# Step Result / evidence
1 Scope ✓ The delta is the fix, its proofs, and the docs that state it: README, CHANGELOG, the upgrade guide and T69. The RFC decision text is untouched. The merge brings only #560's lines: git diff origin/main pr575 and git diff origin/main...pr575 are the same 15 files, +886/−8. No workflow, permission, dependency or pin change, and no test was weakened.
2 Rules ✓ BinaryCollation is internal and has its own ///, so there is no PublicAPI change. CHANGELOG [Unreleased] and the upgrade guide are updated. T69 and #560's T68 are both kept, in number order, with no collision.
3 Confidentiality ✓ The denylist grep (case-insensitive, \bbtk\b) over the full diff against main: 0 hits.
4 Reproduce ✓ dotnet build Goldpath.sln -c Release: 0 warnings, 0 errors. Goldpath.Campaign.Tests: 522/522. R4 under DOTNET_CULTURE=tr-TR LANG=tr_TR.UTF-8: 16/16. CampaignOutcomesPostgresTests (ICU en-US) and CampaignOutcomesOracleTests (Oracle Free 23.26.3, NLS_SORT=GENERIC_M session): 2/2. Plant (var collation = (string?)null;): both red with Expected: { Code = B-UPPER, Count = 1 } / Actual: { Code = a-lower, Count = 1 }. Restored: green. Gates: docs-freshness, ledger-check, schema-honesty, skills-parity, template-pins, api-review-gate: rc 0 for all.
5 CI ✓ The required checks are green: gates, integration, kit, golden manifests (PR subset), every gm / *, CodeQL and review. merge-policy is red by design (Tier C without owner-approved). oracle (not required) is red on 1 of 74: NotificationOracleTests.The_renewal_mail_actually_lands… with ORA-12516: Listener … does not have a protocol handler … for service FREEPDB1, a container listener failure. This PR's CampaignOutcomesOracleTests passed in that same run, and the same Notification test fails on main, as recorded in my morning verdict.
6 Charter n.a.

Deep review (delta)

Dimension Result
a Security ✓ The collation name is a constant chosen by provider name, never input, so nothing can be injected through COLLATE. No new endpoint or dependency.
b Correctness & edge cases ✓ Probes P1–P5 below cover NULL inside the boundary tie, Turkish İ/ı/I/i across the cut, exactly 20 codes (not truncated), and NLS_COMP=LINGUISTIC with a case-insensitive sort. The UTF-8 byte order vs UTF-16 ordinal residual (U+E000–U+FFFF against supplementary characters) is recorded honestly in T69.
c Concurrency n.a. The change is read-only.
d Data & dialects ✓ No migration. Oracle COLLATE with MAX_STRING_SIZE=STANDARD works. I started the same gvenzl/oracle-free:23.26.3 image by hand: max_string_size=STANDARD, compatible=23.6.0, and select 'x' from dual order by 'a' collate binary succeeds. So the expression-level COLLATE does not need EXTENDED strings. 12.2+ supports it, which covers the DatabaseVersion19 compatibility the repo targets.
e Performance ✓ The collation sorts the ≤ N grouped rows, not the items. I did not re-run the bench; the PR says it was not re-run either.
f Compatibility ✓ No public API change. The result now matches R4.3's accepted text on PostgreSQL with a linguistic default collation, which is the intended fix.
g Test quality ✓ The plant reddens both real-database proofs. A theory pins the mapping from provider to collation.
h Code quality ✓ Clear, and the comment explains why. NIT 1 below.
i Observability n.a.
j Honesty ✓ README, CHANGELOG and the upgrade guide now say the tie is ordinal "on every provider Campaign is proven on", which is what the code and the proofs show.

Edge-case probes (throwaway file, not pushed; run on real PostgreSQL 17 with an ICU tr-TR default collation, and on Oracle with NLS_SORT=GENERIC_M_CI NLS_COMP=LINGUISTIC)

# Probe PostgreSQL Oracle
P1 19 codes × 10, then NULL, a, B × 1: the 20th must be B, and the list truncated ✓ B, truncated ✓ B, truncated
P2 19 × 10, then ı-x, İ-x, i-x, I-x × 1: the 20th must be I-x (ordinal) ✓ I-x ✓ I-x
P3 Exactly 20 distinct codes: 20 entries, not truncated ✓ ✓
P4 Oracle COLLATE BINARY with MAX_STRING_SIZE=STANDARD (sqlplus, by hand) — ✓ works
P5 Plant: no collation at all red on both red on both

NIT (optional)

  1. packages/Goldpath.Campaign/README.md:215: the re-wrapped sentence leaves one long line, "…every provider Campaign is proven on. It answers from two grouped counts…". This is cosmetic.

Labels: changes-requested removed, agent-verified added. Tier C: the owner merges after adding owner-approved. I do not merge.

Owner: safe to merge. Summary: the campaign admin surface gains /failures?afterSeq=&errorCode= (a cursor over failed items) and /{id}/outcomes (counts by state, and the top 20 failure codes in ordinal order on PostgreSQL, Oracle and SQLite, the tie at 20th place included). Existing R3 clients see no change.


Generated by Claude Code

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

Labels

agent-pr PR opened by the overnight agent agent-verified Independently verified by the verifier agent: ready for owner merge tier:C ADR-0014 Tier C: decisions, releases, gates, policy, agent layer; the owner merges

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A live campaign governor: auto-refresh, binding constraint, failures by code with a cursor

2 participants