Skip to content

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

Closed

Description

@schlessera

Context

A module job runs from the generated crontab (brain-ui-cron run <module>-<job> -- brain <command>). Like every repository job, it runs inside a maintenance worker while the host execution boundary holds. That worker gives a module two things it may need and cannot have.

1. No durable state outside the brain. Inside the worker the host data directory, the app home and the brain are all read-only. Writes go to the private output stage (BRAIN_WORKER_DATA_ROOT/BRAIN_ROOT = /tmp/brain-maintenance-output), and only what lands under the brain's own paths is published back. XDG_STATE_HOME is a per-run tmp directory (MAINTENANCE_XDG_DIRS, packages/ui-sdk/src/server/worker-launcher.ts:157). A module that keeps operational state in a host directory, as the module config allowed before 0.44.0, now fails on its first mkdir with EROFS: read-only file system. The only durable place left is a gitignored path inside the brain. That works, but it goes through output staging and publication on every run, and core neither names nor documents such a place for modules (packages/core/src/lib/module-loader.ts:65 declares cron with no state contract).

2. No credential for another repository. Module jobs are credentialed and exclusive (cronJobClass, packages/ui-server/src/brain/host-boundary.ts:150-156). In practice that means the model OAuth token and the provider relay. GITHUB_TOKEN and the other HOST_GIT_CREDENTIAL_ENV names (packages/ui-sdk/src/server/subprocess-env.ts:227-231) are kept from the worker, and no git credential helper is configured inside it. Only sync reaches GitHub, through the host mirror transport. So a module that has to clone or fetch a private repository other than the brain cannot do it from cron at all.

Example: the Odysseus brain declares a local module ./modules/beacon whose run job, every 30 minutes, refreshes a shallow clone of the private ithaca/watchtower repository and runs that repo's scripts/beacon.ts, keeping per-check "last ran" state between runs. On 0.43.x this worked with the clone and state in a host directory and GITHUB_TOKEN in the environment. On 0.44.0 every run fails. Remove the EROFS and the clone still fails (git ls-remote on the private repo fails without a credential).

Scope

Decide, and then document, how a module's cron job:

  • keeps small durable state between runs (a named per-module state area, or a documented "use <brain>/.brain-ui/modules/<name>/ and expect publication" rule); and
  • gets a scoped, non-brain repository credential when its configuration declares one. One possible shape is a host-transported fetch like the sync mirror, keyed by a repository allow-list in module config. That needs a decision; this issue does not presume it.

Out of scope

  • Restoring host-directory writes or forwarding generic GITHUB_TOKEN into maintenance workers.
  • The sync transport itself.

Acceptance criteria

  • The integration contract states where a module job may keep durable state, and a test shows state written by one cron run is readable by the next.
  • Either a module job can authenticate to a configured private repository through a scoped route, proven by a fixture with a synthetic credential and helper, or the limitation is documented as a decision with the supported alternative.
  • A module job that hits a read-only host path fails with a message that names the boundary, not a bare EROFS.

Verification

Use a fictional local module and a fixture git server or helper. No real credentials.

Contract impact

Yes: module cron state and credential rules become part of the module contract.

Activity

  1. added
    type: fixSomething is broken and must behave the way it is documented.
    area: modulesFirst-party content modules and the module seam.
    area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    on Nov 2, 2026
  2. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-11-02):

    1. Durable state: core defines a named per-module state area inside the brain, a gitignored directory per module (for example <brain>/.brain-ui/modules/<name>/, exact path to be fixed in the contract). It is part of the module contract and is published through output staging on each run. A test proves that state written by one cron run is readable by the next.
    2. Other repositories: the host performs a scoped fetch for repositories on an allow-list declared in module config, the same way the sync mirror works, using the host's credential. The worker never holds GITHUB_TOKEN or a generic credential. Prove it with a fixture git server and a synthetic credential and helper.

    Both are additive module-contract changes (CONTRACT: prefix, contract docs updated in the same commit). The existing out-of-scope items stand: no host-directory writes, and no generic GITHUB_TOKEN forwarding into maintenance workers. A read-only host path must fail with a message naming the boundary.

  3. removed
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    on Nov 2, 2026
  4. added this to the 0.45.0 milestone on Nov 2, 2026
  5. added
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    priority: p1Scheduled into the current or next milestone.
    contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.
    on Nov 2, 2026
  6. self-assigned this
    on Nov 2, 2026
  7. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Claimed (token wi-3380-c7e1), branch fix/3380-module-cron-state. Plan per the 2026-11-02 ruling, in slices: (a) the named per-module state area and a boundary-naming read-only error, then (b) the host-performed scoped fetch for allow-listed repositories. Collision report: path overlap with #3335 on packages/ui-server/src/brain/host-boundary.ts; the rest is closure-only. Staying out of #3381's scope (cron module discovery retry).

  8. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Slice (a) delivered for review in #3384 (state area, ctx.stateDir(), boundary-naming read-only errors; acceptance criteria 1 and 3). It uses Refs, so this issue stays open for ruling point 2.

    Slice (b), the host-performed scoped fetch, needs two rulings the 2026-11-02 decision does not settle. Everything else in (b) follows the sync mirror. That means a host-private bare mirror per allow-listed repository beside the sync mirror, refreshed by a separate transport worker that holds the host credential and never mounts the brain. The job's worker gets the mirror read-only, plus url.file://<mirror>.insteadOf <url>, so the module's own git clone https://github.com/ithaca/watchtower reads the mirror without any credential.

    Question 1: who may grant a repository? "Declared in module config" means brain.config.ts, which is Tier B: protected by default, but a governance policy may release it. Once released, a governed turn could add any repository the host token can read, for example a private ithaca/treasury. The next cron run would then fetch it into the brain, where turns can read it.

    • A. A core-owned key in the module's config block, e.g. modules: { "./modules/beacon": { repositories: ["https://github.com/ithaca/watchtower"] } }, stripped before the module's schema like enabled. Authority equals brain.config.ts's protection. Simplest, and matches the ruling's wording.
    • B. As A, but the host also refuses any repository missing from a host-side allow-list in trusted server configuration (an environment setting the operator owns). The repository can narrow the host's grant but never widen it.
    • C. Host configuration only, keyed by module name. Nothing in the brain can widen it, but it departs from "declared in module config".

    Recommendation: B. It keeps the ruling's shape, and a released config cannot turn the host token into a read of every private repository that token can reach.

    Question 2: how does the runner learn a job's module and allow-list at run time? A job is named <module>-<entry>, and both module and entry names may contain -, so the name alone is ambiguous.

    • A. Before each module job, run a credential-free brain module list --json in a maintenance worker (shared gate) and match the job by name and command. module list --json gains an additive repositories field. This costs one extra short worker per module run, and leaves the crontab untouched.
    • B. Emit the module name into the crontab line (brain-ui-cron run <job> --module <name> -- …). This touches emit.ts and brain-ui-cron.ts, which overlaps ui-server: a transient module discovery failure at cron start silently drops every module job until the next restart #3381's scope, and the allow-list would still have to be read at run time.

    Recommendation: A. It needs no crontab change and avoids colliding with #3381.

    Credential scope assumed in both cases: the host's existing GitHub credential (BRAIN_UI_SYNC_GITHUB_TOKEN, falling back to GITHUB_TOKEN), sent only to https://github.com exactly as syncTransportCommand does. The proof would use a loopback smart-HTTP fixture that requires Basic auth with a synthetic token, reached through an @internal host-side origin override that no repository input can set. Please say if a different credential or host scope is intended.

    Completion evidence to resume: a maintainer comment choosing an option for each question.

  9. added
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    and removed
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    on Nov 2, 2026
  10. 2 remaining items

  11. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Decision (maintainer, 2026-11-02), slice (b):

    1. Grant: option B. The module config declares the repositories it wants. The host refuses any repository that is not also on an operator-owned allow-list in host configuration, outside the brain. A governed turn that edits brain.config.ts therefore cannot widen access by itself.
    2. Job-to-module mapping: option A. Before each module job, the runner runs a credential-free brain module list --json with an additive repositories field to map the job to its module. The crontab layout, owned by ui-server: a transient module discovery failure at cron start silently drops every module job until the next restart #3381, is unchanged.

    Both changes are additive contract changes. Slice (a) is in #3384.

  12. added
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    and removed
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    on Nov 2, 2026
  13. self-assigned this
    on Nov 2, 2026
  14. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Claimed slice (b) (token wi-3380-b4d2), branch fix/3380-module-repositories, stacked on #3384's branch (fix/3380-module-cron-state, head 4a743c56) as an ordinary PR because native gh stack is not installed here. Plan per the 2026-11-02 slice (b) ruling: module-config repositories intersected with an operator host allow-list, host-performed scoped mirror fetch with the host credential, job-to-module mapping via credential-free brain module list --json. Crontab layout (#3381) unchanged.

  15. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Handoff (claim wi-3380-b4d2): slice (b) is draft #3393, head 960c23a6, stacked on #3384 (base fix/3380-module-cron-state @ 4a743c56). Local preflight against that parent passed (1050 pass, 0 fail), and the PR body has the failing-first and mutation receipts. Hosted native proof is still needed: the real-worker cron test, sync-mirror and the provider-history guard cannot run on a host without user namespaces. To resume: land #3384 first (bun scripts/integrate.ts confirm 3384 --issues schlessera/brain-kit#3380). Then either retarget #3393 to main (rebase onto origin/main, rerun bun run check:pr --base origin/main) and run bun scripts/integrate.ts confirm 3393 --issues schlessera/brain-kit#3380, or merge both through the stack procedure. #3380 closes once both layers are on main. Releasing the assignment.

  16. removed their assignment
    on Nov 2, 2026
  17. self-assigned this
    on Nov 15, 2026
  18. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    Claimed for implementation. Claim token: claim-bd9fbeb3. Branch: fix/3380-module-repositories-main.

    Resuming slice (b) from draft #3393 (its commit onto current main); path collision only with #3393 itself, which this replaces.

  19. schlessera commented on Nov 15, 2026

    @schlessera
    OwnerAuthor

    Delivered. Slice (b) merged in #4008 as e1ce188d79dd47c88a4478359d38277098444a21 (candidate run 43755383702). Slice (a) is #3384 (6f1d7d93), so all three acceptance criteria are on main:

    1. State area. A module job keeps durable state in its module state area (CONTRACT: feat(core): give each module a durable state area and name the boundary on read-only writes #3384).
    2. Other repositories. A module job reads a private repository that its module config lists and that the operator's BRAIN_UI_MODULE_REPOSITORIES also allows. The host fetches it with its sync credential into a private mirror, and the job's worker reads the mirror through a Git URL rewrite without ever holding the credential. Proven with a loopback Git fixture, a synthetic token and a real-worker cron test (CONTRACT: feat(ui-server): fetch allow-listed repositories for module cron jobs on the host #4008).
    3. Read-only paths. A write to a read-only host path fails with a message that names the boundary (CONTRACT: feat(core): give each module a durable state area and name the boundary on read-only writes #3384).

    #4008 replaced the earlier stacked draft #3393, now closed. It also reuses #3382's module-list reader, so a job that cannot learn its module says why. Heavy post-merge proof runs on the squash's main run.

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

Metadata

Metadata

Assignees

Labels

agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: modulesFirst-party content modules and the module seam.area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.priority: p1Scheduled into the current or next milestone.type: fixSomething is broken and must behave the way it is documented.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions