Revert "Keep managed Codex homes in sync"

This reverts commit bce1ecdc38.
This commit is contained in:
Jinwoo-H
2026-05-10 20:14:36 -04:00
parent f6ea59bae8
commit ef92abfd33
5 changed files with 10 additions and 77 deletions
@@ -396,8 +396,6 @@ describe('CodexRuntimeHomeService', () => {
})
it('returns the managed home for managed Codex launch and rate-limit preparation', async () => {
const runtimeConfigPath = join(testState.fakeHomeDir, '.codex', 'config.toml')
writeFileSync(runtimeConfigPath, 'approval_policy = "trusted"\n', 'utf-8')
const managedHomePath = createManagedAuth(
testState.userDataDir,
'account-1',
@@ -426,14 +424,7 @@ describe('CodexRuntimeHomeService', () => {
const service = new CodexRuntimeHomeService(store as never)
expect(service.prepareForCodexLaunch()).toBe(managedHomePath)
expect(readFileSync(join(managedHomePath, 'config.toml'), 'utf-8')).toBe(
'approval_policy = "trusted"\n'
)
writeFileSync(runtimeConfigPath, 'approval_policy = "on-request"\n', 'utf-8')
expect(service.prepareForRateLimitFetch()).toBe(managedHomePath)
expect(readFileSync(join(managedHomePath, 'config.toml'), 'utf-8')).toBe(
'approval_policy = "on-request"\n'
)
})
it('does not overwrite auth.json when no managed account was ever active', async () => {
@@ -233,21 +233,9 @@ export class CodexRuntimeHomeService {
// refresh. Managed sessions must run from their account-owned home so old
// PTYs on account B cannot race a newly launched account A process through
// the shared ~/.codex runtime file.
this.syncCanonicalConfigIntoManagedHome(activeAccount.managedHomePath)
return activeAccount.managedHomePath
}
private syncCanonicalConfigIntoManagedHome(managedHomePath: string): void {
const canonicalConfigPath = join(homedir(), '.codex', 'config.toml')
if (!existsSync(canonicalConfigPath)) {
return
}
writeFileAtomically(
join(managedHomePath, 'config.toml'),
readFileSync(canonicalConfigPath, 'utf-8')
)
}
private runtimeAuthMatchesAccount(
runtimeAuthContents: string,
activeAccount: CodexManagedAccount,
+2 -36
View File
@@ -1,39 +1,5 @@
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from 'fs'
import { tmpdir } from 'os'
import { join } from 'path'
import { afterEach, describe, expect, it } from 'vitest'
import { attributeCodexUsageEvent, listCodexSessionFiles, parseCodexUsageRecord } from './scanner'
const tempDirs: string[] = []
afterEach(() => {
delete process.env.CODEX_HOME
for (const dir of tempDirs.splice(0)) {
rmSync(dir, { recursive: true, force: true })
}
})
describe('listCodexSessionFiles', () => {
it('includes managed Codex account session roots alongside the default root', async () => {
const defaultHome = mkdtempSync(join(tmpdir(), 'orca-codex-default-'))
const managedHome = mkdtempSync(join(tmpdir(), 'orca-codex-managed-'))
tempDirs.push(defaultHome, managedHome)
const defaultSessions = join(defaultHome, 'sessions')
const managedSessions = join(managedHome, 'sessions')
mkdirSync(defaultSessions, { recursive: true })
mkdirSync(managedSessions, { recursive: true })
const defaultFile = join(defaultSessions, 'default.jsonl')
const managedFile = join(managedSessions, 'managed.jsonl')
writeFileSync(defaultFile, '{}\n', 'utf-8')
writeFileSync(managedFile, '{}\n', 'utf-8')
process.env.CODEX_HOME = defaultHome
await expect(listCodexSessionFiles([managedSessions])).resolves.toEqual([
defaultFile,
managedFile
])
})
})
import { describe, expect, it } from 'vitest'
import { attributeCodexUsageEvent, parseCodexUsageRecord } from './scanner'
describe('parseCodexUsageRecord', () => {
it('uses cumulative totals to avoid double-counting repeated token snapshots', () => {
+7 -16
View File
@@ -112,20 +112,12 @@ export function getCodexSessionsDirectory(): string {
return DEFAULT_CODEX_SESSIONS_DIR
}
export async function listCodexSessionFiles(extraSessionDirs: string[] = []): Promise<string[]> {
const sessionDirs = [getCodexSessionsDirectory(), ...extraSessionDirs]
const files = new Set<string>()
for (const sessionDir of sessionDirs) {
try {
for (const file of await walkJsonlFiles(sessionDir)) {
files.add(file)
}
} catch {
// Missing or unreadable session roots are expected for accounts that have
// not launched Codex yet. Keep scanning the remaining roots.
}
export async function listCodexSessionFiles(): Promise<string[]> {
try {
return (await walkJsonlFiles(getCodexSessionsDirectory())).sort()
} catch {
return []
}
return [...files].sort()
}
export async function getProcessedFileInfo(filePath: string): Promise<CodexUsageProcessedFile> {
@@ -774,14 +766,13 @@ export async function parseCodexUsageFile(
export async function scanCodexUsageFiles(
worktrees: CodexUsageWorktreeRef[],
previousProcessedFiles: CodexUsagePersistedFile[],
extraSessionDirs: string[] = []
previousProcessedFiles: CodexUsagePersistedFile[]
): Promise<{
processedFiles: CodexUsagePersistedFile[]
sessions: CodexUsageSession[]
dailyAggregates: CodexUsageDailyAggregate[]
}> {
const files = await listCodexSessionFiles(extraSessionDirs)
const files = await listCodexSessionFiles()
const previousByPath = new Map(previousProcessedFiles.map((file) => [file.path, file]))
const processedFiles: CodexUsagePersistedFile[] = []
const worktreesWithCanonicalPaths = await buildWorktreesWithCanonicalPaths(worktrees)
+1 -4
View File
@@ -267,10 +267,7 @@ export class CodexUsageStore {
const worktreeFingerprint = getWorktreeFingerprint(worktreesByRepo)
const result = await scanCodexUsageFiles(
createWorktreeRefs(repos, worktreesByRepo),
this.state.worktreeFingerprint === worktreeFingerprint ? this.state.processedFiles : [],
this.store
.getSettings()
.codexManagedAccounts.map((account) => join(account.managedHomePath, 'sessions'))
this.state.worktreeFingerprint === worktreeFingerprint ? this.state.processedFiles : []
)
this.state.processedFiles = result.processedFiles
this.state.sessions = result.sessions