Skip to content
Merged
Show file tree
Hide file tree
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 Oct 15, 2026
8256fa6
test(native-chat): consolidate transcript refusal cases
brennanb2025 Oct 15, 2026
0ebb6f4
test(native-chat): keep ownership coverage at the launch boundary
brennanb2025 Oct 15, 2026
1e649eb
test(native-chat): update adoption fixture for early ownership admission
brennanb2025 Oct 15, 2026
19a79bf
test(native-chat): align resume admission assertions with host ownership
brennanb2025 Oct 15, 2026
92e4773
test(native-chat): keep RPC coverage focused on ownership proof
brennanb2025 Oct 15, 2026
bd557bf
test(native-chat): assert blank request presence before optional source
brennanb2025 Oct 15, 2026
4ce33f9
fix(native-chat): admit the actual CLI source during chat creation
brennanb2025 Oct 15, 2026
1a2a3f7
fix(native-chat): satisfy source admission lint checks
brennanb2025 Oct 15, 2026
eec3ff8
test(native-chat): provide the waiting hook prompt
brennanb2025 Oct 15, 2026
8fbcdac
test(native-chat): isolate source admission fixtures from host homes
brennanb2025 Oct 15, 2026
1103026
test(native-chat): canonicalize adoption fixture directories
brennanb2025 Oct 15, 2026
7cf362c
test(native-chat): preserve early ownership admission in source stack
brennanb2025 Oct 15, 2026
2a17fbb
fix(native-chat): preserve resume refusal behavior and honest transcr…
brennanb2025 Oct 15, 2026
876c72c
fix(native-chat): retain import read evidence in typed result
brennanb2025 Oct 15, 2026
c846967
Merge commit '876c72ce9ab1c563a21cbd2b1b4b6daae8215002' into brennanb…
brennanb2025 Oct 15, 2026
837aea0
fix(native-chat): preserve admitted source and prepared execution home
brennanb2025 Oct 15, 2026
3ee200d
fix(chat): retain source evidence for dispatched adoption
brennanb2025 Oct 15, 2026
8cd662b
fix(chat): keep source capture within module limits
brennanb2025 Oct 15, 2026
a836a6c
test(chat): allow host evidence in create routing
brennanb2025 Oct 15, 2026
9ce2f30
fix(native-chat): admit an unsaved transcript under a linked account …
brennanb2025 Oct 16, 2026
88d5f53
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-a-ow…
brennanb2025 Oct 16, 2026
9bf2229
Merge remote-tracking branch 'origin/brennanb2025/rcc-a-owner-refusal…
brennanb2025 Oct 16, 2026
9baf0ad
refactor(native-chat): move the newest-item import window into its ow…
brennanb2025 Oct 16, 2026
aadb207
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-a-ow…
brennanb2025 Oct 16, 2026
0aef11d
fix(native-chat): restore the refusal error import lost in the main m…
brennanb2025 Oct 16, 2026
28b50c9
Merge remote-tracking branch 'origin/brennanb2025/rcc-a-owner-refusal…
brennanb2025 Oct 16, 2026
370d6b7
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-a-ow…
brennanb2025 Oct 16, 2026
6676f7a
Merge remote-tracking branch 'origin/brennanb2025/rcc-a-owner-refusal…
brennanb2025 Oct 16, 2026
a2e56d3
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-b-so…
brennanb2025 Oct 16, 2026
9f3adee
fix(native-chat): admit Pi transcripts against the root Session Histo…
brennanb2025 Oct 16, 2026
1a6d44a
Merge remote-tracking branch 'origin/main' into brennanb2025/rcc-b-so…
brennanb2025 Oct 16, 2026
0fdce13
refactor(native-chat): admit and look up CLI transcripts in one store…
brennanb2025 Oct 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/main/ai-vault/session-scanner-discovery-wsl-gate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,3 +148,19 @@ describe('discoverFiles containment for a stalled WSL root', () => {
}
})
})

it('execution admission preserves native access errors while confirmed missing roots remain absent', async () => {
for (const code of ['EACCES', 'ENOENT']) {
const failure = Object.assign(new Error(code), { code })
const search = walkSessionFiles('/account/sessions', 'codex', [], {
extensions: new Set(['.jsonl']),
strictErrors: true,
readDirectory: async () => {
throw failure
}
})
await (code === 'ENOENT'
? expect(search).resolves.toEqual([])
: expect(search).rejects.toBe(failure))
}
})
3 changes: 2 additions & 1 deletion src/main/ai-vault/session-scanner-discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ export type SessionFileWalkOptions = {
// Return false to skip descending into a directory; depth 0 is a child of
// rootDir, so pruned subtrees are never stat'd or parsed.
directoryPredicate?: (name: string, depth: number) => boolean
strictErrors?: boolean
readDirectory?: (dirPath: string) => Promise<Dirent[]>
signal?: AbortSignal
}
Expand Down Expand Up @@ -295,7 +296,7 @@ export async function forEachSessionFile(
options.signal?.throwIfAborted()
// Why: a gate refusal means the scan could not run, not that the tree is
// empty — swallowing it would misreport a stalled distro as "no transcript".
if (error instanceof WslTranscriptFsError) {
if (error instanceof WslTranscriptFsError || (options.strictErrors && !isMissingSidecarError(error))) {
throw error
}
return
Expand Down
6 changes: 4 additions & 2 deletions src/main/claude/claude-cli-conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import {
} from '../native-chat/structured-agent-cli-conversations'

const CLAUDE_TRANSCRIPT_IMPORT = directoryTranscriptImport({
transcriptRoot: ({ accountHomePath }) => join(accountHomePath, 'projects'),
accountHomeCandidates: ({ selectedAccountHomePath }) => [
selectedAccountHomePath,
join(homedir(), '.claude'),
...(getClaudeProfileRouter()?.accountHomes() ?? [])
],
findTranscript: ({ providerSessionId, accountHomePath }) =>
findTranscript: ({ providerSessionId, accountHomePath, strictErrors }) =>
resolveSessionFilePath('claude', providerSessionId, {
claudeProjectsDir: join(accountHomePath, 'projects')
claudeProjectsDir: join(accountHomePath, 'projects'),
strictErrors
})
})

Expand Down
18 changes: 18 additions & 0 deletions src/main/codex/codex-ai-vault-session-resume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ type CodexAiVaultResumeOptions = {
preparePinnedLaunchHome: (home: string) => Promise<void>
}

export type NativeCodexResumePreparation = (
args: AiVaultPrepareSessionResumeArgs,
nativeSystemHomePath?: string
) => Promise<AiVaultPrepareSessionResumeResult>

/** Native adoption supplies its execution target; History keeps its configured storage target. */
export function codexAiVaultSessionResumePreparation(
getOptions: () => CodexAiVaultResumeOptions
): NativeCodexResumePreparation {
return (args, nativeSystemHomePath) => {
const options = getOptions()
return prepareCodexAiVaultSessionResume(args, {
...options,
systemCodexHomePath: nativeSystemHomePath ?? options.systemCodexHomePath
})
}
}

/** Keeps window and serve AI Vault resumes behind the same refusing account-home gate. */
export async function prepareCodexAiVaultSessionResume(
args: AiVaultPrepareSessionResumeArgs,
Expand Down
6 changes: 4 additions & 2 deletions src/main/codex/codex-cli-conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import {
import { getOrcaManagedCodexHomePath, getSystemCodexHomePath } from './codex-home-paths'

const CODEX_TRANSCRIPT_IMPORT = directoryTranscriptImport({
transcriptRoot: ({ accountHomePath }) => join(accountHomePath, 'sessions'),
accountHomeCandidates: ({ settings, selectedAccountHomePath }) => [
selectedAccountHomePath,
...(settings.codexManagedAccounts ?? []).map((account) => account.managedHomePath),
...configuredAdditionalCodexHomePaths(),
getOrcaManagedCodexHomePath(),
getSystemCodexHomePath()
],
findTranscript: ({ providerSessionId, accountHomePath }) =>
findTranscript: ({ providerSessionId, accountHomePath, strictErrors }) =>
resolveSessionFilePath('codex', providerSessionId, {
codexSessionsDirs: [join(accountHomePath, 'sessions')]
codexSessionsDirs: [join(accountHomePath, 'sessions')],
strictErrors
})
})

Expand Down
5 changes: 3 additions & 2 deletions src/main/grok/grok-transcript-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,20 @@ import { resolveSessionFilePath } from '../native-chat/session-file-resolver'
import { directoryTranscriptImport } from '../native-chat/structured-agent-cli-conversations'

export const GROK_TRANSCRIPT_IMPORT = directoryTranscriptImport({
transcriptRoot: ({ accountHomePath }) => join(accountHomePath, 'sessions'),
// The chat's own home, then the one Session History lists Grok's conversations from.
accountHomeCandidates: ({ selectedAccountHomePath }) => [
selectedAccountHomePath,
resolveGrokHomeDir()
],
findTranscript: async ({ providerSessionId, accountHomePath, workspaceCwd }) => {
findTranscript: async ({ providerSessionId, accountHomePath, workspaceCwd, strictErrors }) => {
const sessionsDir = join(accountHomePath, 'sessions')
return (
(await findGrokChatHistoryByCwd({
sessionId: providerSessionId,
cwd: workspaceCwd,
sessionsDir
})) ?? resolveSessionFilePath('grok', providerSessionId, { grokSessionsDir: sessionsDir })
})) ?? resolveSessionFilePath('grok', providerSessionId, { grokSessionsDir: sessionsDir, strictErrors })
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
)
}
})
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
})
}
51 changes: 23 additions & 28 deletions src/main/native-chat/agent-session-journal/journal-legacy-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// never be spliced into a sequence space that a structured session is also
// writing; a later structured resume rolls the epoch again and rebuilds.

import { adoptedTranscriptSourceObserver, validateAdoptedOpenCodeSource, type AdoptedTranscriptSource } from './adopted-transcript-source'
import { createReadStream } from 'node:fs'
import type { AgentType } from '../../../shared/agent-status-types'
import type {
Expand All @@ -31,6 +32,7 @@ import { readOpenCodeNativeChatTranscriptFull } from '../transcript-opencode'
import { boundSubagentEntryId } from '../subagent-entry-id-bounds'
import { createLegacyIdentityTracker } from './journal-legacy-identity'
import { createPiTranscriptCollector } from './journal-pi-active-branch'
import { createNewestItemWindow } from './journal-newest-item-window'
import type { JournalReplacementItem } from './journal-epoch-replacement'
import {
boundInlineText,
Expand All @@ -43,6 +45,7 @@ import type { AgentSessionJournal } from './journal-store'
export type LegacyImportOptions = ResolveSessionFileOptions & {
/** Resolve directly to this file, skipping path discovery. */
filePath?: string
source?: AdoptedTranscriptSource
limits?: JournalPayloadLimits
decodedMessageIdentities?: true
}
Expand Down Expand Up @@ -118,6 +121,7 @@ export async function prepareLegacyTranscriptImport(input: {
transcriptAgent,
agent: input.agent,
sessionId: input.sessionId,
source: options.source,
decodedMessageIdentities: options.decodedMessageIdentities,
limits
})
Expand All @@ -136,6 +140,16 @@ async function prepareOpenCodeImport(input: {
limits: JournalPayloadLimits
}): Promise<PreparedLegacyImport> {
const dbPath = input.options?.filePath
if (input.options?.source) {
if (!dbPath) {
return { ok: false, error: 'The conversation database is unavailable.' }
}
try {
await validateAdoptedOpenCodeSource(dbPath, input.options.source)
} catch (error) {
return { ok: false, error: error instanceof Error ? error.message : String(error) }
}
}
const read = await readOpenCodeNativeChatTranscriptFull(
input.sessionId,
dbPath ? { resolveDbPath: async () => dbPath } : {}
Expand Down Expand Up @@ -198,8 +212,13 @@ async function decodeReplacementItems(input: {
agent: AgentType
sessionId: string
decodedMessageIdentities?: true
source?: AdoptedTranscriptSource
limits: JournalPayloadLimits
}): Promise<{ items: JournalReplacementItem[]; consumedBytes: number }> {
const source = input.source ? adoptedTranscriptSourceObserver({
agent: input.agent, filePath: input.filePath, source: input.source,
maxSourceBytes: MAX_LEGACY_IMPORT_RECORD_BYTES
}) : null
const tracker = createLegacyIdentityTracker({
transcriptAgent: input.transcriptAgent,
agent: input.agent,
Expand All @@ -220,6 +239,7 @@ async function decodeReplacementItems(input: {
input.filePath,
0,
(line, fallbackId) => {
source?.observe(line)
const currentLineIndex = lineIndex
lineIndex += 1
if (pi) {
Expand Down Expand Up @@ -247,6 +267,9 @@ async function decodeReplacementItems(input: {
true,
MAX_LEGACY_IMPORT_RECORD_BYTES
)
if (consumedBytes > 0) {
await source?.validate()
}
if (pi) {
await pi.project(retained.push)
}
Expand All @@ -256,34 +279,6 @@ async function decodeReplacementItems(input: {
}
}

/** The newest complete items that fit `maxBytes`; the latest item is always kept. */
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] : []))
}
}

/**
* A message whose only content is a tool invocation becomes a tool-call item so
* the reducer renders it as one. Everything else stays a message item with its
Expand Down
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] : []))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function readAdoptedTranscript(
const prepared = await prepareLegacyTranscriptImport({
agent: params.agent,
sessionId: adopt.providerHandle.nativeId,
options: { filePath: adopt.transcriptPath }
options: { filePath: adopt.transcriptPath, source: adopt.source }
})
if (!prepared.ok) {
throw new Error(prepared.error)
Expand Down Expand Up @@ -111,7 +111,7 @@ async function applyAdoptedTranscript(
agent: params.agent,
sessionId: adopt.providerHandle.nativeId,
fence: record.lease.runtimeFence,
options: { filePath: adopt.transcriptPath }
options: { filePath: adopt.transcriptPath, source: adopt.source }
})
if (!imported.ok) {
throw new Error(imported.error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ export type AgentSessionAttachParams = {
providerHandle: AgentSessionProviderHandle
/** Omitted only when the exact committed operation replays an already-imported journal. */
transcriptPath?: string
source?: { providerSessionId: string; workspaceCwd: string }
}
}

Expand Down
Loading
Loading