From 56405b17141d7dd4c2b9f3df689c12ce699235a1 Mon Sep 17 00:00:00 2001 From: mikemikimike <13286568797@163.com> Date: Sun, 23 Aug 2026 16:32:20 +0800 Subject: [PATCH 1/2] fix(storage): clear obsolete onboarding intent Generated-by: Codex --- .../__tests__/runtime-policy-stores.test.ts | 44 +++++++++++++++++++ .../storage/src/runtime-policy/coordinator.ts | 13 ++++++ 2 files changed, 57 insertions(+) diff --git a/packages/storage/src/__tests__/runtime-policy-stores.test.ts b/packages/storage/src/__tests__/runtime-policy-stores.test.ts index f0d695967d..655effe6eb 100644 --- a/packages/storage/src/__tests__/runtime-policy-stores.test.ts +++ b/packages/storage/src/__tests__/runtime-policy-stores.test.ts @@ -3331,6 +3331,50 @@ describe('runtime policy stores', () => { }); }); + test('clears a stale onboarding intent when its connection id conflicts with the catalog', async () => { + await withInteractiveRoot(async ({ root, capability }) => { + const owner = await tryAcquireInteractiveRootOwner(capability); + assert.ok(owner); + if (!owner) return; + try { + const stores = await openInteractiveRuntimePolicyStoresForWrite(owner.lease); + const connection = await createConnection( + stores, + 0, + connectionDraft('openai', 'openai', 'Stale onboarding'), + ); + await writeFile( + join(root, 'runtime-policy-onboarding.json'), + `${JSON.stringify({ + schemaVersion: 1, + connectionId: '11111111-1111-4111-8111-111111111111', + providerType: connection.providerType, + suppliedSecret: null, + enabledModelIds: connection.enabledModelIds, + discovery: { + models: [{ id: 'gpt-5' }], + source: 'fetched', + fetchedAt: 1_800_000_000_000, + }, + invalidateLastTest: false, + })}\n`, + ); + } finally { + await owner.close(); + } + + const successor = await tryAcquireInteractiveRootOwner(capability); + assert.ok(successor); + if (!successor) return; + try { + await openInteractiveRuntimePolicyStoresForWrite(successor.lease); + assert.equal(existsSync(join(root, 'runtime-policy-onboarding.json')), false); + } finally { + await successor.close(); + } + }); + }); + test('interactive OAuth login commits only against its frozen connection and credential basis', async () => { await withInteractiveOwner(async ({ root, stores }) => { const claude = await createConnection( diff --git a/packages/storage/src/runtime-policy/coordinator.ts b/packages/storage/src/runtime-policy/coordinator.ts index e3b541c736..f0be29e378 100644 --- a/packages/storage/src/runtime-policy/coordinator.ts +++ b/packages/storage/src/runtime-policy/coordinator.ts @@ -1326,6 +1326,11 @@ export class RuntimePolicyCoordinator { await clearConnectionOnboardingIntent(root); this.onboardingRecoveryRequired = false; } catch (error) { + if (isObsoleteConnectionOnboardingIntent(error)) { + await clearConnectionOnboardingIntent(root); + this.onboardingRecoveryRequired = false; + return; + } if (isCommitOutcomeUnknown(error)) throw error; throw commitOutcomeUnknown('Connection onboarding recovery did not converge', error); } @@ -1391,6 +1396,14 @@ function isCommitOutcomeUnknown(error: unknown): error is RuntimePolicyStoreErro return error instanceof RuntimePolicyStoreError && error.code === 'commit_outcome_unknown'; } +function isObsoleteConnectionOnboardingIntent(error: unknown): boolean { + return ( + error instanceof RuntimePolicyStoreError && + error.code === 'invalid_document' && + error.message === 'Onboarding intent conflicts with the connection id' + ); +} + function commonSemanticConnectionBasis( prepared: PreparedConnectionMaterial, ): CommonSemanticConnectionBasis { From bdc1d702dc34b254748cbfac4a38dbd6a2cb0c86 Mon Sep 17 00:00:00 2001 From: mikemikimike <13286568797@163.com> Date: Sun, 23 Aug 2026 16:37:37 +0800 Subject: [PATCH 2/2] test(storage): verify stale onboarding cleanup persists Generated-by: Codex --- .../src/__tests__/runtime-policy-stores.test.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/packages/storage/src/__tests__/runtime-policy-stores.test.ts b/packages/storage/src/__tests__/runtime-policy-stores.test.ts index 655effe6eb..446de15a7a 100644 --- a/packages/storage/src/__tests__/runtime-policy-stores.test.ts +++ b/packages/storage/src/__tests__/runtime-policy-stores.test.ts @@ -3372,6 +3372,16 @@ describe('runtime policy stores', () => { } finally { await successor.close(); } + + const reopened = await tryAcquireInteractiveRootOwner(capability); + assert.ok(reopened); + if (!reopened) return; + try { + await openInteractiveRuntimePolicyStoresForWrite(reopened.lease); + assert.equal(existsSync(join(root, 'runtime-policy-onboarding.json')), false); + } finally { + await reopened.close(); + } }); });