Repository navigation
PR-S2: switch served math to the Python engine and stop starting Clojure (held until the evidence bar and the backfill) - #2895
Closed
colinmegill wants to merge 9 commits into
Closed
colinmegill wants to merge 9 commits into
colinmegill wants to merge 9 commits into
Conversation
…eneration math_tick is per (zid, math_env). When the served label changes (MATH_ENV prod -> python at the switch to the Python engine, or back on a rollback), the new label's tick for a conversation is usually far LOWER than the entity tag a browser cached from the old label. The API sends Cache-Control: no-cache, so browsers revalidate pca2 with If-None-Match on every load, and the route treated the tag as a "newer than" floor: it answered 304 until the new label's tick passed the old tag, so returning visitors kept seeing the old label's cached result, possibly for the rest of a conversation's life. The route now fetches the latest generation and answers 304 only when it equals a tag the client holds; any other generation, lower or higher, is served with its own ETag. While the label is unchanged ticks only grow, so for the single tag a browser sends the answer is the same as before. `*` and the explicit math_tick parameter keep their handling. Tests pin the switch direction, the rollback direction, weak tags and the cached path; the two switch-direction tests fail on the previous handler. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s
…from the deploy PR-S2 of the Clojure-to-Python cutover (delphi/docs/CUTOVER_RUNBOOK.md). The readers move: one shared MATH_ENV in the production env secret sets the label the server (env_file) and Delphi (compose interpolation) read, and at the switch it becomes `python`, the label math-python has written since the shadow started. The secret change is a deploy step, not part of this diff. - scripts/after_install.sh: the math role starts nothing (the hook has already removed every container, so the Clojure box runs nothing until the math tier is deleted). The Delphi role line is unchanged (`delphi math-python`); its comment now describes the served writer, the MATH_ENV secret line, the switch order (stable, then secret, then box deploy) and the rollback order (secret MATH_ENV=prod first, then restore `up -d math`, redeploy). Stopping math-python now stops the served math, so the emergency stop points at the rollback. - delphi/scripts/math_poller.py: no logic change. The guard refuses to WRITE `prod`, Clojure's label, which is served again after a rollback; `python` is admitted whatever the readers serve. The single-writer lock key stays polis-math-python:python. - docker-compose.yml, example.env, poller docstring: comments only. math-python's label still comes only from MATH_PYTHON_ENV, so moving the readers never moves the writer. - Tests: the math role starts nothing, no role starts `math`, the hook documents both orders, readers and writer agree on `python` under the post-switch secret, a rollback secret moves only the readers, math-python has no env_file; the guard admits `python`, refuses `prod` whatever the readers serve, and the lock key is unchanged. Not safe to deploy on its own: conversations with no votes since the shadow's 10-day boot window have `prod` rows and no `python` rows, so the server would present them as empty. The switch waits for a backfill of those conversations under `python`. No schema change. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s
math_tick is allocated per (zid, math_env), so prod tick 57 and python tick 57 are unrelated bodies. The previous commit compared If-None-Match to the served tick by equality, which fixed a lower or higher tick across a label switch but still answered 304 at an EQUAL tick: review 1439 R2 reproduced a stale 304 prod -> python, python -> prod and at tick 0. pca2 now sends ETag "<math_env>-<math_tick>" (the label percent-encoded) and compares held tags as opaque values, weakly (a GET). A legacy numeric tag, which client-participation builds from the JSON math_tick, never matches, so old pages get a 200 on every poll instead of a 304 that may belong to the other label. A 304 carries the current tag. JSON math_tick stays numeric, and `*` and the explicit math_tick cursor keep their handling. The empty presentation synthesized for a conversation with no committed row no longer carries a generation tag: its math_tick 0 is a placeholder, and "<label>-0" would have answered 304 to the conversation's first real publication, also generation 0. Express derives a weak validator from its body instead. pca.ts exports isSynthesizedPca for this. Tests: same tick across labels in both directions and at 0 gets 200 and the new body; legacy numeric tags (quoted, bare, weak, listed) get 200; the label's own tag (strong, weak, in a list, from a warm cache) gets 304 with the tag; the synthesized body never carries "<label>-0". 17 of the pca2 HTTP tests fail on the previous handler. The integration expectation moves to the new tag and adds the legacy-tag case. This commit touches only server/ and cherry-picks onto fd0325b as the prerequisite ETag PR, ahead of the reader switch. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s
…box runs no Clojure Review 1439 R3. The unknown-role fallback ran an unnamed `docker-compose up -d`, which starts every unprofiled service, `math` included, under whatever MATH_ENV the secret holds: after the switch that is Clojure writing `python` beside the Python poller. And the math role announced retirement while both cleanup calls (`down`, `docker rm -f`) had their failures ignored, so a surviving Clojure container left the deploy green. - Unknown or empty role: log, start nothing, exit 1. A missing role file already failed under `set -e`. - Math role: after the shared cleanup, list containers of the compose service `math` (label com.docker.compose.service=math, running or stopped). Any left, or a failed `docker ps`, fails the deploy; otherwise it logs "retirement verified". An already empty box still passes (its ignored `docker rm -f` failure is the idempotent case). - The switch-order comment now reads merge to stable, box deploy while the secret still says prod, secret to python, second box deploy, and says why: CodeDeploy runs the PACKAGED hook and gives ASG replacements the last successful revision (R1). Tests execute the hook's role section under bash with inert sudo, docker, docker-compose and aws: unknown/empty/near-miss roles and a missing role file start nothing and fail; the math role verifies after cleanup and logs it; a container surviving failed cleanup fails with its id; a failed `docker ps` fails; an empty box passes; the server and delphi roles still start exactly their services. Ten of these fail on the previous hook. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s
… prod
Review 1439 R1. A `stable` merge does not replace the hook CodeDeploy has
packaged: an ASG replacement gets the last successful revision, and an old
revision's math role still runs `up -d math --build`. Run after the secret
says MATH_ENV=python, that hook builds math/ from the stable checkout with
the current compose, which hands Clojure ${MATH_ENV}: Clojure would write
`python` beside the Python poller.
The engine's entrypoint now checks its write label before the restart loop,
so before anything polls or writes:
- `python` is refused always (exit 78, EX_CONFIG);
- any other label but exactly `prod` (unset, empty, `dev`, `PROD`,
`prod `) is refused unless MATH_CLOJURE_ALLOW_NONPROD_ENV=1.
Only the dev and test overlays set that opt-in (both run MATH_ENV=dev), and
math/example.env for runs outside docker. docker-compose.yml deliberately
does not forward it, so production Clojure runs `prod` or nothing, whatever
the secret carries. This protects `python` independently of which hook ran;
it does not show that Clojure stopped (the hook's retirement check does).
Tests: math/bin/test-run-guard.sh stubs `timeout` (the JVM's wrapper) and
runs bin/run under 11 environments; 8 fail without the guard. In
test_compose_math_env.py: the production compose with the post-switch
secret (with and without the opt-in in the secret) yields a math
environment bin/run refuses; the rollback secret starts; the test stack
opts in and starts under `dev`; the shell suite passes. python-ci copies
math/bin/run and the shell test beside the hook.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s
…he label-bound ETag and the Clojure guard Review 1439 R1-R3, as built on this branch: the four-step switch (stable, box deploy under prod, secret to python, box deploy) and why the first deploy is needed; pca2's "<math_env>-<math_tick>" tag and its legacy handling; math/bin/run's write-label guard; the fail-closed hook and the math role's retirement check; a rollback that restores only the math role's `up -d math` line. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s
…abel to prod
Review 1441 (answer (i), in place of "the math role runs nothing"). The math
role reads the label the way Compose will hand it to the `math` service,
`docker-compose config --format json` -> .services.math.environment.MATH_ENV,
with the same invocation as its `up`; the hook never exports MATH_ENV, and a
variable in Compose's environment beats .env while ${MATH_ENV:-prod} would
default a missing key silently. The written .env must also define MATH_ENV
exactly once with that same value.
- `prod`: `up -d math --build --force-recreate`, then after a wait exactly
one `math` container, state running, exit code 0, no restart (the guard's
exit 78 restarts it), else the deploy fails.
- `python`: start nothing; no container of the compose service `math` may
remain after cleanup (unchanged check).
- unreadable config, no value, missing/duplicate key, an override from
outside .env, or any other label: start nothing, fail the deploy.
math/bin/run's guard stays the independent second layer.
This removes the inter-deployment freeze: deploy #1 under `prod` keeps
Clojure writing, deploy #2 under `python` stops it and verifies retirement.
Rollback is MATH_ENV=prod in the secret and a redeploy, no hook edit.
Tests execute the hook's role section with stateful stand-ins (one state
directory per box): both branches, readiness failures (guard restarting or
exited, restarted, crashed, not started, up/ps/inspect failing, two
containers), 14 unresolved-label cases, the hook's own MATH_ENV ignored,
six precedence cases against the installed docker-compose on the real
compose file, a fresh replacement box under each label, deploy #1 -> #2 on
one box, and rollback python -> prod. 41 fail on the previous hook.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s
… by ETag and version Review 1441 R1b. The workflow uploaded every package to the one key deployments/deployment.zip and passed CodeDeploy neither version nor eTag, so the deployment group's last successful revision (what an ASG replacement runs) named a key whose bytes a later upload could replace: omitting version takes the object's latest version, omitting eTag skips validation. Now each run uploads to deployments/<git sha>-<run id>-<run attempt>.zip with `put-object --if-none-match '*'` (an existing key is refused), reads the object back with head-object and requires the same ETag, and passes `--s3-location bucket=…,key=…,bundleType=zip,eTag=<ETag>` plus `,version=<VersionId>` when S3 returns one (the bucket reported versioning Enabled on 2026-09-29; both cases are handled). The binding (deployment id, bucket, key, eTag, version, git sha, ref, run id/attempt, archive sha256, after_install.sh sha256) goes to the job summary, the log and a deployment-binding-<run id>-<attempt> artifact. The `production` environment gates on both jobs are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s
…ive or hook hash
`echo "archive_sha256=$(sha256sum ...)"` let a failed sha256sum through as
an empty value, so the step could succeed and record empty hashes (review
C1). Each hash is now assigned on its own line under set -euo pipefail,
before the upload, and must match ^[0-9a-f]{64}$ or the job fails. A
comment names s3:GetObjectVersion, which the versioned head-object needs
from the workflow's AWS identity; that policy is not in the repo, so the
runbook's step 0 carries the check.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s
Contributor
Delphi Coverage Report
|
Member
Author
|
superseded by #2911 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Status: DRAFT — do not merge yet
Held until (a) the light-shadow evidence bar is met (three covered UTC days of rolling hourly receipts, zero certified failures, ≥ 100 certified battery entries) and (b) the pre-switch backfill (P‑070) has computed every conversation the Clojure engine has results for, verified by an aggregate-only count. Reviewed design and revisions: design review, re-review of R1–R3, and approval of revisions A/B.
What it does after merge + deploy
python(sharedMATH_ENV=python, a secret change made at deploy time — see the runbook; not hard-coded).math-pythonkeeps writingpython(MATH_PYTHON_ENV); the single-writer lock key is unchanged and pinned by a test.docker-compose configand requires a single matching.envassignment: exactlyprod→ starts the guarded Clojure and verifies it is running (one container, running, exit 0, zero restarts); exactlypython→ starts nothing and verifies no math container exists; anything else → fails closed. Unknown roles fail closed.math/bin/runrefuses any label but exactlyprod(exit 78) as an independent second layer (dev/test opt in withMATH_CLOJURE_ALLOW_NONPROD_ENV=1).deployments/<sha>-<run>-<attempt>.zip, conditional put), re-reads its ETag, and passes ETag + VersionId to CodeDeploy; bindings are recorded as a job artifact. Hash assignments fail the job on any malformed value.Runbook (summary; full version in the program notes)
Stable merge → box deploy #1 (packages the new hook; Clojure keeps writing under
prod) → verify Clojure writer progress → secretMATH_ENV=python→ box deploy #2 (readers switch; the math role starts nothing and verifies retirement) → verification lines (pca2 tick, Delphi label, poller lock line, zero containers on the math box). Rollback: secretMATH_ENV=prod→ redeploy (no hook edit; Clojure re-polls 10 days on start).Tests
Delphi hook/compose/guard + report-label 107; hook + served-env guard 100;
math/bin/test-run-guard.sh11/11; server pca2 suites 90/90; new tests fail against the previous hook/handler.🤖 Generated with Claude Code
https://claude.ai/code/session_018NVGBuYCk4EZmiz4csUv9s