Skip to content

fix(db): survive sqlmodel's UTC default, and keep production alive on Hobby - #995

Merged
yadava5 merged 20 commits into
mainfrom
ci/estate-fix-2026-10
Oct 15, 2026
Merged

yadava5 merged 20 commits into
mainfrom
ci/estate-fix-2026-10

Conversation

@yadava5

@yadava5 yadava5 commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Backend CI has been red on main since 2026-09-28 and ML Monitoring Weekly for three Mondays. This makes them green with a version-agnostic fix, closes the production landmine behind them, and moves the 15-minute sync off a Vercel cron the Hobby plan would reject.

Root cause

sqlmodel 0.0.45 (2026-09-21) made plain datetime fields a tz-aware UTCDateTime that raises on naive values; requirements.txt floats sqlmodel>=0.0.42. No backend code changed between the last green run and the first red one — the resolver moved. A fresh install of main's manifest today resolves sqlmodel 0.0.48 + SQLAlchemy 2.1.4, and on that tests/test_database.py is 15 failed / 2 passed.

Fix

  • fix(db) — the 16 naive columns (10 field definitions) declare sa_type=DateTime(timezone=False), sqlmodel's documented Keep-Naive-Storage. DDL is byte-identical on sqlmodel 0.0.42, 0.0.44 and 0.0.48; alembic check clean; no migration. The four already-timestamptz columns are untouched.
  • test(db) — every datetime field must declare its storage, read from the FIELD definitions (compiled metadata can't tell the difference below 0.0.45). Mutation-proven red on 0.0.42, 0.0.44 and 0.0.48.
  • build(deps) — sqlmodel<0.0.45, sqlalchemy<2.1 in both manifests, plus Dependabot ignore for both until the timezone migration; .python-version 3.12 (what Vercel already builds with).

Hobby plan + the outage

  • The Vercel team is on Hobby, which rejects any cron more frequent than daily — the next api deploy would have failed. vercel.json cron → daily backstop 0 7 * * *; .github/workflows/sync-cron.yml runs /cron/sync every 15 min (counts only in the log — never the body, which carries user ids).
  • keepalive.yml — a SELECT 1 against production Postgres every 6 h, straight from GitHub. On 2026-09-29→10-05 the Vercel account block stopped every function (0 invocations on all projects), Supabase paused the project at 7 idle days, and /health (which never touches the DB) kept reporting ok.

Also folded: #981 #982 #984 #987 #988 #989 #991 #992 (floors) and #990 #993 (actions). No apps/web or backend/alembic file changes; EXPECTED_REVISION unchanged.

Verified (fresh envs, Docker testcontainers)

env collected passed xfailed failed skipped
CI (py3.11, sqlmodel 0.0.44) 3764 3751 13 0 0
production (py3.12, Vercel's uv resolution) 3764 3751 13 0 0

rls-postgres 26 · migrations 10 · verify-rls 6 · expand-only 25 revisions · classifier non-regression + hybrid benchmark PASS · cloud smoke 9/9 · README facts, citations, test data, decisions OK.

Supersedes #985 and #983.

Ayush Yadav added 20 commits October 14, 2026 18:51
Every `datetime` field on a table class in `database/models.py` now declares
its storage, and the naive ones say `sa.DateTime(timezone=False)` instead of
leaving it to sqlmodel's default. The default is what moved.

WHY. Up to sqlmodel 0.0.44 a plain `datetime` annotation compiled to
`DateTime(timezone=False)` — `timestamp without time zone`, which is what 16
of the 20 datetime columns in `backend/alembic/versions/` actually are. From
0.0.45 the same annotation compiles to `UTCDateTime`, sqlmodel's own
`TypeDecorator` over `DateTime(timezone=True)`, and that type REFUSES a naive
value on write. This codebase writes `datetime.utcnow()` — naive, by
convention, in ~46 producer sites — and the upgrade migrates no columns, so a
bare annotation turns every insert on those tables into a `StatementError`
against a column that did not change.

That is not hypothetical here: the root `requirements.txt` carried only
`sqlmodel>=0.0.42`, so a fresh install of the CI/Vercel manifest today
resolves 0.0.48 + SQLAlchemy 2.1.4. `Field(sa_type=DateTime(timezone=False))`
is sqlmodel's own documented "Keep Naive Storage" escape and it pins the
behaviour on both sides of 0.0.45, so there is no migration and no
`backend/alembic/` change in this commit.

Ten field definitions, sixteen columns: `TimestampMixin.{created_at,
updated_at}` (inherited by applications, contacts, emails, interviews),
`applications.{dismissed_at,due_at}`, `emails.received_at`,
`interviews.scheduled_at`, `sync_state.{last_sync_at,sync_started_at}`,
`training_data.created_at`, `email_embeddings.created_at`. The four columns
that are already `timestamptz` in production —
`user_credentials.{revoked_at,created_at,updated_at}` and
`gmail_sync_enrollment.enrolled_at` — declare their type inside an explicit
`sa_column` and are deliberately untouched. On the mixin `sa_type` is the only
correct spelling: one `Column` object cannot attach to four tables.

HOW VERIFIED. A script compiled every datetime column against the postgresql
dialect and printed type, timezone, nullable, index, default, onupdate and
server_default plus the full `CREATE TABLE`:

  * sqlmodel 0.0.44 / SQLAlchemy 2.0.54, before vs after: byte-identical
    (`diff` empty), which is what shows `updated_at`'s `onupdate` and every
    default and index survived `sa_type`.
  * sqlmodel 0.0.48 / SQLAlchemy 2.1.4 after vs 0.0.44 after: byte-identical,
    32 `WITHOUT TIME ZONE` occurrences. Before this commit the same dump on
    0.0.48 showed all 16 as `UTCDateTime` / `TIMESTAMP WITH TIME ZONE`.
  * A runtime probe on 0.0.48: an unannotated field refuses a naive write
    (`StatementError: (builtins.ValueError) Datetime values must have timezone
    information`) while the annotated form accepts it. On 0.0.44 both accept —
    which is why the gate that follows this commit has to read field
    definitions and not compiled metadata.
  * `pytest tests/test_alembic.py tests/test_database.py
    tests/test_schema_version.py` — 25 passed, including `alembic check`, so
    the metadata still agrees with the committed migration chain.
  * `ruff check jobtracker/database/models.py --statistics`: 73 findings before
    and 73 after, all pre-existing.
The previous commit annotated ten field definitions. Nothing stops the
eleventh from being written bare, and bare is the shorter thing to type.

WHAT IT ASSERTS, AND WHY NOT ON THE METADATA. Below sqlmodel 0.0.45 an
annotated field and a bare one compile to the SAME Column — `DateTime()`,
`timezone=False`, byte-identical DDL. A test that introspected
`SQLModel.metadata` would be green on the capped version whatever the source
said: green from birth and green forever. So this walks the mapper registry
and reads the FIELD DEFINITIONS — the `FieldInfo` carries an `sa_type`, or an
`sa_column` whose type is a real `sa.DateTime`. Both are things a human wrote
and neither can arrive by default. The `isinstance` check is the load-bearing
half rather than "not Undefined", because on >= 0.0.45 the default for a bare
field is `UTCDateTime`, a `TypeDecorator` that is NOT a `DateTime` subclass,
and a looser check would accept precisely what this gate refuses.

The rule is "is it declared", not "is it naive": four columns are legitimately
`timestamptz` and a gate demanding naive storage would be wrong about them.

Four tests. One asserts mapped classes == tables in the metadata, so a class
cannot drop out of the walk while its table stays in the schema. One is a
positive control naming four fields that must be discovered — a plain
`datetime`, an `Optional[datetime]`, one inherited from `TimestampMixin` and
one declared through `sa_column` — so an empty iteration cannot read as a pass.
One is the gate itself. One checks the declaration agrees with the column it
compiled to, which is the independent failure a `sa_column` on a mixin
produces.

PROVEN ABLE TO FAIL. Deleting `sa_type=sa.DateTime(timezone=False)` from
`Application.due_at` (Optional) and, separately, from `Email.received_at`
(plain) each reds the gate naming that field, on sqlmodel 0.0.44 AND 0.0.48:

  BASELINE                       4 passed  / 4 passed
  - Application.due_at           1 failed, 3 passed (both versions)
      "declare no storage: Application.due_at"
  - Email.received_at            1 failed, 3 passed (both versions)
      "declare no storage: Email.received_at"
  AFTER RESTORE                  4 passed  / 4 passed

Each mutation was checked to have actually applied (`git diff --numstat`
non-empty, removed line printed) rather than assumed, because a mutation that
silently no-ops prints exactly like a gate that survived it. The positive
control was mutated too — pointing it at a field that does not exist reds it
and lists all 20 fields it did find.

ALSO VERIFIED. `scripts/check_test_data.py`: OK, baseline unmoved (891
addresses across 111 files, 156 id-shaped tokens across 29 — this file adds
neither). `ruff check` on the new file: clean.
`sqlmodel>=0.0.42` with no upper bound meant the version production and CI ran
was "whatever PyPI published last". A fresh install of the root manifest today
resolves sqlmodel 0.0.48 + SQLAlchemy 2.1.4 — the releases that change what a
plain `datetime` field compiles to — so a breaking change arrived without
anyone choosing it. That is the defect this commit fixes; the annotations two
commits back fix the symptom.

  requirements.txt      sqlmodel>=0.0.42,<0.0.45   sqlalchemy[asyncio]>=2.0.52,<2.1
  backend/pyproject.toml  sqlmodel>=0.0.14,<0.0.45   sqlalchemy[asyncio]>=2.0.25,<2.1

The floors in pyproject.toml are untouched on purpose: the shared FLOOR is
declared once, in the root manifest (#704), and
`tests/test_one_source_for_a_shared_floor.py` fails if a package declares one
in two places. An upper bound is not a floor, so it may live in both.

THE CAP IS A HOLD, NOT A FIX. `models.py` is now correct on both sides of
0.0.45 — the compiled DDL is byte-identical — so nothing breaks if the bound
is lifted today. What is NOT done is the tz-aware migration: ~46 producer sites
and ~190 test sites construct naive datetimes, and moving the 16 naive columns
to `timestamptz` is an Alembic contract step. Until that lands, the resolved
version should be a decision. The reason is written out beside the pins rather
than here, because that is where the next person raising a floor will be, and
the file's preamble claim that every constraint in it is an unbounded `>=` is
corrected to name these two as the exceptions.

SQLAlchemy moves with it at `<2.1`: 2.1 is the major sqlmodel 0.0.45+ is built
against, and letting it travel alone pairs an untested combination under the
deployed function.

`.github/dependabot.yml` gains matching `ignore` entries on BOTH pip entries —
rules are per-entry, and the `/backend` one is the only entry that can see
`pyproject.toml`. `versions: [">=0.0.45"]` rather than an `update-types`
ignore, deliberately: 0.0.45 is not a semver major, and a patch inside the
allowed range must still arrive. Dependabot refiled #983 and #985 against the
bounds already; the comment says that lifting these is tracked with the
migration and that the entries and the caps come out in one change, so neither
half can be deleted on its own and quietly restore the noise.

HOW VERIFIED.
  * `uv pip compile` from scratch on all three manifests — root requirements
    (py3.12, production's interpreter), backend/requirements-dev.txt (py3.11,
    CI's) and backend/pyproject.toml — each resolves sqlmodel 0.0.44 /
    SQLAlchemy 2.0.54. Deterministic, and no "No solution found".
  * `.github/dependabot.yml` parses and validates against schemastore's
    `dependabot-2.0.json`; both pip entries carry the two ignore rules and the
    three non-pip entries carry none.
  * `pytest tests/test_one_source_for_a_shared_floor.py
    tests/test_every_datetime_field_declares_its_storage.py` — 7 passed.
  * `scripts/check_test_data.py` — exit 0.
The deployed function's interpreter was never declared anywhere. Vercel's
Python runtime reads `pyproject.toml`, `.python-version` or `Pipfile.lock`, and
this repository's root carries none of the three — there is no root
`pyproject.toml` and no `Pipfile`, and `backend/pyproject.toml` is outside the
Root Directory Vercel builds from. So the version came from Vercel's default,
which today is 3.12 (the 2026-09-09 build log ran 3.12, and the docs list
"3.12 (default), 3.13, 3.14"). That is the right version; what is wrong is that
it was never chosen. The default moves when Vercel moves it, and this is a
backend whose dependency floors have already been bitten once by "whatever is
latest" — a silent interpreter bump is the same failure with a longer fuse.

`3.12` is therefore a no-op against the current deployment on purpose. Nothing
about this commit is intended to change the running function; it is intended to
make the next change to it deliberate.

CI IS UNAFFECTED, checked rather than assumed: all 13 `actions/setup-python`
steps across the 10 workflows that use it set `python-version:` explicitly
("3.11" or '3.11') and none uses `python-version-file`, which is the only input
that would read this file. The backend suite stays on 3.11, as
`backend/pyproject.toml`'s `requires-python = ">=3.11"` and CLAUDE.md both say.

LOCAL `uv`, measured on uv 0.11.6 rather than inferred:

  cwd = repo root   `uv python find`  3.13 before this commit, 3.12 after
  cwd = backend/    `uv python find`  3.13 before, 3.13 after

So the default moves at the ROOT and does not reach `backend/` — uv did not
walk up to the parent's `.python-version` from there. That means the two
commands in `backend/pyproject.toml`'s own header, `cd backend && uv sync` and
`uv pip install -e .`, pick the same interpreter they did before. The venv the
docs tell you to build is explicit anyway: `python3.11 -m venv .venv311` in
README.md:817 and docs/SETUP.md:48. Nothing in the repository relies on uv's
default interpreter at the root.

ONE THING WORTH KNOWING AND NOT FIXED HERE. `.python-version` is not in
`vercel-ignore-build.sh`'s api path set (`api requirements.txt
backend/jobtracker vercel.json .vercelignore`), so a future commit touching
only this file would be SKIPPED and the pin would not reach a deployment on its
own. It is not a problem for this merge, which also changes `requirements.txt`
and `vercel.json`, and adding a path to that list is a change to the build
trigger that deserves its own commit and its own proof.
Folded from #981.

A Dependabot floor bump, taken as its own commit so the merge it lands in
stays readable and so a revert names one package. The diff is the version
string and nothing else; the comment beside it is unchanged.
Folded from #982.

A Dependabot floor bump, taken as its own commit so the merge it lands in
stays readable and so a revert names one package. The diff is the version
string and nothing else; the comment beside it is unchanged.
Folded from #984.

A Dependabot floor bump, taken as its own commit so the merge it lands in
stays readable and so a revert names one package. The diff is the version
string and nothing else; the comment beside it is unchanged.
Folded from #987.

A Dependabot floor bump, taken as its own commit so the merge it lands in
stays readable and so a revert names one package. The diff is the version
string and nothing else; the comment beside it is unchanged.
Folded from #988.

A Dependabot floor bump, taken as its own commit so the merge it lands in
stays readable and so a revert names one package. The diff is the version
string and nothing else; the comment beside it is unchanged.
Folded from #989.

A Dependabot floor bump, taken as its own commit so the merge it lands in
stays readable and so a revert names one package. The diff is the version
string and nothing else; the comment beside it is unchanged.
Folded from #991.

A Dependabot floor bump, taken as its own commit so the merge it lands in
stays readable and so a revert names one package.

It was the only one of the ten that conflicted, and trivially: #987 bumped
`mypy` on the line directly above `ruff` in both backend/pyproject.toml and
backend/requirements-dev.txt, so cherry-picking the second onto the first gave
an adjacent-line conflict. Resolved as the union — ruff 0.16.9 AND mypy 2.3.1 —
and the staged diff against the previous commit was checked to be exactly the
two ruff lines and nothing else, which is what proves the mypy bump was not
quietly reverted by the diff3 base section.
Folded from #992.

A Dependabot bump, taken as its own commit so the merge it lands in stays
readable and so a revert names one dependency. The diff is the version string
(and, for an action, its pinned SHA) and nothing else.
Folded from #990.

A Dependabot bump, taken as its own commit so the merge it lands in stays
readable and so a revert names one dependency. The diff is the version string
(and, for an action, its pinned SHA) and nothing else.
Folded from #993.

A Dependabot bump, taken as its own commit so the merge it lands in stays
readable and so a revert names one dependency. The diff is the version string
(and, for an action, its pinned SHA) and nothing else.
Between 2026-09-29 and 2026-10-05 the production database was PAUSED and the
product was down, and nothing in this repository could have told anyone.

THE CHAIN. A Vercel account block stopped every function on the account — zero
invocations on all projects for seven consecutive days. The `*/15` platform
cron was the only thing touching this database, so the database saw no traffic
for those same seven days, and the Supabase free tier pauses a project at seven
idle days.

WHY IT RUNS ON GITHUB AND NOT VERCEL, which is the whole design. The outage WAS
Vercel; a keep-alive hosted on the thing that stopped is a second copy of the
same single point of failure. And `/health` could not have caught it from
anywhere: its docstring says "No database hit" and it means it, so an uptime
check pointed at it reports 200 against a paused database. This opens a real
connection and reads a real row.

Six hours, not daily: the window being defended is seven days, so the probe
tolerates 27 consecutive failures before the pause it prevents could happen and
a transient fault is not an incident. Non-zero exit is the notification —
GitHub emails the repository owner when a scheduled workflow fails, and there
is no alerting integration here because that is sufficient and a second one
would be a second thing to maintain.

Reuses `db-migrate.yml`'s `environment: production` and its `DIRECT_URL`
secret, so there is one credential to rotate and a rotation that breaks the
migration breaks this within six hours instead of on the next merge to main.
Budgets are on the STEPS, per #702/#712: a job-level `timeout-minutes` ends the
job `cancelled`, the same conclusion a supersede produces, and a hang would
hide among routine traffic. `cancel-in-progress: false` for the same reason —
cancelling would turn the only notification channel into noise.

THE URL NORMALISER IS LOADED BY PATH, not imported. `db-migrate.yml` does
`from jobtracker.database.migration_url import ...`, and that cannot be copied
here: this job installs only psycopg, and `jobtracker/database/__init__.py`
imports `connection`, which imports SQLAlchemy — measured, the package import
dies with `ModuleNotFoundError: No module named 'sqlalchemy'`. Inlining the
scheme stripping instead is the thing `migration_url.py`'s own docstring exists
to refuse (two copies of one rule drifted, and the guard passed on a URL the
migration then died on), so this loads that exact file with
`importlib.util.spec_from_file_location` and skips only the package `__init__`
it does not need. The psycopg constraint is likewise read out of
`backend/requirements-migrate.txt` with a `grep` rather than retyped.

PROVEN ABLE TO FAIL, against a local postgres:16 in Docker, running the probe
text extracted from the committed workflow rather than a retyped copy:

  good URL (postgresql://)                    exit 0  "SELECT 1 -> 1"
  postgresql+asyncpg:// (normalises)          exit 0  "SELECT 1 -> 1"
  postgres:// legacy scheme (normalises)      exit 0  "SELECT 1 -> 1"
  wrong port                                  exit 1  paused hint
  wrong password                              exit 1  paused hint, and the
                                                      second line names the
                                                      real cause ("password
                                                      authentication failed")
  SELECT 1 mutated to SELECT 2                exit 1  "returned (2,), not (1,)"
  migration_url.py absent                     exit 1  refuses to guess

The `SELECT 2` mutation is there because a result check that only ever sees the
value it expects is indistinguishable from dead code. Also verified: the YAML
parses, the triggers are `schedule` + `workflow_dispatch`, permissions are
`contents: read`, and there is no job-level timeout.

The header records the one way this stops silently — GitHub disables `schedule`
triggers after 60 days with no commit activity — so a future paused database
sends you to check that before looking for a bug in here. The only container
started for this was named `applied-keepalive-probe-ci` and only it was removed.
… daily backstop

`vercel.json` declared `"schedule": "*/15 * * * *"`. On the Hobby plan that is
not coarsened, it is REFUSED — "cron jobs can only run once per day.
Expressions that run more frequently will fail deployment" — so the next
production deploy of this project FAILS on that line. It is changed to
`0 7 * * *`, a shape that deploys on any plan, and the fifteen-minute cadence
moves to `.github/workflows/sync-cron.yml`.

TWO SCHEDULERS, AND THEY ARE NOT REDUNDANT.

  * The workflow, every 15 min — BEST EFFORT. GitHub queues scheduled runs
    rather than guaranteeing them, delays them under load, and DISABLES them
    after 60 days with no commit activity on the repository. A product
    behaviour resting on that alone fails silently on a repo that goes quiet.
  * `vercel.json`, daily — THE BACKSTOP, and the reason the platform cron is
    not simply deleted. It is the one schedule the platform itself guarantees,
    so the floor on "mail gets filed while nobody is looking" stays a day even
    with the workflow suspended.

They collide at 07:00 once a day and that costs nothing: `/cron/sync` takes a
per-user lease and skips a mailbox already syncing, counting it in `skipped`.

THE WORKFLOW. One job, one step, `timeout-minutes` on the step (#702/#712 — a
job budget ends `cancelled`, indistinguishable from a supersede).
`cancel-in-progress: false`, because a call can take most of the 45 s run
budget and killing it mid-flight is how a sync stops without advancing a
cursor. `Authorization: Bearer <secret>` is one of the two carriers
`cloud/cron.py::_presented_secrets` already accepts — the same header Vercel's
scheduler builds — so this is the identical authenticated request from a
different caller, and it needs `CRON_SECRET` as a GitHub secret holding the
same value as the Vercel env var of that name. The secret is passed to `curl`
through a `--config` file on stdin, never as an argument: a process list and
`set -x` both leak an argument.

200 is success. Anything else gets ONE retry after 60 s and then fails, because
the schedule is the real retry — the next run is fifteen minutes away — and a
job that keeps retrying turns an outage into a slow job instead of an email.
403 and a total connection failure get their own messages, since "the two
halves of CRON_SECRET disagree" and "the deployment is down" need different
actions.

429 IS TREATED AS SUCCESS, AND THE COMMENT SAYS WHAT IS ACTUALLY TRUE. 429 is
what the per-user lease means in this app (`SyncAlreadyRunning`), but the
aggregate `/cron/sync` route does NOT propagate it — it catches
`SyncAlreadyRunning` per user, increments `skipped` and still answers 200. So a
429 reaching this step would have to come from somewhere the route does not
produce today: a platform rate limit, or a future change letting the lease
reach the top. It is accepted anyway because in every one of those cases it
means "something is already doing this work", which must not email the owner
every fifteen minutes. Stated that way rather than as "429 is the lease",
which would have been a claim the code does not support.

`scripts/readme_facts.py` HAD TO CHANGE OR THE REQUIRED CHECK WOULD GO RED.
`cron_runs_per_day()` raised `SystemExit` on anything but `*/N * * * *`, so
`0 7 * * *` alone would have failed "README numbers agree with the code". It
now reads BOTH schedules — the workflow's and the platform's, each out of the
file that declares it — and returns the sum, because the figure the capacity
sentence in docs/DEPLOYMENT.md is about is invocations of one Vercel Function
per day, and that is 96 + 1 = 97 whichever side of the fence the scheduler sits
on. Moving the cadence off Vercel did not move the function usage, and the doc
now says so. The "raise rather than guess" behaviour is kept and widened to
exactly two shapes.

PROVEN ABLE TO FAIL. Five mutations against the rewritten fact:

  vercel.json "0 7 * * * *"   RAISED  "has 6 fields, not 5"
  vercel.json "0 7 * * 1"     RAISED  "not a plain daily or every-N-minutes"
  workflow "*/30 * * * *"     49, and --check reds: "docs/DEPLOYMENT.md:376
                                      says 97 ... is 49"
  workflow cron line deleted  RAISED  "found 0 cron expressions, expected 1"
  workflow "*/7 * * * *"      RAISED  "*/7 does not divide the day evenly"
  restored                    97

ALSO VERIFIED. `sync-cron.yml` parses; triggers are `schedule` +
`workflow_dispatch`; `permissions: contents: read`; concurrency group
`sync-cron` with `cancel-in-progress: false`; the step carries the only
timeout. `readme_facts.py` compiles and its ruff count is unchanged at 16.
`pytest tests/test_cron_sync.py tests/test_the_deployed_app_is_the_cloud_app.py
tests/test_schema_version.py` — 40 passed. `scripts/check_test_data.py` exit 0.
`scripts/readme_facts.py` is the only consumer of `vercel.json`'s `crons` in
the tree (checked across backend/tests, scripts and apps/web/tests) and no test
asserts the workflow set.

Docs: docs/DEPLOYMENT.md's Schedule section is rewritten as a two-scheduler
table with the Hobby refusal and the 60-day suspension both stated, its heading
drops "(Vercel Cron)" since that is no longer the whole story, and the capacity
bullet explains the 96 + 1. docs/WEB_ARCHITECTURE.md's trigger table and cloud
entrypoint list are corrected. DEPLOY.md needed nothing — it names `/cron/sync`
as a route and never states a schedule.

NOT TOUCHED, deliberately: the `apps/web` comments that mention a 15-minute
cadence. They are still true — the cadence is still fifteen minutes — and
`apps/web` is out of scope for this merge.

WHAT THIS COMMIT DOES NOT DO. It does not set the GitHub `CRON_SECRET` secret;
until that exists every scheduled run is a 403, which is loud and is the
intended failure mode rather than a silent no-op.
`python3 scripts/readme_facts.py --write`. Five numbers in README.md, all of
them consequences of commits earlier on this branch rather than editorial
changes:

  workflows      16 -> 18   keepalive.yml and sync-cron.yml (two sites)
  testModules   189 -> 190   test_every_datetime_field_declares_its_storage.py
  testFunctions 2097 -> 2101  its four test functions

Written by the checker, not by hand, because that is the whole point of it —
the README is wrong in a way CI can see, and the fix is to re-run the source of
truth.

"README numbers agree with the code" is now green at this tree: `--check` exits
0 with 106 facts asserted at 334 sites across 33 files and zero disagreements.
It was red before this commit on exactly those five sites, and
`tests/test_readme_facts_writer.py::test_the_same_tree_with_the_version_correct_is_green`
was red with it (it runs `--check` against the real tree); that file is 54
passed now.

`--record` IS STILL OUTSTANDING, AND IT WAS OUTSTANDING BEFORE THIS BRANCH.
`--check` prints a notice, not a failure: the recorded artifact
`docs/readme-facts.json` was taken 2026-09-05 at 36474fd and holds 1725 test
functions across 150 modules, while origin/main's own README already said the
static parse counted 2097 across 189. So the gap is pre-existing — 372
functions of it — and this branch widens it by four functions and one module.
Nothing in CI reds on that, and `--record` needs the full Python 3.11 suite
with Docker reachable (it refuses to write unless the run was whole, since a
skipped test is still a collected one), so it is deliberately NOT run here. It
belongs to whoever next runs the full suite on this tree; `testsCollected`
(3163) and the coverage figures are the numbers it would move.

`docs/readme-facts.json` is untouched by this commit.
… log

The workflow added in the previous commit dumped the response body into the log
on every outcome. `CronSyncResponse.errors` is a `list[str]` whose entries are
built as f"{user_id}: TimeoutError" and f"{user_id}: HTTP{code}"
(`cloud/cron.py`), so the body carries RAW SUPABASE USER IDS — and THIS
REPOSITORY IS PUBLIC, which makes an Actions log world-readable. It would have
published them every fifteen minutes.

That is worse than it first looks. `gmail_sync_enrollment`'s docstring records
the exposure of user-id membership as a deliberate trade and scopes it to
anything connecting as `jobtracker_app`. A public log is a far wider audience
than the one that trade was made for.

So the summary now extracts the counts BY NAME — users_synced, candidates,
skipped, stopped_by — and reduces `errors` to its LENGTH. The operator value is
kept (a 200 that synced nobody is a different fault from one that synced
everybody, and the status code shows neither) without the identifiers. Whoever
needs to know which user failed reads the function's runtime logs, which are
not public.

TWO MORE BUGS, BOTH FOUND BY RUNNING THE SCRIPT RATHER THAN READING IT:

  * `curl` does not truncate `--output` when it fails to connect, so the
    retry's summary printed the FIRST attempt's counts under the second
    attempt's status code. `call()` now clears the file first. Observed
    directly: the harness read a body left behind by an earlier run.
  * The summary printed a `FileNotFoundError` traceback into the log on the
    exact runs where there is no body — i.e. the failing ones somebody is
    actually reading. stderr is discarded and the fallback line is plain.

PROVEN BY EXECUTION. The `run:` block was extracted from the committed file
(only edit: `sleep 60` -> `sleep 0`) and driven against a local stub that
answers a scripted status sequence and records the `Authorization` header it
received:

  scenario             exit  stub saw           outcome
  200                   0    [200]              "scheduled sync accepted"
  429                   0    [429]              notice, no retry
  403 twice             1    [403, 403]         the 403-specific message
  500 then 200          0    [500, 200]         "accepted on retry"
  500 twice             1    [500, 500]         the generic twice message
  connection refused    1    (no listener)      "could not be reached at all"

`auth_ok=True` on every request the stub received, which is the only proof that
passing the header through `curl --config -` works at all. The attempt count
reconciles exactly: 10 curl attempts = 1+1+2+2+2+2, and 10 summaries = 8 with
counts plus 2 no-body.

LEAK CHECKS over the whole captured output, with a positive control that the
grep finds the string in a file that does contain it:

  the secret                 0 occurrences
  the stub's user id         0 occurrences
  the raw `errors` value     0 occurrences
  python tracebacks          0

The stub's body deliberately includes a user id inside `errors`, so a zero
there is a measurement and not an absence of input.
Two of the four tests in this file had never been shown to red, and the repo's
standing rule is that a gate which has never failed has not been tested. Both
are unreachable from `models.py`, so both are mutated at RUNTIME; the module
docstring now records all four proofs instead of two.

  test_every_table_class_is_reachable_from_the_registry
      adding a bare `sa.Table` to `SQLModel.metadata` reds it:
      "9 mapped classes against 10 tables in the metadata"

  test_the_declared_storage_matches_the_column_it_compiles_to
      repointing `Application.__table__.c.due_at.type` at
      `DateTime(timezone=True)` reds it: "declared timezone=False but the
      column compiled to timezone=True"; repointing it at `String()` reds it:
      "declared DateTime() but the column compiled to String()" — the
      not-a-DateTime case a `UTCDateTime` presents as. Reverting either
      returns it to green, confirmed in the same run.

AND ONE CLAIM REMOVED BECAUSE IT WAS NOT TRUE. That test's docstring said the
two assertions "have failed independently in this repository's history — a
`sa_column` on a mixin compiles for one table and silently loses the others". I
have no evidence of that ever happening here; I inferred the failure mode from
the API and wrote it as history. It is replaced by what the test actually
guards, which is better and is checkable: no edit to `models.py` CAN make it
fail, because the column is built from the declaration — what it catches is a
future sqlmodel release that ignores or reinterprets `sa_type`, leaving the
source looking correct while the compiled column moves. That is the shape of
the 0.0.45 change this whole file exists because of, and the one thing the
declaration-side assertion cannot see.

Verified: the file is 4 passed, ruff clean. Docstring-only change to the test
bodies — no assertion was altered.
Three corrections, each measured rather than reasoned.

1. `requirements.txt` said SQLAlchemy is capped "because 2.1 is the major
   sqlmodel 0.0.45+ is built against". Both halves are wrong. sqlmodel 0.0.48
   declares `SQLAlchemy<2.2.0,>=2.0.14` — read with
   `importlib.metadata.requires('sqlmodel')` in the 0.0.48 venv — so it
   resolves fine against 2.0.x and does not require 2.1; and 2.1 is a minor of
   SQLAlchemy 2, not a major. The real reason is kept and stated plainly: the
   uncapped pair is what shipped the surprise, a fresh resolve took 0.0.48 AND
   2.1.4 together, and pinning one while the other roams leaves the deployed
   function on a combination nothing here has exercised.

2. `keepalive.yml` claimed `workflow_dispatch` is "also how you re-enable it: a
   manual run is allowed on a repository whose schedules have been suspended."
   GitHub's "Disable and enable workflows" page does not say that either way —
   it documents "Enable workflow" on the Actions tab and `gh workflow enable`,
   and is silent on dispatching a suspended workflow. The header now quotes
   what the page does say about the 60-day auto-disable, names the explicit
   re-enable, and says the dispatch behaviour is undocumented rather than
   asserting it.

3. `docs/DEPLOYMENT.md` said **six** workflows carry no path filter and named
   them. Parsing every workflow's `on:` block for `paths`/`paths-ignore` gives
   ELEVEN. Three were already missing before this branch — `citations.yml`,
   `decisions.yml` and `test-data.yml`, and that last one is a REQUIRED check
   whose own header explains at length why it is deliberately unfiltered — and
   `keepalive.yml` and `sync-cron.yml` are the two this merge adds. The
   sentence is corrected to the measured set with a note recording what it used
   to say, so the pre-existing omission is visible rather than quietly folded
   into my change. The CI workflow table gains rows for the two new files,
   including what each one does and does not gate.

ALSO: the citation line numbers I broke. `scripts/check_citations.py` exits 1 on
this branch and 0 on a pristine `origin/main` tree, so this is mine:
`fix(db)` added 66 lines above the `gmail_sync_enrollment` block, moving it from
models.py:1164-1171 to 1230-1237, and
`docs/casa/ARCHITECTURE-AND-TENANT-ISOLATION.md:273` cites it by line range.
Fixed with the gate's own sanctioned `--write`, which rewrote exactly those two
numbers in one line. `citations.yml` carries no path filter, so this would have
been red on the pull request.

Gates re-run with everything staged: readme_facts `--check` 0, test-data 0,
citations 0, decisions 0 (14 entries, every gate and marker resolves).
@vercel

vercel Bot commented Oct 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
jobtracker-web Ignored Ignored Oct 15, 2026 1:09am UTC

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant