Skip to content

Fix cloned background service failing to load - #12973

Closed
kvnloo wants to merge 1 commit into
omacom:quattrofrom
kvnloo:fix/12959-background-plugin-clone
Closed

kvnloo wants to merge 1 commit into
omacom:quattrofrom
kvnloo:fix/12959-background-plugin-clone

Conversation

@kvnloo

@kvnloo kvnloo commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

What

Fixes the cloned "omarchy.background" service load path without widening the plugin trust boundary.

  • Service entry points load asynchronously, matching the path already used for asynchronously loaded shell components.
  • "omarchy-plugin-clone" verifies that every declared entry point exists in the completed clone, copying a missing entry point from the built-in source when necessary.
  • In-flight service compilation is now claimed per plugin before it starts, so repeated registry synchronization cannot launch duplicate instances.
  • A completing async load must still own the current claim, refer to the current manifest and entry-point URL, and still be enabled before it may publish an instance.
  • Third-party and cloned services remain detached from "serviceHost". "manifest.omarchy.clonedFrom" is descriptive plugin metadata, not host authorization.

Why

"omarchy plugin clone omarchy.background" could leave an enabled clone whose "Background.qml" failed to load with a spurious "No such file or directory".

The first version switched service loading to "Component.Asynchronous", but review found two additional problems:

  1. two "_syncServices()" passes while compilation was pending could each start a load and create duplicate service instances;
  2. treating a manifest-authored "clonedFrom: "omarchy.*"" value as permission to parent under "serviceHost" allowed third-party metadata to widen access to the host QObject tree.

This revision keeps the async loading fix while closing both ownership boundaries.

Invariants

A logical service ID may have at most one current in-flight load.

A late asynchronous callback may publish only if it still owns that service ID and the plugin is still the same enabled service with the same entry point.

Plugin-authored clone metadata cannot grant host-tree access.

Tests

"plugin-clone-test.sh" covers the cloned background artifact:

  • "Background.qml" exists after cloning;
  • the service entry point named by the cloned manifest exists;
  • cloned identity and "clonedFrom" metadata remain intact.

"plugin-auth-boundary-test.sh" now covers:

  • third-party/cloned/authentication services remain detached from the host object tree;
  • current enabled service-load claim may publish;
  • superseded claim cannot publish;
  • replaced manifest invalidates a pending claim;
  • changed entry point invalidates a pending claim;
  • disabled service invalidates a pending claim;
  • loader source wiring records the pending claim before publication and revalidates it on completion.

Verification status

Rebuilt as one commit on current "quattro" ("28ceaae7").

Executable Quickshell/Wayland verification has not been rerun from this environment, so the original live cloned-background symptom remains the final integration check.

Fixes #12959.

@llstrk

llstrk commented Sep 23, 2026

Copy link
Copy Markdown

Two service-loader issues were found at 2ff6664c: duplicate instances during asynchronous loading, and manifest-controlled access to the host object tree.

Track pending service loads before starting another

In ensureService(), a Loading component leaves no pending marker. A registry scan emits pluginsChanged() and then scanFinished(), both of which can call _syncServices() before compilation finishes:

first sync  -> start load A -> service map still empty
second sync -> start load B -> service map still empty
Ready A/B   -> create twice -> map retains only the last instance
                              earlier host-parented instance remains alive

Verified: With the extracted base/head loader in Quickshell 0.3.1, synthetic services and a modeled two-sync scan completion, four services produced four instances on base and eight on head. The head retained both instances of each first-party service under serviceHost.

Impact: Repeated synchronization during compilation can leave duplicate service objects outside lifecycle cleanup. For the background service, that risks duplicate surfaces and work; actual desktop surfaces were not tested. A late callback also does not recheck whether the plugin was disabled or replaced while loading.

Suggested change: Claim each pending service ID before starting compilation, as loadPluginWidget() already does. Invalidate pending loads on disable/reload, and verify the current manifest, enabled state and load generation before creating or publishing an instance. Clear the pending claim on success and error.

Do not grant host parenting from a self-declared clone name

The new attachment rule accepts any omarchy.clonedFrom starting with omarchy., including a nonexistent source. A third-party manifest can supply that field without passing through the clone command.

Verified: In the same synthetic QML check:

Third-party service Base Head
No clone metadata Detached Detached
clonedFrom: "omarchy.not-a-real-plugin" Detached Parented to serviceHost; reached the host shell through a first-party sibling's shell property

Impact: A service can bypass its scoped shell facade through the shared object tree. This is a service API-boundary regression, not a demonstrated credential leak or same-process sandbox escape: authentication services remain detached, and plugin code is already unsandboxed.

Suggested change: Keep third-party services detached unless the required integration can be granted through host-controlled state or a narrow API. A user-editable clone-name prefix is not provenance. The reported component-load error occurs before createObject(), so parenting alone does not explain that error.


Review information

Test scope: Source review and isolated offscreen Quickshell checks using the extracted production loader, synthetic services and modeled registry callbacks. No Wayland compositor, real background surface, or original No such file or directory reproduction was tested; an end-to-end fix for that symptom remains unverified.

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Automated AI review: Astra Medium performed initial inspection and synthesis; Opus 5.5 High and GPT 6 Sol Xhigh completed independent technical assessments. Claims were checked against source and targeted evidence, followed by a fresh Astra Medium editorial check.

@sanjyay

sanjyay commented Sep 23, 2026

Copy link
Copy Markdown
Contributor

Tested in the Omarchy VM running Omarchy 4.0.4-1 with Quickshell 0.3.1:

While ensure_entry_points in omarchy-plugin-clone resolves missing entry point files when cloning, testing the changes to ensureService() in Quickshell reveals two issues:

1. Duplicate service instances created during asynchronous compilation

In shell/shell.qml, switching Qt.createComponent(url, Component.PreferSynchronous) to Component.Asynchronous introduces an in-flight race. Because _services[key] is only populated once finalize() runs after compilation, multiple _syncServices() passes (such as pluginsChanged followed by scanFinished on startup) see !_services[key] and invoke ensureService(key) again while compilation is still in Component.Loading.

In the Omarchy VM, simulating back-to-back _syncServices() calls during compilation confirms that multiple component instances are compiled and instantiated, resulting in duplicate active instances parented to serviceHost.

Suggested fix:
Track in-flight service loads with a pending map (mirroring how loadPluginWidget() records { url: url, component: null } in pluginWidgetComponents before kicking off async compilation). In finalize(), verify that the service was not already populated and is still enabled before calling createObject(), and clear the pending entry.

2. Self-declared clonedFrom metadata attaches arbitrary third-party services to serviceHost

In ensureService():

var attachToHost = !authenticationService
  && (!!manifest.__isFirstParty || clonedFrom.indexOf("omarchy.") === 0)
var inst = comp.createObject(attachToHost ? serviceHost : null)

Because clonedFrom is read directly from manifest.omarchy.clonedFrom, any untrusted third-party plugin can declare "omarchy": { "clonedFrom": "omarchy.background" } in its manifest.json. This causes attachToHost to evaluate to true, parenting the third-party service directly to serviceHost and allowing it to traverse the host QObject hierarchy.

Suggested fix:
Do not rely solely on manifest-authored clonedFrom strings for parenting privileges. Provenance should be tracked through host-controlled state (or third-party services should remain detached, providing necessary desktop capabilities through explicit scoped facades).

@kvnloo
kvnloo force-pushed the fix/12959-background-plugin-clone branch from 2ff6664 to 2c1c92a Compare September 23, 2026 22:52
@kvnloo

kvnloo commented Sep 23, 2026

Copy link
Copy Markdown
Contributor Author

Updated at "2c1c92a5" on current "quattro".

Addressed both review findings.

Async service loads now take a per-plugin pending claim before compilation. A second sync cannot start another copy, and the completion callback only publishes if it still owns that claim, the same manifest/entry-point is current, and the service is still enabled. Disable/remove/reload invalidates stale claims.

I also removed the "clonedFrom" host-parenting exception. Cloned/third-party services are detached again; only first-party non-auth services may be parented to "serviceHost". "clonedFrom" remains descriptive/routing metadata, not trust provenance.

The cloned-background entry-point repair remains: clone completion verifies every declared entry point exists and restores a missing one from the built-in source.

Added behavioral claim tests for current, superseded, replaced-manifest, changed-URL, and disabled-service cases.

Branch is one commit ahead / zero behind current "quattro".

Executable Quickshell/Wayland validation still pending.

@llstrk

llstrk commented Sep 24, 2026

Copy link
Copy Markdown

Automated AI review

Community review: Independent automated community review, unaffiliated with the Omarchy team, intended to help prepare PRs for their review.

Follow-up to the earlier review of 2ff6664c, checked at 2c1c92a5 in response to the author's update. Verified: both earlier findings are resolved. Separately, the linked issue's symptom (#12959) is not shown to be fixed by this revision.

Earlier finding At 2c1c92a5
Duplicate service instances during asynchronous loading Resolved
Host parenting granted by a self-declared clonedFrom name Resolved

Verified: In an offscreen Quickshell 0.3.1 check using the extracted loader from each revision and synthetic services:

                                   2ff6664c (earlier)        2c1c92a5 (current)
two syncs while compiling          2 instances per service   1 instance per service
disabled or removed while loading  instance published        not published
clone / fake-clone service parent  serviceHost               detached (same as base)

Re-enable, rescans with replaced manifests, a changed entry point, reload, load errors and a createObject() failure also ended with one instance or none, and no stuck pending claim. In the same offscreen check, a detached service shaped like Background.qml still created its window; a real Wayland layer surface was not tested.

The linked issue's symptom is not shown to be fixed

In the same synthetic check, a service whose entry file was missing on its first load logged service plugin load failed for <id>: file:///<plugin dir>/Service.qml: No such file or directory. After the file was created, the next sync logged the same error again. This occurred on base, the earlier head and the current head:

first load, file absent   -> Qt caches the failed load for that URL
file created              -> later createComponent(url), either mode -> same cached error
shell plugin reload       -> Qt.clearComponentCache is undefined in QML, cache kept

In Qt 6.11.2 source, the missing-file check and the per-URL cache of the failed load are the same for Component.Asynchronous and Component.PreferSynchronous. The cache-clear guard in finishPluginReload() never runs, because Qt.clearComponentCache is not a QML method (it is on the C++ QQmlEngine). For omarchy.background, the clone command already copies the whole plugin directory, so the new ensure_entry_points() check does not change that clone.

Impact: The issue's report (the error repeating while Background.qml exists, and the original plugin still working) matches a cached failed load for the clone's URL, which neither the asynchronous switch nor the clone check affects. What made the file unavailable at the first load was not determined, so Fixes #12959 is not supported by the evidence found.

Suggested change: Reproduce the clone in a real Quickshell session, logging the first load's resolved URL and whether the file is visible at that moment, and identify that trigger before relying on Fixes #12959. If a cached failed load is confirmed, recovery needs a new cache key or a fresh engine (for example a full shell restart) rather than another createComponent() call on the same URL; these options were not tested.

Optional test improvement: The new loader coverage checks the pure claimCurrent() helper and source regexes, not ensureService() or _syncServices() behavior. The new background clone assertions also pass against the base clone command, so they do not detect this PR's change. A behavioral loader test driving repeated syncs and disable/reload during compilation would cover the new claim logic.

Optional: finalize() clears the pending claim right after createObject(), before shell and other properties are injected and before the instance is stored. In the synthetic check, a service whose property-change handler triggered a sync during injection produced a second instance on all three revisions, so this is pre-existing, and no current built-in service has such a handler. Clearing the claim after publication (for example in a try/finally) would close that window.


Review information

Test scope: Source review of the current head, Qt 6.11.2 and Quickshell 0.3.1 source, plus isolated offscreen Quickshell 0.3.1 checks using the extracted production loader from base, 2ff6664c and 2c1c92a5 with synthetic services and modeled registry events. The repository's clone and auth-boundary tests were run without a compositor, so the auth test's runtime section was skipped. No Wayland compositor, real background layer surface, live clone of omarchy.background or original issue trigger was tested.

AI process: Opus 5.5 Medium coordination and synthesis; independent Opus 5.5 Xhigh and GPT 6 Sol Xhigh technical assessments, with targeted follow-up questions; Opus 5.5 Medium editorial check.

Opt out: To stop receiving these reviews, reply to this comment saying so.

@omarchybot

Copy link
Copy Markdown
Collaborator

Reviewed at 2c1c92a5. This doesn't fix #12959. The pending-load claims are useful, but older #11492 already proposes the same mechanism.

What ran, and where. An Omarchy ISO worker, with the shell serving the merge base 28ceaae7 and then this head:

  • A plain clone works on both base and head. omarchy plugin clone omarchy.background loads the clone's Background.qml and leaves one omarchy-background layer, with no load error. On base, the clone command already copies the whole plugin into a staging directory and renames it into place before the shell rescans. So ensure_entry_points() copies nothing for omarchy.background.
  • The issue's symptom reproduces on base, and is unchanged on this head. If the shell's first load of a clone's Background.qml happens while the file is absent, service plugin load failed ... Background.qml: No such file or directory keeps repeating after the file is back. Disabling and re-enabling the plugin and rescanning don't clear it. This head logs exactly the same, so switching to Component.Asynchronous doesn't change it. Restarting the shell clears it.
  • Fix hot reload of local plugins by busting the component cache #13911's cache-busting URL doesn't clear it either. Running the same steps on that branch, the error becomes Background.qml?v=3: File name case mismatch. That suggests Qt also caches what it saw in the plugin's directory, so a new query string isn't enough. We still don't know what made the file unavailable at first load on the reporter's machine. Until that trigger is found, Fixes #12959 isn't supported.
  • Tests on this head: plugin-clone-test.sh 20/20, plugin-auth-boundary-test.sh 19/19, and plugins-test.sh, plugin-enable-test.sh, installed-service-test.sh and plugin-registry-contract-test.sh all pass. ./test/cli has one failure, vscode generated theme references current theme file, which fails the same way on base. The new background assertions in plugin-clone-test.sh also pass against base's clone command, so they don't detect this change.

Overlap. The per-plugin pending claim and the revalidation before publishing are the mechanism #11492 (opened 2026-09-12) already proposes. The older one keeps it unless it is shown to miss a case.

Second opinion (Codex Medium). It agreed that neither the async switch nor the clone check affects a cached failed load, and that the new clone assertions pass on base. It may have read this review's working notes, so that agreement isn't independent. It also pointed out that finalize() clears the claim at shell/shell.qml:964 before injecting shell and publishing the instance. A service whose property handler starts a sync during that window can be created twice. The community review above saw the same window on base, so it predates this PR. The reviewer also expected #13911 to fix the cached case, which the worker run above contradicts.

Nothing was pushed. Waiting on the maintainer to decide what to do with this alongside #11492, and on finding the first-load trigger behind #12959.

@kvnloo

kvnloo commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing: a plain clone of omarchy.background already loads on base, so this does not fix #12959, and the pending-load claims are now on quattro via #19961 (0810fdb). Prepared by Claude Opus 5.5 via Hermes Agent; reviewed under kvnloo's account.

@kvnloo kvnloo closed this Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloning the omarchy.background service plugin fails to load (No such file or directory)

4 participants