Skip to content

Latest commit

 

History

History
561 lines (387 loc) · 58.3 KB

deploy-trunk.en.md

File metadata and controls

561 lines (387 loc) · 58.3 KB

English · 中文

Trunk / storage-only deployment

This document is the operations runbook for push_policy=trunk and storage-only HTTP. User-visible paths, branches, tags, and push rules are in the User Guide; design details of the N-based push split, invariants, tombstones, and the path index are in refactoring/trunk-push.md. config/config.toml is authoritative for configuration keys.

Scope: a storage and distribution deployment that does not connect to the mega2 user system, does not use Issues / Change Lists, and has no review gate. push_policy defaults to trunk, and the default config/config.toml uses push_auth = "none" (local machine or trusted network only); a deployment that still needs the CL / review pipeline must set push_policy = "review" explicitly; see config/config-review.toml for an example.

This deployment shape provides the Monorepo Git service; the Traces session archive is an optional service surface ([traces].enabled=true): sessions are uploaded through the dedicated scoped traces Git ref (refs/libra/traces) and queried through the /api/v1/traces API. Configuration requirements and the protocol contract are in refactoring/traces.md; the legacy [agent_capture] HTTP API is fully retired.

1. push_policy=trunk

[monorepo]
push_policy = "trunk"
max_push_commits = 250   # trunk chain length; review still uses MAX_CL_CHAIN_COMMITS = 250

[git]
push_auth = "token"      # or "none"; if omitted, startup is refused
ssh_receive_pack = false # storage-only must write false explicitly; omitting it refuses startup
# [[git.push_tokens]]: see section 3

CL merges go only through the MonoWriteQueue; [monorepo] has no merge_writer key (plan-20260910.md). A leftover key is rejected at startup as an unknown field.

[monorepo].object_format: sha1 is standard Git; sha256 and blake3 are a git-internal / Libra extension and are not claimed to interoperate with standard Git clients (refactoring/protocol.md, plan/plan-20260907.md). The Git object format and the LFS digest are independent: Git=blake3/LFS=sha256 and Git=sha256/LFS=blake3 can both be expressed; the LFS BLAKE3 business surface belongs to DEFER-B3-LFS-01.

Product API writes (POST /api/v1/create-entry, POST /api/v1/delete-entry, POST /api/v1/move-entry, POST /api/v1/edit/save) under trunk are authenticated by git.push_auth, then write objects to storage and advance the path tip through the MonoWriteQueue (same tip authority as git push; see plan-20260904.md). delete-entry / move-entry can delete / move files when is_directory=false (an omitted field still targets directories only; see refactoring/directory-entry-api.md). The cl_link in a successful response is null; no mega_cl / refs/cl/* is created. After a write, git clone / git pull against the same stack sees the new content. For the integration black-box test, see integration_api_write_trunk in refactoring/integration.md. Monorepo tag writes (POST /api/v1/tags, DELETE /api/v1/tags/{name}; mounted on storage-only since plan-20260917 LB-04) are also authenticated by git.push_auth — create uses path_context (default /), delete uses the selector path (omitted or empty = /): a delete that omits path and a create with a root or default path_context need a token that covers / (paths omitted/empty = whole repo), while a delete with ?path=/project and a create with a non-root path_context can use a token that covers that path — but they write only tag metadata (refs/tags/*; annotated tags also write mega_tag.path), do not go through the MonoWriteQueue, and do not advance the path tip; GET /api/v1/tags/list and GET /api/v1/tags/{name} do not require Authorization; POST /api/v1/tags/list returns 405.

Where product writes land: when a non-root main tip already exists above the write path, the write lands on the deepest such tip (unchanged from before). On a fresh stack (after service init only the root / has a tip) you do not need to clone any ancestor path first: when the write path is valid (its first component is listed in root_dirs and it is not under import_dir), the server first lazily materializes its top-level root (for example /project, the same primitive as the materialization triggered by clone / ls-remote) and then lands the write on it; the parent of the landing commit is the materialization commit. Exception: when import_dir is nested under a root (such as /third-party/vendor), that top-level root (/third-party) is a strict ancestor of import_dir, and the server never materializes it (otherwise ImportRepo mounts under it would be rejected); writes under that root with no tip yet return 409 MONO_PATH_UNINITIALIZED, and a deeper non-import path must be provisioned first. The following writes return 400 MONO_PATH_NOT_ALLOWED: … before landing resolution (for the error contract, see the PathPolicyError section of errors.md): paths outside the roots (first component not in root_dirs, such as /vendor/x or an existing /.cedar); creating a top-level directory under /, and cross-top-level moves / top-level directory deletes whose common parent is / (product writes never land on /); operands inside the import_dir namespace that are not handled by an ImportRepo: import_dir itself; deleting / moving a mount leaf from its parent directory (path=/third-party, name=<repo> — whether or not that repository is live, because the request is dispatched to the Monorepo by its parent path); paths inside a leaf whose git_repo row no longer exists (after cleanup); and move destinations (whether or not main@/third-party was ever materialized — ImportRepos are created only by Git pushes). Paths inside a live ImportRepo are still dispatched to that ImportRepo by git_repo, with unchanged behavior (edit/save can write; delete / move return the existing 409; a move whose destination is a live ImportRepo returns 409). Error messages name the path the user wrote; only cross-top-level moves and top-level directory deletes (first component is a valid root, but the landing point can only be /) name /. The provisioning CLI / API mentioned in the MONO_PATH_UNINITIALIZED message ships in a later release (plan-20260923 FU-07 / FU-08). When a write is already queued or running on the same landing tip (on a fresh stack, the same top-level root, for example writing /project/a and /project/b at the same time), the second concurrent write is still rejected per ADR-TP-10 (currently surfaced as 500; see DEFER-FU-12 in plan-20260923.md); clients should serialize writes or retry.

Startup fail-closed checks (Config::validate / AppContext::new):

  1. trunk + cedar.enforcement != "off" → refused.
  2. trunk + open CLs still exist → refused.
  3. push_policy changed while push_queue has non-terminal rows → refused (drain/cancel them first).
  4. push_auth ∈ {token, none} ⇒ push_policy=trunk is required.
  5. push_policy=trunk ⇒ an explicit push_auth is required.
  6. storage-only (explicit push_auth) ⇒ git.ssh_receive_pack = false is required (omitted ≠ disabled).
  7. After a mode switch, reset the index watermark (section 5).

HTTP surface: read-only preview + product writes (create-entry / delete-entry / move-entry / edit/save; directory change contract in refactoring/directory-entry-api.md) + monorepo tags (POST /tags, GET /tags/list, GET / DELETE /tags/{name}; LB-04 / FT-04 / FT-06; POST /tags/list is 405) + Git smart HTTP + LFS (/info/lfs, /api/v1/lfs) + optional Traces read API (/api/v1/traces/* mounted when [traces].enabled); CL / issue / reviewer / OAuth user routes are not registered (the old /api/v1/agent-capture is not mounted either); OpenAPI (/api/openapi.json) lists LFS, the write paths, and, when enabled, the Traces routes; CL/issue are empty. Read-only blob/tree/blame are kept.

2. Security boundary (no review authorization ≠ no access control)

Trunk has no review gate and no Cedar decisions: cedar.enforcement must be off, and the authorization snapshot is neither built nor consumed.

The retained UN-16 write-side hook (refuse deleting refs/heads/main + notify) is not authorization protection. It is a structural protection (if the snapshot is enabled in the future, it still takes /.mega_cedar.json on main as its source), not review or Cedar.

Access control that still applies:

  • push_auth=token: constant-time lookup of static tokens; on a match, the identity is the token name. paths prefixes authorize on component boundaries (/project/foo does not authorize /project/foobar). The authenticated identity is separate from the commit author — the author is self-declared provenance and plays no part in the decision. Git receive-pack, LFS batch/lock writes, and product API writes share this model (see section 6 and the API write paragraph above). Missing credentials / bad token → HTTP 401; path not authorized → HTTP 403.
  • push_auth=none: allows API writes without credentials (requester=anonymous); only for controlled networks (section 3).
  • Object storage and pack transfer still follow the existing storage configuration.
  • Tags from Git clients are still forbidden.

3. push_auth=token and push_auth=none

Inject credentials through SecretRef / file mounts; do not put plaintext into a committed config.toml.

[git]
push_auth = "token"

[[git.push_tokens]]
name = "agent-ci"
token = "${file:/run/secrets/mega2-push-token}"
paths = ["/project"]   # omitted or empty = whole repo

push_auth=none must be written in the configuration (omitted ≠ none). It bypasses the token/OAuth front check of Git HTTP and is only for deployments behind a controlled internal network, loopback, or Unix socket front end. Exposing none to the public internet means anonymous receive-pack and anonymous LFS upload (batch/lock writes are on the same level as receive-pack). Startup logs a diagnosable warning; SSH receive-pack stays disabled under storage-only (section 4), so "push without credentials / LFS write without credentials" can only happen on the HTTP surface you explicitly opened.

4. SSH

Storage-only (explicit push_auth) does not expose SSH receive-pack. Startup requires ssh_receive_pack = false in the configuration; omitting it fails closed rather than silently disabling. To push, use Git smart HTTP + token (or none + a network boundary).

ssh_receive_pack = false does not disable SSH clone/fetch/pull (upload-pack). Storage-only reads share git.anonymous_access with HTTP:

  • anonymous_access = true: SSH auth_none is accepted; no UserStorage public key and no password needed.
  • push_auth = "none" and anonymous_access = false: SSH reads fail closed (no password channel; do not rely on UserStorage under trunk+none).
  • push_auth = "token" and anonymous_access = false: SSH auth_password, where the password field = the [[git.push_tokens]] secret (consistent with HTTP Basic, which takes only the password and ignores the username). Clients use SSH_ASKPASS / sshpass / a custom GIT_SSH_COMMAND. Storage-only still offers no SSH receive-pack.

The review shape (push_auth omitted) still uses UserStorage public keys; with the default anonymous access on, it does not accept auth_none as a success, so that OpenSSH does not skip public-key push.

5. Mode switching

Direction Preconditions Index
review → trunk No open CLs; drain non-terminal push_queue rows; cedar.enforcement=off; explicit push_auth UPDATE blob_paths SET indexed_push_id = NULL (RESET INDEX WATERMARK)
trunk → review Drain non-terminal rows likewise The watermark must be reset; otherwise review, which only writes IS NULL rows, leaves the existing watermark permanently stale

trunk → review does not rebuild the CL history from before the roll-up. After switching back, new pushes go through the CL pipeline again.

6. LFS follows push_auth

Trunk / storage-only mounts /info/lfs and /api/v1/lfs. LFS batch/lock write authorization shares git.push_auth with Git receive-pack (plan-20260909.md ADR-LF-01; supersedes the plan-20260905 TP-18 product decision to "disable LFS", without rewriting that card's historical acceptance):

push_auth LFS read LFS write (batch upload / locks)
none Anonymous allowed Anonymous allowed (same network boundary as anonymous receive-pack; see the warning in section 3)
token anonymous_access or a valid token A valid [[git.push_tokens]] entry whose paths cover the LfsRepoContext path

Object PUT/GET still use the capability URLs registered by the batch call and are not authenticated per request. The review shape (push_auth omitted) still uses the UserStorage mono access token. SSH git-lfs-transfer is outside the storage-only delivery scope; LFS goes over HTTP.

Token-aware LFS is no longer listed as an open issue. Multi-token rotation/audit/rate limiting remains under DEFER-TP-05 (section 7), independent of whether LFS is available.

7. Phase 5 multi-token operations (DEFER-TP-05)

Basic authentication (single/multi-token lookup, component-boundary prefixes, the none bypass) shipped with phase 4.2a (TP-19/20). Operational hardening such as token rotation, auditing, and rate limiting is not specified and is registered as DEFER-TP-05 (restart condition: phase 5 of trunk-push.md gains an executable specification).

8. Local Compose stack

docker/docker-compose-storage-only.yml at the repository root mirrors the IT docker/docker-compose.test.yml, keeping Postgres / Redis / RustFS / mega2, and mounts config/config-storage-only.toml and /run/secrets/mega2-push-token (default secrets/mega2-push-token.local). It has no website, mailpit, or OAuth.

Object storage defaults to RustFS (s3compatible). Do not add --env-file for the default start; --env-file config/compose.env.storage-only.local is needed only when switching mega2 to the local filesystem backend (the RustFS container still starts; only mega2's storage_type changes).

# Default RustFS (s3compatible) — no --env-file needed
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml up -d --wait

# Empty-volume bootstrap (copy-pasteable)
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml exec -T mega2 \
  mega2 --config /etc/mega2/config.toml service init --yes

# Clean rerun (destructive: deletes named volumes)
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml down -v

# Optional: switch mega2 to the local filesystem (only this case adds --env-file)
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml \
  --env-file config/compose.env.storage-only.local up -d --wait

# HTTP http://127.0.0.1:9000/  SSH ssh://git@127.0.0.1:2222/
# RustFS API/console: 127.0.0.1:29000 / 29001
# Default push token: mega2-storage-only-local-dev-token-0001

Presigned URL signing host (plan-20261001 FIX-BB-03): inside the network, mega2 reads and writes objects through http://rustfs:9000; compose sets MEGA_OBJECT_STORAGE__S3__PUBLIC_ENDPOINT_URL to http://127.0.0.1:29000 by default, so artifacts / LFS presigned URLs are signed for the RustFS port published on the host, and host clients can follow them directly (key semantics in orbit; for in-network LFS see §8.1). Host-side round-trip check (batch → presigned PUT → commit → follow the 302 download → compare sha256; the whole round is limited to 60 seconds, adjustable with MEGA2_PRESIGN_CHECK_BUDGET):

MEGA2_BASE_URL=http://127.0.0.1:9000 MEGA2_IT_SEED_TOKEN="$(cat secrets/mega2-push-token.local)" \
  scripts/artifacts_presign_host_check.sh

The script prints presign-put: <status>, commit-status: <status>, and sha256 match step by step; it exits 0 only when both the upload URL and the download redirect target are signed for MEGA2_PRESIGN_ORIGIN (default http://127.0.0.1:29000), the presigned PUT is 2xx, the commit is ok, and the downloaded content's sha256 matches; it exits 2 when a tool or the token is missing. The token is not echoed, and signed URLs are printed without their query.

The interop black-box runner interop-smoke (profile interop, plan-20261001; registered in test-infra) does not start with the default up; build and start it separately when needed:

docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile interop up -d --wait --build interop-smoke

A loopback relay inside the container makes 127.0.0.1:9000 (HTTP), 127.0.0.1:2222 (SSH), and 127.0.0.1:29000 (RustFS) match the host addresses.

Opt-in cases (cases that need a different mega2 configuration) always run through the host-side helper, which uses trap to restore mega2 to the default configuration whether the case passes or fails; after the switch and after the restore, it reads the compose config hash label of the running mega2 container and compares it with the hash of the switched configuration and of the default configuration, respectively (plan-20261001 FIX-BB-07):

scripts/bb_optin_run.sh <none|gc|local|views> <script> '<case>' target/tmp/<log>
scripts/bb_optin_run.sh --selftest local target/tmp/<log>   # self-test: stub command exits 1

views mode overlays docker/docker-compose-storage-only.views.yml and accepts only libra_view_smoke.sh; before switching stacks it recreates the separate database mega2_hp25_views and flushes Redis logical database 1. --selftest views runs the reset, the stack switch, the stub command, and the default stack restore, but not the prepare step.

  • scripts/bb_optin_run.sh exit code 0: the case passed and mega2 has been restored to the default configuration (the log contains bb-optin: restored mega2 (config hash match)).
  • scripts/bb_optin_run.sh exit code 1: the case failed, or after the switch the compose config hash label of the running mega2 container is not the hash of the switched configuration (the case did not run); in both cases mega2 has been restored to the default configuration.
  • scripts/bb_optin_run.sh exit code 2: argument or precondition error (unknown mode, missing env-file, script does not match the mode, another helper holds the stack lock); the stack was not switched.
  • scripts/bb_optin_run.sh exit code 3: restore failed (the config hash of the running mega2 is not the default configuration's hash, or mega2 is unhealthy); run docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml up -d --wait --force-recreate mega2 manually.

8.1 Compose black-box Git protocol smoke (git client)

The trunk / storage-only protocol smoke uses scripts/git_protocol_smoke_storage_only.sh, which calls the published ports with real git / git-lfs / ssh inside the git-smoke container of compose --profile smoke. This is a compose black box, layered alongside the cargo CARGO_BIN_EXE black box; do not use libra as the protocol client, and do not run the review/CL-semantics scripts/git_protocol_smoke.sh against trunk.

Product API write → Git visibility uses scripts/api_write_smoke_storage_only.sh (curl + git; the libra client is likewise forbidden):

Scope note (2026-10-02, plan-20261001 ADR-BB-03): this constrains the clients of the Git protocol smoke and the API write smoke; the Libra↔mega2 interop black box (scripts/libra_smoke_storage_only.sh) uses libra as the client under test; see plan-20261001.

TOKEN='mega2-storage-only-local-dev-token-0001'
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile smoke \
  exec -T \
  -e MEGA2_HTTP_REPO_URL="http://x:${TOKEN}@mega2:8000/" \
  -e MEGA2_API_BASE=http://mega2:8000 \
  -e MEGA2_IT_SEED_TOKEN="${TOKEN}" \
  git-smoke bash /repo/scripts/api_write_smoke_storage_only.sh

Stable cases: API create-entry then git clone sees file, API edit/save then git pull sees update, API write rejects unauthenticated; plan-20260917 LB-05 adds delete-entry-git-visible, move-entry-git-visible, tags-list-create-delete, delete-entry-unauth-401; plan-20260918 FT-07 adds delete-file-git-visible, move-file-git-visible, tags-get-list-create-delete, tags-path-get-delete, delete-file-unauth-401 (after a file delete/move, the git clone / git pull worktree matches GET /tree; anonymous GET list is 200, POST list is 405; ?path= get/delete are isolated; an unauthorized file delete is 401). Select a single case with MEGA2_SMOKE_CASE=<exact name> (no match exits 2); -h lists all case names. The summary must show 0 failed — run the full suite on a clean stack (down -v rebuild + service init --yes), or use MEGA2_SMOKE_CASE to select only the cases you need: AW-04's API create-entry then git clone sees file uses a fixed file name, so a second full run on the same stack hits a duplicate-name 500 and reports failed=1 (the named LB-05 / FT-07 cases use names unique to each run). These can be absorbed into plan-20260906 as additional cases (see docs/refactoring/test-infra.md). For the matrix row, see integration_api_write_trunk in refactoring/integration.md.

docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile smoke \
  exec -T \
  -e MEGA2_HTTP_REPO_URL=http://mega2:8000/ \
  git-smoke bash /repo/scripts/git_protocol_smoke_storage_only.sh

Single case: MEGA2_SMOKE_CASE='HTTP ls-remote' (exact case name; no match exits non-zero). Registered read-only cases: HTTP ls-remote, HTTP clone, HTTP fetch, HTTP protocol v2 fetch, HTTP shallow clone depth=1, HTTP protocol v2 ls-remote, HTTP protocol v2 blob:none clone. Write cases (need MEGA2_GIT_SMOKE_PUSH=1 + token / MEGA2_IT_SEED_TOKEN): HTTP trunk push — asserts that the tip of /project advances (not the root /; B0 rejects the root path); creating a new refs/cl is not a success condition. When given the root URL, the script rewrites it to /project automatically. Also: HTTP reject Git-client tag push (tag push exits non-zero and no tag is left on the remote). Negative case (default token stack, URL without credentials): HTTP reject unauthenticated push.

Token write example:

docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile smoke \
  exec -T \
  -e MEGA2_HTTP_REPO_URL=http://mega2:8000/ \
  -e MEGA2_IT_SEED_TOKEN=mega2-storage-only-local-dev-token-0001 \
  -e MEGA2_GIT_SMOKE_PUSH=1 \
  -e MEGA2_SMOKE_CASE='HTTP trunk push' \
  git-smoke bash /repo/scripts/git_protocol_smoke_storage_only.sh

push_auth=none stack (ADR-SO-06): a second -f overrides the mount with config/config-storage-only.none.toml, followed by --force-recreate mega2. Opt-in cases: HTTP trunk push (none) (tip advances without credentials), HTTP reject Git-client tag push (none) (tag push exits non-zero and nothing is left on the remote).

docker compose -p mega2-trunk \
  -f docker/docker-compose-storage-only.yml \
  -f docker/docker-compose-storage-only.auth-none.yml \
  up -d --wait --force-recreate mega2

docker compose -p mega2-trunk \
  -f docker/docker-compose-storage-only.yml \
  -f docker/docker-compose-storage-only.auth-none.yml \
  --profile smoke \
  exec -T \
  -e MEGA2_HTTP_REPO_URL=http://mega2:8000/ \
  -e MEGA2_GIT_SMOKE_PUSH=1 \
  -e MEGA2_SMOKE_CASE='HTTP trunk push (none)' \
  git-smoke bash /repo/scripts/git_protocol_smoke_storage_only.sh

To switch back to the default token sample: drop the second -f, then --force-recreate mega2.

In-network LFS URLs (ADR-SO-04): --env-file config/compose.env.storage-only.lfs-innetwork sets MEGA_HTTP__PUBLIC_BASE_URL / MEGA_LFS__SSH__HTTP_URL to http://mega2:8000 and sets MEGA_OBJECT_STORAGE__S3__PUBLIC_ENDPOINT_URL=http://rustfs:9000 (presigned LFS URLs are then signed for the in-network RustFS, plan-20261001 FIX-BB-03), so LFS hrefs are reachable from inside the git-smoke container. Opt-in case: HTTP LFS push and pull (trunk) (needs MEGA2_GIT_SMOKE_PUSH=1 + MEGA2_GIT_SMOKE_LFS=1 + token).

docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml \
  --env-file config/compose.env.storage-only.lfs-innetwork \
  up -d --wait --force-recreate mega2

docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile smoke \
  exec -T \
  -e MEGA2_HTTP_REPO_URL=http://mega2:8000/ \
  -e MEGA2_IT_SEED_TOKEN=mega2-storage-only-local-dev-token-0001 \
  -e MEGA2_GIT_SMOKE_PUSH=1 \
  -e MEGA2_GIT_SMOKE_LFS=1 \
  -e MEGA2_SMOKE_CASE='HTTP LFS push and pull (trunk)' \
  git-smoke bash /repo/scripts/git_protocol_smoke_storage_only.sh

To switch back to host LFS URLs: drop --env-file, then --force-recreate mega2.

SSH read-only (anonymous_access=true → auth_none; does not depend on UserStorage public keys). The first connection writes known_hosts:

# Inside git-smoke (or any OpenSSH client on the compose network):
export GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=accept-new -o UserKnownHostsFile=/tmp/mega2-smoke-known_hosts'
# Or omit GIT_SSH_COMMAND: scripts/git_protocol_smoke_storage_only.sh defaults the same
# StrictHostKeyChecking=accept-new + a workdir UserKnownHostsFile.
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile smoke \
  exec -T \
  -e MEGA2_SSH_REPO_URL=ssh://git@mega2:2222/ \
  -e MEGA2_SMOKE_CASE='SSH ls-remote' \
  git-smoke bash /repo/scripts/git_protocol_smoke_storage_only.sh

Registered SSH cases: SSH ls-remote, SSH clone, SSH fetch, SSH protocol v2 fetch, SSH shallow clone depth=1, SSH protocol v2 ls-remote, SSH protocol v2 blob:none clone, SSH reject receive-pack (the last one SKIPs when MEGA2_SSH_REPO_URL is not set).

docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile smoke \
  exec -T \
  -e MEGA2_SSH_REPO_URL=ssh://git@mega2:2222/ \
  -e MEGA2_SMOKE_CASE='SSH reject receive-pack' \
  git-smoke bash /repo/scripts/git_protocol_smoke_storage_only.sh

Collecting results (stdout is primary; tee on the host is recommended):

mkdir -p target/tmp
LOG="target/tmp/so-smoke-$(date -u +%Y%m%dT%H%M%SZ)-${MEGA2_SMOKE_CASE:-all}.log"
set -o pipefail
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile smoke \
  exec -T git-smoke bash /repo/scripts/git_protocol_smoke_storage_only.sh \
  2>&1 | tee "$LOG"

Troubleshooting workspace (not primary PASS evidence): host ${MEGA2_IT_GIT_WORKDIR:-/tmp/mega2-trunk-git} (mounted as /work in the container).

It can coexist with the -p mega2-it test stack (ports 25432 / 26379 / 9000 / 2222 / 29000). Override production credentials with MEGA2_PUSH_TOKEN_FILE; do not commit them.

9. Agent workflow notes

After every trunk push, run:

git fetch && git reset --hard origin/main

This is a no-op when N = 1; when N > 1 it aligns to the squash tip. Clone a subpath (for example /project/foo); do not assume a root clone of / for this deployment shape.

9.1 API commits written before the upgrade and strict clients

Before 0.38.24, unsigned commits synthesized by the product write API (create-entry, edit/save, delete-entry, move-entry, including ImportRepo edit/save), by review-mode CL merges, and by legacy descendant continuation lack the blank line between header and body: git log --format=%s shows an empty subject, git fsck (including --strict) reports unterminatedHeader, and clients with transfer.fsckObjects / fetch.fsckObjects enabled refuse to clone / fetch paths whose history contains such objects. Commits written after the upgrade are framed correctly; existing objects are not rewritten, because of commit identity (plan-20260923.md ADR-FU-02 / DEFER-FU-07).

unterminatedHeader is a fatal-class check that Git does not allow to be demoted (fetch.fsck.unterminatedHeader=ignore reports Cannot demote); clients that need strict verification use a per-object skip list instead:

git -c transfer.fsckObjects=false -c fetch.fsckObjects=false clone <url> probe
LC_ALL=C git -C probe fsck 2>&1 | sed -n 's/^error in commit \([0-9a-f]*\): unterminatedHeader.*/\1/p' > mega2-fsck-skiplist.txt
git -c transfer.fsckObjects=true -c fetch.fsck.skipList="$PWD/mega2-fsck-skiplist.txt" clone <url> work

A local git fsck can likewise add -c fsck.skipList=<the same file>. The skip list exempts only the listed objects; all other objects are still checked under strict rules.

9.2 ImportRepo alias path canonicalization on upgrade

The first startup after upgrading to 0.40.4 runs the one-time migration m20260923_000200_canonicalize_import_repo_paths: rows in git_repo whose repo_path is not in canonical form, that is, legacy aliases written before TP-08 (duplicate slashes, trailing slashes, . segments, for example /third-party//foo/), are rewritten to the canonical path (/third-party/foo); repo_id and its ref and object rows are unchanged. The migration decides by the row itself, independent of monorepo.import_dir, so non-default import roots are covered as well; the whole rewrite runs in one transaction, rerunning it changes nothing, and no configuration is needed. Protocol-level TP-08 canonicalization is unchanged, and old alias URLs still hit the same repository (regression cases import_repo_alias_*, plan-20260923.md FU-15).

The startup log prints a one-line summary:

canonicalized ImportRepo alias paths rewritten=<N> collisions=<M> invalid=<K>
Counter Meaning
rewritten Number of alias rows rewritten to the canonical path.
collisions Number of alias rows left as-is because the canonical path is already taken by another row: the same repository has already split into two repo_ids. Each such row also gets a WARN containing only the repo_id and the canonical path.
invalid Number of rows left as-is because the path cannot be canonicalized (for example it contains a .. segment or \); each such row also gets a WARN containing only the repo_id.

When both counters are 0, no action is needed.

When collisions is not 0, the same repository has split into two repo_ids (it was already so before the upgrade; the migration does not change that):

  • Git requests (clone / fetch / push) always resolve by the canonical path and hit the row that holds the canonical path;
  • Web / API lookups of a repository by path prefix take the longest stored path: when the alias ends with / or /., queries and writes for files, tags, and commits under the canonical path still land on the alias row;
  • ImportRepo cleanup in later releases looks up repositories by exact canonical path: it does not delete such alias rows and does not count them as child repositories (plan ADR-FU-10 item 3, DEFER-FU-10).

Steps:

  1. Use the repo_id and canonical path from the WARN to compare the two rows and their refs:

    SELECT id, repo_path, created_at, updated_at FROM git_repo
     WHERE id = <repo_id from the WARN> OR repo_path = '<canonical path from the WARN>';
    SELECT repo_id, ref_name, ref_git_id FROM import_refs
     WHERE repo_id IN (<both ids>) ORDER BY ref_name, repo_id;
  2. Do not manually rewrite or delete either of the two rows: automatic merging is not available yet (plan DEFER-FU-10); file an issue with the query results above attached. The migration does not delete the alias row's data.

When invalid is not 0, the counted rows have no canonical form and therefore no corresponding canonical row: the protocol layer always rejects requests for such paths (TP-08 canonicalization fails), they were not served before or after the upgrade, and the migration does not touch them. Inspect them by the repo_id from the WARN:

SELECT id, repo_path, created_at, updated_at FROM git_repo WHERE id = <repo_id from the WARN>;
SELECT ref_name, ref_git_id FROM import_refs WHERE repo_id = <the same id> ORDER BY ref_name;

If you need their content, likewise do not rewrite the row by hand; file an issue with the query results attached.

10. storage-only OCI Distribution (/v2)

Source of truth for architecture and endpoints: refactoring/oci.md (plan-20260902). This section covers only operational enablement and docker login authentication semantics.

10.1 Enablement conditions

/v2 has a double gate; both must hold:

  1. storage-only: the configuration sets git.push_auth explicitly (token or none) — same as section 3;
  2. [oci] enabled = true.

If either is missing, /v2 is not mounted (bare 404). enabled=true without storage-only → startup refused. The config/config-storage-only.toml sample already contains the enabling section; the review shape / shapes with push_auth omitted must not turn this switch on.

10.2 docker login and push

Authentication reuses [[git.push_tokens]] (there is no separate OCI token service):

# username can be any value; password = the push token secret
docker login <host> -u oci -p '<push-token>'
docker tag <local-image> <host>/<repo>:<tag>   # repo can have multiple segments, e.g. team/app
docker push <host>/<repo>:<tag>
docker pull <host>/<repo>:<tag>

A plain-HTTP registry (such as the local compose http://127.0.0.1:9000) must be configured as an insecure registry on the client; production should terminate TLS.

Host live smoke: bash scripts/oci_smoke_storage_only.sh (default registry http://127.0.0.1:9000; token from MEGA2_OCI_SMOKE_TOKEN or secrets/mega2-push-token.local). When docker or the endpoint is unreachable, the script SKIPs and exits 0.

10.3 Authentication semantics summary

Surface Behavior
Write (push / upload) push_auth=token: Basic/Bearer supplies the token, and paths must cover "/" + repo; otherwise DENIED. push_auth=none: all writes allowed (same controlled-network premise as section 3).
Read (pull / ping) Follows git.anonymous_access: on → readable without credentials; off → a valid token is required. Invalid credentials always get 401 (including GET /v2/, so that a failed docker login is reported).
Cross-repo mount Write authorization on the target + read authorization on the source.

Manifest/blob DELETE routes exist but always return OCI UNSUPPORTED (405). _catalog / referrers are not implemented.

10.4 Compose black box (oras / curl)

The OCI black-box script scripts/oci_client_smoke_storage_only.sh from plan-20261001 runs inside the interop-smoke container (clients are oras and curl, not libra) and reaches http://127.0.0.1:9000/v2/ through the in-container loopback relay. Start the stack and interop-smoke per §8 first, then run a single case and tee the result locally (output and exit code contract: ==> / PASS: / FAIL: / SKIP:, last line oci client smoke storage_only summary: …; 0 pass, 1 failures, 2 precondition error or unmatched case name):

mkdir -p target/tmp; set -o pipefail
CASE='OCI ping'   # replace with the case name to run
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile interop exec -T -e MEGA2_SMOKE_CASE="$CASE" interop-smoke bash /repo/scripts/oci_client_smoke_storage_only.sh 2>&1 | tee target/tmp/bb-oci-case.log

Registered cases: OCI ping, OCI oras push and pull, OCI reject unauthenticated push, OCI chunked blob upload, OCI cross-repo blob mount, OCI manifest HEAD and conditional GET, OCI blob range, OCI tags list pagination, OCI image index manifest, OCI reject manifest with unknown blob, OCI delete unsupported, OCI catalog not implemented, OCI not mounted without oci section (none).

Without MEGA2_SMOKE_CASE, all default-stack cases run; opt-in cases (auth-none) run only through scripts/bb_optin_run.sh none oci_client_smoke_storage_only.sh '<case>' <log>.

11. storage-only Artifacts protocol black box (curl)

The Artifacts black-box script scripts/artifacts_smoke_storage_only.sh from plan-20261001 runs inside the interop-smoke container (client is curl, not libra) and reaches http://127.0.0.1:9000/api/v1/repos/<repo>/artifacts/ through the in-container loopback relay; each run reads and writes under a repo and namespace that carry the RUN_ID, so it can be rerun on a dirty volume. Start the stack and interop-smoke per §8 first, then run all cases or a single case and tee the result locally (output and exit code contract: ==> / PASS: / FAIL: / SKIP:, last line artifacts smoke storage_only summary: …; 0 pass, 1 failures, 2 precondition error or unmatched case name):

mkdir -p target/tmp; set -o pipefail
# Run all registered default-stack cases (opt-in cases are recorded as SKIP)
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile interop exec -T interop-smoke bash /repo/scripts/artifacts_smoke_storage_only.sh 2>&1 | tee target/tmp/bb-art-all.log
# Single case: set CASE to a name from "Registered cases" below
CASE='<case>'
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile interop exec -T -e MEGA2_SMOKE_CASE="$CASE" interop-smoke bash /repo/scripts/artifacts_smoke_storage_only.sh 2>&1 | tee target/tmp/bb-art-case.log

Registered cases: ART discovery, ART presigned upload and commit, ART server PUT upload and commit, ART presigned download, ART reject unauthenticated write, ART commit with missing objects, ART commit replay and conflict, ART list sets pagination, ART metadata filters, ART resolve file, ART set detail, ART repo isolation, ART input validation, ART conditional GET and HEAD, ART anonymous write (none), ART GC removes unreferenced object, ART proxied download range (local).

Without MEGA2_SMOKE_CASE, all default-stack cases run; opt-in cases (auth-none, GC, local storage) run only through scripts/bb_optin_run.sh <none|gc|local> artifacts_smoke_storage_only.sh '<case>' <log>. GC mode uses config/compose.env.storage-only.artifacts-gc (collects every 5 seconds with a 1-second grace period; lab stacks only); the default stack takes the code defaults (disabled) through the MEGA_ARTIFACTS_GC__* variables passed through by compose.

12. storage-only Libra client black box

scripts/libra_smoke_storage_only.sh from plan-20261001 runs inside the interop-smoke container. The script invokes the Libra client in the image with an isolated HOME, first checks that its version is at least 0.30.26, and checks the mega2 HTTP endpoint with a read-only git ls-remote. The client reaches http://127.0.0.1:9000/ through the in-container loopback relay; start the default stack and interop-smoke per §8 first.

mkdir -p target/tmp; set -o pipefail
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile interop exec -T interop-smoke bash /repo/scripts/libra_smoke_storage_only.sh 2>&1 | tee target/tmp/bb-libra-all.log
CASE='<case>'
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml --profile interop exec -T -e MEGA2_SMOKE_CASE="$CASE" interop-smoke bash /repo/scripts/libra_smoke_storage_only.sh 2>&1 | tee target/tmp/bb-libra-case.log

Registered cases: LIBRA clone HTTP, LIBRA fetch HTTP, LIBRA ls-remote HTTP, LIBRA trunk push HTTP, LIBRA multi-commit push HTTP, LIBRA reject unauthenticated push, LIBRA reject tag push, LIBRA reject non-main branch push, LIBRA clone SSH, LIBRA reject SSH push, LIBRA LFS push and clone, LIBRA browser list root, LIBRA browser list at ref, LIBRA browser unknown path, LIBRA browser list text, LIBRA browser create dir, LIBRA browser delete dir, LIBRA browser move dir, LIBRA browser rename dir, LIBRA browser list tags, LIBRA browser tags page two, LIBRA browser create lightweight tag, LIBRA browser create annotated tag, LIBRA browser delete tag. The HTTP clone case writes a seed file carrying the RUN_ID under /project and compares the SHA-256 of the file in the Libra clone against a read-only Git clone; the fetch case adds a server-side file after cloning and compares Libra's origin/main against a read-only Git ls-remote; the ls-remote case compares the refs/heads/main OID read by the two clients; the trunk push case configures an encrypted loopback HTTP token in the isolated HOME through stdin, then pushes one Libra commit with an origin that carries no credentials, and a read-only Git observer verifies the tip and file content; the multi-commit push case pushes three consecutive Libra commits at once, and the Git observer checks the three file contents; the unauthenticated push case uses a fresh HOME and Libra configuration store and confirms that authentication is rejected and that the remote tip seen by the Git observer is unchanged; the tag push case pushes a unique annotated tag with isolated credentials and checks that the server explicitly rejects it and that the Git observer sees no remote tag; the non-main push case uses local main as the source to try writing a unique remote branch and checks that the server rejects it under trunk and that the Git observer sees no remote branch; the SSH clone case strictly verifies the loopback SSH host with an isolated known_hosts and compares the /project tip and the seed file SHA-256 between the Libra SSH clone and a read-only Git HTTP observer. The current Libra SSH client strips the first slash from the URL path, so the SSH URL is ssh://git@127.0.0.1:2222//project, which makes the server receive the absolute path /project. To stay compatible with repositories that already contain LFS pointers, this case first fetches the Git objects over SSH with --no-checkout, then temporarily points origin at the HTTP LFS endpoint of the same /project to check out the worktree, and restores the SSH origin after verification. The SSH push case commits a new file in the verified SSH clone and requires that the Libra push exits non-zero, that the isolated SSH stderr contains the server's explicit rejection stating that receive-pack is disabled, and that the remote tip seen by the read-only Git observer is unchanged. The LFS case tracks *.bin, creates a 1 MiB object through commit -a in an isolated clone and pushes it, confirms the OID and size of the remote LFS pointer with a read-only Git observer, and then checks the SHA-256 with a fresh Libra clone; the default stack's upload action provides Content-Length, so the RustFS presigned PUT can be used directly. The browser root case compares, in a non-TTY, the items[].name of Libra's JSON with the name set from HTTP /api/v1/tree?path=/. The browser ref case first creates a root tag and records the historical listing of /project, then writes a unique file on main, and confirms that the --ref <tag> listing is unchanged while the current listing contains the file; afterwards it makes a best effort to delete the temporary root tag. The browser unknown-path case injects a sentinel environment token used only for leak detection, requires that the command exits non-zero, that stderr is LBR-NET-002 JSON containing HTTP 404, and that stdout is empty, and confirms that neither stdout nor stderr contains the token. The browser list-text case first creates a unique directory under /project using a 0600 header file, then, in a non-TTY, requires that stdout contains the exact line dir <NAME>, is not JSON, and that stderr is empty, and checks the directory of the same name with content_type=directory from the anonymous tree API. The browser create-dir case performs one JSON write operation with a 0600 token file, checks the full target and a non-empty receipt, and then confirms the directory of the same name and its type with the anonymous tree API, without a token. The browser delete-dir case creates a unique directory with curl and confirms it anonymously, then performs a JSON delete operation with a 0600 token file, checks the full target and a non-empty receipt, and confirms with the anonymous tree API that the entry of that name is gone. The browser move-dir case creates a unique source directory and a destination parent directory with curl and confirms them anonymously, then performs a JSON move operation with a 0600 token file, checks the full from/to targets and a non-empty receipt, and confirms the move anonymously from both the source and the destination side. The browser rename-dir case creates the old-name directory with curl and confirms anonymously that it exists and the new name does not, then performs a JSON rename operation with a 0600 token file, checks the full from/to targets sharing the parent directory and a non-empty receipt, and confirms anonymously that the old name is gone and the new-name directory exists. The browser list-tags case creates a unique annotated root tag with curl, then queries the first page of two tags through credential-less Libra JSON and through the anonymous HTTP API, compares names in order and the total, and finally deletes the fixture tag. The browser tags-page-two case creates two unique annotated root tags with curl, then compares the single second-page result and the total between Libra and the anonymous HTTP API, also confirms that the HTTP first and second pages have different names, and finally deletes both fixture tags. The browser create-lightweight-tag case records the root HEAD with read-only Git, creates a lightweight root tag through Libra with a 0600 token-file, confirms with an anonymous tag GET that both tag_id and object_id equal that HEAD, then deletes the fixture and scans for the token. The browser create-annotated-tag case records the root HEAD with read-only Git, creates an annotated root tag with a message through Libra with a 0600 token-file, confirms with an anonymous tag GET that the message and object_id match HEAD and that tag_id differs, then deletes the fixture and scans for the token. The browser delete-tag case creates a unique annotated root tag with curl and confirms it anonymously, then deletes it through Libra with a 0600 token-file, and checks the delete receipt and an anonymous GET 404; on failure it cleans up the fixture. The client working directories are cleaned up after the run. Naming a case that is not registered exits 2.

13. View operations (P0)

The three SQL blocks in this section are for maintenance windows with the service stopped only. Before running them, stop all mega2 processes, including the HTTP and SSH services. These statements take neither view locks nor root-chain locks; running them online would interleave with the worker's batch transactions. Online recycling and rebuild without stopping the service remain under DEFER-HP-04. The connection string used for the SQL must be the same as mega2's [database].db_url, or the MEGA_DATABASE__DB_URL that overrides it, and must keep its search_path. Table names are not schema-qualified, so connecting with a different search_path does not operate on the tables mega2 actually uses.

Save each code block to a file and run it as follows; ON_ERROR_STOP=1 is required:

psql "<database connection string>" -v ON_ERROR_STOP=1 -f <file>

The three marker lines are a stable interface: the cases in this section and HP-25's scripts/libra_view_smoke_setup.sh both extract the SQL by marker. When recycling a single filter, fill in the value of the filter_id field from the stop alert.

-- view-ops: recycle-filter
BEGIN;
DELETE FROM mega_view_commit_map
WHERE filter_pk = (SELECT id FROM mega_view_filter WHERE filter_id = '<filter_id>');
DELETE FROM mega_view_object_ref
WHERE filter_pk = (SELECT id FROM mega_view_filter WHERE filter_id = '<filter_id>');
UPDATE mega_view_filter
SET projected_seq = 0,
    ready_seq = NULL,
    warming_since = NULL
WHERE filter_id = '<filter_id>';
COMMIT;
-- view-ops: rebuild-all
BEGIN;
DELETE FROM mega_view_root_chain;
DELETE FROM mega_view_root_chain_scan;
DELETE FROM mega_view_commit_map;
DELETE FROM mega_view_object;
DELETE FROM mega_view_object_ref;
UPDATE mega_view_filter
SET projected_seq = 0,
    ready_seq = NULL,
    warming_since = NULL;
COMMIT;
-- view-ops: clear-root-chain-scan
DELETE FROM mega_view_root_chain_scan;

recycle-filter and rebuild-all both use explicit transactions. If a statement before COMMIT fails, psql stops and disconnects, and the transaction is not committed. recycle-filter recycles only the target filter's derived commit map and object references, keeping the objects for a later sweep; rebuild-all clears all derived state. Both put filters into the recycled state: projected_seq = 0, with ready_seq and warming_since NULL. The worker runs catch_up only for active views (ready_seq or warming_since non-null), so recycled views wait to be warmed up again. clear-root-chain-scan clears only the staging table and does not change view state; the next root-chain extension re-evaluates against the current main@/.

None of the three SQL blocks uses TRUNCATE, deletes mega_view_filter, mega_view, or mega_view_register_log, or changes last_access_at or the filter definition columns. rebuild-all is a full-table DELETE, so the maintenance window grows with the number of derived rows. This section records maintenance-window operations and recovery semantics; view Git URLs already support read-only clone and fetch; see the User Guide for usage.

When projection stops, the first failure point is reported as an ERROR event. Besides the message, the stop alert fields are metric=view_projection_stops_total, filter_id, s, commit_id, and reason; when the reason is row_absent or unparsable it also carries tree_id. For example: metric=view_projection_stops_total s=7 reason=row_absent. Handle by reason:

  • premise_check_failed: wait for the L0 fix (DEP-HP-05). Until it lands, warming up again stops at the same position; to free a cold-start slot, run recycle-filter with the filter_id from the alert.
  • row_absent: restore the mega_tree row that tree_id points to; catch-up then resumes automatically from s.
  • unparsable: restore the row that tree_id points to to its original bytes; catch-up then resumes automatically.
  • commit_row_missing: restore the mega_commit row that commit_id points to; catch-up then resumes automatically.

The signal for a failed batch premise is an ERROR event with metric=view_batch_premise_failures_total, with fields filter_id, s0, tip, and batch_size. It counts toward view_batch_premise_failures_total, not view_projection_stops_total, and does not emit a stop alert. batch_size is limited to 1..=10000 by configuration validation; treat it as a hole in the root chain table and use rebuild-all.

When the root chain is first judged discontinuous, an ERROR event with reason and commit_id is emitted, with no metric field. The evidence is the row with the largest pos in mega_view_root_chain_scan: if main@/ has been restored to a descendant of the chain tail, use clear-root-chain-scan; otherwise use rebuild-all and announce that view history may change.

P0 does not provide the root-chain audit SQL from design §4.2: the audit needs to recompute SHA-1 item by item, Postgres has no built-in sha1, and this repository has no pgcrypto migration. Deployments with review-shape history need this audit before enabling views; P0 can only rely on stop alerts to find the first failure point. The full audit is taken over by mega2 view status under DEFER-HP-04.

13.1 View projection worker

The projection worker starts only with the HTTP service: use service http, or a service multi replica that includes HTTP. A process that runs only service ssh does not start the projection worker and does not run periodic compensation; at least one replica in the deployment must run the HTTP service.

worker_interval_secs is a hot-reloadable period and also the upper bound on extra view lag after a push when no in-process signal is available, plus the time one round takes to run. When the root chain is judged discontinuous, the worker skips compensation for the whole round; after restoring the root chain with the maintenance-window steps in this section, restarting the HTTP service resumes from the committed watermark.

On shutdown the worker drops the round in progress. Committed root-chain segments and projection batches are kept, and the uncommitted current transaction is rolled back; after the service restarts, it catches up from those committed watermarks.

13.2 View registration wait, lookup, and metrics (experimental)

The APIs in this section are experimental and apply to trunk, sha1 deployments that have enabled [views] per the Configuration Guide; this does not mean view Git URLs are available.

Send a JSON body {"filter_spec":":/project/a","name":"agent/task-1"} to POST /api/v1/views. name may be omitted. Registration is authenticated by git.push_auth; when tokens are used, the push token must cover all source paths of the filter. A successful response contains filter_id, name, version, and ready. With ?wait=true, after admission is committed the call waits for readiness, up to 20 seconds; when it returns ready=false, poll GET /api/v1/views/{filter_id}. Without wait=true, registration returns immediately.

GET /api/v1/views/{filter_id} returns seven fields: filter_id, canonical_spec, src_paths, push_enabled, ready, projected_seq, and lag_commits. lag_commits is seq(main@/) minus the filter's projection watermark; when main@/ has not yet entered the root chain, the commits between it and the root chain tail that are not yet linked are also counted. It is null when main@/ is missing, when walking back cannot reach the root chain tail within views.max_append_walk commits, or when discontinuous history is encountered, such as a rollback, a fork, multiple parents, or a missing first parent.

GET /api/v1/views?name=agent%2Ftask-1 looks up by name. A name containing / must be percent-encoded; omitting version takes the latest version, and &version=1 selects a version. The response contains only filter_id, name, and version.

GET /api/v1/views/metrics returns in-process atomic counters and the live-queried view_cold_start_slots_in_use. These metadata endpoints are not authenticated: views are not a path-level read permission boundary (ADR-HP-05). If /api/v1 is exposed to untrusted networks, rate-limit /api/v1/views at the reverse proxy; you can hot-lower views.max_append_walk to cap the walk-back steps per lag query, at the cost of also lowering the per-run budget of root-chain extension.

13.3 Recovery exits for recycled views

After recycle-filter or rebuild-all is run during a maintenance window, a recycled view has two recovery exits: POST /api/v1/views again with the same filter_spec, or a reader accessing the enabled view URL, which triggers warm-up again. Re-registration counts toward the registration rate of that token (or anonymous), and exceeding it returns 429; reader access does not count toward the rate. Both exits take a cold-start slot and are subject to max_filters.

When no slot is available, registration returns 429 and reader access returns 503 with Retry-After. After a slot is freed, or after hot-raising max_filters or max_concurrent_cold_starts, access can be retried. During warm-up, access also returns 503 with Retry-After, and advertisement resumes once the view is ready. When views.enabled is false, access returns 404 and does not trigger warm-up.

View history after recycle-filter is the same as before recycling; view history after rebuild-all may change and needs to be announced.

13.4 Libra view smoke (opt-in)

First rebuild the mega2 image from the current worktree and start interop-smoke; see §8 for the commands. Run the three cases one at a time; on each run the helper recreates the separate database, switches to the views configuration, prepares the view state, and restores the default stack on exit:

scripts/bb_optin_run.sh views libra_view_smoke.sh '<case>' target/tmp/hp25-<case>.log

<case> takes view_http_clone_fetch, view_unready, and view_l0_mismatch in turn. Setup first provisions /project/hp25-view-smoke and clones its initial commit, then uses git mktree to build the trees for ok/, unready/, and l0/ and the root tree, and pushes on top of the initial commit. l0/ contains an inconsistent 100664 entry, which falls under the R2 limitation of the history projection design; it is written only to the separate database, so as not to break root repository clones on the default stack. It first registers and recycles hp25-unready, then registers two ready views to fill the slots, so that access to the unready view reliably gets 503 / 75.

The SSH cases use LIBRA_SSH_COMMAND to point at a wrapper script for the current run; the script reads the loopback relay host key from an isolated known_hosts and keeps StrictHostKeyChecking=yes. Until DEP-HP-04 lands, the unready SSH case asserts only status 75; the L0 ERR case asserts the remote reported an error: prefix and the recomputed tree id.

The views stack's database mega2_hp25_views does not inherit pg_trgm from the default database mega2. An existing volume does not rerun docker/traces_pg_trgm_init.sql either. Set MEGA2_TRACES_PG_ADMIN_URL and MEGA2_TRACES_PG_APP_ROLE for this database separately, then run scripts/traces_pg_trgm_bootstrap.sh --apply. --check only reads the catalog. If the extension is already in another schema, the script refuses and leaves the catalog unchanged. The auth-none overlay does not change the Postgres service, so it keeps the base init mount.

The views stack shares the RustFS bucket mega2 with the default stack; the separate database and Redis logical database 1 can be cleaned up manually when the helper is not running:

docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml exec -T postgres psql -U mega2 -d postgres -c 'DROP DATABASE IF EXISTS mega2_hp25_views WITH (FORCE)'
docker compose -p mega2-trunk -f docker/docker-compose-storage-only.yml exec -T redis redis-cli -n 1 FLUSHDB