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(codex): 跨账号分支使用源线程索引

Dash17a6c2ffc680
diff --git a/apps/desktop/src/renderer/__tests__/schedulerModelPopoverOverlay.test.tsx b/apps/desktop/src/renderer/__tests__/schedulerModelPopoverOverlay.test.tsx
index 1aec69c3b0..1850033744 100644
--- a/apps/desktop/src/renderer/__tests__/schedulerModelPopoverOverlay.test.tsx
+++ b/apps/desktop/src/renderer/__tests__/schedulerModelPopoverOverlay.test.tsx
@@ -121,7 +121,8 @@ beforeEach(() => {
describe('scheduler model popover overlay behavior', () => {
it('pins an explicitly selected native default instead of storing automatic selection', () => {
const onChangeProviderId = vi.fn();
- render(<ModelEffortChip agentKind="codex" modelValue="gpt-5.5"
+ render(<ModelEffortChip onSelect={vi.fn()} onFollowSession={vi.fn()}
+ agentKind="codex" modelValue="gpt-5.5"
onChangeModel={vi.fn()} effortValue="" onChangeEffort={vi.fn()}
providerId="" onChangeProviderId={onChangeProviderId} />);
fireEvent.click(screen.getByTestId('model-selector-content'));
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.ts
index e07e1199b7..f336adc26c 100644
--- a/packages/maker-core/src/agents/codex/index.test.ts
+++ b/packages/maker-core/src/agents/codex/index.test.ts
@@ -22608,6 +22608,34 @@ describe('CodexAgent native fork anchor events', () => {
});
describe('CodexAgent.forkSdkSession', () => {
+ it('reads cross-account fork boundaries and records the child in the source index', async () => {
+ const recordCodexThreadLocation = vi.fn(async () => {});
+ const agent = new CodexAgent(createDeps({}, {
+ isCodexAccountProvider: (id) => id === 'account-b',
+ resolveCodexThreadStorageHome: async () => '/account-a',
+ prepareCodexResumeSession: async () => '/account-a/sessions/source.jsonl',
+ recordCodexThreadLocation,
+ }));
+ const host = installFakeHost(agent, method => {
+ if (method === Method.ThreadTurnsList) {
+ expect(host.getHost).toHaveBeenCalledWith(undefined, 'oauth-bearer',
+ expect.objectContaining({ providerId: 'account-b', sqliteHome: '/account-a' }));
+ return { data: [{ id: 'boundary', status: 'completed', startedAt: 100 }], nextCursor: null };
+ }
+ if (method === Method.ThreadFork) return {
+ thread: { id: 'child', path: '/account-b/sessions/child.jsonl' },
+ };
+ }, { userAgent: 'mock-codex/0.153.4', codexHome: '/account-b' });
+ await expect(agent.forkSdkSession({
+ sourceSdkSessionId: 'source', upToMessageId: undefined,
+ providerId: 'account-b', tailTurnsToDrop: 1, forkAtTimestampMs: 110_123,
+ })).resolves.toMatchObject({ newSdkSessionId: 'child', usedNativeForkAnchor: true });
+ expect(host.request).toHaveBeenCalledWith(Method.ThreadFork, expect.objectContaining({
+ path: '/account-a/sessions/source.jsonl', lastTurnId: 'boundary',
+ }));
+ expect(recordCodexThreadLocation).toHaveBeenCalledWith('child', '/account-a', '/account-b/sessions/child.jsonl');
+ });
+
it('forks failed paginated history without rollback when no UI anchor was saved', async () => {
const agent = new CodexAgent(createDeps());
const host = installFakeHost(agent, method => {
diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.ts
index 8a0b87245f..55abafc4e4 100644
--- a/packages/maker-core/src/agents/codex/index.ts
+++ b/packages/maker-core/src/agents/codex/index.ts
@@ -13782,10 +13782,14 @@ export class CodexAgent extends BaseAgent {
await assertCodexRolloutRewriteSupported(preparedSourcePath || await this.findRolloutPath(opts.sourceSdkSessionId));
historyChecked = true;
}
+ // ID-only turn queries must use the source thread's index even when the
+ // account supplying credentials has changed. Keep the child in that index.
+ const forkSqliteHome = await this.deps.resolveCodexThreadStorageHome?.(opts.sourceSdkSessionId);
stage = 'host-create';
const host = await this.getHost(undefined, forkCredentialMode, {
keyOverride: forkHostKey,
...(forkAccountId ? { providerId: forkAccountId } : {}),
+ ...(forkSqliteHome ? { sqliteHome: forkSqliteHome } : {}),
hostPurpose: 'control-plane',
}).catch((error) => {
// This is the outgoing source's offline fork host, not a target send.
@@ -13846,7 +13850,7 @@ export class CodexAgent extends BaseAgent {
const resp = await host.request<ThreadForkResponse>(Method.ThreadFork, params);
let newSdkSessionId = resp.thread.id;
if (forkCodexHome && typeof resp.thread.path === 'string') {
- await this.deps.recordCodexThreadLocation?.(newSdkSessionId, forkCodexHome, resp.thread.path);
+ await this.deps.recordCodexThreadLocation?.(newSdkSessionId, forkSqliteHome ?? forkCodexHome, resp.thread.path);
}
createdThreadIds.add(newSdkSessionId);
if (!usedNativeForkAnchor && tailTurnsToDrop > 0) {
@@ -13865,7 +13869,7 @@ export class CodexAgent extends BaseAgent {
createdThreadIds.add(rollbackThreadId);
newSdkSessionId = rollbackThreadId;
if (forkCodexHome && typeof rollbackResp.thread.path === 'string') {
- await this.deps.recordCodexThreadLocation?.(newSdkSessionId, forkCodexHome, rollbackResp.thread.path);
+ await this.deps.recordCodexThreadLocation?.(newSdkSessionId, forkSqliteHome ?? forkCodexHome, rollbackResp.thread.path);
}
}
if (opts.stripEncryptedReasoning) {