Repository navigation
fix(agent): keep update policy across agent moves and reconnect recreates (1.6) - #1036
Conversation
… on prune (#1033) The startup prune of controller-owned container records got two things wrong. DR-112: it deleted the record with a plain deleteContainer(), so nothing was stashed, and the stash it would have written could not have been read back anyway. deleteContainer's replacementExpected stash is keyed on agent plus watcher plus name, which is exactly what a hand-off to an agent (or a watcher rename) changes, so the incoming record looked up a key nothing had written. A snooze, a maturity mode and minimum age, and skipped tags or digests all went back to defaults, and an absent maturity policy reads as no gate rather than the default gate. deleteContainer now takes identityChangeExpected, which stashes the same overrides under the container's Docker id: the id is the one thing the move leaves alone, because it is the same physical container on both sides, while the identity is what it changes. insertContainer tries the identity key first and falls back to the id key, so a recreate (new id, same identity) still takes the #496 path untouched. A container recreated as part of the move mints a new id and matches neither key. DR-113: the prune kept only records whose watcher was registered, and #1025 protected the all-failed case only. With two configured local watchers where one fails on an unreadable CA file, a missing socket or a rejected value, the survivor keeps the registered set non-empty, so the failed watcher's records were pruned as though it had been renamed away. registerWatchers now returns the configured watcher names rather than a count, and the prune keeps a record whose watcher is registered or still configured. It also awaits allSettled rather than all: Promise.all resolves the await on the first rejection while the other registrations are still in flight, so the prune could read a registry emptier than the one the run actually produced. (cherry picked from commit 4a4162f)
DR-103: watch() was fixed to prune before ingest (DR-99, #1015), but three other AgentClient container-reconcile entry points still called processAuthoritativeContainers() (insert/update) before pruneOldContainers() (delete + stash) for the same batch: _doHandshake(), handleWatcherSnapshotEvent() and handleContainerSync(). insertContainer() restores a same-identity replacement's stashed update policy as its first action, and that stash is only written by deleteContainer(..., {replacementExpected: true}), so running the insert first left nothing to consume. A container recreated while its agent was disconnected silently lost its snooze, maturity mode, minimum age, and any skipped tags or digests on the very next handshake, watcher snapshot, or edge sync. Each of the three now prunes first, mirroring watch() and the v1.7 line's #922 reorder, with the same zero-container/zero-report guard on the two paths where an empty inventory is ambiguous (skip the prune, log a warning, instead of wiping every container the batch would otherwise own). Reordering handleWatcherSnapshotEvent() also flips when dd:container-removed fires relative to the dd:container-added/dd:container-updated events for the batch replacing it: removed now fires first, matching the v1.7 line. The audit subscriber's per-identity lifecycle dedupe state benefits from this: previously a replacement's container-added ran first and seeded the state, and the removal that followed for the outgoing id shared the same identity key and deleted it again, so the very next unchanged update for the surviving container found no baseline, failed open, and recorded a spurious duplicate row. Removed-then-added means the removal only ever clears the stale state belonging to the container actually leaving. Adds AgentClient.container-reconcile.test.ts (ported from the v1.7 line), which drives the real store/container.js module against an in-memory Loki collection rather than mocking it, so the insert/stash ordering contract is actually exercised for _doHandshake(), watch(), handleContainerSync() and handleWatcherSnapshotEvent(), plus a regression test in audit-subscriptions.test.ts for the dedupe-state ordering fix.
|
Deployment failed for project drydock-website with the following error: |
|
Warning Review limit reachedNext included review available in 21 minutes. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Team Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (11)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
biggest-littlest
left a comment
There was a problem hiding this comment.
1.6 backports of the id-keyed policy stash (DR-112), the registered-plus-configured keep-set with allSettled registration (DR-113) and prune-before-ingest on handshake, snapshot and sync (DR-103). Coverage 100%, gate and CI green.
ALARGECOMPANY
left a comment
There was a problem hiding this comment.
1.6 backports of the id-keyed policy stash (DR-112), the registered-plus-configured keep-set with allSettled registration (DR-113) and prune-before-ingest on handshake, snapshot and sync (DR-103). Coverage 100%, gate and CI green.
Two 1.6 fixes in the agent ingest path.
DR-112/113 port (cherry-pick of #1033 from dev/v1.8): a container handed from the controller's local watcher to an agent keeps its update policy, via a second policy stash keyed on the Docker container id (
id::<id>) written when a record is deleted for an identity change; one local watcher failing to register no longer deletes its records when another registers (keep-set is registered plus configured names, andregisterWatchersusesallSettledso a late success cannot land after the prune). This also closes thePromise.allrace CodeRabbit flagged on #1030. The #1030 CHANGELOG bullet and both docs pages no longer claim the overrides are lost.DR-103: three 1.6 ingest paths still pruned after ingest, so a container recreated while the agent was disconnected lost its update policy.
insertContainer()restores the same-identity stash as its first statement, and onlydeleteContainer(id, { replacementExpected: true })writes it, but_doHandshake(),handleWatcherSnapshotEvent()andhandleContainerSync()inAgentClientall ingested first and pruned after, so the stash was written after its only consumer ran and the replacement landed on the global default policy (the #565 symptom on reconnect). #922 reordered all three on 1.7; DR-99 ported onlywatch(). All three now prune before ingest, with a call-order and policy-retention test for each, a zero-container guard test on the snapshot and watch paths, and an audit-subscription test that the lifecycle row describes the surviving container.DR-105 (deterministic DashboardGrid resize spec) needed no commit: 1.6's spec is already byte-identical to the #976 version and passes three runs in a row.
AgentClient.ts 100% on all four metrics; 401 files / 12871 tests, coverage 100% globally, biome and build clean.