| 1 | # Live database structural check, 2026-11-26 |
| 2 | |
| 3 | Branch `fix/check-db`, from main `8a3f1d92`. The one-shot `equipo check-db` |
| 4 | runs before configuration, mail, migrations or application boot. No live |
| 5 | instance was checked and no deployment was performed by this branch. |
| 6 | |
| 7 | ## Live path and read-only behavior |
| 8 | |
| 9 | CARLOS supplies `CARLOS_DB` to the command from the serving instance's actual |
| 10 | `dbPath`: `carlos/platform/internal/activator/cmdunit.go`, `ExecBackend.cmdVars`. |
| 11 | This command requires that path to be absolute and a regular file. It has no |
| 12 | fallback to a replica, a default filename or the application's boot resolver. |
| 13 | The filename is URL-encoded before adding the fixed SQLite `mode=ro` option. |
| 14 | It does not use `immutable`, which would miss committed WAL changes. |
| 15 | |
| 16 | One read transaction runs `PRAGMA quick_check(100)`, then |
| 17 | `PRAGMA integrity_check(100)`, followed by page count, page size and journal |
| 18 | mode. There are no setters, migrations, checkpoints or writes. The deadline is |
| 19 | 60 seconds, including opening and reading. The serving writer remains usable. |
| 20 | WAL size is observed if visible; otherwise it is null, as are failed metadata |
| 21 | reads. SQLite diagnostics, filenames, table/index names, expressions and row |
| 22 | contents never appear in the output. |
| 23 | |
| 24 | The bounded JSON carries status, a reviewed failure message, per-check status, |
| 25 | error count, a limit flag, at most five b-tree/page coordinates, metadata and |
| 26 | elapsed milliseconds. Per-check results distinguish `findings`, `error` and |
| 27 | `findings_and_error`, as well as `ok` and `not_run`. The count is the number of |
| 28 | observed diagnostics and query/metadata failures, not unique corrupt pages: |
| 29 | both checks can report the same damage. Each check stops at 100 findings. |
| 30 | Failure, timeout and inability to write the report all exit nonzero. |
| 31 | |
| 32 | Known limitation: constraint violations may not be reported; this checks file |
| 33 | structure. A CHECK-constraint fixture was not reported by the pinned SQLite |
| 34 | driver. Per the controller's ruling, it is not an assertion or a claim of |
| 35 | coverage. The permanent byte-flipped b-tree fixture proves structural damage |
| 36 | is detected. The command doc comment records the same limitation. |
| 37 | |
| 38 | ## Operator invocations after deployment |
| 39 | |
| 40 | Staging: |
| 41 | |
| 42 | ```sh |
| 43 | carlos run --app equipo-staging --account bds \ |
| 44 | --console https://console.carloku.com \ |
| 45 | --instance equipo-staging.bds.oncarlos.com --timeout 75s -- check-db |
| 46 | ``` |
| 47 | |
| 48 | Production: |
| 49 | |
| 50 | ```sh |
| 51 | carlos run --app equipo --account oficina \ |
| 52 | --console https://console.carloku.com \ |
| 53 | --instance equipo.bds.oncarlos.com --timeout 75s -- check-db |
| 54 | ``` |
| 55 | |
| 56 | These app/account/host values come from `scripts/staging-thin.py` and |
| 57 | `scripts/upgrade-thin.sh`. Use the instance host, not the public alias. The |
| 58 | 75-second outer timeout allows the 60-second check to return its JSON. |
| 59 | The local installed CARLOS CLI predates `run`; these commands require the |
| 60 | run-capable CLI used by the controller. Platform source confirms its syntax. |
| 61 | |
| 62 | ## Copy |
| 63 | |
| 64 | All seven `CopyDB*` messages and their Plan 3 inventory rows carry |
| 65 | `COPY ACCEPTED BY DELEGATION (Luna, 2026-11-26)`, explicitly approved by the |
| 66 | controller. Per-check status values are machine-readable enums. No unreviewed |
| 67 | operator prose or raw database errors are emitted. |
| 68 | |
| 69 | ## Tests and mutations |
| 70 | |
| 71 | Tests were written first; the initial run failed to compile on the missing |
| 72 | check-db symbols. Implemented tests cover an intact live WAL database, a |
| 73 | flipped b-tree page, write refusal even with `query_only` disabled, reading |
| 74 | committed WAL data, clean missing/invalid paths, command dispatch without app |
| 75 | configuration, diagnostic redaction and bounds, findings versus query errors, |
| 76 | the command's own deadline, and output failure. |
| 77 | |
| 78 | Local commands use `GOMAXPROCS=2 GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0` and `-p 1`. |
| 79 | Each mutation is applied alone, runs |
| 80 | `go test -p 1 ./cmd/equipo -run TestCheckDB -count=1`, and is restored. A kill |
| 81 | requires a runtime assertion failure; compilation errors do not count. |
| 82 | |
| 83 | Mutation results and final gate results are recorded below before handoff. |
| 84 | Full local suites and simulators are deliberately avoided under the |
| 85 | controller's loaded-machine ruling. Linux CI is the full gate. This CLI-only |
| 86 | change adds no route, schema, protocol or performance endpoint record. |
| 87 | |
| 88 | All 17 mutations were killed at runtime: |
| 89 | |
| 90 | - Change `mode=ro` to `mode=rw`; add `immutable=1`. |
| 91 | - Remove the command's deadline; change the fixed 60-second bound. |
| 92 | - Remove the five-issue bound; emit raw diagnostic text; exceed 100 findings. |
| 93 | - Skip quick_check; skip integrity_check. |
| 94 | - Ignore the final row error; report a query failure as success. |
| 95 | - Ignore output failure; return success despite integrity findings. |
| 96 | - Remove the absolute-path check; remove the regular-file check. |
| 97 | - Remove check-db dispatch; accept extra arguments. |
| 98 | |
| 99 | Restored focused tests passed (`TestCheckDB|TestCheckGitHub`). |
| 100 | `make fmt-check budget copy-release-check` passed. The sole size allowance |
| 101 | change is the measured nine source lines for approved operator copy: |
| 102 | `internal/equipo` 23239 to 23248. No timing budget changes. |
| 103 | Post-commit dead-reference results and Linux CI are reported with the pushed |
| 104 | SHA in the handoff. |
| 105 | |
| 106 | ## Inventory gate follow-up |
| 107 | |
| 108 | CI at `70831711` caught a missing entry in the inventory test's explicit |
| 109 | key/date acceptance list. The seven new keys now require the exact approved |
| 110 | `COPY ACCEPTED BY DELEGATION (Luna, 2026-11-26)` status in that list. No generic |
| 111 | scanner rule was widened. `git fetch origin` and `git merge origin/main` |
| 112 | reported already up to date at main `8a3f1d92`. |
| 113 | |
| 114 | `go test -p 1 ./internal/plan3test -run '^TestPlan3ReleaseBoundaries$' -count=1` |
| 115 | passed (4.262s), and `python3 scripts/plan3-copy-check.py` passed. The measured |
| 116 | Plan 3 test budget increases by two lines, 11976 to 11978, for that acceptance |
| 117 | entry. The earlier statement about the sole size allowance applies to the |
| 118 | initial implementation; this follow-up also adjusts the measured test count. |
| 119 | |