Repository navigation
fix(native-chat): verify the actual CLI conversation during resume #29124
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
Merged
Merged
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
5ff60af
fix(native-chat): identify the owner when resume create is refused
brennanb2025 8256fa6
test(native-chat): consolidate transcript refusal cases
brennanb2025 0ebb6f4
test(native-chat): keep ownership coverage at the launch boundary
brennanb2025 1e649eb
test(native-chat): update adoption fixture for early ownership admission
brennanb2025 19a79bf
test(native-chat): align resume admission assertions with host ownership
brennanb2025 92e4773
test(native-chat): keep RPC coverage focused on ownership proof
brennanb2025 bd557bf
test(native-chat): assert blank request presence before optional source
brennanb2025 4ce33f9
fix(native-chat): admit the actual CLI source during chat creation
brennanb2025 1a2a3f7
fix(native-chat): satisfy source admission lint checks
brennanb2025 eec3ff8
test(native-chat): provide the waiting hook prompt
brennanb2025 8fbcdac
test(native-chat): isolate source admission fixtures from host homes
brennanb2025 1103026
test(native-chat): canonicalize adoption fixture directories
brennanb2025 7cf362c
test(native-chat): preserve early ownership admission in source stack
brennanb2025 2a17fbb
fix(native-chat): preserve resume refusal behavior and honest transcr…
brennanb2025 876c72c
fix(native-chat): retain import read evidence in typed result
brennanb2025 c846967
Merge commit '876c72ce9ab1c563a21cbd2b1b4b6daae8215002' into brennanb…
brennanb2025 837aea0
fix(native-chat): preserve admitted source and prepared execution home
brennanb2025 3ee200d
fix(chat): retain source evidence for dispatched adoption
brennanb2025 8cd662b
fix(chat): keep source capture within module limits
brennanb2025 a836a6c
test(chat): allow host evidence in create routing
brennanb2025 9ce2f30
fix(native-chat): admit an unsaved transcript under a linked account …
brennanb2025 88d5f53
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-a-ow…
brennanb2025 9bf2229
Merge remote-tracking branch 'origin/brennanb2025/rcc-a-owner-refusal…
brennanb2025 9baf0ad
refactor(native-chat): move the newest-item import window into its ow…
brennanb2025 aadb207
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-a-ow…
brennanb2025 0aef11d
fix(native-chat): restore the refusal error import lost in the main m…
brennanb2025 28b50c9
Merge remote-tracking branch 'origin/brennanb2025/rcc-a-owner-refusal…
brennanb2025 370d6b7
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-a-ow…
brennanb2025 6676f7a
Merge remote-tracking branch 'origin/brennanb2025/rcc-a-owner-refusal…
brennanb2025 a2e56d3
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-b-so…
brennanb2025 9f3adee
fix(native-chat): admit Pi transcripts against the root Session Histo…
brennanb2025 1a6d44a
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-b-so…
brennanb2025 0fdce13
refactor(native-chat): admit and look up CLI transcripts in one store…
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
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
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
96 changes: 96 additions & 0 deletions
96
src/main/native-chat/agent-session-journal/adopted-transcript-source.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,96 @@ | ||
| import { dirname, join } from 'node:path' | ||
| import { sessionIdFromFileName } from '../../ai-vault/session-scanner-accumulator' | ||
| import type { AgentType } from '../../../shared/agent-status-types' | ||
| import { normalizeRuntimePathForComparison } from '../../../shared/cross-platform-path' | ||
| import { readNodeFileWithinLimit } from '../../../shared/node-bounded-file-reader' | ||
| import { asRecord, extractString, parseJsonObject } from '../../ai-vault/session-scanner-values' | ||
| import { readOpenCodeTranscriptSignalViaWorker } from '../../ai-vault/session-scanner-opencode-sqlite-worker-spawn' | ||
| import { samePiDirectory } from '../../pi/rpc-launch-resolution' | ||
| import { admitTranscriptPath } from '../transcript-path-admission' | ||
|
|
||
| export type AdoptedTranscriptSource = { providerSessionId: string; workspaceCwd: string } | ||
|
|
||
| export function assertAdoptedSourceIdentity( | ||
| source: AdoptedTranscriptSource, | ||
| actual: { sessionId: string | null; cwd: string | null }, | ||
| requireCwd = true | ||
| ): void { | ||
| if (actual.sessionId !== source.providerSessionId) { | ||
| throw new Error('The saved conversation does not match the requested provider identity.') | ||
| } | ||
| if ( | ||
| requireCwd && | ||
| (!actual.cwd || | ||
| normalizeRuntimePathForComparison(actual.cwd.trim()) !== | ||
| normalizeRuntimePathForComparison(source.workspaceCwd.trim())) | ||
| ) { | ||
| throw new Error('This conversation belongs to another directory.') | ||
| } | ||
| } | ||
|
|
||
| /** Metadata is observed from the same lines that become the imported journal. */ | ||
| export function adoptedTranscriptSourceObserver(input: { | ||
| agent: AgentType | ||
| filePath: string | ||
| source: AdoptedTranscriptSource | ||
| maxSourceBytes: number | ||
| }) { | ||
| let sessionId: string | null = | ||
| input.agent === 'claude' || input.agent === 'codex' ? sessionIdFromFileName(input.filePath) : null | ||
| let cwd: string | null = null | ||
| let sawCodexMetadata = false | ||
| return { | ||
| observe(line: string) { | ||
| const record = parseJsonObject(line) | ||
| if (!record) { | ||
| return | ||
| } | ||
| if (input.agent === 'claude') { | ||
| sessionId = extractString(record.sessionId) ?? sessionId | ||
| cwd ??= extractString(record.cwd) | ||
| } else if (input.agent === 'codex' && record.type === 'session_meta' && !sawCodexMetadata) { | ||
| sawCodexMetadata = true | ||
| const payload = asRecord(record.payload) | ||
| sessionId = extractString(payload?.id) ?? sessionId | ||
| } else if ((input.agent === 'omp' || input.agent === 'pi') && record.type === 'session') { | ||
| sessionId = extractString(record.id) | ||
| cwd = extractString(record.cwd) | ||
| } | ||
| }, | ||
| async validate() { | ||
| if (input.agent === 'grok') { | ||
| const summaryPath = join(dirname(input.filePath), 'summary.json') | ||
| if (!(await admitTranscriptPath(dirname(input.filePath), summaryPath))) { | ||
| throw new Error('The conversation summary is outside its storage directory.') | ||
| } | ||
| const { buffer } = await readNodeFileWithinLimit(summaryPath, input.maxSourceBytes, { | ||
| regularFileOnly: true | ||
| }) | ||
| const summary = asRecord(asRecord(JSON.parse(buffer.toString('utf8')))?.info) | ||
| sessionId = extractString(summary?.id) ?? sessionIdFromFileName(dirname(input.filePath)) | ||
| cwd = extractString(summary?.cwd) | ||
| } | ||
| if (input.agent === 'pi' && sessionIdFromFileName(input.filePath) !== sessionId) { | ||
| throw new Error('The saved conversation header does not match its file identity.') | ||
| } | ||
| if (input.agent === 'pi' && cwd && (await samePiDirectory(cwd, input.source.workspaceCwd))) { | ||
| cwd = input.source.workspaceCwd | ||
| } | ||
| assertAdoptedSourceIdentity(input.source, { sessionId, cwd }, input.agent !== 'codex') | ||
| } | ||
| } | ||
| } | ||
|
|
||
| export async function validateAdoptedOpenCodeSource( | ||
| dbPath: string, | ||
| source: AdoptedTranscriptSource | ||
| ): Promise<void> { | ||
| const signal = await readOpenCodeTranscriptSignalViaWorker({ | ||
| dbPath, | ||
| sessionId: source.providerSessionId | ||
| }) | ||
| assertAdoptedSourceIdentity(source, { | ||
| sessionId: signal ? source.providerSessionId : null, | ||
| cwd: signal?.cwd ?? null | ||
| }) | ||
| } |
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
29 changes: 29 additions & 0 deletions
29
src/main/native-chat/agent-session-journal/journal-newest-item-window.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,29 @@ | ||
| import type { JournalReplacementItem } from './journal-epoch-replacement' | ||
|
|
||
| /** The newest complete items that fit `maxBytes`; the latest item is always kept. */ | ||
| export function createNewestItemWindow(maxBytes: number): { | ||
| push(item: JournalReplacementItem): void | ||
| items(): JournalReplacementItem[] | ||
| } { | ||
| let entries: ({ item: JournalReplacementItem; bytes: number } | undefined)[] = [] | ||
| let head = 0 | ||
| let bytes = 0 | ||
| return { | ||
| push(item) { | ||
| const itemBytes = Buffer.byteLength(JSON.stringify(item), 'utf8') | ||
| entries.push({ item, bytes: itemBytes }) | ||
| bytes += itemBytes | ||
| while (bytes > maxBytes && head < entries.length - 1) { | ||
| bytes -= entries[head]?.bytes ?? 0 | ||
| entries[head] = undefined | ||
| head += 1 | ||
| } | ||
| // Drop evicted entries in batches so a long source stays linear. | ||
| if (head > 1024 && head * 2 > entries.length) { | ||
| entries = entries.slice(head) | ||
| head = 0 | ||
| } | ||
| }, | ||
| items: () => entries.slice(head).flatMap((entry) => (entry ? [entry.item] : [])) | ||
| } | ||
| } |
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
Oops, something went wrong.
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.