Skip to content

CONTRACT: feat(ui-server): fetch allow-listed repositories for module cron jobs on the host - #4008

Merged
schlessera merged 16 commits into
mainfrom
fix/3380-module-repositories-main
Nov 15, 2026
Merged

schlessera merged 16 commits into
mainfrom
fix/3380-module-repositories-main

Conversation

@schlessera

@schlessera schlessera commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Closes #3380

What changed

Slice (b) of #3380, on main. Slice (a), the module state area and the boundary-naming read-only error (criteria 1 and 3), merged in #3384. This PR replaces draft #3393, which was stacked on #3384's branch. It carries #3393's commit onto current main and adds three commits.

A module's cron job can now read another repository, including a private one, and its worker never holds a Git credential.

  • Request. A module's config block lists what it wants under a new core-owned repositories key (modules: { "./modules/beacon": { repositories: ["https://github.com/ithaca/watchtower"] } }). Core validates the list and strips it before the module's schema sees it, as it does for enabled. Each URL must be HTTPS (or loopback HTTP) with no credential, query, fragment or dot segment, and a module may list at most 16. brain module list --json adds repositories: string[] to each configured module, and LoadedModule gains the optional field.
  • Grant. The cron runner fetches only repositories that also appear on the operator's new BRAIN_UI_MODULE_REPOSITORIES allow-list. That list is host configuration: the runner reads it as a cron control variable, and it is never forwarded to a job. Editing brain.config.ts alone cannot widen access.
  • Mapping. Before each module job (a name containing -), the runner runs a credential-free, shared-gate brain module list --json. It matches the job by its <module>-<entry> name and its brain … command. The crontab layout is unchanged. That read is now CONTRACT: fix(ui-server): retry crontab module discovery, name its cause and record a skip #3382's readModuleList, so if the job cannot learn its module, its stderr says why. A dashed job name whose command is not brain … is no module's job: it reads no module list and prints nothing. Hosted heavy feedback caught this on the first head, in cron-bin.test.ts's extra-env job.
  • Transport. The existing sync transport (syncTransportCommand) fetches each granted repository with the sync credential (BRAIN_UI_SYNC_GITHUB_TOKEN, else GITHUB_TOKEN, sent only to https://github.com). It fetches into a host-private bare mirror beside the sync mirror, and the transport worker never mounts the brain.
  • Job. The job's worker gets each mirror read-only, plus url.file://<mirror>.insteadOf rewrites for the URL's plain, /, .git and .git/ spellings. The module's own git clone https://github.com/ithaca/watchtower therefore reads the mirror with no credential and no network.
  • Refusal. If a module asks for a repository the operator has not allowed, or a fetch fails, the job is refused before it starts. It exits 1, and stderr and cron_runs.error_message name the repository and the setting.

Why this shape

This follows the 2026-11-02 slice (b) rulings: grant option B, mapping option A. They are recorded in docs/decisions/governed-writable-workers.md.

Guard checklist (proportionate containment)

  • Trigger. A module job whose owning module lists a repository that is missing from BRAIN_UI_MODULE_REPOSITORIES, or whose granted fetch fails. It does not cover a module job that asks for nothing, a core job, or a job whose module list cannot be read. That last job runs as before with no repository and a stderr note naming the cause.
  • Restriction. One run of one job. Nothing persists: the next run decides again. Core jobs and other modules' jobs are untouched.
  • Restricted mode considered. Running the job without the repository. It was rejected because the job's declared need would then fail opaquely inside the module.
  • Clearing. The refusal clears by itself on the next run once the operator adds the repository to the host allow-list. A human must act because widening a host credential's reach is the operator's decision by ruling. A failed fetch clears by itself on a later run.
  • Record. The job's stderr and cron_runs.error_message, which /api/status cronJobs shows, name the repository and the setting.
  • Scope test. a job no module owns, or a core job, fetches nothing and needs no module list and a refused repository fails the run… (packages/ui-server/tests/module-repositories.test.ts).

Proof

Receipt head 4c3e4a4510e6e0eb230956bb009cc41dd165b110, which merges origin/main @ 2702e2bd. A second heavy-feedback request on the fixed head was cancelled by that refresh before admission; the native categories' evidence is the first run's. Heavy feedback run 43718462495 on the first head a42a98fa passed every category except unit (4). Its one failure was cron-bin.test.ts › run re-admits a generated wrapper extra…, where stderr carried a module-list note for the non-brain job extra-env. The latest commit fixes that.

bun run check:pr --base origin/main    # Local preflight passed
bun run typecheck                      # clean
bun run build                          # clean (core's exports changed)
bun scripts/check-citations.ts         # no drift in any file this PR touches
{"version":1,"kind":"brain-check-pr-receipt","head":"4c3e4a4510e6e0eb230956bb009cc41dd165b110","base":"origin/main","mode":"focused","startedAt":"2026-11-15T18:59:55.436Z","finishedAt":"2026-11-15T19:01:44.749Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":12532.995780000001},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":105.84481500000038},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":70.1271369999995},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":27.112923000000592},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":96560.610548}]}

New and changed tests:

  • packages/core/tests/module-repositories.test.ts (9):
    • module list --json reports deduplicated repositories, and a strict module schema never sees the key.
    • With none declared, the list is empty.
    • Seven unsafe spellings each make the module unavailable with Invalid repositories for module "beacon".
  • packages/ui-server/tests/module-repositories.test.ts (12, keyless and offline). A loopback smart-HTTP Git fixture requires Basic auth with a synthetic token. The tests run the transport's exact argv on the host with exactly the environment maintenanceLaunch gives its worker. They cover:
    • an allow-listed repository is fetched, authenticated with the host credential;
    • an unlisted repository is refused, and nothing is fetched;
    • a brain.config.ts edit alone grants nothing;
    • the job's worker never holds the credential, and it clones from the mirror without reaching the network;
    • the allow-list reaches the runner and never the job;
    • jobs are matched to their modules;
    • a refused run never launches, and it records its reason;
    • new: MODULE_LIST_CAUSE_NAMED, an unreadable module list names its cause and fetches nothing;
    • new: NON_BRAIN_COMMAND_SKIPS_MODULE_LIST, a dashed job running a non-brain command reads no module list.
  • packages/ui-server/tests/host-execution-boundary.test.ts (+1, real worker). A cron run of the Odysseus beacon module goes through the real boundary and fetches with the synthetic credential. The job clones from the mirror, and its dumped process.env lacks the token. A later brain.config.ts edit adding ithaca/treasury is refused. This host cannot run maintenance workers (unshare: write failed /proc/self/uid_map: Operation not permitted). The test therefore fails here at the boundary, like every worker test in that file, and its execution is hosted native proof.

Failing-first. #3393 recorded packages/core/tests/module-repositories.test.ts failing all 9 tests on the pre-change tree: the strict schema rejected the unstripped key. The ui-server tests import new modules, so their receipts are mutations.

Mutation receipts. Each mutation was restored and the tree was clean afterwards. The first three were rerun on this branch; the rest are from #3393's head 960c23a6, whose code this PR carries unchanged.

Mutation Failing test → assertion
the non-brain command guard is removed a job no module owns, or a core job… → NON_BRAIN_COMMAND_SKIPS_MODULE_LIST (listed 2, expected 1)
the job note drops the module list's cause a module list that cannot be read names its cause… → MODULE_LIST_CAUSE_NAMED
any non-empty allow-list grants every request GRANT_IS_INTERSECTION, UNLISTED_REPOSITORY_REFUSED (2 fail)
transport drops the host credential fetch refused with Authentication failed; 3 tests fail
an absent allow-list defers to brain.config.ts BRAIN_CONFIG_ALONE_GRANTS_NOTHING, BRAIN_CONFIG_EDIT_ALONE_REFUSED, the refused cron run test
maintenanceLaunch keeps HOST_GIT_CREDENTIAL_ENV for a non-transport worker JOB_WORKER_NEVER_HOLDS_CREDENTIAL
runJob ignores a refusal a refused repository fails the run… → expected exit 1, received 0

Provider-history guard. host-boundary.ts's command() is on a turn's path, but it adds nothing unless an execution carries repositories, and only a cron launch does. The guard needs the worker boundary, which this host lacks, so hosted CI must run it.

Collisions (bun scripts/collisions.ts --json --pr 4008, head 68f4b89f): a textual overlap with draft #3806 on docs/integration-contract.md (separate index sections); 12 closure-only. #3393 is closed in favour of this PR.

Refreshed to head d75a4cb6 on origin/main @ 2702e2bd by merge only; the merged commits touch none of this PR's files, so the receipt stands.

Checklist

  • Focused local preflight/behavioral receipts and complete selected hosted proof passed; actual head/base/job checkout evidence is in Proof. (local passed; hosted proof via confirmation)
  • Acceptance criteria from the issue are all met, or the gap is named below. (criteria 1 and 3 in CONTRACT: feat(core): give each module a durable state area and name the boundary on read-only writes #3384, criterion 2 here)
  • The PR and completed/advanced issues have verified release milestones under docs/process/github.md. (0.45.0)
  • A changeset is included, or this changes nothing a consumer can see.
  • No personal data anywhere in the diff — the leakage gate covers the whole tree.
  • The integration contract index or relevant component is updated in this same commit, or nothing in the machine surface moved.
  • Docs under docs/ reflect the change, or nothing documented moved.
  • A fail-closed guard added or changed answers the proportionate-containment checklist in this body, or no guard changed.
  • Provider history stays append-only (docs/decisions/provider-history.md): the provider-history guard passes, or nothing on a turn's path changed. (hosted)

Anything left open

Nothing beyond the hosted native proof. The core job hygiene-propagation has a dashed name and runs brain, so each of its runs pays the credential-free module-list read that ruling A accepts for module jobs. No module can own it, so it never fetches anything.

🤖 Generated with Claude Code

schlessera and others added 3 commits November 15, 2026 13:11
… cron jobs on the host

A module job runs in a maintenance worker that holds no Git credential, so a
module that needs another repository, such as a private one with scripts it
runs, could not reach it from cron (#3380).

Per the maintainer's 2026-11-02 slice (b) rulings:

- A module's config block declares the repositories it wants with a new
  core-owned `repositories` key, validated and stripped before the module's
  schema like `enabled`. `brain module list --json` reports it on each
  configured module, and `LoadedModule` gains the optional field.
- The host grants only the intersection with the operator's allow-list,
  `BRAIN_UI_MODULE_REPOSITORIES`, read by the cron runner from host
  configuration and never forwarded to a job. An edit to brain.config.ts
  alone therefore cannot widen access.
- Before each module job the runner runs a credential-free
  `brain module list --json` and maps the job to its module by its
  `<module>-<entry>` name and command. The crontab layout is unchanged.
- The sync transport fetches each granted repository with the host's sync
  credential into a host-private bare mirror beside the sync mirror, never
  mounting the brain. The job's worker gets the mirror read-only and
  `url.file://<mirror>.insteadOf` rewrites, and never holds the credential.
- A refused or failed fetch refuses the job before it starts: exit 1, with
  the repository and the setting named on stderr and in cron_runs.

Contract: docs/integration-contract.md, the cli and package-api components,
docs/modules.md and the hosting guide. The ruling is recorded in
docs/decisions/governed-writable-workers.md. Moved citations follow their
anchors.

Refs #3380

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

#3382 landed readModuleList, which names why a module list read failed.
The job's repository step now uses it instead of a duplicate reader, so a
job that cannot learn its module says why on stderr.

Refs #3380

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Refs #3380

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera schlessera added this to the 0.45.0 milestone Nov 15, 2026
@schlessera schlessera added type: fix Something is broken and must behave the way it is documented. area: modules First-party content modules and the module seam. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. labels Nov 15, 2026
schlessera and others added 3 commits November 15, 2026 13:46
…ot brain

A module job always runs `brain <command>`. A dashed job name running
anything else is no module's job, so it now skips the module list and
prints no note.

Refs #3380

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@schlessera
schlessera marked this pull request as ready for review November 15, 2026 19:58
@schlessera
schlessera merged commit e1ce188 into main Nov 15, 2026
50 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: modules First-party content modules and the module seam. area: ui-server Hono app factory: turn coordinator, auth, session catalog, routes, cron. contract Touches the integration contract: CONTRACT: commit, contract doc updated in the same commit. type: fix Something is broken and must behave the way it is documented.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui-server: a module cron job in a maintenance worker has no durable state area and no credential for another repository

1 participant