From 41e59768977f9f538f814beef353a50dc620010e Mon Sep 17 00:00:00 2001 From: Agent Workbench Dev Date: Thu, 12 Nov 2026 09:27:08 +0800 Subject: [PATCH] fix(credentials): save resident keys without replacing live credentials --- AGENTS.md | 2 +- docs/CREDENTIAL-PERSISTENCE-1.25.14-PLAN.md | 6 +++++- docs/QA-CREDENTIAL-PERSISTENCE-1.25.14.md | 5 ++++- scripts/retained-host-state.mjs | 14 +++++++++++- scripts/verify-credential-persistence.mjs | 17 ++++++++++----- scripts/verify-previous-patch-install.mjs | 21 +++++++++++++++++- src/client/ModelCenter.tsx | 5 +++++ src/core/models/credential-vault.mjs | 2 +- src/core/models/model-hub.mjs | 9 +++++++- tests/credential-defaults.test.mjs | 24 +++++++++++++++++++++ 10 files changed, 93 insertions(+), 12 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index ec34891f..281d8807 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -1,6 +1,6 @@ # Agent Workbench项目执行规范 -2026-11-12 用户指出重启丢 Key,本轮按授权修复正常配置默认临时的问题:Windows 手填/目录/确认导入默认 DPAPI,旧配置接口原子保存,显式临时/清除不复活旧副本,普通编辑和同源模型保持。见[计划](docs/CREDENTIAL-PERSISTENCE-1.25.14-PLAN.md)和[验收](docs/QA-CREDENTIAL-PERSISTENCE-1.25.14.md)。52相关/最后旧配置3项、最终构建和实际Edge8步/真实新进程恢复鉴权通过;所有首失败及211117e0两项虚拟目录基线失败保留,相关目录守卫已修。当前1.25.14源码限定提交/程序包/实际安装与正式更新收尾中;正式原数据入口仍4318/1.25.13/PID14388,不读取或重存真实Key,不续旧样本/真实请求/Purge,不委派。原M4/Claude403/unknown/历史封存和未验边界保持,既有GitAtlas增量推送授权有效。下方只读协调“不查正式/不写代码”是原时点,不覆盖本轮明确修复授权。 +2026-11-12 用户指出重启丢 Key,本轮按授权修复正常配置默认临时的问题:Windows 手填/目录/确认导入默认 DPAPI,旧配置接口原子保存,显式临时/清除不复活旧副本,普通编辑和同源模型保持。见[计划](docs/CREDENTIAL-PERSISTENCE-1.25.14-PLAN.md)和[验收](docs/QA-CREDENTIAL-PERSISTENCE-1.25.14.md)。首源码5b51151f/首候选保留;新增“保存当前 Key”由工作台内部明确加密,不向工具回传Key、不改变原对象和凭据修订,合成2项和实际Edge9步/真实新进程恢复鉴权通过。最新公开核对正式4318/1.25.13/PID14388七条Key均已有有效加密副本,因此保留原副本、不重新加密;完成最终候选/隔离安装后保留PID升级,全部保存状态复核后才正式重启。工具不读取/复制Key,不续旧样本/真实请求/Purge,不委派。原首失败/虚拟目录基线/M4/Claude403/unknown和未验边界保持,既有GitAtlas增量推送授权有效。下方旧只读/不重存说明是原时点,不覆盖本轮明确修复授权。 2026-11-12 新协调来源只读登记在[同Goal工件连接记录](docs/integration/MNEMO-GOAL-WORKER-READONLY-2026-11-12.md):Mnemo指定旧AG42aacbd1/b330b966有限连接/显式complete已过,113=19+94、独立69及31隔离HTTP仅按来源回执范围,原9/build/57未重跑,本增量模型0;4321原观察404、未载入,生产者/完整指纹/派发接收/父交付/语义未验。AD与M4三工程分别登记,旧AG异常/Purge未验和Claude现有两403/unknown及541/41封存不改签。本消息不请求新执行或源线程回复;本次不读Key、不查正式服务、不重跑/重派或新增Claude/Purge,仅本地登记来源,后续开发阶段再按既有授权增量推送。 diff --git a/docs/CREDENTIAL-PERSISTENCE-1.25.14-PLAN.md b/docs/CREDENTIAL-PERSISTENCE-1.25.14-PLAN.md index 944f6b04..557c083c 100644 --- a/docs/CREDENTIAL-PERSISTENCE-1.25.14-PLAN.md +++ b/docs/CREDENTIAL-PERSISTENCE-1.25.14-PLAN.md @@ -13,6 +13,10 @@ - 先保留当前源码的复现失败,再执行针对性回归、构建、网页/桌面与 390px 核对,使用合成 Key 运行安装包的真实 Windows DPAPI、退出/新进程恢复和本机兼容服务鉴权。 - 按阶段审查并限定提交;发行 1.25.14 源码、程序及安装器,隔离验证后更新正式服务,按既有 GitAtlas 授权增量推送。 -不读取、复制或重存用户真实 Key,不向聊天或日志输出凭据。已经退出且没有加密副本的旧内存 Key 无法恢复,修复后需要由用户在模型中心填写一次。使用原正式数据目录,历史原文、失败、unknown、重复读取及 Purge 未验证结论保持;本轮不请求真实供应商、续旧任务或推进新的 Purge 实验。 +工具不读取、复制或回传真实 Key,不向聊天或日志输出凭据。已经退出且没有加密副本的旧内存 Key 无法恢复。使用原正式数据目录,历史原文、失败、unknown、重复读取及 Purge 未验证结论保持;本轮不请求真实供应商、续旧任务或推进新的 Purge 实验。 + +首源码提交/首候选包后公开核对发现用户已重新补填七条 Key,原 PID14388 保持。按本轮修复授权增加“保存当前 Key”:工作台在自身进程内加密当前凭据,调用方只传连接 ID/修订并收到状态,原 Key 对象和凭据修订不改变。先用合成凭据验证,再由新处理器在保留原宿主的升级后保存当前七条连接,全部成功才正式重启,不要求用户再次填写。首候选包保留,新增能力需另冻最终候选并复验。 + +后续 `18-formal-status.json` 公开复核:七条连接都已有有效 DPAPI 副本,连接登记193、请求仍420、原PID/instance保持且空闲。因此正式升级和重启保留原加密副本,不再次保存或加密;“保存当前 Key”通过合成旧版本保留进程升级及新进程恢复验证。正式操作前再次冻结最新公开状态,任何未保存/来源失配不得先停止宿主。 关联升级回归发现已有虚拟数据目录案例在读取宿主索引前未采用物理根目录。`211117e0` 独立导出基线复现原两项失败。此次复用同一无符号链接校验/物理根目录解析,先按物理根读取索引,原 Store 的采用仍在可回退阶段中完成,不重开已有 SQLite、不改变原行或 Provider;保留首失败和基线记录。首次 UI 验收的配置格式选择器过于严格,四个已过步骤及失败原件保留,修正验收选择器后另根复验。 diff --git a/docs/QA-CREDENTIAL-PERSISTENCE-1.25.14.md b/docs/QA-CREDENTIAL-PERSISTENCE-1.25.14.md index 4839e18f..352dff47 100644 --- a/docs/QA-CREDENTIAL-PERSISTENCE-1.25.14.md +++ b/docs/QA-CREDENTIAL-PERSISTENCE-1.25.14.md @@ -8,7 +8,7 @@ Windows 上手动填写、上游目录选择及确认导入默认用 CurrentUser 普通名称、并发及原生参数编辑不重复要求 Key、不重加密旧块。显式清除或改用临时 Key 时删除旧保存副本,防止重启恢复旧值。目录新增型号共用源连接;自动同步保持来源原保存选择,旧来源不自动变更。旧配置接口也原子保存新 Key。地址、型号或鉴权变化仍保留原保存块和具体不匹配状态,界面提示更新本机保存。 -已经退出且没有保存副本的旧 Key 无法恢复;安装修复后由用户在模型中心补填一次。助手和验收脚本均未读取、复制或重存真实 Key。 +已经退出且没有保存副本的旧 Key 无法恢复;首候选包后公开核对到用户已补填七条 Key,原 PID14388 保持。本轮增加明确的“保存当前 Key”操作,工作台在原进程内加密保存,调用方不接收 Key、原对象和凭据修订保持。先验合成凭据,再在保留原宿主的升级后处理当前七条连接,全部成功后才正式重启。工具不读取、复制或回传真实 Key。 ## 源码与进程证据 @@ -18,6 +18,9 @@ Windows 上手动填写、上游目录选择及确认导入默认用 CurrentUser - 初次网页验收四步骤已过,配置格式选择器的严格文本匹配失败原件保留;修正验收选择器后另根完成 8 步。 - 实际 Edge:手动保存、留空编辑、临时选择、上游两型号共源、导入、退出及新进程恢复、恢复后鉴权、390px 保存失败保留输入通过,三图已实际查看。截图位置之后调整为直接展示目标凭据字段,最终程序包继续复验。 - 四个加密保存来源重启后恢复为五条可用连接,临时连接没有恢复;密文 SHA 不变、公开数据和 SQLite 检查未包含合成 Key 明文。两宿主均正常退出。只向本机合成接收器发送 1 次模型请求,真实供应商请求 0。 +- 增加“保存当前 Key”后,`14-current-key-tests.log` 2/2 验证原对象/请求身份保持及磁盘失败原数据回退;`16-source-ui-current/` 实际Edge9步通过,五个保存来源恢复六条连接、临时选项不恢复、两个进程正常退出、三图实际查看。本机合成请求1次,真实供应商0。 +- 最终相关 `17-related-current-final.log` 54/54,覆盖新增操作、默认保存、旧配置HTTP、目录/共源、事务回退及保留原SQLite/Provider的升级。安装复核仅放行1.25.13→1.25.14四类精确公开文案/默认字段变化,全部原行、导出、密文和工件仍逐项相同。 +- 最新 `18-formal-status.json` 显示正式七条连接均已有有效DPAPI副本、原PID14388/instance保持、请求420且空闲;正式阶段保留这些原副本,不重复加密。最终安装包及旧版保留进程升级/当前Key保存/新进程恢复继续单独验证。 证据根:`.qa/credential-persistence-1.25.14-2026-11-12/`。源码网页成功根 `09-source-ui/`;全部首失败、基线失败及后续日志保留。源码、程序/安装器、实际安装副本和正式服务在以下阶段分别登记,源码包不含用户项目数据。 diff --git a/scripts/retained-host-state.mjs b/scripts/retained-host-state.mjs index 7f7d3505..cf89cea5 100644 --- a/scripts/retained-host-state.mjs +++ b/scripts/retained-host-state.mjs @@ -43,11 +43,23 @@ export async function publicSnapshot(url, dataRoot) { storage: bootstrap.storage, eventCursor: bootstrap.eventCursor, database, exports, persistent: snapshotPersistentData(dataRoot), scope: 'Read-only public state, every original session export digest, original table/row/schema hashes and every original artifact byte hash. No credential extraction, model probe, execution or mutation.' }; } -export function compareOriginalState(before, after, { modelCenterSchemaChange = false } = {}) { +export function compareOriginalState(before, after, { modelCenterSchemaChange = false, credentialDefaultsSchemaChange = false } = {}) { for (const field of ['pid', 'hasKey', 'configSha256', 'projectsSha256', 'sessionsSha256', 'eventCursor']) assert.deepEqual(after[field], before[field], field); assert.deepEqual(canonical(after.database.tables), canonical(before.database.tables), 'All original table schemas and every persistent row'); assert.deepEqual(after.database.sessionIds, before.database.sessionIds); assert.deepEqual(after.exports, before.exports); assert.deepEqual(after.persistent, before.persistent, 'Every original artifact byte, persistent row and public disk config'); + if (credentialDefaultsSchemaChange) { + assert.equal(before.version, '1.25.13'); assert.equal(after.version, '1.25.14'); + const expected = structuredClone(before.modelCenter); + expected.storage = { ...expected.storage, credentialPersistenceSupported: true, defaultPersistKey: true, + restart: '新填凭据默认本机加密保存并在重启后恢复;只有明确选择仅本次使用的凭据需要重新填写。' }; + for (const connection of expected.connections) { + if (connection.savedCredential?.status === 'not_saved') connection.savedCredential.message = '尚无本机加密副本;仅本次使用的凭据不会在重启后恢复。'; + } + assert.deepEqual(after.modelCenter, expected, 'Only the exact 1.25.14 credential-default public fields may change'); + return { originalRows: 'exact', originalExports: 'exact', originalArtifactBytes: 'exact', originalCredentialsAndRouting: 'exact', + modelCenterChanges: ['storage.credentialPersistenceSupported', 'storage.defaultPersistKey', 'storage.restart', 'not_saved.message'] }; + } if (modelCenterSchemaChange) { const original = structuredClone(before.modelCenter), next = structuredClone(after.modelCenter); // 1.15 changes only the public explanatory text about optional DPAPI storage. diff --git a/scripts/verify-credential-persistence.mjs b/scripts/verify-credential-persistence.mjs index b4df19e9..552a16a2 100644 --- a/scripts/verify-credential-persistence.mjs +++ b/scripts/verify-credential-persistence.mjs @@ -29,7 +29,7 @@ fs.mkdirSync(output, { recursive: false }); const nodePath = fs.existsSync(path.join(appRoot, 'runtime/node.exe')) ? path.join(appRoot, 'runtime/node.exe') : process.execPath; const disposers = [], t = { after: dispose => disposers.push(dispose) }; const f = fixture(t, { modernDefaults: true }); f.store.close(); -const keys = Object.fromEntries(['manual', 'temporary', 'catalog', 'import', 'legacy'].map(name => [name, 'owned-restart-' + name + '-' + randomUUID()])); +const keys = Object.fromEntries(['manual', 'temporary', 'current', 'catalog', 'import', 'legacy'].map(name => [name, 'owned-restart-' + name + '-' + randomUUID()])); const marks = [], screenshots = [], starts = [], exits = []; const sha = value => createHash('sha256').update(value).digest('hex'); const mark = step => { marks.push({ step, passed: true }); console.log(JSON.stringify({ step, passed: true })); }; @@ -127,6 +127,13 @@ try { await expect(dialog.locator('.mc-connection').filter({ hasText: 'owned-manual-edited' })).toContainText('重启自动恢复'); mark('editing without a new key preserves the saved credential and permits submission'); await manual(dialog, 'owned-temporary', keys.temporary, true); mark('explicit temporary choice is reflected accurately'); + const currentCard = await manual(dialog, 'owned-current', keys.current, true); + const currentBefore = (await first.api('/model-center')).connections.find(value => value.name === 'owned-current'); + await currentCard.getByRole('button', { name: '保存当前 Key', exact: true }).click(); + await expect(currentCard).toContainText('重启自动恢复'); + const currentAfter = (await first.api('/model-center')).connections.find(value => value.name === 'owned-current'); + assert.equal(currentAfter.credentialRevision, currentBefore.credentialRevision); assert.equal(currentAfter.revision, currentBefore.revision); + mark('one-click current-key save needs no key input and keeps its credential and connection revisions'); await dialog.getByRole('button', { name: '从上游添加模型', exact: true }).click(); const catalog = dialog.getByRole('region', { name: '上游模型目录', exact: true }); @@ -154,14 +161,14 @@ try { await first.api('/config', { ...first.bootstrap.config, mode: 'compatible', model: 'owned-legacy', baseUrl: mock.baseUrl, apiKey: keys.legacy }); const center = await first.api('/model-center'); - assert.equal(center.attemptCount, 0); assert.equal(center.connections.filter(value => value.hasKey).length, 6); - const saved = vaultSnapshot(); assert.equal(saved.entries.length, 4); assert.equal(saved.plaintextAbsent, true); + assert.equal(center.attemptCount, 0); assert.equal(center.connections.filter(value => value.hasKey).length, 7); + const saved = vaultSnapshot(); assert.equal(saved.entries.length, 5); assert.equal(saved.plaintextAbsent, true); write('before-restart.json', { saved, connections: center.connections.map(({ id, name, hasKey, savedCredential, credentialSource }) => ({ id, name, hasKey, savedCredential, credentialSource })) }); assert.equal(Object.values(keys).some(key => JSON.stringify(center).includes(key)), false); await page.goto('about:blank'); await first.close(); const second = await start('after-restart'); assert.notEqual(second.child.pid, first.child.pid); const restored = await second.api('/model-center'); - assert.equal(restored.attemptCount, 0); assert.equal(restored.connections.filter(value => value.hasKey).length, 5); + assert.equal(restored.attemptCount, 0); assert.equal(restored.connections.filter(value => value.hasKey).length, 6); assert.equal(restored.connections.find(value => value.name === 'owned-temporary').hasKey, false); assert.equal(restored.connections.filter(value => value.name !== 'owned-temporary').every(value => value.hasKey), true); assert.equal(vaultSnapshot().sha256, saved.sha256); @@ -212,7 +219,7 @@ try { const final = await second.api('/model-center'); assert.equal(final.attemptCount, 1); report = { status: 'passed', version: '1.25.14', appRoot, starts, exits, assertions: marks, screenshots, - savedCiphertextUnchangedAcrossRestart: true, plaintextAbsent: saved.plaintextAbsent, restoredSavedConnections: 5, + savedCiphertextUnchangedAcrossRestart: true, plaintextAbsent: saved.plaintextAbsent, restoredSavedConnections: 6, syntheticModelRequests: 1, realProviderRequests: 0, localCatalogRequests: mock.requests.filter(value => value.url === '/v1/models').length, temporaryCredentialRestored: false, pageErrors: errors }; } catch (error) { diff --git a/scripts/verify-previous-patch-install.mjs b/scripts/verify-previous-patch-install.mjs index 917a4544..f008aaab 100644 --- a/scripts/verify-previous-patch-install.mjs +++ b/scripts/verify-previous-patch-install.mjs @@ -95,7 +95,8 @@ try { controller = new HostController({ appRoot: installedRoot, dataRoot, port, timeoutMs: 60000 }); const connected = await controller.connect(); assert.equal(connected.identity.pid, original.pid); assert.equal(connected.identity.instanceId, original.instanceId); - const after = await publicSnapshot(controller.url, dataRoot), retention = compareOriginalState(before, after); + const after = await publicSnapshot(controller.url, dataRoot), retention = compareOriginalState(before, after, + { credentialDefaultsSchemaChange: previous.version === '1.25.13' && candidate.version === '1.25.14' }); assert.equal(after.version, candidate.version); assert.equal(fs.realpathSync.native(after.runtimeRoot), fs.realpathSync.native(installedRoot)); const pointer = read(path.join(installRoot, 'current.json')); assert.equal(pointer.revision, pointerBefore.revision + 1); assert.equal(pointer.previous.version, previous.version); @@ -107,6 +108,24 @@ try { const receiptBytes = fs.statSync(operationFile).size; assert.ok(receiptBytes > 4 * 1024 * 1024); save('state-updated.json', after); save('pointer-updated.json', pointer); passed(stage, { ...receipt, from: previous.version, to: after.version, pid: after.pid, instanceId: original.instanceId, retention, authenticated, receiptBytes }); + if (candidate.version === '1.25.14') { + stage = 'save the retained old-process key internally and restore it in a new packaged process'; + const current = (await controller.api('/model-center')).connections.find(connection => connection.id === 'legacy-default'); + assert.equal(current.hasKey, true); assert.notEqual(current.savedCredential?.status, 'saved'); + const saved = await controller.api('/model-center/credentials', { method: 'POST', input: { id: current.id, revision: current.revision, action: 'save-current' } }); + assert.equal(saved.credential.status, 'saved'); + const retained = saved.center.connections.find(connection => connection.id === current.id); + assert.equal(retained.revision, current.revision); assert.equal(retained.credentialRevision, current.credentialRevision); + const savedState = await publicSnapshot(controller.url, dataRoot); save('state-saved.json', savedState); + await controller.stop(); const fresh = await controller.start(); + assert.notEqual(fresh.identity.pid, original.pid); assert.notEqual(fresh.identity.instanceId, original.instanceId); + const restored = await publicSnapshot(controller.url, dataRoot); + const restartRetention = compareOriginalState(savedState, { ...restored, pid: savedState.pid }); + await controller.api('/config/models', { method: 'POST', input: {} }); assert.equal(authenticated, 3); + save('state-restarted.json', restored); + passed(stage, { pid: fresh.identity.pid, oldPid: original.pid, credentialRevision: retained.credentialRevision, + restartRetention, authenticated, savedCiphertextUnchanged: true }); + } stage = 'owned program uninstall preserves data'; await controller.stop(); controller = null; const baseline = snapshotPersistentData(dataRoot), uninstallLog = path.join(root, 'uninstall.log'); diff --git a/src/client/ModelCenter.tsx b/src/client/ModelCenter.tsx index a93d2653..5e96d055 100644 --- a/src/client/ModelCenter.tsx +++ b/src/client/ModelCenter.tsx @@ -103,6 +103,10 @@ export function ModelCenter({ onConfig, busy, runModel }: { onConfig: (value: Co : '连接设置已保存,原凭据保持。'); } } + async function saveCurrentCredential(value: Connection) { + await api('/model-center/credentials', { id: value.id, revision: value.revision, action: 'save-current' }); + if (alive.current) setNotice('当前 Key 已加密保存,重启后自动恢复。'); + } async function selectRoute(value: string) { await act(async () => { const [type, id] = value.split(':'); await api('/model-center/select', { type, id }); @@ -174,6 +178,7 @@ export function ModelCenter({ onConfig, busy, runModel }: { onConfig: (value: Co {value.health.reason &&

{value.health.reason}{!!value.health.cooldownUntil && value.health.cooldownUntil > Date.now() && ' · 冷却至 ' + new Date(value.health.cooldownUntil).toLocaleTimeString()}

}