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
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: preserve only persisted provider api keys
[._.]/ Adam Eivy3af4832d32a4
diff --git a/server/routes/providers.composite.test.js b/server/routes/providers.composite.test.jsindex a77df7a3f4..54e6fb5c59 100644--- a/server/routes/providers.composite.test.js+++ b/server/routes/providers.composite.test.js@@ -216,6 +216,36 @@ describe('POST /api/providers/:id/derive', () => {});describe('PUT /api/providers/:id on a derived preset', () => {+ it('does not treat a gateway wrapper\'s execution-only sibling key as a direct apiKey edit', async () => {+ const inherited = {+ ...DERIVED,+ id: 'opencode-nvidia-nim-tui',+ name: 'OpenCode NVIDIA NIM TUI',+ command: 'opencode',+ harnessId: 'opencode',+ serviceId: 'nvidia-nim',+ };+ Object.defineProperty(inherited, 'apiKey', { value: 'nim-key', enumerable: false, configurable: true });+ providerService.getProviderById.mockResolvedValue(inherited);+ presetService.materializeStoredPreset.mockImplementation(async (candidate, { updates }) => {+ if (Object.hasOwn(updates, 'apiKey')) {+ throw new ServerError(+ 'apiKey is derived from service "nvidia-nim"; edit the service instead',+ { status: 400, code: 'PRESET_FIELD_DERIVED', context: { fields: ['apiKey'], serviceId: 'nvidia-nim' } },+ );+ }+ return { ...candidate, rederived: true };+ });++ const res = await request(app()).put('/api/providers/opencode-nvidia-nim-tui').send({ effort: 'low' });++ expect(res.status).toBe(200);+ const [, { updates }] = presetService.materializeStoredPreset.mock.calls[0];+ expect(updates).toMatchObject({ effort: 'low' });+ expect(updates).not.toHaveProperty('apiKey');+ expect(providerService.updateProvider).toHaveBeenCalledWith('opencode-nvidia-nim-tui', expect.objectContaining({ rederived: true, effort: 'low' }));+ });+it('stores what the service re-derives from the merged record, with redacted secrets restored first', async () => {const res = await request(app()).put('/api/providers/pi-tui-nvidia-nim-free').send({ effort: 'low', envVars: { NVIDIA_API_KEY: '***' } });expect(res.status).toBe(200);diff --git a/server/routes/providers.js b/server/routes/providers.jsindex dfb899937b..3d0c788261 100644--- a/server/routes/providers.js+++ b/server/routes/providers.js@@ -1142,8 +1142,12 @@ export function createPortOSProviderRoutes(aiToolkit) {const updates = { ...validation.data };- // Preserve existing apiKey if client didn't send a new one- if (!('apiKey' in updates)) {+ // Preserve an actually persisted apiKey if the client didn't send a new+ // one. Gateway-backed CLI/TUI wrappers receive their sibling API key as a+ // non-enumerable, execution-only property; carrying that value into a+ // derived-preset update turns an inherited credential into a direct edit+ // and makes an otherwise harmless save fail with PRESET_FIELD_DERIVED.+ if (!('apiKey' in updates) && Object.prototype.propertyIsEnumerable.call(existing, 'apiKey')) {updates.apiKey = existing.apiKey;}