Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 远程镜像路径写预算前复核账号边界(#4598)

Zhang Yunjin55216f6e20ef
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
index 8a6d3d09c7..f1006aeb07 100644
--- a/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
+++ b/apps/desktop/src/main/localDb/ipc/__tests__/sessionsUpdate.test.ts
@@ -947,6 +947,15 @@ describe('local-db:sessions:update handler wiring', () => {
expect(readSessionContextWindowBudget('cc-local')).toBeNull();
});
+ it('does not mirror a remote budget into the next account after an owner change', async () => {
+ // 远程镜像落库(persistSessionFields)同样是 await 之后才写偏好文件:保存期间切账号,
+ // 这条过期更新不得把预算写进新账号的文件(Greptile P1,2026-10-24)。
+ h.captureOwnerScope = true;
+ h.ownerCurrent = false;
+ await persistSessionFields('pi-local', { contextWindowBudget: 300_000 });
+ expect(readSessionContextWindowBudget('pi-local')).toBeNull();
+ });
+
it('does not write the context window budget into the next account after an owner change', async () => {
// 偏好文件按「当前」账号的 userData 解析,而 DB 更新是 await 出来的:保存期间切账号
// 时,过期请求不得把原任务的预算写进新账号的文件(Greptile P1,2026-10-24)。
diff --git a/apps/desktop/src/main/localDb/ipc/sessions.ts b/apps/desktop/src/main/localDb/ipc/sessions.ts
index cbe0f714ea..ede3502023 100644
--- a/apps/desktop/src/main/localDb/ipc/sessions.ts
+++ b/apps/desktop/src/main/localDb/ipc/sessions.ts
@@ -919,9 +919,13 @@ export async function persistSessionFields(
// 人工修),若先写就会让同一个 patch 里的其它字段(改名、归档…)整包失败。
// 纯预算请求不能降级:那是用户唯一的意图,吞掉错误等于「看着成功、实际还是旧窗口」。
const budgetOnlyPatch = Object.keys(rowPatch).length === 0;
+ // 账号边界:偏好文件按「当下」账号的 userData 解析,而上面 db.update /
+ // 下面 apply 都是 await 出来的 —— 期间切账号时这条远程镜像更新必须整条作废
+ // (与 updateSessionInDb 同口径)。Greptile P1,2026-10-24。
+ const budgetScopeCurrent = isOwnerScopeCurrent(ownerScope);
let budgetWritten = false;
let nextContextWindowBudget: number | null = null;
- if (hasBudgetChange) {
+ if (hasBudgetChange && budgetScopeCurrent) {
try {
nextContextWindowBudget = writeSessionContextWindowBudget(
sessionId, (clean.contextWindowBudget as number | null) ?? null,
@@ -951,7 +955,8 @@ export async function persistSessionFields(
}
if (isOwnerScopeCurrent(ownerScope)) broadcastSessionPatched(sessionId, { ...clean, ...runtimeProjection }, ownerScope);
// 远程 set-* 落库后同样要把新预算应用到被控端活实例(语义与 updateSessionInDb 一致)。
- if (budgetWritten && registeredSessionIpcOpts.applyContextWindowBudget) {
+ if (budgetWritten && budgetScopeCurrent && isOwnerScopeCurrent(ownerScope)
+ && registeredSessionIpcOpts.applyContextWindowBudget) {
try {
await registeredSessionIpcOpts.applyContextWindowBudget(sessionId, {
previous: previousContextWindowBudget,