Repository navigation
fix(agent-hooks): keep Node 18 relay companion loadable - #13135
Conversation
Co-authored-by: Jinwoo-H <[email protected]>
📝 WalkthroughWalkthroughThe pull request adds a Node 18 CI job for managed-hook companion artifacts. The job builds relay companions and runs an isolated runtime smoke test across six platforms for Codex and Claude hooks. Aggregate verification now requires this job to pass. A reliability gate records coverage, evidence, budgets, and promotion rules. The SQLite database wrapper now loads 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b063ae86-4912-4690-93bd-392ec3ade7b1
📒 Files selected for processing (5)
.github/workflows/pr.ymlconfig/reliability-gates.jsoncconfig/scripts/pr-workflow-parallelism.test.mjsconfig/scripts/smoke-managed-hook-runtime-node18.mjssrc/main/sqlite/sync-database.ts
| it('smokes managed-hook companions under their supported Node 18 runtime', () => { | ||
| const steps = workflow.jobs.managed_hook_node18.steps | ||
| const installIndex = steps.findIndex( | ||
| (step) => step.uses === './.github/actions/install-node-dependencies' | ||
| ) | ||
| const buildIndex = steps.findIndex((step) => step.run === 'pnpm run build:relay') | ||
| const node18Index = steps.findIndex( | ||
| (step) => step.uses === 'actions/setup-node@v6' && step.with['node-version'] === '18' | ||
| ) | ||
| const smokeIndex = steps.findIndex( | ||
| (step) => step.run === 'node config/scripts/smoke-managed-hook-runtime-node18.mjs' | ||
| ) | ||
|
|
||
| expect(installIndex).toBeLessThan(buildIndex) | ||
| expect(buildIndex).toBeLessThan(node18Index) | ||
| expect(node18Index).toBeLessThan(smokeIndex) | ||
| }) |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Assert each step index is found before comparing order.
findIndex returns -1 when no step matches. If any of installIndex, buildIndex, node18Index, or smokeIndex stops matching a step (for example after a future rename), it becomes -1. Because -1 can be less than a valid index, toBeLessThan can still pass even though the corresponding step is missing. Add an explicit presence check before the ordering assertions.
🐛 Proposed fix to guard against a silently missing step
const smokeIndex = steps.findIndex(
(step) => step.run === 'node config/scripts/smoke-managed-hook-runtime-node18.mjs'
)
+ for (const [label, index] of [
+ ['install-node-dependencies', installIndex],
+ ['build:relay', buildIndex],
+ ['setup-node 18', node18Index],
+ ['smoke script', smokeIndex]
+ ]) {
+ expect(index, `${label} step not found`).toBeGreaterThanOrEqual(0)
+ }
expect(installIndex).toBeLessThan(buildIndex)
expect(buildIndex).toBeLessThan(node18Index)
expect(node18Index).toBeLessThan(smokeIndex)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('smokes managed-hook companions under their supported Node 18 runtime', () => { | |
| const steps = workflow.jobs.managed_hook_node18.steps | |
| const installIndex = steps.findIndex( | |
| (step) => step.uses === './.github/actions/install-node-dependencies' | |
| ) | |
| const buildIndex = steps.findIndex((step) => step.run === 'pnpm run build:relay') | |
| const node18Index = steps.findIndex( | |
| (step) => step.uses === 'actions/setup-node@v6' && step.with['node-version'] === '18' | |
| ) | |
| const smokeIndex = steps.findIndex( | |
| (step) => step.run === 'node config/scripts/smoke-managed-hook-runtime-node18.mjs' | |
| ) | |
| expect(installIndex).toBeLessThan(buildIndex) | |
| expect(buildIndex).toBeLessThan(node18Index) | |
| expect(node18Index).toBeLessThan(smokeIndex) | |
| }) | |
| it('smokes managed-hook companions under their supported Node 18 runtime', () => { | |
| const steps = workflow.jobs.managed_hook_node18.steps | |
| const installIndex = steps.findIndex( | |
| (step) => step.uses === './.github/actions/install-node-dependencies' | |
| ) | |
| const buildIndex = steps.findIndex((step) => step.run === 'pnpm run build:relay') | |
| const node18Index = steps.findIndex( | |
| (step) => step.uses === 'actions/setup-node@v6' && step.with['node-version'] === '18' | |
| ) | |
| const smokeIndex = steps.findIndex( | |
| (step) => step.run === 'node config/scripts/smoke-managed-hook-runtime-node18.mjs' | |
| ) | |
| for (const [label, index] of [ | |
| ['install-node-dependencies', installIndex], | |
| ['build:relay', buildIndex], | |
| ['setup-node 18', node18Index], | |
| ['smoke script', smokeIndex] | |
| ]) { | |
| expect(index, `${label} step not found`).toBeGreaterThanOrEqual(0) | |
| } | |
| expect(installIndex).toBeLessThan(buildIndex) | |
| expect(buildIndex).toBeLessThan(node18Index) | |
| expect(node18Index).toBeLessThan(smokeIndex) | |
| }) |
| function loadDatabaseSync(): typeof DatabaseSync { | ||
| if (typeof process.getBuiltinModule !== 'function') { | ||
| throw new Error('node:sqlite is unavailable in this Node.js runtime') | ||
| } | ||
| return (process.getBuiltinModule('node:sqlite') as { DatabaseSync: typeof DatabaseSync }) | ||
| .DatabaseSync |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
node -p "JSON.stringify({node: process.version, hasGetBuiltinModule: typeof process.getBuiltinModule === 'function', hasSqlite: typeof process.getBuiltinModule === 'function' && !!process.getBuiltinModule('node:sqlite')})"Repository: stablyai/orca
Length of output: 215
🌐 Web query:
Node.js process.getBuiltinModule return undefined when built-in module unavailable documentation
💡 Result:
In Node.js, the process.getBuiltinModule(id) method is designed to provide a way to load built-in modules synchronously [1][2][3]. According to official documentation and implementation details, its behavior regarding the return value is as follows: If the provided id corresponds to a valid built-in module recognized by module.isBuiltin(id), the method returns that built-in module [2][3][4]. If the provided id does not correspond to any built-in module, the method returns undefined [2][3][4]. It is important to note that if an invalid argument type (such as a number, null, or object) is passed as the id, the method will throw an ERR_INVALID_ARG_TYPE error rather than returning undefined [5]. Additionally, some built-in modules may require the node: prefix to be correctly identified [4][6]. This method was introduced to allow ES modules to conditionally load Node.js built-in modules in a cross-environment compatible way, avoiding the resolution errors associated with import in non-Node.js environments or the complexities of dynamic import [2][3]. Because it is a newer API (introduced in Node.js v22.3.0, with backports to some earlier LTS versions like v20.16.0), developers should ensure the environment supports it, typically by checking for its existence (e.g., if (globalThis.process?.getBuiltinModule)) before use [3][7][8].
Citations:
- 1: https://nodejs.org/api/process.md
- 2: process: add process.getBuiltinModule(id) nodejs/node#52762
- 3: https://nodejs.org/en/blog/release/v20.16.0
- 4: https://nodejs-api-docs-tooling.vercel.app/process.html
- 5: https://github.com/nodejs/node/blob/d90d9d55/test/parallel/test-process-get-builtin.mjs
- 6: https://beta.docs.nodejs.org/process.html
- 7: feat: support process.getBuiltinModule nodejs/require-in-the-middle#92
- 8: Instrument modules loaded via
process.getBuiltinModule? open-telemetry/opentelemetry-js#4742
🌐 Web query:
Node.js v20.16.0 node sqlite DatabaseSync node:sqlite
💡 Result:
The node:sqlite module, introduced in Node.js v22.5.0, provides a built-in, zero-dependency way to interact with SQLite databases [1][2]. The DatabaseSync class within this module allows for synchronous interaction with SQLite databases, making it well-suited for scripts, migrations, CLI tools, and test fixtures [3][4]. Key details regarding DatabaseSync and the node:sqlite module: 1. Synchronous Design: All APIs exposed by the DatabaseSync class are synchronous [3][5]. This is a deliberate choice for simplicity in specific use cases and means operations will block the event loop [4][2]. 2. Initialization: You can create a new database instance by providing a file path or the special string ':memory:' to use an in-memory database [3][5]. import { DatabaseSync } from 'node:sqlite'; const database = new DatabaseSync(':memory:'); 3. Evolution of Status: While the module was initially experimental and required the --experimental-sqlite flag in early v22.x releases, it has matured in later versions of Node.js [1][4]. In Node.js v24 and v26, the module is available without experimental flags or warnings [4]. 4. Functionality: The DatabaseSync class includes methods for executing SQL, preparing statements, and managing database connections. Common methods include: - database.exec(sql): Executes one or more SQL statements without returning results, often used for DDL [6][4]. - database.prepare(sql): Compiles a SQL statement into a prepared statement for parameterized queries [7][4]. - database.open: Opens the database connection if it was not opened automatically by the constructor [5][8]. As of August 2026, node:sqlite is a stable, built-in feature in modern Node.js versions [4]. Developers are encouraged to use it for single-process services, local tooling, and prototypes, while considering its synchronous nature when evaluating it for high-concurrency environments [4].
Citations:
- 1: https://www.infoworld.com/article/3537050/intro-to-nodes-built-in-sqlite-module.html
- 2: https://blog.logrocket.com/using-built-in-sqlite-module-node-js/
- 3: https://nodejs.org/api/sqlite.md
- 4: https://codewithnodejs.com/node-sqlite-a-built-in-database-with-zero-dependencies/
- 5: https://nodejs.org/docs/v22.12.0/api/sqlite.html
- 6: https://nodejs.org/docs/v22.11.0/api/sqlite.html
- 7: https://docs.deno.com/api/node/sqlite/~/DatabaseSync
- 8: https://nodejs.org/docs/v22.14.0/api/sqlite.html
🌐 Web query:
Node.js process.getBuiltinModule v20.16.0 getBuiltinModule added documentation
💡 Result:
The process.getBuiltinModule(id) method was introduced in Node.js version 20.16.0, which was released on July 24, 2024 [1][2]. This method provides a synchronous, globally available function to load Node.js built-in modules [1]. It is particularly useful for ES Modules that need to conditionally load Node.js built-in modules in a cross-environment compatible way, avoiding issues with dynamic import (which can introduce asynchronicity) or import errors in non-Node.js environments [1][2]. Key details regarding process.getBuiltinModule(id): - Availability: It accepts module IDs recognized by module.isBuiltin(id) [1][2]. - Return Value: It returns the corresponding built-in module if the ID is valid, or undefined if the ID does not correspond to any built-in module [1][2]. - Behavior: The references returned by this method always point to the original built-in module, even if a user modifies require.cache to return a different object for that module ID [1][2]. The addition of this feature was tracked in pull request #52762 [3][2] and commit 67333a5796 [4][5]. Documentation for this method was added to the Node.js process API documentation as part of this same implementation [4][5].
Citations:
- 1: https://nodejs.org/en/blog/release/v20.16.0/
- 2: https://github.com/nodejs/node/releases/tag/v20.16.0
- 3: process: add process.getBuiltinModule(id) nodejs/node#52762
- 4: nodejs/node@67333a5796
- 5: nodejs/node@374743cd4e
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Node version:"
node -p "process.version"
echo "Process function existence before loading file:"
node -p "JSON.stringify({hasGetBuiltinModule: typeof process.getBuiltinModule === 'function'})"
echo "Loaded module shape:"
node - <<'JS'
const sqliteModule = process.getBuiltinModule('node:sqlite')
console.log(JSON.stringify({
node: process.version,
sqliteModuleNullish: sqliteModule == null,
sqliteModuleType: sqliteModule == null ? 'nullish' : typeof sqliteModule,
databaseSyncNullish: sqliteModule && sqliteModule.DatabaseSync == null,
databaseSyncType: sqliteModule && sqliteModule.DatabaseSync == null ? 'nullish' : sqliteModule.DatabaseSync === Function.prototype.constructor ? 'class' : 'not constructor-like'
}, null, 2))
JS
echo "loadDatabaseSync import behavior:"
node - <<'JS'
try {
const module = await import('./src/main/sqlite/sync-database.js')
const LoadDatabaseSync = module.loadDatabaseSync ?? module.loadDatabaseSync?.default
const DatabaseSync = typeof LoadDatabaseSync === 'function' ? LoadDatabaseSync() : LoadDatabaseSync
console.log(JSON.stringify({
node: process.version,
loadDatabaseSyncType: typeof LoadDatabaseSync,
returnedDatabaseSyncType: typeof DatabaseSync
}, null, 2))
} catch (error) {
console.log(JSON.stringify({
node: process.version,
errorName: error && error.name,
errorMessage: error && error.message,
stackFrameContainsSyncDatabase: (error && error.stack) && error.stack.includes('sync-database')
}, null, 2))
}
JSRepository: stablyai/orca
Length of output: 699
🏁 Script executed:
#!/bin/bash
set -euo pipefail
# Locate and inspect the TypeScript source without importing building any repository code.
fd -a 'sync-database\.(ts|tsx|js|jsx)$' . | sed 's#^\./##'
file="$(fd 'sync-database\.ts$' . | head -n 1)"
if [ -z "${file:-}" ]; then
file="$(fd 'sync-database\.js$' . | head -n 1)"
fi
if [ -n "${file:-}" ]; then
echo "file=$file"
wc -l "$file"
sed -n '1,80p' "$file" | cat -n
fiRepository: stablyai/orca
Length of output: 2717
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "Node metadata files:"
git ls-files | rg '(^|/)(package\.json|package-lock\.json|pnpm-lock\.yaml|yarn\.lock|\.nvmrc|\.node-version|\.tool-versions)$' || true
for file in $(git ls-files | rg '(^|/)(package\.json|package-lock\.json|pnpm-lock\.yaml|yarn\.lock|\.nvmrc|\.node-version|\.tool-versions)$' || true); do
echo "--- $file"
sed -n '1,220p' "$file" | rg -n 'node|engines|NODE|volta|volta|getBuiltinModule|sqlite|Dependencies|devDependencies|packageManager|engineStrict|typesVersions|ts-node|main|module|exports|engines|node18|node20|node22' -i || true
done
echo "--- read-only simulated loadDatabaseSync behavior from TypeScript source"
python3 - <<'PY'
from pathlib import Path
src = Path('src/main/sqlite/sync-database.ts').read_text()
checks = [
'if (typeof process.getBuiltinModule !== \'function\')',
'process.getBuiltinModule(\'node:sqlite\')',
'.DatabaseSync',
'export default SyncDatabase',
]
for needle in checks:
print(f"{needle!r}: {needle in src}")
PYRepository: stablyai/orca
Length of output: 11351
🌐 Web query:
Node.js v22.3.0 process.getBuiltinModule backport version getBuiltinModule added
💡 Result:
The process.getBuiltinModule(id) method was introduced in Node.js v22.3.0 [1][2]. Following its introduction, it was subsequently backported to Node.js v20.16.0 (LTS) [3][4]. This method provides a synchronous way to load Node.js built-in modules, which is particularly useful in ES Modules or environments where standard resolution might encounter issues [3][5]. It accepts built-in module identifiers recognized by module.isBuiltin(id) and returns the corresponding module, or undefined if the identifier does not correspond to a built-in module [3][6]. References returned by this method are not affected by modifications to require.cache [3][6].
Citations:
- 1: https://github.com/nodejs/node/releases/tag/v22.3.0
- 2: https://github.com/nodejs/node/blob/v22.3.0/doc/changelogs/CHANGELOG_V22.md
- 3: https://nodejs.org/en/blog/release/v20.16.0/
- 4: https://github.com/nodejs/node/releases/tag/v20.16.0
- 5: process: add process.getBuiltinModule(id) nodejs/node#52762
- 6: nodejs/node@67333a5796
Check the returned node:sqlite module before accessing DatabaseSync.
process.getBuiltinModule() can return undefined, while DatabaseSync was added later than the backported API. If process.getBuiltinModule('node:sqlite') returns no module, Line 24 throws TypeError instead of the existing runtime error.
Proposed fix
- return (process.getBuiltinModule('node:sqlite') as { DatabaseSync: typeof DatabaseSync })
- .DatabaseSync
+ const sqlite = process.getBuiltinModule('node:sqlite') as
+ | { DatabaseSync?: typeof DatabaseSync }
+ | undefined
+ if (!sqlite?.DatabaseSync) {
+ throw new Error('node:sqlite is unavailable in this Node.js runtime')
+ }
+ return sqlite.DatabaseSync[nice?]
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| function loadDatabaseSync(): typeof DatabaseSync { | |
| if (typeof process.getBuiltinModule !== 'function') { | |
| throw new Error('node:sqlite is unavailable in this Node.js runtime') | |
| } | |
| return (process.getBuiltinModule('node:sqlite') as { DatabaseSync: typeof DatabaseSync }) | |
| .DatabaseSync | |
| function loadDatabaseSync(): typeof DatabaseSync { | |
| if (typeof process.getBuiltinModule !== 'function') { | |
| throw new Error('node:sqlite is unavailable in this Node.js runtime') | |
| } | |
| const sqlite = process.getBuiltinModule('node:sqlite') as | |
| | { DatabaseSync?: typeof DatabaseSync } | |
| | undefined | |
| if (!sqlite?.DatabaseSync) { | |
| throw new Error('node:sqlite is unavailable in this Node.js runtime') | |
| } | |
| return sqlite.DatabaseSync |
Co-authored-by: Jinwoo-H <[email protected]>
Summary
node:sqliteonly when the synchronous DB adapter is constructedRegression from #12617.
Deterministic evidence
Baseline/current-main artifact:
Exited 1 before exports with
ERR_UNKNOWN_BUILTIN_MODULE: node:sqlite.Candidate: all six companions load; Codex and Claude return 2 installers / 0 errors and create executable managed scripts plus configs. Restoring the eager import makes the byte-identical oracle red again.
Validation
DatabaseSyncconstruction: passThe full suite reached 48,164 passing tests. Six known order/platform-sensitive failures matched the release audit; relay execution and PTY groups passed in isolation (10/10 and 114/114), while three unchanged root-guard tests remain incompatible with macOS Bash 3.2.