Skip to content

fix(agent): keep update policy across agent moves and reconnect recreates (1.6) - #1036

Merged
scttbnsn merged 2 commits into
dev/v1.6from
fix/v1.6-agent-policy-and-prune-order
Sep 5, 2026
Merged

scttbnsn merged 2 commits into
dev/v1.6from
fix/v1.6-agent-policy-and-prune-order

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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, and registerWatchers uses allSettled so a late success cannot land after the prune). This also closes the Promise.all race 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 only deleteContainer(id, { replacementExpected: true }) writes it, but _doHandshake(), handleWatcherSnapshotEvent() and handleContainerSync() in AgentClient all 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 only watch(). 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.

… 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.
@vercel

vercel Bot commented Sep 5, 2026

Copy link
Copy Markdown

Deployment failed for project drydock-website with the following error:

Resource is limited - try again in 24 hours (more than 100, code: "api-deployments-free-per-day").

Learn More: https://vercel.com/codeswhat?upgradeToPro=build-rate-limit

@coderabbitai

coderabbitai Bot commented Sep 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 21 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 8039828f-4822-4c9b-a716-c5a0fff30406

📥 Commits

Reviewing files that changed from the base of the PR and between d52615f and 09122cf.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (11)
  • app/agent/AgentClient.container-reconcile.test.ts
  • app/agent/AgentClient.ts
  • app/event/audit-subscriptions.test.ts
  • app/model/container.test.ts
  • app/model/container.ts
  • app/registry/index.test.ts
  • app/registry/index.ts
  • app/store/container.test.ts
  • app/store/container.ts
  • content/docs/current/configuration/agents/index.mdx
  • content/docs/current/configuration/watchers/index.mdx

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 Sep 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@biggest-littlest biggest-littlest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ALARGECOMPANY left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@scttbnsn
scttbnsn merged commit d530ab8 into dev/v1.6 Sep 5, 2026
30 of 33 checks passed
@scttbnsn
scttbnsn deleted the fix/v1.6-agent-policy-and-prune-order branch September 5, 2026 02:38
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.

3 participants