Repository navigation
fix: recover orchestration mail after interrupted chats #32108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
9c6168d
fix(orchestration): settle mail handoffs per message and recover inte…
brennanb2025 e3d767a
fix: preserve independent mail authorization through grouped delivery
brennanb2025 1cbdded
fix: preserve routed mail identity and private inbox state
brennanb2025 3545d0c
test: bound mailbox query work on repeated delivery
brennanb2025 505b722
Merge origin/main into brennanb2025/fix-stuck-codex-review
brennanb2025 8c4ec2e
Merge origin/main to resolve current integration conflicts
brennanb2025 04e58b0
fix(orchestration): consolidate terminal mail imports
brennanb2025 c35b0fc
Validate mailbox query rows and type delivery fixtures
brennanb2025 6342786
Keep host forwarders typed and inline single-use mail evidence reader
brennanb2025 8c96b57
Merge origin/main to include adapter lint repair
brennanb2025 b5516cc
Declare the mail handoff store method boundary
brennanb2025 fa658a3
Preserve mailbox contracts across typed boundaries
brennanb2025 0c4d606
Retain existing main cleanup row boundaries
brennanb2025 b29676d
Fix mailbox handoff fixtures and helper mail transfer
brennanb2025 bf68389
Name the mailbox fixture constructor type
brennanb2025 3679048
Merge main into mail recovery fix
brennanb2025 6b9ce8b
test: complete mailbox dialog pane identity
brennanb2025 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/agent-hooks/server/retained-provider-session-row.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import type { EnrichedAgentHookEventPayload } from './server-types' | ||
|
|
||
| // Resume identity survives retiring the pane's live status claims. | ||
| export function retainedProviderSessionRow( | ||
| entry: EnrichedAgentHookEventPayload | null | undefined | ||
| ): EnrichedAgentHookEventPayload | null { | ||
| if ( | ||
| !entry?.providerSession || | ||
| !entry.payload.agentType || | ||
| entry.payload.agentType === 'unknown' | ||
| ) { | ||
| return null | ||
| } | ||
| const { launchToken: _launchToken, ...resumeIdentity } = entry | ||
| return { ...resumeIdentity, providerSessionOnly: true, retainedForLiveness: true } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| import type { AgentHookEventPayload } from '../../../shared/agent-hook-listener/listener-event' | ||
| import { | ||
| isSameAgentProcess, | ||
| readAgentProcessIdentity, | ||
| type AgentProcessIdentity | ||
| } from '../../../shared/agent-process-presence' | ||
|
|
||
| export type TerminalMailTarget = { | ||
| paneKey: string | ||
| process: AgentProcessIdentity | ||
| owner: string | ||
| turnKey: string | ||
| } | ||
|
|
||
| export function openTerminalMailTarget( | ||
| row: AgentHookEventPayload | undefined | ||
| ): TerminalMailTarget | null { | ||
| const turn = row?.hostTurn | ||
| const process = row?.agentPresence?.process | ||
| if ( | ||
| !row || | ||
| row.connectionId !== null || | ||
| row.restoredUnconfirmed || | ||
| !process || | ||
| !turn || | ||
| turn.currentTurnKey === 'seed' || | ||
| turn.completed?.turnKey === turn.currentTurnKey || | ||
| row.payload.mainAgent?.state !== 'working' || | ||
| row.payload.mainAgent.stopping | ||
| ) { | ||
| return null | ||
| } | ||
| return { paneKey: row.paneKey, process, owner: turn.owner, turnKey: turn.currentTurnKey } | ||
| } | ||
|
|
||
| export function sameTerminalMailTarget(a: TerminalMailTarget, b: TerminalMailTarget): boolean { | ||
| return ( | ||
| a.paneKey === b.paneKey && | ||
| a.owner === b.owner && | ||
| a.turnKey === b.turnKey && | ||
| isSameAgentProcess(a.process, b.process) | ||
| ) | ||
| } | ||
|
|
||
| export function readTerminalMailTarget(value: unknown): TerminalMailTarget | null { | ||
| if ( | ||
| !value || | ||
| typeof value !== 'object' || | ||
| !('paneKey' in value) || | ||
| typeof value.paneKey !== 'string' || | ||
| !('owner' in value) || | ||
| typeof value.owner !== 'string' || | ||
| !('turnKey' in value) || | ||
| typeof value.turnKey !== 'string' || | ||
| !('process' in value) | ||
| ) { | ||
| return null | ||
| } | ||
| const process = readAgentProcessIdentity(value.process) | ||
| return process | ||
| ? { paneKey: value.paneKey, owner: value.owner, turnKey: value.turnKey, process } | ||
| : null | ||
| } | ||
|
|
||
| export class TerminalMailTargets { | ||
| private readonly abandoned = new Map<string, TerminalMailTarget>() | ||
|
|
||
| read(row: AgentHookEventPayload | undefined): TerminalMailTarget | null { | ||
| return row?.agentPresence?.ended || row?.providerSessionOnly | ||
| ? null | ||
| : openTerminalMailTarget(row) | ||
| } | ||
|
|
||
| observeExit( | ||
| row: AgentHookEventPayload | undefined, | ||
| process: AgentProcessIdentity | undefined | ||
| ): void { | ||
| const target = openTerminalMailTarget(row) | ||
| if (!target || !process || !isSameAgentProcess(target.process, process)) { | ||
| return | ||
| } | ||
| this.abandoned.set(target.paneKey, target) | ||
| if (this.abandoned.size > 256) { | ||
| const oldest = this.abandoned.keys().next().value | ||
| if (oldest !== undefined) { | ||
| this.abandoned.delete(oldest) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| wasAbandoned( | ||
| target: TerminalMailTarget, | ||
| row: AgentHookEventPayload | undefined, | ||
| exit: AgentProcessIdentity | undefined | ||
| ): boolean { | ||
| const turn = row?.hostTurn | ||
| if (row?.payload.mainAgent?.outcome === 'cancellation') { | ||
| return false | ||
| } | ||
| if ( | ||
| turn && | ||
| turn.currentTurnKey !== 'seed' && | ||
| (turn.owner !== target.owner || | ||
| turn.currentTurnKey !== target.turnKey || | ||
| turn.completed?.turnKey === target.turnKey) | ||
| ) { | ||
| return false | ||
| } | ||
| const proof = this.abandoned.get(target.paneKey) | ||
| if (proof && sameTerminalMailTarget(proof, target)) { | ||
| return true | ||
| } | ||
| const retained = openTerminalMailTarget(row) | ||
| return Boolean( | ||
| row?.providerSessionOnly && | ||
| retained && | ||
| exit && | ||
| sameTerminalMailTarget(retained, target) && | ||
| isSameAgentProcess(exit, target.process) | ||
| ) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/native-chat/agent-session-journal/journal-submission-handoff.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { expect, it } from 'vitest' | ||
| import { applyJournalRow, createJournalReducerState } from './journal-reducer' | ||
| import { journalSubmissionHandoff } from './journal-submission-handoff' | ||
|
|
||
| it('requires original handover scope or an exact opener, rather than reduced positional scope', () => { | ||
| const state = createJournalReducerState('session', 'epoch') | ||
| const base = (seq: number) => ({ v: 1, epoch: 'epoch', seq, fence: 1, ts: seq }) | ||
| applyJournalRow(state, { | ||
| ...base(1), | ||
| kind: 'item', | ||
| itemId: 'turn', | ||
| revision: 1, | ||
| body: { kind: 'turn', turnId: 'turn-1', state: 'running' } | ||
| }) | ||
| applyJournalRow(state, { | ||
| ...base(2), | ||
| kind: 'submission', | ||
| clientMessageId: 'notice', | ||
| payloadFingerprint: 'fingerprint', | ||
| providerHandle: { kind: 'codex', threadId: 'thread' }, | ||
| body: { kind: 'message', role: 'user', blocks: [{ type: 'text', text: 'notice' }] } | ||
| }) | ||
| expect(journalSubmissionHandoff(state, 'notice')).toBeNull() | ||
| applyJournalRow(state, { | ||
| ...base(3), | ||
| kind: 'dispatch', | ||
| clientMessageId: 'notice', | ||
| state: 'pending', | ||
| providerItemId: null, | ||
| reason: null, | ||
| turnScope: { kind: 'turn', turnItemId: 'turn' } | ||
| }) | ||
| applyJournalRow(state, { | ||
| ...base(4), | ||
| kind: 'dispatch', | ||
| clientMessageId: 'notice', | ||
| state: 'accepted', | ||
| providerItemId: null, | ||
| reason: null | ||
| }) | ||
| expect(journalSubmissionHandoff(state, 'notice')).toMatchObject({ itemId: 'turn' }) | ||
| applyJournalRow(state, { | ||
| ...base(5), | ||
| kind: 'item', | ||
| itemId: 'unrelated', | ||
| revision: 1, | ||
| body: { kind: 'turn', turnId: 'turn-2', state: 'completed', outcome: 'failure' } | ||
| }) | ||
| expect(journalSubmissionHandoff(state, 'notice')).toMatchObject({ itemId: 'turn' }) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.