OED_M: fjerne Storage-koden, fasen og migreringen (steg 6 av #1884)

Open
#1,907 1 comment 0 reactions 1 assignee View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
15/100
Issue type
Refactor
Clarity
Clearly specified
Activity status
Active
Domain
backend

Research direction

Start with the referenced design in parent issue #1884, then review the listed OedModel infrastructure, registrations, tests, and CLAUDE.md sections. Confirm production has been in the Database phase for the required period and settle the open choices about audit tables and #1898’s guard. Done means the Storage-backed code and phase are removed or documented as retained, the database-only guidance and tests are updated, and the release verification and retention issue are complete.

Written by the indexing model from the issue text.

Description

Kort fortalt

Steg 6 i #1884 (designdokumentets §5.4, siste avsnitt, og §8). Når prod har stått i fase Database en stund, fjerner vi det som bare fantes for å lese og skrive OED_M i Storage og for å flytte dødsboene:

  • Storage-leseren og -skriveren, og rutingen mellom dem og databasen
  • advisory lock-en
  • fasen
  • kopieringen, feiejobben og verifiseringen
  • paritetstesten mot app-libs endepunkt
  • Storage-veien i oed-admin

CLAUDE.md oppdateres, så den beskriver hvordan det er nå og ikke hvordan det var. Regel 5 (ingen eldre bygg) faller bort.

De frosne Storage-kopiene og oed-datatypen blir liggende. De fjernes i oppbevaringssaken (design §7), ikke her.

Spesifikasjonen (engelsk) står under.


Spec: remove the Storage-backed OED_M code, the phase and the migration

Parent: #1884, design §5.4 and §8 step 6
Depends on: step 5 #1906 (production in phase Database, and observed for a week). Production reached Database on 3.12. 08:20 UTC. Decided 3.12.: this issue is done on Wednesday 9.12., instead of waiting two weeks: every estate has a row, so going back to Storage is no longer a real option. Before it is deployed, #1906's last verify (Mismatch 0) and its observation summary must be posted, since this removes the verify, the admin copy and the metrics the observation uses. Prepare it on a branch kept rebased onto master until then. The pieces removed here come from 3b #1900, 3c #1904, 3d #1901, 3e #1902 and 3f #1903. Start no earlier than two weeks after production reached Database, so that a problem found in that time is still fixed with the old code at hand.
Date: 2026-11-10. Line numbers are from this date; check them again when building.

0. Before deploying: the observation, 3.12.–8.12. (moved from #1906, closed 3.12.)

Production has been in phase Database since 3.12. 08:20:22 UTC (#1906: sweep finished 2.12. 23:07 UTC, verify b0e99eb0 ready with Missing 0, day 1 clean). This release removes the verify, the admin copy and the metrics below, so the observation has to be finished first. Post the summary here, before this is deployed on 9.12.

  • A verify each working day (4.12., 7.12., 8.12.), from oed-admin's «OED_M-migrering»; the last one on 8.12. or the morning of 9.12. Mismatch = 0 means nothing wrote to Storage after the copy. NotLive (rows whose instance was deleted; 2 on 3.12.) is not a failure.
  • Don't start a verify within 10–15 min of a production publish: the rollout runs 3–6 pods for about 8 min, then scales back to 2, and a run on a removed pod stops until another pod continues it (#1906, 2.12.). Storage's first listing page takes 20–30 s, close to its ~30 s 500; the runner retries, so a slow start is expected.
  • What to watch, and what each hit means:
    • oed_model_missing_row and its Critical "no database row in phase Database": must be zero. Each hit is an estate the migration missed: copy it through the admin copy (oed-admin «Kopier») and find out why it was missed. After this release the admin copy is gone.
    • oed_model_read{source} / oed_model_write{target}: storage must stay at zero.
    • oed_model_db_write_retry and oed_model_db_write_timeout (reason: attempts, deadline, lock, deadlock, serialization): retries are expected under concurrency; each timeout should be understood.
    • oed_estate_model_recreated: every hit is a lost transaction that was repaired. Look at each one.
    • oed_applib_oed_element_request{mode="blocked"}: who still asks app-lib for the frozen element (the read guard stays, §3).
    • oed-admin search and counts give believable results (estate count 22 066 on 3.12. ~08:50 UTC, equal to the model rows).
  • Mismatch > 0 is an incident: something wrote to Storage after the copy. Find the writer (release history for rule 5, oed-admin, other repos). Never re-copy over the row. Don't deploy this issue until it is understood.
  • Pausing (PUT phase to Storage) is still possible until this release, but changes nothing for estates that have a row, which is all of them; new estates would go back to Storage. Fix forward instead.
  • Rule 5 still holds until this release is out: never deploy a build older than #1904.

1. Goal

After this change:

  1. The app has one implementation of IOedModelReader and IOedModelWriter, the database one, registered directly, with no routing and no phase.
  2. Nothing in App/ reads or writes the oed element in Storage. What's left of the element is the guards that keep app-lib from serving or changing the frozen copies.
  3. Tests and CLAUDE.md describe the database store only.

2. Remove

What Where (2026-11-10 plan) Notes
RoutingOedModelReader, RoutingOedModelWriter 3c Register DatabaseOedModelReader/DatabaseOedModelWriter as the interfaces. Rename them to plain names, or keep them, builder's call.
StorageOedModelReader App/Infrastructure/OedModel/StorageOedModelReader.cs And StorageOedModelReaderTests.
Storage OedModelWriter App/Infrastructure/OedModel/OedModelWriter.cs And its tests, incl. OedModelWriter_DoesNotDependOnIInstanceHttpClient.
IOedModelLock, PostgresOedModelLock App/Infrastructure/OedModel/, registration in Infrastructure/Database/Extensions.cs ~27 Lock namespace 1837 is then free. PostgresAdvisoryLock stays: PostgresSubAppInvocationLock (#1789) uses it, and 3e's run lock goes with 3e. Since #1945 (3.12. note): PostgresAdvisoryLock has two scopes; AdvisoryLockScope.Transaction (pooled) is what the sub-app lock uses, and AdvisoryLockScope.Session (unpooled, with the tcp_keepalives_* session setup) is used only by OedModelMigrationRunLock (namespace 1902). With the run lock gone, remove the Session scope, its keepalive setup and their tests, and rewrite the lock bullet in CLAUDE.md for the sub-app lock only. Never go back to a new connection per lock (#1945). Keep OedModelLockTimeoutException (3b reused it for "could not write in time"), or rename it now along with its five catch sites.
The phase 3c: IOedModelPhase, the phase table, the admin GET/PUT, the startup guard on BlockAppLibOedDataRoutes, the gauge, oedModelPhase in health/details A migration drops the table. Keep the startup check that estate_model exists. Replace the BlockAppLibOedDataRoutes guard with a decision on #1898's middleware (§3).
The orphan endpoint (added after this spec) App/Infrastructure/OedModel/Orphans/OedModelOrphanRemover.cs, App/Features/Admin/OedModel/SoftDeleteOrphanEndpoint.cs, its registration in Program.cs and Features/Admin/WebAppExtensions.cs, SoftDeleteOrphanEndpointTests, both OedModelOrphanRemoverTests, its entries in OedModelAdminContractTests/OedModelAdminHost/OedModelRegistrationTests, and oed-admin's «Slett …» buttons Not in the 10.11. plan; ask the user when implementing. It takes IOedModelLock, which goes, and it is fed by the verify's Broken/NoDeceasedInfo items, which go too. Recommendation: remove it. Note #1941 (DeceasedStateMiddleware answers 500 when DAN reports the deceased not found in Freg, so oed's own DELETE …/instances fails for such an estate): without this endpoint, such an estate can't be deleted through oed at all.
IOedModelCopier and the admin copy endpoint 3c And its tests and contract snapshot.
Estate.Create overload with created 3c Keep it if 3d's creator still uses it, which it should.
The sweep and verify 3e's code, IOedModelMigrationReadiness, docs/oed-model-migration.md, the guard allowlist entries, the contract snapshots Decided 3.12.: not kept. A migration drops oed_model_migration_run and oed_model_migration_run_item (and the partial index ux_oed_model_migration_run_active with them). Keep the model rows' migrated_at and migrated_from_storage_last_changed columns either way: they record which rows came from Storage, and when.
The Storage path of IEstateInstanceCreator 3d The handler can create the instance, the Estate row and the model row directly again, or keep the abstraction with one implementation. The phase read goes.
The "has an oed element and no row" branch 3d §3.3 With no Storage path left, it is only the Critical throw. Keep that, or fold it into the reader's null.
IOedModelWriter.CreateOedModel's NotSupportedException branch 3b §2 Goes with the Storage writer.
GetOedModelParityTests ApiTest/Features/OedModel/GetOedModelParityTests.cs #1892 §6.1 says so: parity with app-lib's endpoint can't be tested once app-lib has nothing to serve. GetOedModelContractTests stays, as the guard on the frontend's JSON.
StorageServiceDataClientTests cases for the oed element StorageOedModelReaderReadsOedFormDataWithoutAUserToken, OedModelWriterReadsAndWritesOedFormDataAsXml, 3c's byte read The other cases in the file stay (sub-app models, instances without a user token).
Metrics that no longer mean anything oed_model_read{source}, oed_model_write{target}, oed_model_copied, oed_model_copy_failed, oed_model_missing_row, oed_model_lock_wait, oed_model_lock_timeout Remove any dashboards and alerts that use them.
oed-admin's Storage fallback 3f, in oed-admin A separate PR in that repo: the row-first reader becomes a row reader.
Test doubles that fake Storage for OED_M ApiTest/TestDoubles/, remaining IDataClient fakes for the oed element, the phase fake in OedWebApplicationFactory Grep for OedDataElement, "oed" and OED_M in the test fakes of IDataClient.
StorageService's throw for the oed element App/Services/StorageService.cs ~123 Keep it if anything can still reach the oed element through StorageService. Otherwise, remove the branch together with OedDataElement's last caller in StorageService.
Rule 5 CLAUDE.md "Deploying", and the deploy script check if 3c added one Once this release is out, an older release can no longer break anything new. Still, don't redeploy one older than this release without thinking: it would bring the Storage code back.

3. Keep (with a note why)

  • The oed data type in applicationmetadata.json (autoCreate: false, minCount: 0 since 3d). Migrated estates still have a frozen element in Storage, and app-lib needs the type to exist for those instances. The retention issue removes it once the copies are deleted.
  • OedDataElement and #1898's guards. They keep app-lib's routes from serving or changing the frozen copies. Decided 3.12.:
    • AppLibOedDataRouteMiddleware (reads) stays, always on. Remove OedConfig:BlockAppLibOedDataRoutes (option and the three appsettings*.json entries) and the counting-only mode: the middleware always answers 404 to a GET/HEAD of the oed element on app-lib's data routes. Without it anyone with access to the instance could read the model as it was frozen at migration.
    • Everything else that reads the switch goes with the phase and the copy: the checks in OedModelStoreStartup, PhaseEndpoints, MigrationRunEndpoints, OedModelCopier/OedModelCopyResult.NotAllowed, OedModelMigrationRunner and RoutingOedModelWriter.
    • AppLibWriteRouteGuardMiddleware (writes): open, ask the user before implementing. Recommendation: keep it as it is. It is not only about OED_M: it answers 403 to every write through app-lib's own routes (…/data… for every data type, …/process…, …/actions) before app-lib runs. oed writes data only server-side, so these routes have no legitimate caller; without the guard a user with write access to the instance could change any data element or move the process through app-lib, and could delete the frozen oed element (minCount: 0 since 3d). If it is kept, nothing of #1898 is removed except the switch.
  • OedModelReadGuardTests and OedModelWriteGuardTests, updated. The Storage patterns stay forbidden everywhere except OedDataElement and the guards that still need them. The estate_model patterns keep an allowlist of the database writer only (plus the reader for reads).
  • IOedModelReader.GetOedModel(Instance). It costs nothing with the database reader (#1891 §2). Remove it only if that simplifies callers.

4. Documentation

Rewrite every CLAUDE.md passage that describes OED_M in Storage, the routing or the phase. At least:

  • the OED_M/IDataClient overload bullet;
  • "All reads of OED_M go through IOedModelReader" and "All writes …" (rewritten for routing in 3c);
  • the advisory-lock bullet (now only xmin);
  • the IInstanceHttpClient self-call caveat (3b's new form);
  • the TaskQueue notes that mention reading OED_M from Storage;
  • StorageServiceDataClientTests as the only test that catches a regression;
  • rule 5.

Keep the "Model schemas are stale" note only if it is still true.

When done, add a short note to #1884, and close it if nothing else is open under it.

5. Also

  • Create the retention issue if it doesn't exist yet (design §7). Out of scope for this issue (decided 3.12.). It covers: four years from estate_model.created; what is deleted (model rows, Estate rows, the frozen Storage copies, the instances, and rows orphaned by hard-deleted instances from 3d §3.5); what a heir sees afterwards; and that queue tasks must not be cancelled from inside a TaskQueue handler (CLAUDE.md).

6. Tests

  • Full ApiTest, IntegrationTest and Jest suites green. The handler integration tests that ran in several set-ups (3c §9.2) now run with the database store only. Make sure none of them silently lost its assertions in the process.
  • GetOedModelContractTests still green: the frontend's JSON hasn't changed.
  • Guard tests: add a GetFormData on the oed element to an App file and see OedModelReadGuardTests go red. Add a write to estate_model outside the writer and see OedModelWriteGuardTests go red.
  • Check unused usings by hand: removing classes leaves usings behind, and the build doesn't warn (CLAUDE.md).

7. Verification

TT02, then prod (a person publishes in Studio): an estate opens, a probate choice is saved, and a new estate from oed-testdata-app gets a model row. dd-e2e-test green, and error rates unchanged for a few days.

8. Done when

  • Observation 3.12.–8.12. done (§0): a verify each working day, the last with Mismatch = 0, summary posted here
  • Everything in §2 removed, or kept with the reason written here
  • Keep-list in §3 decided, incl. #1898's guard and the audit tables (3.12.: audit tables dropped; read guard kept, always on; write guard still to be decided by the user when implementing, recommendation keep)
  • CLAUDE.md rewritten for the database store; rule 5 removed
  • oed-admin's Storage fallback removed (separate PR in oed-admin)
  • Retention issue exists and is linked from #1884 (out of scope, 3.12.)
  • Full ApiTest, IntegrationTest and Jest suites green; usings checked by hand
  • Deployed to TT02 and prod, verified
Dominant language
No language data
Stars
5
Forks
2
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Altinn/oed

All issues in Altinn/oed

Similar issues

More Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.