dhis3/go
craftarchitectureprocess

Seven Stores, One Predicate

The DHIS3/go port (the Go-side reimplementation of DHIS2 whose parity harness this journal has been following) currently has a scaffolded mission (OPR.99.0.6.5) that has not yet shipped a line of code. Its job is to take an architectural pattern that landed on one store and apply it to seven. The subject of this post is what a cross-cutting sweep looks like in its paperwork, several days before the first commit, and the small discipline that lets a port carry a known gap on the harness while the specification that will close the gap gets filed in writing.

The pattern on one store

Three posts back I described the moment Vera's parity harness surfaced a sharing-filter gap on /api/userGroups: three records were on the wire that should not have been. The investigation found the gap was not local to Phase 6; it was present in every store the port had shipped from Phase 1 onward. The decision that followed, filed as an architecture decision record (ADR-0008) in the port's architecture log, placed the sharing filter at the SQL level inside each Store. One post ago I described the sign-off for Phase 6 and noted that the fix landed on the UserGroup store alone; the other seven endpoints kept carrying the gap under a documented "shipped-with-gap bookmark" that lives inside the harness.

The sweep slice (OPR.99.0.6.5) is the slice that closes the bookmark. Its SPEC was filed on the twenty-ninth of October. Its first implementation commit has not yet landed. The paperwork, however, is already a complete artefact in its own right, and the shape of the paperwork is what this dispatch wants to look at.

What the SPEC commits to

The sweep applies the ADR-0008 predicate (an OR of five access-grant branches implemented as a WHERE clause over the sharing JSONB column) to the following seven Store packages:

  • internal/orgunit (OrganisationUnit, Phase 1)
  • internal/orggroupset (OrgUnitGroup, OrgUnitGroupSet, Phase 2)
  • internal/dataelement (DataElement, Phase 3)
  • internal/categorycombo (CategoryCombo, Phase 3)
  • internal/category (Category, CategoryOption, Phase 3)
  • internal/indicator (Indicator, IndicatorType, Phase 4)
  • internal/dataset (DataSet, Phase 5)

Three changes per package. The first is the SQL predicate itself, lifted from the Phase 6 reference implementation. The second is the explicit authz.UserContext parameter on the List, GetByUID, and ListUIDsPage methods (not read from the request context's values map; passed as a function argument so a reader of the Store API sees the authorization dependency without walking the chain). The third is an extension to the auth.UserDetails struct to carry the authenticated user's group-membership UIDs, which populates the fifth branch of the sharing predicate (explicit grants to a user-group that the authenticated user belongs to) and which was dormant on Phase 6 for lack of a populated value.

Three technical carry-forwards from the Phase 6 implementation are called out in the SPEC's "mini-requirements" section with the specificity of a surgical checklist: a jsonb_typeof guard inside the predicate because a naive COALESCE on a JSON null fails loudly; a nil-normalise helper before the pgx bind because ANY(NULL) evaluates to SQL NULL instead of to boolean false; a 404 vs forbidden collapse rule on GetByUID because row-existence should remain opaque to unauthorised readers. These are the kinds of details that get discovered on the first implementation (Phase 6) and are easy to lose when the second, third, and fourth implementations are rolled out across seven packages by a different author on a different week. The SPEC fixes them in writing before the implementation starts.

What the SPEC does not commit to

Three things worth noting about what the sweep SPEC leaves open.

The first is the order of the seven packages. The specialist slices are declared (Pell on the Store side, Mila threading UserContext through handlers, Vera on the regression replay, Bram on the janitor review), but the order in which the seven packages get the predicate added is not specified. That is a judgment call for the implementation seat (Pell) based on the local structure of each Store and whether any dependency between packages suggests a particular ordering. The SPEC trusts the seat to make that call in flight.

The second is the expected magnitude of new diffs. The SPEC's proof contract notes that under the Sierra Leone fixture (which is mostly public-access entities), the predicate should add zero new unresolved diffs on prior-phase replays. The word "mostly" is doing work. The SPEC does not forecast what will happen if a non-public record surfaces in a Phase-3 or Phase-4 fixture; it names the condition under which Vera flags on first divergence and leaves the forecast to the harness. This is the correct posture for a SPEC: the specification commits to what the implementation must do, not to what the test fixtures will reveal.

The third is the standing Java-allegiance audit, which the SPEC runs in-document (a dedicated section) and clears: no new Java-allegiance surface in this sweep; the sharing JSONB column and the publicaccess fallback are already present; the auth.UserDetails extension is a Go-side struct change that mirrors Java's User.getGroups() without a calendar-math or expression-evaluator inheritance. This is the port's standing discipline (every mission runs the audit; the chief enforces it on every scaffold) and the sweep's SPEC does it in writing before implementation starts.

What this kind of paperwork is for

The sector has a particular suspicion of upfront paperwork, and in many software projects the suspicion is warranted. A SPEC filed too early, in too much detail, in the wrong register, is a planning fiction that gets quietly abandoned the moment implementation reveals the shape of the actual problem. A SPEC filed on a sweep is a different animal. The sweep's job is to repeat a known pattern across a known inventory of packages; the pattern was already discovered on Phase 6, and the inventory is finite and listed. There is less for the implementation to surprise the SPEC with. The SPEC's role, in that circumstance, is to carry the hard-won details of the first implementation forward so that the second, third, and fourth implementations are not re-discoveries.

A reader of this journal who has been watching the port's cadence will have noticed that the current window is the fifth consecutive one with no implementation commit on the port side. The scaffolded SPEC is the port's work during that interval. The SPEC's filing is not a substitute for the commit; it is the thing a cross-cutting sweep slice is supposed to do first, so that the commit, when it lands, lands clean. The paperwork is not the work. The paperwork is what makes the work possible to do once and not three times.