files: the first nextcloud-cron run races the app-install oneshots and Nextcloud DELETES the freshly registered background jobs (richdocuments ObtainCapabilities, user_oidc CleanupSessions, calendar, contacts) — permanently, silently #1828

Closed
opened 2026-09-24 17:11:56 +00:00 by ben · 2 comments
Owner

Symptom

Whakatōhea Demo run #2 (gateway 134.199.167.181, founded 2026-09-23 22:38Z): oc_jobs holds none of the background jobs the founding's apps register — richdocuments ObtainCapabilities + Cleanup, OCA\Calendar\BackgroundJob\CleanUpOutdatedBookingsJob, OCA\Contacts\Cron\SocialUpdateRegistration, OCA\UserOIDC\Cron\CleanupSessions. Visible consequence: Collabora capabilities never fetched → no New document in Files (#1827). Invisible ones: user_oidc sessions never cleaned, calendar bookings never expired.

Cause (journal + Nextcloud source on the box)

Timeline on the box:

  • 22:38:50–22:39:00Z nextcloud-setup.service
  • 22:39:01Z the app oneshots start: nextcloud-richdocuments (→22:39:11), nextcloud-calendar (→22:39:10), nextcloud-oidc (→22:39:10) — each app:install/app:enable registers the app's info.xml background jobs in oc_jobs
  • 22:39:03Z nextcloud-cron.service starts (unit is After=nextcloud-setup.service only; timer OnBootSec=5m, OnUnitActiveSec=5m) and runs until 22:40:42Z
  • 22:40:42Z cron logs, for each of the five classes: Could not resolve OCA\Richdocuments\Backgroundjobs\ObtainCapabilities! Class … does not exist

OC\BackgroundJob\JobList::buildJob (Nextcloud 32.0.11, lib/private/BackgroundJob/JobList.php:319): when the container cannot build the job and class_exists is false, it logs "failed to create instance of background job" and removes the row ("Remove job from disabled app or old version of an app"). The cron process loaded apps at 22:39:03 — before those apps were installed — so the freshly registered rows were unresolvable in that process and were deleted. They are never re-registered: only Installer::installAppLastSteps (install) and AppManager::upgradeApp (version bump) add them; app:enable on an installed app does not.

So every founding whose first cron run overlaps the app-install oneshots loses those jobs permanently. On a fast box it is a near-certainty (2 s gap here).

Fix

Order the first cron run after the app installs. Proposed: in the files render (internal/clan/files.go), the node that renders any of nextcloud-richdocuments / nextcloud-calendar / nextcloud-oidc / nextcloud-brand also emits

systemd.services.nextcloud-cron.after = [ "nextcloud-richdocuments.service" … ];

for exactly the oneshots it rendered (or before = [ "nextcloud-cron.service" ] on each oneshot — same effect, pick the one that keeps the render honest about which units exist). Ordering only; no requires, so a failed oneshot does not block cron forever. Both units start in the same activation, so systemd holds cron's start job until the oneshots finish.

Repair for the already-founded demo: no occ path re-adds jobs short of an app version bump. Options: (a) leave — the demo will re-register on the next richdocuments/calendar/user_oidc upgrade; (b) a one-off occ app:remove + app:install is NOT acceptable for user_oidc (drops the provider config). Recommend (a) and note it in the ticket close-report; #1827's activate-config covers the capabilities half regardless of the job.

Acceptance criteria

  • Render test pins the ordering (nextcloud-cron.after names every rendered app oneshot, and nothing when none is rendered).
  • On a fresh founding drive, after the first cron run, oc_jobs contains OCA\Richdocuments\Backgroundjobs\ObtainCapabilities and OCA\UserOIDC\Cron\CleanupSessions (a post-founding probe over ssh: sudo -u nextcloud psql -d nextcloud -At -c "select class from oc_jobs where class like 'OCA\\Richdocuments%' or class like 'OCA\\UserOIDC%'").
  • The journal of the first cron run carries no Could not resolve OCA\… line.
  • GOTCHAS entry (same commit): "Nextcloud's job list DELETES a job whose class it cannot load — a cron run that overlaps an app install silently strips that app's background jobs forever".

Why it matters

A silent, permanent loss of every background job of every app installed by founding — on every community, not just the demo — with nothing red anywhere. #1020 was the last time the first cron activation bit us; this is the same window, a different wound.

## Symptom Whakatōhea Demo run #2 (gateway `134.199.167.181`, founded 2026-09-23 22:38Z): `oc_jobs` holds **none** of the background jobs the founding's apps register — richdocuments `ObtainCapabilities` + `Cleanup`, `OCA\Calendar\BackgroundJob\CleanUpOutdatedBookingsJob`, `OCA\Contacts\Cron\SocialUpdateRegistration`, `OCA\UserOIDC\Cron\CleanupSessions`. Visible consequence: Collabora capabilities never fetched → no New document in Files (#1827). Invisible ones: user_oidc sessions never cleaned, calendar bookings never expired. ## Cause (journal + Nextcloud source on the box) Timeline on the box: - 22:38:50–22:39:00Z `nextcloud-setup.service` - 22:39:01Z the app oneshots start: `nextcloud-richdocuments` (→22:39:11), `nextcloud-calendar` (→22:39:10), `nextcloud-oidc` (→22:39:10) — each `app:install`/`app:enable` registers the app's `info.xml` background jobs in `oc_jobs` - **22:39:03Z `nextcloud-cron.service` starts** (unit is `After=nextcloud-setup.service` only; timer `OnBootSec=5m`, `OnUnitActiveSec=5m`) and runs until 22:40:42Z - 22:40:42Z cron logs, for each of the five classes: `Could not resolve OCA\Richdocuments\Backgroundjobs\ObtainCapabilities! Class … does not exist` `OC\BackgroundJob\JobList::buildJob` (Nextcloud 32.0.11, `lib/private/BackgroundJob/JobList.php:319`): when the container cannot build the job **and `class_exists` is false**, it logs "failed to create instance of background job" and **removes the row** ("Remove job from disabled app or old version of an app"). The cron process loaded apps at 22:39:03 — before those apps were installed — so the freshly registered rows were unresolvable **in that process** and were deleted. They are never re-registered: only `Installer::installAppLastSteps` (install) and `AppManager::upgradeApp` (version bump) add them; `app:enable` on an installed app does not. So every founding whose first cron run overlaps the app-install oneshots loses those jobs permanently. On a fast box it is a near-certainty (2 s gap here). ## Fix Order the first cron run after the app installs. Proposed: in the files render (`internal/clan/files.go`), the node that renders any of `nextcloud-richdocuments` / `nextcloud-calendar` / `nextcloud-oidc` / `nextcloud-brand` also emits ```nix systemd.services.nextcloud-cron.after = [ "nextcloud-richdocuments.service" … ]; ``` for exactly the oneshots it rendered (or `before = [ "nextcloud-cron.service" ]` on each oneshot — same effect, pick the one that keeps the render honest about which units exist). Ordering only; no `requires`, so a failed oneshot does not block cron forever. Both units start in the same activation, so systemd holds cron's start job until the oneshots finish. Repair for the already-founded demo: no occ path re-adds jobs short of an app version bump. Options: (a) leave — the demo will re-register on the next richdocuments/calendar/user_oidc upgrade; (b) a one-off `occ app:remove` + `app:install` is NOT acceptable for user_oidc (drops the provider config). Recommend (a) and note it in the ticket close-report; #1827's `activate-config` covers the capabilities half regardless of the job. ## Acceptance criteria - Render test pins the ordering (`nextcloud-cron.after` names every rendered app oneshot, and nothing when none is rendered). - On a fresh founding drive, after the first cron run, `oc_jobs` contains `OCA\Richdocuments\Backgroundjobs\ObtainCapabilities` and `OCA\UserOIDC\Cron\CleanupSessions` (a post-founding probe over ssh: `sudo -u nextcloud psql -d nextcloud -At -c "select class from oc_jobs where class like 'OCA\\Richdocuments%' or class like 'OCA\\UserOIDC%'"`). - The journal of the first cron run carries no `Could not resolve OCA\…` line. - GOTCHAS entry (same commit): "Nextcloud's job list DELETES a job whose class it cannot load — a cron run that overlaps an app install silently strips that app's background jobs forever". ## Why it matters A silent, permanent loss of every background job of every app installed by founding — on every community, not just the demo — with nothing red anywhere. #1020 was the last time the first cron activation bit us; this is the same window, a different wound.

swarm-claim host=matou-dev-server-01 run=31950
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=31950 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #1828 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 1828,
  "status": "success",
  "commits": [
    "01d69e06e8748659f958148dbf056045e3df6ac4"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/GOTCHAS.md",
    "internal/clan/files.go",
    "internal/clan/files_test.go"
  ],
  "tests": [
    {
      "command": "nix develop .#go-ci -c go test ./internal/clan/",
      "exit_code": 0
    },
    {
      "command": "nix develop .#go-ci -c bash -c 'gofmt -l internal/clan/files.go internal/clan/files_test.go && go vet ./internal/clan/ && go build ./internal/clan/'",
      "exit_code": 0
    }
  ],
  "criteria": {
    "Render test pins the ordering (nextcloud-cron.after names every rendered app oneshot, and nothing when none is rendered)": "internal/clan/files_test.go TestRenderFiles_FirstCronRunOrderedAfterAppInstalls: files-only cron.after == `after = [ \"nextcloud-setup.service\" ];` (nothing extra); a docs+OIDC node's cron.after names nextcloud-richdocuments.service AND nextcloud-oidc.service; calendar named when placed. Implemented in internal/clan/files.go renderFilesFirstActivation(cfg).",
    "First cron run leaves oc_jobs holding the richdocuments + user_oidc jobs (post-founding ssh probe)": "Root-caused and fixed by ordering: nextcloud-cron.after now names the job-registering oneshots, so cron cannot start until they finish and the jobs survive. Ordering-only edge (never requires) verified by the test asserting the oneshots are absent from cron.requires. Live post-founding probe not runnable from the render seam (no live founding drive this iteration); pinned at the render seam per the manifest.",
    "The journal of the first cron run carries no `Could not resolve OCA\\...` line": "Consequence of the same ordering fix — cron no longer loads apps before the installs register them, so no class is unresolvable in that process. Not separately reproducible without a live founding drive.",
    "GOTCHAS entry (same commit)": "docs/GOTCHAS.md #334 'Nextcloud's job list DELETES a job whose class it cannot load — a cron run that overlaps an app install silently strips that app's background jobs forever', added in commit 01d69e06."
  },
  "summary": "Ordered the first founding nextcloud-cron run after the job-registering app-install oneshots so it stops silently deleting their freshly registered background jobs.",
  "blockers": []
}
**close-report** for #1828 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 1828, "status": "success", "commits": [ "01d69e06e8748659f958148dbf056045e3df6ac4" ], "changed_files": [ "STATUS.md", "docs/GOTCHAS.md", "internal/clan/files.go", "internal/clan/files_test.go" ], "tests": [ { "command": "nix develop .#go-ci -c go test ./internal/clan/", "exit_code": 0 }, { "command": "nix develop .#go-ci -c bash -c 'gofmt -l internal/clan/files.go internal/clan/files_test.go && go vet ./internal/clan/ && go build ./internal/clan/'", "exit_code": 0 } ], "criteria": { "Render test pins the ordering (nextcloud-cron.after names every rendered app oneshot, and nothing when none is rendered)": "internal/clan/files_test.go TestRenderFiles_FirstCronRunOrderedAfterAppInstalls: files-only cron.after == `after = [ \"nextcloud-setup.service\" ];` (nothing extra); a docs+OIDC node's cron.after names nextcloud-richdocuments.service AND nextcloud-oidc.service; calendar named when placed. Implemented in internal/clan/files.go renderFilesFirstActivation(cfg).", "First cron run leaves oc_jobs holding the richdocuments + user_oidc jobs (post-founding ssh probe)": "Root-caused and fixed by ordering: nextcloud-cron.after now names the job-registering oneshots, so cron cannot start until they finish and the jobs survive. Ordering-only edge (never requires) verified by the test asserting the oneshots are absent from cron.requires. Live post-founding probe not runnable from the render seam (no live founding drive this iteration); pinned at the render seam per the manifest.", "The journal of the first cron run carries no `Could not resolve OCA\\...` line": "Consequence of the same ordering fix — cron no longer loads apps before the installs register them, so no class is unresolvable in that process. Not separately reproducible without a live founding drive.", "GOTCHAS entry (same commit)": "docs/GOTCHAS.md #334 'Nextcloud's job list DELETES a job whose class it cannot load — a cron run that overlaps an app install silently strips that app's background jobs forever', added in commit 01d69e06." }, "summary": "Ordered the first founding nextcloud-cron run after the job-registering app-install oneshots so it stops silently deleting their freshly registered background jobs.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/idss#1828
No description provided.