← Back to Pull requests

Stop outdated and orphaned sync controllers #211

Open
unknown opened this pull request with 467 lines diff across 5 files
View on GitHub
unknown unknown commented on Nov 28, 2026 13:29 UTC
Author

Summary

The sync manager records sync controllers by the UID and resourceVersion of their
PublishedResource. Any change to a PublishedResource therefore started a second controller next to
the existing one, and both kept reconciling the same objects (#182). The same applies when the
change is the one that should stop the controller: setting the deletionTimestamp or
spec.synchronization.enabled: false produces a new resourceVersion, so cleanupController looked
for the new key and did not find the running controller. And since PublishedResources have no
finalizer, a deleted PublishedResource only shows up as NotFound in Reconcile, which was ignored,
so its controller was never stopped.

This change records controllers per PublishedResource name, together with the key they were
created for:

  • If the key differs from the recorded one, a new controller is created and started, and only

  • after a successful start it is recorded and the outdated one is stopped. If the start fails, the
    outdated controller keeps running and the reconcile is retried with backoff.
  • cleanupController looks up the controller by name, so disabling sync and setting the

  • deletionTimestamp stop it.
  • A NotFound in Reconcile stops the controller of the deleted PublishedResource.

  • A PublishedResource that no longer matches --published-resource-selector stops its

  • controller. The watch predicate lets an update through if the old or the new labels match, so
    the relabelling is reconciled once, but Reconcile did not check the selector itself.

    Assumptions and limits:

  • The outdated controller is cancelled, not drained. Both controllers run side by side from the

  • new one's start until it is pre-seeded and the old one is cancelled; after that only in-flight
    reconciles of the old one can overlap with the new one. The issue suggests draining first; I
    kept the change small. Happy to add a drain step if you prefer.
  • A start that fails asynchronously (e.g. a cache sync timeout after StartController returned)

  • is not detected here; that is #190, addressed by #201. Until #201 lands, such a failure of the
    successor leaves the PublishedResource without a controller, because the outdated one has
    already been cancelled (on main it would keep running).

    Design note: when the replacement controller fails to start (probe error, resource not bound yet,
    create error, pre-seed error), the outdated controller keeps running until a successor has started.
    This favours availability; the start-error path is covered by
    TestFailedStartKeepsOutdatedController. For spec changes (new
    generation or schema) you may prefer stopping the outdated controller first; happy to change that.

    Unit tests cover the replacement, a failed start of the successor, deletion (NotFound), the
    deletionTimestamp case and a PublishedResource that no longer matches the selector. Tested with go test -race ./..., make lint and make test-e2e (kcp 0.32).

    Overlap with open PRs: #191 and #201 change the same map and functions in the sync manager. They do
    not fix this issue, but the code conflicts; whichever lands first, I will rebase this PR onto it.
    This PR already includes #191's behaviour (a controller is recorded only after a successful
    start); if #191 lands first I will rebase onto its startAndRecord helper. Draining the old controller before the new one starts could be a follow-up on top of
    #201, which adds an exit signal for sync controllers.

    What Type of PR Is This?

    /kind bug

    Related Issue(s)

    Fixes #182

    Release Notes

    ``release-note
    Fix outdated sync controllers continuing to run after a PublishedResource is updated, disabled, deleted or no longer matches the PublishedResource selector.
    ``

    Diff: 467 lines (+350 / -117) across 5 files Reviewer: neolit123 Review duration: 2918m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.46) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.46 · 467 lines diff across 5 files
    0.46
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.368
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #211"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 45.6% (MEDIUM) · Higher = larger blast radius
    45.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 24.3% · Safe to merge
    24.3%