Skip to content

overlord/ifacestate: use state as source of truth in interface handlers - #17692

Open
bboozzoo wants to merge 7 commits into
canonical:masterfrom
bboozzoo:bboozzoo/repo-as-intermediate-state
Open

bboozzoo wants to merge 7 commits into
canonical:masterfrom
bboozzoo:bboozzoo/repo-as-intermediate-state

Conversation

@bboozzoo

@bboozzoo bboozzoo commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Use state information in connection task handlers, instead of the in-memory repository. The information returned by the interface repository may not correctly represent the actual connection state, if the task handlers were to be retried or exit early.

The changes from this patch are a prerequisite for supporting retries of task handlers in scenarios where an operation on a snap becomes temporarily impossible to execute, e.g. due to snap locks being held by other processes.

Cherry picked from #17587
Related: SNAPDENG-37471

Use state information in connection task handlers, instead of the
in-memory repository. The information returned by the interface
repository may not correctly represent the actual connection state,
if the task handlers were to be retried or exit early.

The changes from this patch are a prerequisite for supporting retries
of task handlers in scenarios where an operation on a snap becomes
temporarily impossible to execute, e.g. due to snap locks being held
by other processes.

Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

A disabled connection peer can have removed security profiles unintentionally recreated.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
What changed in this PR

Updates disconnect-related handlers to use durable connection state, improving retry safety.

Changes:

  • Derives affected snaps from persisted connections.
  • Tolerates already-disconnected repository entries during retries.
  • Adds retry regression tests and clarifies repository/state documentation.
File Description
overlord/​ifacestate/​handlers.go Makes disconnect and undo handling retry-tolerant.
overlord/​ifacestate/​ifacestate_test.go Adds retry and stale-connection tests.
overlord/​ifacestate/​ifacemgr.go Documents repository ephemerality.
overlord/​ifacestate/​helpers.go Clarifies persisted connection states.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread overlord/ifacestate/handlers.go
Comment thread overlord/ifacestate/ifacestate_test.go Outdated
Comment thread overlord/ifacestate/ifacestate_test.go
…t handlers

fixup! overlord/ifacestate: use state as source of truth in disconnect handlers

Fix no-op repo.Plug assertions in TestDoRemoveAlreadyDisconnectedInRepo
and TestDoRemoveIgnoresStaleUndesiredConn: consumer's plug is named
"plug", not "slot", so the lookup was nil regardless of whether the
snap had actually been removed from the repository.

Caught by Copilot PR review on canonical#17692.
…t handlers

fixup! overlord/ifacestate: use state as source of truth in disconnect handlers

Assert security is actually re-applied in
TestUndoConnectAlreadyDisconnectedInRepo, matching the sibling
TestUndoConnect. Previously only conns cleanup and task status were
checked, so an implementation that returned early from the tolerated
NotConnectedError branch (skipping the re-apply-security step) would
still have passed.

Caught by Copilot PR review on canonical#17692.
@codecov

codecov Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.25397% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.11%. Comparing base (4c50dda) to head (6159c8e).
⚠️ Report is 9 commits behind head on master.

Files with missing lines Patch % Lines
overlord/ifacestate/handlers.go 68.25% 15 Missing and 5 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #17692      +/-   ##
==========================================
+ Coverage   78.36%   79.11%   +0.74%     
==========================================
  Files        1415     1422       +7     
  Lines      200459   207768    +7309     
  Branches     2503     2503              
==========================================
+ Hits       157084   164369    +7285     
- Misses      33950    33970      +20     
- Partials     9425     9429       +4     
Flag Coverage Δ
unittests 79.11% <68.25%> (+0.74%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread overlord/ifacestate/handlers.go Outdated
task.Errorf("skipping security profiles setup for snap %q when handling snap %q: %v", affectedInstanceName, affectingSnap, err)
continue
}
if !snapst.Active {

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.

This might miss some cases where snapst.PendingSecurity is non-nil. Possibly something like:

if !snapst.Active &&
	(snapst.PendingSecurity == nil || snapst.PendingSecurity.SideInfo == nil) {
	continue
}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟡 Changes recommended

Inactive peers can have security profiles regenerated from the wrong revision instead of their pending-security state.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (3)

Comment thread overlord/ifacestate/handlers.go
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Wed Sep 23 06:05:07 UTC 2026
The following results are from: https://github.com/canonical/snapd/actions/runs/35742877665

Test Predictor Analysis

Preparing

Test Success %
openstack:ubuntu-20.04-64:tests/main/nss-modules:winbind 🟢 76.6%
openstack:ubuntu-core-24-64:tests/main/graphical-user-daemons 🟢 99.0%

Executing

Test Success %
openstack:debian-12-64:tests/main/snapshot-basic 🟡 60.7%
openstack:ubuntu-26.04-64:tests/main/snap-user-service 🟡 62.9%
openstack:ubuntu-core-18-64:tests/core/remodel-base 🟢 99.0%
openstack:ubuntu-core-18-64:tests/main/component-sideload 🟢 99.0%
openstack:ubuntu-core-24-64:tests/main/snap-services 🔴 20.7%

Restoring

Test Success %
openstack:ubuntu-24.04-64:tests/main/snapd-reexec:core 🟢 77.1%
openstack:ubuntu-core-18-64:tests/core/ 🟢 99.0%
openstack:ubuntu-core-18-64:tests/core/remodel-base 🟢 99.0%

Skipped tests from snapd-testing-skip

If you wish to have any of the below tests run in your PR, in your PR description, add 'unskip:' followed by a copy-and-pasted list of the below tests you wish to run (unskip plus test list must be valid yaml)

  • openstack:arch-linux-64:tests/main/interfaces-location-control
  • openstack:debian-12-64:tests/main/interfaces-location-control
  • openstack:ubuntu-20.04-64:tests/main/interfaces-location-control
  • openstack:ubuntu-24.04-64:tests/main/auto-refresh-retry
  • openstack:ubuntu-24.04-64:tests/main/i18n
  • openstack:ubuntu-24.04-64:tests/main/interfaces-location-control
  • openstack:ubuntu-24.04-64:tests/main/network-retry
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-flag-restart
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-integration-tests
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-prompt-restoration
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-smoke
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-snapd-startup
  • openstack:ubuntu-26.04-64:tests/main/apparmor-prompting-support
  • openstack:ubuntu-26.04-64:tests/main/interfaces-location-control
  • openstack:ubuntu-26.04-64:tests/main/interfaces-requests-activates-handlers

…t handlers

fixup! overlord/ifacestate: use state as source of truth in disconnect handlers

Drop TestDoRemoveStillUpdatesMidRefreshPeer: it was a strict subset of
TestDoRemoveMidRefreshPeerUsesPendingRevision (both assert the peer is
not skipped; only the latter also asserts the correct pending revision
is used, and with Current == PendingSecurity.SideInfo it could not have
caught a wrong-revision regression anyway).

TestDoRemoveMidRefreshPeerUsesPendingRevision now establishes
PendingSecurity via the real OnSnapLinkageChanged hook first (matching
production wiring) before pinning it forward to a distinct revision,
so it covers both properties in one, higher-fidelity test.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

The retry paths are handled consistently and covered by focused regression tests.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@bboozzoo

Copy link
Copy Markdown
Contributor Author

The PR had a bit of scope creep during as reviews as preexisting issues with components and security profiles for mid-refresh snaps. All of this has been addressed.

@bboozzoo bboozzoo changed the title overlord/ifacestate: use state as source of truth in disconnect handlers overlord/ifacestate: use state as source of truth in interface handlers Sep 24, 2026

This branch has not been deployed

No deployments
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