Skip to content

Neops Core 2.7.0

Released 2026-11-18

These notes cover lock history: core keeps every lock row and its links when a lock is released, a repeated unlock answers from that history, the workflow engine can retire a lock with retireLock, and manage.py prune_lock_history deletes retired history.

Upgrade notes

Locks and unlocks fail until the migrate Job finishes

Migration 0209_lock_history adds two columns to core_compositelock, released_by and retired_at, and five indexes. Every lock request and every unlock reads them. It also lets the device and group links of a lock outlive the device or group: core_devicelock.device_id and core_devicegrouplock.device_group_id become nullable, and each link gets a copy of what it holds (device_id_snapshot and device_hostname_snapshot, device_group_id_snapshot and device_group_name_snapshot), and each lock row a copy of the interfaces it holds (interface_snapshots in _lock_information), which the migration fills for the links and locks already there. The chart runs migrations in the post-upgrade migrate Job while the new pods already serve, so until that Job has migrated, a new pod refuses lock and unlock requests with UNEXPECTED and writes nothing; retireLock fails with a GraphQL error. The workflow engine retries all three. The indexes are built while the migration holds a lock on core_compositelock, which is small before this release because it deleted every released lock.

Old pods that still serve after the Job keep deleting the locks they release, as before, so those releases leave no history. A repeated unlock of a lock an old pod released answers Lock not found with releasedBy: null, the same answer as before this release. Their index sync still deletes every released row synced more than an hour ago, whichever pod released it. A pod older than 2.3.0 also deletes, in its expiry sweep, every released row whose expiry has passed: a release keeps the lock’s expiry. An old pod also neither reads nor honours a retirement: it lets the owner lock a retired reference again. It deletes the lock links of a device or group it hard-deletes, and the links and locks it creates carry no snapshot; nothing fills those in later, so a device, group or interface deleted afterwards leaves only its id there. Once every old pod is gone, run the migration’s backfill again. It fills only links and locks that have no snapshot yet, from the devices, groups and interfaces that still exist, and leaves every snapshot already taken as it is:

UPDATE core_devicelock l SET device_id_snapshot = l.device_id, device_hostname_snapshot = d.hostname
FROM core_device d WHERE d.id = l.device_id AND l.device_id_snapshot IS NULL;

UPDATE core_devicegrouplock l SET device_group_id_snapshot = l.device_group_id, device_group_name_snapshot = g.name
FROM core_devicegroup g WHERE g.id = l.device_group_id AND l.device_group_id_snapshot IS NULL;

UPDATE core_compositelock c SET _lock_information = jsonb_set(c._lock_information, '{interface_snapshots}',
  (SELECT COALESCE(jsonb_agg(jsonb_build_object(
            'id', i.id, 'name', i.name, 'device_id', d.id, 'device_hostname', d.hostname) ORDER BY i.id),
          '[]'::jsonb)
   FROM core_interface i JOIN core_device d ON d.id = i.device_id
   WHERE i.id IN (SELECT jsonb_array_elements_text(c._lock_information -> 'interface_ids')::int)))
WHERE NOT c._lock_information ? 'interface_snapshots';

Lock rows are kept: a repeated unlock answers from history

Core no longer deletes a lock when it is released. The row in core_compositelock and its device and group links stay, marked locked = false with the time it was released (unlocked_at) and how (released_by): owner_unlock, admin (the admin’s “Unlock composite locks” action), expiry_sweep or clear_all (manage.py clear_lock). Index sync no longer deletes the rows it kept for its writes, nor their links, and NEOPS_UNLOCK_INDEX_SYNC_RETENTION_SECONDS is gone.

A link outlives its device or group: deleting a device or group, soft or hard, from the admin, GraphQL or a provider, keeps the link, and a hard delete sets its device or group to null. The link keeps the id and hostname or name it held when the lock was taken (device_id_snapshot, device_hostname_snapshot, device_group_id_snapshot, device_group_name_snapshot). Interfaces have no link: the lock row keeps each interface it held beside interface_ids, with its id, name, and its device’s id and hostname as they were when the lock was taken (interface_snapshots in _lock_information, which the LockInformation field of the CompositeLock GraphQL type returns too), so it still names an interface deleted since.

The Django admin shows lock rows and their links read-only: it can neither change nor delete them. A lock row shows the interfaces it held under “Interfaces held”. The “Composite Locks” count on a global lock now opens the held locks it counts; it used to open every lock row of that global lock, released ones too. Its two lock actions still work. “Unlock composite locks” releases only a lock that is still held, reports one released meanwhile as already released, and records each release in the admin log under the admin who made it. “Refresh composite locks” moves the expiry of a held lock only.

The newest row for a reference and owner decides what unlockResources answers:

Newest row Answer
held the unlock, as before
released by its owner’s unlock success: true, lockExists: false, alreadyReleased: true, releasedBy: OWNER_UNLOCK, message: "Lock already released"; nothing is written, however long ago it was
released by the admin, the expiry sweep or clear_lock success: false, lockExists: false, message: "Lock not found", and releasedBy says which: the run’s writes were never applied
retired code: RETIRED, success: false; nothing is written or changed
none success: false, lockExists: false, message: "Lock not found", releasedBy: null

A new lock with the same reference and owner after a release creates a new row, as before, and from then on that row decides.

Retiring a lock: retireLock

The new mutation retireLock(reference) marks the newest row for that reference and the caller retired: the owner will never touch it again. From then on unlockResources answers code: RETIRED and getAndLockResources with that reference and owner is refused with RETIRED; neither changes anything. It answers success: true when it retired the lock now, when the lock was already retired (alreadyRetired: true), and when there is no lock (lockExists: false). It refuses a lock that is still held with code: LOCK_HELD and changes nothing. Callers that never retire, such as core’s own providers, are unaffected.

Retire only after every lock request of the reference has been answered. A retire that runs while the owner’s first getAndLockResources of the reference is still in flight finds no lock and marks nothing (lockExists: false), so the lock that request then takes is not retired, and it stays held until it is released or expires.

Pruning lock history: prune_lock_history

Lock rows are kept until an operator prunes them. manage.py prune_lock_history --retired-before <days> deletes every row of each reference and owner whose newest row was retired more than that many days ago, with their device and group links, and prints how many it deleted; --dry-run only counts them. It refuses fewer than 1 day. It leaves a reference and owner whole while its newest row is not retired, or while any of its rows still owes search-index writes. Nothing prunes automatically.

A pruned reference and owner then answers like one that never existed: an unlock answers Lock not found, and a new lock is granted, no longer refused with RETIRED.

Workflow engine

The engine reads alreadyReleased, releasedBy and retireLock, so it needs this core: against an older one every unlock fails with Cannot query field 'releasedBy' on type 'UnlockResources'. Upgrade core first. The operations in neops-graphql/graphql/unlock_resources.graphql and neops-graphql/graphql/retire_lock.graphql select the new fields.

Going back

An earlier release runs with migration 0209_lock_history in place: it ignores the new columns and the indexes. It treats a kept released row as nothing, but its lock and unlock filter on locked = true, so the kept rows block nothing. Its index sync deletes every released row synced more than an hour ago, whichever pod released it, and an expiry sweep or clear_lock on it deletes the locks it releases.

migrate core 0208_pending_group_index_first_due_at drops retired_at, so every retirement is lost and the engine can lock a retired reference again. It also drops released_by and the link snapshots, and keeps the released rows. The interface snapshots stay in _lock_information, which an earlier release ignores. It fails while a link of a hard-deleted device or group is kept, because the link’s key becomes required again; delete those links first, which loses what they held:

DELETE FROM core_devicelock WHERE device_id IS NULL;
DELETE FROM core_devicegrouplock WHERE device_group_id IS NULL;

An environment that ran the first image of this change has a table core_lockrelease and a migration record 0209_lock_release that no release uses. This release neither reads nor removes them; drop them by hand:

DROP TABLE IF EXISTS core_lockrelease;
DELETE FROM django_migrations WHERE app = 'core' AND name = '0209_lock_release';