Skip to content

ADFA-4951: EnvironmentLock primitive (foundation) - #303

Merged
luisguzman-adfa merged 2 commits into
mainfrom
feat/ADFA-4951-environment-lock
Jul 31, 2026
Merged

luisguzman-adfa merged 2 commits into
mainfrom
feat/ADFA-4951-environment-lock

Conversation

@luisguzman-adfa

Copy link
Copy Markdown
Collaborator

What

One app-wide coordination lock for deep-environment operations (module runrole, backup, restore,
clone) so they never overlap over the rootfs. Ask EnvironmentLock.isHeld() — a POSITIVE signal —
instead of "is the server alive?", which is unsafe: an op that stops the server makes alive=false,
so another op reads that as "free to go" and collides.

Changes

  • EnvironmentLock (new): isBusyNow() (process-scoped: runrole + REST downloads — matches the
    legacy InstallJobs), isHeld(ctx) (adds the durable InstallGuard + a durable OWNER marker for
    backup/restore/clone), plus acquire()/release()/currentOwner()/heldSince().
  • InstallJobs.isBusy() now delegates to EnvironmentLock.isBusyNow() (thin alias; callers unchanged).
  • Module/maps entry points (ModuleHubFragment, ModuleDetailFragment, MapsConfirmFragment) check
    isHeld(ctx), so they also refuse while a durable install/owner op is in progress.
  • InstallGuard unchanged (damaged-install recovery keys on it).
  • Design doc: controller/docs/ENVIRONMENT_LOCK_AND_BACKUP_RESTORE.md.

Foundation only — nothing acquires an owner yet. Follow-ups (same ticket): InstallService acquires
INSTALL/MODULE; clone acquires + stops the server (it clones live today); then backup/restore
(ADFA-4952) acquire BACKUP/RESTORE.

Notes

Behavior-preserving refactor. Blocks ADFA-4952.

Introduce one app-wide coordination lock for deep-environment operations (module runrole, backup,
restore, clone) so they never overlap over the rootfs. Ask EnvironmentLock.isHeld() — a POSITIVE
signal — instead of 'is the server alive?', which is unsafe (an op that stops the server makes
alive=false, so another op reads that as 'free to go' and collides).

- EnvironmentLock: isBusyNow() (process-scoped: runrole + REST downloads, == legacy InstallJobs),
  isHeld(ctx) (adds the durable InstallGuard + a durable OWNER marker for backup/restore/clone),
  plus acquire()/release()/currentOwner()/heldSince().
- InstallJobs.isBusy() now delegates to EnvironmentLock.isBusyNow() (thin alias; callers unchanged).
- Module/maps entry points (ModuleHubFragment, ModuleDetailFragment, MapsConfirmFragment) now check
  isHeld(ctx), so they also refuse while a durable install/owner op is in progress.
- InstallGuard stays as-is (damaged-install recovery keys on it).

Design doc: controller/docs/ENVIRONMENT_LOCK_AND_BACKUP_RESTORE.md.

Follow-ups (same ticket): make InstallService/module acquire owner INSTALL/MODULE; migrate clone to
acquire + stop the server (it clones live today) with a graceful stop/restart; then backup/restore
(ADFA-4952) acquire BACKUP/RESTORE.
…orever

Code-review follow-up (#303, suggestion 1). The durable owner marker had no staleness story: a
BACKUP/CLONE killed mid-run would leave it, making isHeld() permanently true and blocking every
deep-env op. Make the coordination lock SESSION-SCOPED — the marker carries a token unique to the
process launch; a marker from a now-dead process reads as stale and self-heals (cleared) in
ownerHeld(). After a kill no op is actually running, so the lock never stays held.

Damage recovery stays separate: an interrupted WRITE op (half-applied restore/runrole) is recovered
via the durable InstallGuard + its existing recovery, so a write op sets BOTH (lock + guard);
read-only ops (backup, clone-send) set only the lock. Also synchronized the reads
(currentOwner/heldSince/ownerHeld) — suggestion 2 — so they never race a write. Doc updated.
@luisguzman-adfa
luisguzman-adfa merged commit b5e0077 into main Jul 31, 2026
3 checks passed
@luisguzman-adfa
luisguzman-adfa deleted the feat/ADFA-4951-environment-lock branch July 31, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant