Skip to content

fix(store): close the retained update policy edge cases - #1293

Merged
scttbnsn merged 10 commits into
dev/v1.8from
fix/v1.8-policy-stash-edges
Oct 3, 2026
Merged

scttbnsn merged 10 commits into
dev/v1.8from
fix/v1.8-policy-stash-edges

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #1290 for the update-policy retention edge cases its review turned up. All on 1.8; refs issue 1280.

  • A late removal no longer leaves an orphan stash when its replacement is already stored. An HTTP inventory pass could stash the old container's policy after the replacement had adopted it, so an override the user cleared came back on the next recreate. Home Assistant still sees replacementExpected: true on that removal.
  • Compose replicas no longer swap policies. They share one identity key, so the stash now records the container name (migration 5 adds a nullable container_name column), and an agent-owned insert only takes an identity-key entry with its own name.
  • When both the identity and id entries hold a policy, the most recently stashed one wins, by stash order rather than expiresAt, so a changed retention TTL can't flip the order.
  • The sibling lookup is skipped when there are no overrides to keep, and migration 6 indexes (watcher, COALESCE(agent, '')) so it no longer scans every agent's local watcher. A test pins the query plan.
  • scripts/security-dependency-versions.test.mjs skips lockfile entries with no version instead of throwing.

Deliberate trade-offs, written down on the roadmap: an agent compose container recreated under a different container name no longer inherits through the shared key (controller-local still does), and nameless stash entries written by 1.7 under an agent compose key are dropped on first read.

Checked locally: full pre-push gate with coverage thresholds met. One independent review pass; its coverage gap and TTL-ordering findings are fixed in the last two commits.

✨ Added

  • Added retention-cache support for containerName, including import, persistence, migration, and legacy-record handling.
  • Added tests for late removals, Compose replica matching, retention ordering, and query-plan use of the watcher-and-agent index.
  • Added a test helper that skips versionless lockfile entries during security-floor checks.

🔧 Changed

  • Agent-owned Compose inserts restore cached policies only when the cached container name matches.
  • When identity-key and container-ID entries both exist, inserts restore the most recently stashed unexpired policy and consume both entries.
  • Migration 6 adds an index on containers(watcher, COALESCE(agent, '')).

🐛 Fixed

  • Prevented late removals from stashing a policy after a stored replacement has adopted it.
  • Prevented inserts without IDs from consuming unrelated ID-keyed retention entries.
  • Avoided sibling lookups when no policy overrides need retention.

⚠️ Breaking

  • UpdatePolicyRetentionCacheRecord adds the optional containerName property.

Concerns

  • Current review findings were not supplied; review concerns are unavailable.

…stored

An inventory pass or snapshot that lists a replacement flags the removal of its
predecessor as replacementExpected, even when a real-time dd:container-added
already stored the replacement and it inherited the update policy on insert.
The unguarded stash then sat under the identity key and handed the policy to
the next recreate, after the user had cleared it.

deleteContainer now skips that stash for an agent-owned record when a
same-identity, same-name record is still stored. The removal event keeps
replacementExpected, so HA/MQTT discovery for the live replacement is
untouched, and controller-local records keep the unconditional stash.

Refs: #1280
Replicas of one compose service share the compose:project/service identity
key, so after a compose down/up the policy one replica stashed could be taken
by whichever replica was re-added first.

A stash now records the canonical container name, and an agent-owned insert
only takes an identity-key entry recorded under its own name, leaving another
replica's entry for that replica. The name is persisted in a new nullable
update_policy_retention_cache.container_name column (schema migration 5) and
carried by the legacy store importer when present.

An entry written before this change has no name. Under a compose key it is
consumed and dropped, since applying it could misapply another replica's
policy and dropping it only loses a policy in flight across the upgrade.
Under a plain identity key the key already names the container, so it is
still applied. Controller-local inserts keep the name-agnostic match that
carries a policy across a compose rename.

Refs: #1280
An insert that found entries under both its identity key and its Docker id
took the identity entry whenever one existed. After an agent to controller to
agent move, that entry is the one the first move left behind, so it shadowed
the policy the controller held when the container moved back. An expired
identity entry also dropped a valid id entry.

The insert still takes both entries, now discards expired ones and restores
the entry stashed last, by expiresAt since every stash uses the same TTL. A
tie, one delete stashing both keys, keeps the identity entry.

Refs: #1280
deleteContainer ran the identity-sibling lookup on every agent removal, even
for a record with no update-policy overrides, where the stash it guards is a
no-op. The lookup now runs only when there is something to retain.

The lookup filters on watcher and COALESCE(agent, ''), and the only index
that served it was containers_watcher_status, which narrows to the watcher
name (shared by every agent's local watcher) and then sorts by rowid.
Schema migration 6 adds containers_watcher_agent on (watcher,
COALESCE(agent, '')), which matches both terms and keeps rowid order, so the
lookup on agent-owned inserts reads one watcher on one agent with no sort.

Refs: #1280
…check

The September runtime floor check split entry.version on every lockfile
entry whose path matched a floored package, so a link entry (link: true,
no version) failed the suite with a bare TypeError instead of a finding.
Entries without a version are now skipped, and versioned entries keep the
vetted-major and floor checks. The check moved into a helper so a node:test
case can cover both paths against a fixture lockfile.

Refs: #1280
…skip

A watcher snapshot that lists a replacement already stored by an earlier
dd:container-added flags its predecessor's prune as replacementExpected, the
same shape as the inventory pass. The test fails without the deleteContainer
guard and pins that the snapshot path leaves no stash behind either.

Refs: #1280
@vercel

vercel Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
drydock-website Ready Ready Preview Oct 3, 2026 1:01am UTC
drydockdemo-website Ready Ready Preview Oct 3, 2026 1:01am UTC

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: CodesWhat/drydock/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1a61dacd-4ba9-430c-b2b4-de5c9e5e5350
📥 Commits

Reviewing files that changed from the base of the PR and between 014a650 and 17a83ac.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (10)
  • app/agent/AgentClient.container-reconcile.test.ts
  • app/agent/agent-inventory.test.ts
  • app/store/container.test.ts
  • app/store/container.ts
  • app/store/db/importers/update-policy-retention-cache.test.ts
  • app/store/db/importers/update-policy-retention-cache.ts
  • app/store/db/migrations.ts
  • app/store/update-policy-retention-cache.test.ts
  • app/store/update-policy-retention-cache.ts
  • scripts/security-dependency-versions.test.mjs

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 1 remain after this review.


📝 Walkthrough

Walkthrough

The store now records container names with retained update policies and uses them when matching agent-owned compose replacements. Deletion and restoration logic handles empty overrides, identity siblings, expired entries, and entries keyed by both identity and container ID. Tests cover cache migration, imports, agent reconciliation, and replacement scenarios. The security-floor test helper skips lockfile entries without string versions.

Possibly related PRs

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 17a83

The change tightens how retained update policies are matched and persisted, and adds migrations and tests for it. No concrete merge-blocking problem was identified in the supplied material.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 17a83

The changes strengthen policy matching and prevent cleared overrides from returning after replacement. No introduced authorization bypass was established. Remaining risk concerns upgrade compatibility and incomplete assurance around interrupted policy transfers.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The evidenced exposure concerns retained update-policy overrides within a controller store. Identity-key matching limits adoption by agent, watcher, identity, and now source name; the container-ID handoff path can carry overrides across those identities by design.

Trust Boundaries and Controls

  • observed — The agent delete route is registered after shared-secret authentication. Missing or incorrect secrets are rejected. Authoritative inventory ingestion separately rejects containers owned by another agent and new IDs currently claimed by a controller-local watcher.

Resilience and Maintainability Implications

  • inferred — Retention transfer is not visibly atomic with container acceptance: overrides are consumed before validation and insertion, and the old container row is deleted before stashing. Failure can therefore lose retained policy state. This ordering predates the PR and was not established as an introduced or worsened security condition.

Hardening Proposals

  • proposed — Consider an atomic or recoverable policy-transfer mechanism that retains ownership until replacement acceptance is durable and keeps in-memory state consistent with database rollback. This addresses the pre-existing failure window rather than a verified regression in this PR.
🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Oct 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttbnsn
scttbnsn merged commit 87f868d into dev/v1.8 Oct 3, 2026
@scttbnsn
scttbnsn deleted the fix/v1.8-policy-stash-edges branch October 3, 2026 01:31
scttbnsn added a commit that referenced this pull request Nov 2, 2026