Skip to content

Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS

refuse a mode-sibling fill when the two modes name disjoint halves of a connection

[._.]/ Adam Eivyd322a994701d
diff --git a/server/lib/aiToolkit/internal/providerModes.js b/server/lib/aiToolkit/internal/providerModes.js
index 7e53adaa9d..bf9d1ba6a9 100644
--- a/server/lib/aiToolkit/internal/providerModes.js
+++ b/server/lib/aiToolkit/internal/providerModes.js
@@ -88,13 +88,21 @@ export function sharedModeUpdates(updates, sibling) {
* once (an endpoint AND its API key) disagrees on two. Only this fill uses the
* loose grouping; the enablement/model convergence below keeps the strict one.
*
- * Only a pair that is INCOMPLETE is repaired, never one that CONTRADICTS: a key
- * two modes both name with different values is a deliberate configuration (two
- * connections that happen to share a command), and picking a winner between two
- * endpoints or two credentials is nobody's call to make silently. One
- * contradiction disqualifies the whole group rather than just that key —
- * filling an API key across a pair that already points at two different
- * backends would send the credential somewhere it was never entered for.
+ * Only a pair that is INCOMPLETE is repaired: ONE mode holds the connection and
+ * the other holds nothing of it. Two conditions enforce that, and either one
+ * failing disqualifies the whole group rather than just the offending key.
+ *
+ * It must not CONTRADICT — a key two modes both name with different values is a
+ * deliberate configuration (two connections that happen to share a command),
+ * and picking a winner between two endpoints or two credentials is nobody's
+ * call to make silently.
+ *
+ * And every fill must come from the SAME donor mode. Two modes naming DISJOINT
+ * halves of a connection contradict nowhere, so the check above waves them
+ * through — yet merging them mints a hybrid neither record described: a CLI
+ * mode holding only an API key beside a TUI mode holding only an endpoint would
+ * hand that credential to a backend it was never entered for. One donor is what
+ * "the editor wrote one mode and the sibling never got it" actually looks like.
*/
function fillModeSiblingIdentity(providers) {
const byId = new Map(providers.map(provider => [provider.id, provider]));
@@ -105,8 +113,9 @@ function fillModeSiblingIdentity(providers) {
const modes = group.map(({ id }) => byId.get(id)).filter(Boolean);
const namers = MODE_GROUPED_KEYS.map(key => [key, modes.filter(mode => namesModeValue(mode, key))]);
if (namers.some(([key, named]) => named.some(mode => !isDeepStrictEqual(mode[key], named[0][key])))) continue;
- for (const [key, named] of namers) {
- if (named.length !== 1) continue;
+ const fills = namers.filter(([, named]) => named.length === 1);
+ if (new Set(fills.map(([, named]) => named[0].id)).size > 1) continue;
+ for (const [key, named] of fills) {
for (const mode of modes) {
if (namesModeValue(mode, key)) continue;
mode[key] = detachModeValue(named[0][key]);
diff --git a/server/lib/aiToolkit/providers.test.js b/server/lib/aiToolkit/providers.test.js
index 00e33b9b14..ecfdd65291 100644
--- a/server/lib/aiToolkit/providers.test.js
+++ b/server/lib/aiToolkit/providers.test.js
@@ -177,9 +177,17 @@ describe('Provider Service', () => {
// endpoint, so the key one of them names must not be handed to the other.
other: { id: 'other', name: 'Other CLI', type: 'cli', command: 'other', enabled: true, models: ['a'], endpoint: 'https://one.example.com', apiKey: 'secret' },
'other-tui': { id: 'other-tui', name: 'Other TUI', type: 'tui', command: 'other', enabled: true, models: ['a'], endpoint: 'https://two.example.com' },
+ // DISJOINT halves contradict nowhere — no key is named twice — but each
+ // mode is the sole namer of a different one. Merging would mint a hybrid
+ // neither record described and hand the CLI's credential to a backend it
+ // was never entered for, so one donor mode is required.
+ halves: { id: 'halves', name: 'Halves CLI', type: 'cli', command: 'halves', enabled: true, models: ['a'], apiKey: 'sk-private' },
+ 'halves-tui': { id: 'halves-tui', name: 'Halves TUI', type: 'tui', command: 'halves', enabled: true, models: ['a'], endpoint: 'https://elsewhere.example.com' },
} }));
expect(await providerService.getProviderById('example-tui')).toMatchObject({ endpoint: 'https://api.example.com', apiKey: 'k' });
expect(await providerService.getProviderById('other-tui')).not.toHaveProperty('apiKey');
+ expect(await providerService.getProviderById('halves-tui')).not.toHaveProperty('apiKey');
+ expect(await providerService.getProviderById('halves')).not.toHaveProperty('endpoint');
});
it.skipIf(process.platform === 'win32')('refreshes Pi models and distinguishes authentication from probe failure', async () => {