-
Notifications
You must be signed in to change notification settings - Fork 0
[WRONG BRANCH] fix(service): bind lifecycle to CODEX_SQLITE_HOME #263
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,6 +15,7 @@ import { loadConfig } from "./config"; | |
| import { restoreNativeCodex, restoreNativeCodexAsync } from "./codex/inject"; | ||
| import { stripGrokConfig } from "./grok/inject"; | ||
| import { isWslRuntime, resolveCodexHomeDir, type CodexHomeDeps } from "./codex/home"; | ||
| import { resolveCodexSqliteHome } from "./codex/paths"; | ||
| import { BUN_RUNTIME_PATH_ENV, BUN_RUNTIME_SOURCE_ENV, durableBunRuntime } from "./lib/bun-runtime"; | ||
| import type { BunRuntimeSource } from "./lib/bun-runtime"; | ||
| import { isProcessAlive, stopProxy } from "./lib/process-control"; | ||
|
|
@@ -130,6 +131,8 @@ export interface ServiceInstallState { | |
| version: 1 | 2; | ||
| codexHome: string; | ||
| opencodexHome: string; | ||
| /** Effective Codex SQLite home used by this service's history integration. */ | ||
| codexSqliteHome?: string; | ||
| /** Baked at install; lets status flag paths gone stale after npm prefix/nvm moves. */ | ||
| bunPath?: string; | ||
| cliPath?: string; | ||
|
|
@@ -145,7 +148,7 @@ export function parseServiceInstallState(value: unknown): ServiceInstallState | | |
| if (state.version !== 1 && state.version !== 2) return null; | ||
| if (typeof state.codexHome !== "string" || state.codexHome.length === 0) return null; | ||
| if (typeof state.opencodexHome !== "string" || state.opencodexHome.length === 0) return null; | ||
| for (const key of ["bunPath", "cliPath", "winswVersion", "winswSha256"] as const) { | ||
| for (const key of ["codexSqliteHome", "bunPath", "cliPath", "winswVersion", "winswSha256"] as const) { | ||
| if (state[key] !== undefined && (typeof state[key] !== "string" || state[key].length === 0)) return null; | ||
| } | ||
| if (state.version === 1) { | ||
|
|
@@ -162,6 +165,7 @@ function writeServiceInstallState(backend: ServiceBackend = "scheduler"): void { | |
| version: 2, | ||
| codexHome: currentCodexHome(), | ||
| opencodexHome: currentOpenCodexHome(), | ||
| codexSqliteHome: resolveCodexSqliteHome({ codexHome: currentCodexHome() }), | ||
| bunPath: bun, | ||
| cliPath: cli, | ||
| backend, | ||
|
|
@@ -315,6 +319,15 @@ export function assertServiceEnvironmentMatchesInstall(): void { | |
| "Run the service command from the same OpenCodex home so service state and secrets match.", | ||
| ); | ||
| } | ||
| if (state.codexSqliteHome !== undefined) { | ||
| const actualCodexSqliteHome = resolveCodexSqliteHome({ codexHome: actualCodexHome }); | ||
|
Comment on lines
+322
to
+323
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. |
||
| if (normalizePathForCompare(state.codexSqliteHome) !== normalizePathForCompare(actualCodexSqliteHome)) { | ||
| throw new ServiceOwnershipError( | ||
| `Service was installed with Codex SQLite home=${state.codexSqliteHome}, but the current Codex SQLite home=${actualCodexSqliteHome}. ` + | ||
| "Run the service command with the same sqlite_home configuration and CODEX_SQLITE_HOME so native Codex history restore updates the correct database.", | ||
| ); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
config.tomlcontains a relativesqlite_home, this records the path resolved against the installer'sprocess.cwd(), but the generated plist, systemd unit, and Windows launcher do not preserve that working directory. The supervised process can therefore resolve the same configuration to another database, while a later command run from the installation directory passes this ownership check and restores the recorded—but wrong—database. Preserve a stable working directory in the service artifact or otherwise ensure the recorded path is exactly the one the child uses, with regression coverage for relativesqlite_home.AGENTS.md reference: src/AGENTS.md:L10-L10
Useful? React with 👍 / 👎.