Skip to content

Demo/read state - #335

Draft
AlexAxthelm wants to merge 11 commits into
mainfrom
demo/read-state
Draft

AlexAxthelm wants to merge 11 commits into
mainfrom
demo/read-state

Conversation

@AlexAxthelm

Copy link
Copy Markdown
Collaborator

Demo for stack of #330, #331, #332, #333, #334

AlexAxthelm and others added 8 commits October 15, 2026 12:21
Add og_field_resource_state (one row per resource and permission
profile, holding each field's winning value, its source, and the commit
that computed it) and its single readiness row, plus the four exact
permission profiles the table is keyed by. Schema only: the tables
start empty and not ready, and nothing writes or reads them yet, so
answers are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: ChatGPT <noreply@openai.com>
Compute each listable resource's rows for the four permission profiles
from the same winner query the live list uses, and add the rebuild
command: a full rebuild in committed batches behind the readiness flag,
--if-stale for the post-deploy step (resumes where a failed run
stopped), and --ids to repair specific resources. A full rebuild
records the commit that built it, redoes rows computed by other code,
checks the result before marking it ready, and holds a Postgres
advisory lock so two can't overlap. Run the Postgres-only tests in CI.

Nothing reads the table yet and API writes don't refresh it, so
answers are unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A full rebuild's integrity check couldn't see an --ids repair's
uncommitted rows, so a repair from another image could commit between
the check and readiness, leaving a table marked as built by one commit
holding rows from another. Do the final check for rows from other code
in the transaction that sets readiness, holding the status row
exclusively (repairs hold it shared): a repair already running is
waited for and its rows get another pass; one starting later waits,
then refuses because other code built the table.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only the rebuild's expected failures print as a single ERROR line;
unexpected ones (e.g. an unreachable database) keep their traceback,
which is what you want for debugging them. Both exit with status 1;
invalid arguments exit with status 2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-766)

Attaching or creating sources, re-ordering a field's sources, and
merging now recompute the affected resources' read-model rows in the
same transaction. Each write locks its resources first (in id order for
merges) and re-reads them after locking: locking later lets two writers
deadlock upgrading the foreign-key locks their inserts take, and a
write that waited must see a merge that committed meanwhile.

Nothing reads the table yet, so answers are unchanged; each write pays
~85 ms at 50K resources for the refresh (~16 ms with #322's index).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
FOR UPDATE conflicts with the key-share lock that inserting any row
referencing a resource takes. Creating a merge candidate for [B, A]
holds key-share on B, then waits on A, while a merge of [A, B] holds A
and waits on B: Postgres aborts one. FOR NO KEY UPDATE (the lock an
update of repointed_id already takes) still makes writers queue but
never conflicts with key-share, so no insert path needs to lock first
to stay safe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-766)

List and filter-options now read precomputed rows when the caller's
licensed sources exactly match a permission profile and the read model
is ready (built by this commit); otherwise they answer live, unchanged.
At 50K resources list requests drop from ~2-3 s to under 10 ms.

Each process caches readiness for up to 5 s, so most requests skip the
lookup. Operators can switch the fast path off with a new `disabled`
flag that rebuilds never clear, so a deploy's rebuild can't undo it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add a Rebuild Read Model job that runs `rebuild --if-stale` from the
deployed API image once the API deploy finishes, so each deploy of new
code gets its fast path back without a manual step. The API deploy now
waits until the previous revision has stopped serving (plus 45 s for
in-flight requests), so the old code's writes can't land after the
rebuild marks the table ready. Nothing waits on the rebuild: if it
fails, lists stay on the slower live path and the PR summary comment
shows a warning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

CD summary 159a814

Frontend: https://brave-cliff-09493391e-335.westus2.7.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-0335-demo-read-stat-ea7c-api.salmonsea-0e166cd2.westus2.azurecontainerapps.io
etl open pr-0335-demo-read-stat-ea7c-etl.salmonsea-0e166cd2.westus2.azurecontainerapps.io
frontend https://brave-cliff-09493391e-335.westus2.7.azurestaticapps.net
stitch-llm open pr-0335-demo-read-stat-ea7c-llm.salmonsea-0e166cd2.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_0335_demo_read_stat_ea7c stitch-staging.postgres.database.azure.com 5432 pr_0335_demo_read_stat_ea7c
Jobs (1)
job image postgres_db
db-migrations ghcr.io/rmi/stitch-api:pr-0335-demo-read-stat-ea7c@sha256:ee0151af9fc637d58fd4c68d51a97bf584a33dffb3839c911f4f19bd3da87904 pr_0335_demo_read_stat_ea7c
Images (2)
build_time commit_time git_sha image image_digest
2026-10-16T09:21:11Z 2026-10-16T09:20:49Z 3585a10 ghcr.io/rmi/stitch-api:pr-0335-demo-read-stat-ea7c ghcr.io/rmi/stitch-api:pr-0335-demo-read-stat-ea7c@sha256:ee0151af9fc637d58fd4c68d51a97bf584a33dffb3839c911f4f19bd3da87904
2026-10-16T09:21:08Z 2026-10-16T09:20:49Z 3585a10 ghcr.io/rmi/stitch-stitch-llm:pr-0335-demo-read-stat-ea7c ghcr.io/rmi/stitch-stitch-llm:pr-0335-demo-read-stat-ea7c@sha256:96066d437b7125d5dca2db03c775ad51a42b121456fb790606feb5cb2df8eedd

AlexAxthelm and others added 3 commits October 16, 2026 11:46
A switched-off table built by commit A accepted a repair from commit B,
leaving B's rows in a table still marked ready as built by A. --if-stale
from A then saw nothing to redo, and switching the table back on served
B's rows under A indefinitely. Apply the version guard whether or not
the table is switched off: repair it from the image that built it, or
rebuild it from the new one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An API process that cached "ready" in the last 5 seconds keeps reading
the table, so a rebuild by other code during that window can hand it
rows the new code just rewrote. Deploys already wait for the previous
revision to stop serving first; say so where rebuilds are documented
and where the cache is defined.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

CD summary 8170eca

Frontend: https://brave-cliff-09493391e-335.westus2.7.azurestaticapps.net

Deployments (4)
service url fqdn
api open pr-0335-demo-read-stat-ea7c-api.salmonsea-0e166cd2.westus2.azurecontainerapps.io
etl open pr-0335-demo-read-stat-ea7c-etl.salmonsea-0e166cd2.westus2.azurecontainerapps.io
frontend https://brave-cliff-09493391e-335.westus2.7.azurestaticapps.net
stitch-llm open pr-0335-demo-read-stat-ea7c-llm.salmonsea-0e166cd2.westus2.azurecontainerapps.io
Database (1)
db_name postgres_host postgres_port postgres_db
pr_0335_demo_read_stat_ea7c stitch-staging.postgres.database.azure.com 5432 pr_0335_demo_read_stat_ea7c
Jobs (1)
job image postgres_db
db-migrations ghcr.io/rmi/stitch-api:pr-0335-demo-read-stat-ea7c@sha256:16e7a084cca5d564716c8902ea6efb855aed6ddae4fad8482b9d2740e1e2cc44 pr_0335_demo_read_stat_ea7c
Images (2)
build_time commit_time git_sha image image_digest
2026-10-16T10:11:32Z 2026-10-16T10:11:16Z 04e7023 ghcr.io/rmi/stitch-api:pr-0335-demo-read-stat-ea7c ghcr.io/rmi/stitch-api:pr-0335-demo-read-stat-ea7c@sha256:16e7a084cca5d564716c8902ea6efb855aed6ddae4fad8482b9d2740e1e2cc44
2026-10-16T10:11:35Z 2026-10-16T10:11:16Z 04e7023 ghcr.io/rmi/stitch-stitch-llm:pr-0335-demo-read-stat-ea7c ghcr.io/rmi/stitch-stitch-llm:pr-0335-demo-read-stat-ea7c@sha256:ebfca9d47241d24bbe53fa20909fed308e3a9550e5884cd527c9e896811995f5

@AlexAxthelm AlexAxthelm self-assigned this Oct 16, 2026

This branch was successfully deployed

1 active deployment
staging — 8170ecaa Deployed Oct 16, 2026 by AlexAxthelm via Deploy frontend / Build and Deploy Job #1229
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