Skip to content

fix(agent-hooks): keep Node 18 relay companion loadable - #13135

Merged
Jinwoo-H merged 1 commit into
mainfrom
release-p1-node18-managed-hook
Aug 8, 2026
Merged

Jinwoo-H merged 1 commit into
mainfrom
release-p1-node18-managed-hook

Conversation

@Jinwoo-H

@Jinwoo-H Jinwoo-H commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • load node:sqlite only when the synchronous DB adapter is constructed
  • keep the Node-18 SSH managed-hook companion loadable when desktop-only Codex state inspection is unused
  • add a real Node 18 smoke that loads all six shipped companions and installs Codex + Claude hooks in an isolated home
  • make the Node 18 lane part of the required PR aggregate check

Regression from #12617.

Deterministic evidence

Baseline/current-main artifact:

pnpm run build:relay
npx -y node@18 config/scripts/smoke-managed-hook-runtime-node18.mjs

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

  • Node 18 packaged smoke: pass
  • focused managed-hook/Codex/SSH suite: 136 passed, 5 skipped
  • workflow contract: 12 passed
  • typecheck: pass
  • full lint: pass
  • relay and Electron production builds: pass
  • Electron 43 / Node 24.18 DatabaseSync construction: pass
  • adversarial review: ship, no P0/P1/P2 findings

The 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.

@Jinwoo-H
Jinwoo-H merged commit cf16eac into main Aug 8, 2026
45 checks passed
Jinwoo-H added a commit that referenced this pull request Aug 8, 2026
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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 DatabaseSync dynamically through process.getBuiltinModule and reports when node:sqlite is unavailable.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the change and validation, but it omits the required Screenshots, AI Review Report, Security Audit, and Notes sections. Add all required template sections, including explicit visual-change status, AI review details, security audit findings, and platform-specific notes.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: keeping the Node 18 relay companion loadable.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between bba32bd and 7f824f3.

📒 Files selected for processing (5)
  • .github/workflows/pr.yml
  • config/reliability-gates.jsonc
  • config/scripts/pr-workflow-parallelism.test.mjs
  • config/scripts/smoke-managed-hook-runtime-node18.mjs
  • src/main/sqlite/sync-database.ts

Comment on lines +100 to +116
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)
})

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 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.

Suggested change
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)
})

Comment on lines +19 to +24
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 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:


🌐 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:


🌐 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:


🏁 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))
}
JS

Repository: 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
fi

Repository: 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}")
PY

Repository: 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:


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.

Suggested change
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

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant