Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

Hook: give Hermes' store as long as the process scan to answer (#390)

Deec9577b429756
diff --git a/cli/hook/notify.mjs b/cli/hook/notify.mjs
index a198ad924..3c4a1904a 100644
--- a/cli/hook/notify.mjs
+++ b/cli/hook/notify.mjs
@@ -794,7 +794,9 @@ async function hermesTopLevelSession(dbPath, sessionId) {
const raw = await execFileText('sqlite3', [
'-json', '-cmd', '.timeout 500', '-cmd', 'PRAGMA query_only=1', `file:${db}?mode=ro`,
`SELECT source FROM sessions WHERE id = '${sessionId}';`,
- ], 1000)
+ // As long as the process scan gets: on a loaded machine a second is not always enough to
+ // spawn sqlite3, and a lookup cut short drops a real session's registration.
+ ], 3000)
if (raw === null) continue // unreadable store — another home may still hold the row
sawStore = true
try {
diff --git a/cli/src/hookNotify.spec.ts b/cli/src/hookNotify.spec.ts
index 4027a15a8..c7e833cd8 100644
--- a/cli/src/hookNotify.spec.ts
+++ b/cli/src/hookNotify.spec.ts
@@ -50,6 +50,8 @@ interface RunHookOpts {
hermesHome?: string
/** Fake Hermes SQLite source; null means the session row has not appeared. */
hermesSource?: 'cli' | 'subagent' | null
+ /** How long Hermes' store takes to answer: a loaded machine. */
+ hermesDelaySeconds?: number
grokHome?: string
devinHome?: string
input?: Record<string, unknown>
@@ -89,7 +91,8 @@ function runHook(opts: RunHookOpts): Promise<string> {
}
if (opts.hermesSource !== undefined) {
const rows = opts.hermesSource === null ? '[]' : JSON.stringify([{ source: opts.hermesSource }])
- writeFileSync(join(binDir, 'sqlite3'), `#!/bin/sh\nprintf '%s\\n' '${rows}'\n`, { mode: 0o755 })
+ const delay = opts.hermesDelaySeconds ? `sleep ${opts.hermesDelaySeconds}\n` : ''
+ writeFileSync(join(binDir, 'sqlite3'), `#!/bin/sh\n${delay}printf '%s\\n' '${rows}'\n`, { mode: 0o755 })
}
env.PATH = `${binDir}:${env.PATH ?? ''}`
}
@@ -720,6 +723,28 @@ describe('hook notify terminal scope', () => {
}
})
+ it('still binds a CLI Hermes session when its store is slow to answer, as on a loaded machine', async () => {
+ const dir = mkdtempSync(join(tmpdir(), 'adapter-hook-hermes-slow-'))
+ tmpDirs.push(dir)
+ const dataDir = join(dir, 'data')
+ await runHook({
+ port: 9,
+ tmuxPane: '%83',
+ engine: 'hermes',
+ processEngine: 'hermes',
+ processExecutable: 'python3',
+ processArgs: 'python3 /opt/venvs/hermes/lib/python3.12/site-packages/hermes-agent/hermes',
+ hermesHome: join(dir, 'hermes'),
+ dataDir,
+ hermesSource: 'cli',
+ hermesDelaySeconds: 1.5,
+ input: { hook_event_name: 'on_session_start', session_id: '20260810_120003_a1b2c3' },
+ })
+ expect(JSON.parse(readFileSync(join(dataDir, 'registry.json'), 'utf8'))).toMatchObject([{
+ sessionId: '20260810_120003_a1b2c3', engine: 'hermes', tmuxPane: '%83',
+ }])
+ })
+
it('does not fallback when the adapter accepts the hook event', async () => {
const dir = mkdtempSync(join(tmpdir(), 'adapter-hook-online-'))
tmpDirs.push(dir)