Skip to content

The upgrade tool's result is not recorded in the store: write a row per upgrade run #9432

Done

Description

@erikdarlingdata

Claude posting for Erik Darling.

The upgrade tool's own result is recorded only in the operator's terminal: its exit code, the result of its stop check, the rollback folder it made, and its own version. When a service start (#9415) looks wrong, the store can't say how the upgrade that preceded it went.

Asked

  1. At the end of an upgrade run, the upgrade tool writes one row to the store when the store is reachable: tool version, target build, start and end time, exit code, the stop check's result, the rollback folder, and the first error if it failed.
  2. If the store is not reachable, it writes the same facts to a small file beside the install, and the service records that file into the store at its next start, then removes it.
  3. The config.service_version keeps only the current start: record each service start with its build, schema change, migration rung timings and error counts #9415 start-history read shows the upgrade row next to the start that followed it.
  4. The row is written when the run starts, with state in_progress, and updated at the end. A separate step marks it verified once the operator's checks pass, as a flag on the upgrade tool or its own command. A read returns the current install state, so a client of the store (an exporter, a scheduled read) can skip its run while an install is in progress. A store that is down during the install is its own reason to skip, so the row only has to exist while the store is up.

Done when an upgrade run against a test install writes its row (in progress, then its result, then verified), a run with the store down leaves the file that the next start records, and behaviour tests cover both.

Activity

  1. erikdarlingdata commented on Nov 24, 2026

    @erikdarlingdata
    OwnerAuthor

    Claude posting for Erik Darling.

    Scope addition: the upgrade row is written when the upgrade starts, before the service stops, with state "in progress", and updated with the outcome at the end. A later "verified" state is set by whoever verifies the install, through an MCP write or a small command, not by the upgrade tool. A read of the latest upgrade row then shows an upgrade that is under way or not yet verified. If the store is down at the start, the file fallback in item 2 carries the start too.

  2. added
    in-progress
    on Nov 24, 2026
  3. erikdarlingdata commented on Nov 24, 2026

    @erikdarlingdata
    OwnerAuthor

    Claude posting for Erik Darling.

    This replaces the earlier text on this issue as the ready-to-use PR body. The work is on branch fix/9432-upgrade-run-rows. No PR is open yet.

    What was wrong

    The upgrade tool's own result was only in the operator's terminal: its exit code, the result of its stop check, the rollback folder, its version. When a service start looked wrong afterwards, the store could not say how the upgrade before it went.

    What changed

    • The upgrade tool writes a run file. Darling/tools/upgrade-darling.ps1 writes upgrade-run.json beside the install. It never opens a PostgreSQL connection, because it has no driver and the store can be down in the middle of an upgrade.
      • At the start of a real run it writes a new run id, state in_progress, tool version, target build and start time. This happens before the service is stopped, so a read of the newest upgrade row shows an upgrade that is under way.
      • In its finally block it rewrites the file with the end time, exit code, stop check result, rollback folder and first error, and state succeeded or failed.
      • A new -MarkVerified switch sets the newest run to verified once the operator's checks pass. It does no upgrade and cannot be combined with -Check, -PruneOnly or -ListRollbacks. It leaves a failed or unfinished run alone.
      • Every write goes to a temp file in the same folder and then moves over the old file. The file holds no secret.
      • A file that cannot be written is a warning. The upgrade goes on.
    • The service records the file. UpgradeRunPickup runs at service start after the migrations, and again on the existing five-minute store-side pass, on its own stamp so it also runs with the alert engine off. The upgrade restarts the service before the script ends, so the result and the verified state are only seen by a pass.
      • One row per run id: in_progress, the result and verified land on the same row.
      • A run written while the store was down is recorded at the next start or pass.
      • The file is removed once the run is verified or failed, or is older than 7 days. A succeeded run stays until it is verified.
      • A file that does not parse warns once per distinct content and stays in place. A file over 64 KB is not read, warns once and stays. A store problem leaves the file for the next pass and never fails a start.
      • Rows are kept for 400 days, the same as the other store self-metric series.
    • New table collect.upgrade_runs, store version 312, keyed on the run id. No existing table changes and no data moves, and an older build never names it. It has a row in docs/darling/store-tables.csv, a sentinel in the Viewer's schema probe, and a top rung in MapProbedSchemaVersion. 312 is its final number: it is stacked on the rung object table branch (311) and merges after it.
    • Lite has no upgrade tool of this kind, so there is no Lite change.

    The defect this pass found and fixed

    The three UpgradeRunPickupTests failed at the first row write. The one read in full showed Could not bind parameter of CLR type System.DateTime to PostgreSQL type timestamp without time zone ... Cannot write DateTime with Kind=UTC.

    Cause, in the code and not the tests: the pickup read the file's times as Unspecified kind, but bound the caller's DateTime.UtcNow (kind UTC) for recorded_at, updated_at and the retention cutoff. Npgsql refuses a UTC-kind value for a timestamp column. The service passes DateTime.UtcNow too, so in the field every pickup would have logged a warning and recorded nothing, and the file would have stayed forever.

    Fix: RecordAsync in Darling/PerformanceMonitor.Darling.Storage/UpgradeRuns.cs now sets the kind to Unspecified once, the way CollectionCaveatStore and AlertDismissStore do, and binds that value for both the upsert and the retention delete.

    Tests

    • UpgradeRunPickupTests (live, each test mints its own scratch database): three pickups (in progress, succeeded, verified) give ONE row and each state is seen, with the file removed only at verified. A run written while the store was down is recorded at the next pickup and a failed run's file goes. A malformed file warns once per content and stays, and an old in-progress file is recorded and removed.
    • DarlingUpgradeRunRecordTests (6 tests, run under PowerShell against a temp folder): the start file, the end rewrite on success, the end rewrite on failure, -MarkVerified on a succeeded run and its refusal on a failed or unfinished one, -MarkVerified with no file, and a failed write that leaves no temp file and the old file untouched.
    • Revert proof: with the upsert changed to a plain insert, the three-pickup test fails and the other eight tests of these two classes pass. The upsert is restored and the break was not pushed.
    • Result: 285 tests passed, 0 failed, across UpgradeRunPickupTests, DarlingUpgradeRunRecordTests, StorageCommandTimeoutTests, StoreTableInventoryLiveTests, AlertReadFailureSurfaceTests, ViewerSchemaVersionGateTests, ViewerDataServiceTests, MigrationLadderPins, MigrationProbeLadderTests, MigrationUpgradeLadderLiveTests and QuietServerWatermarkLadderLiveTests.
    • A Release build of the test project (which builds the service, storage and viewer) succeeded with 0 errors.
    • Pre-push gate: [guard-darling] Total: 4997, Errors: 0, Failed: 0 and [guard-lite] Total: 1248, Errors: 0, Failed: 0. The classes: line was darling 3358, lite 1083, which is the whole suite, so the gate stopped (GATE STOP) and ran no selected class. The classes listed above were run by hand instead. CI runs the rest.

    Not covered by a behaviour test

    • The finally block of upgrade-darling.ps1 that calls Close-DarlingUpgradeRun, and the order of the start write before Stop-Service. The script needs an elevated shell and a registered service, so the tests run the functions it calls (including Close-DarlingUpgradeRun itself) and not the script's main body.
    • The RecordedNotRemoved outcome, where the row is written but the file cannot be deleted.

    Handoff: the start-history read

    The issue's item 3 (show the upgrade row next to the start that followed it, plus the current install state in a block) is not in this change. The start-history read from #9444 is not on dev yet, so there is nothing to attach to. Once it merges, the read joins collect.upgrade_runs to the first start after each run's started_at and adds a current_install block from the newest row. A client that wants to skip its run during an install can already read the newest row's state: in_progress means an upgrade is under way, and succeeded means it is not verified yet.

    Considered, not added

    • A retry or queue for a file that stays unwritable. The pickup runs every five minutes and the file stays until it is recorded.

    Brought onto dev

    • Merged current dev. The new table's rung is renumbered to its final number, V312. It is stacked on the rung object table branch (V311) and merges after it, so its pull request shows only its own change once that one merges. The probe sentinel, its map arm, the GetBoolean list, the version gate test and the rewind artifact all moved with it.
    • This change adds no read tool, so no registration files were needed.
    • Runs: build in Release with no errors. Passing classes: DarlingUpgradeRunRecordTests, UpgradeRunPickupTests, ViewerSchemaVersionGate*, ViewerDataServiceTests, ViewerSchemaSkew*, *Migration* (377 tests), ReadToolRegistration*. The gate's Guard lines were green for both suites (Darling 5001, Lite 1248, no failures). The gate then stopped because the selection was the whole suite, so CI runs the rest.

    Fixes #9432

    Release note: each upgrade run is now recorded in the store, from start to result to verified, including a run made while the store was down.

  4. erikdarlingdata commented on Nov 24, 2026

    @erikdarlingdata
    OwnerAuthor

    Claude posting for Erik Darling. Fixed by #9493.

  5. removed
    in-progress
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions