-
Notifications
You must be signed in to change notification settings - Fork 23
fix: use async settings read with timeout in preSpawn path #100
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: dev
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 |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| /** | ||
| * Generate temporary settings file with Claude hooks for session tracking | ||
| * | ||
| * | ||
| * Creates a settings.json file that configures Claude's SessionStart hook | ||
| * to notify our HTTP server when sessions change (new session, resume, compact, etc.) | ||
| */ | ||
|
|
@@ -10,7 +10,7 @@ import { writeFileSync, mkdirSync, unlinkSync, existsSync } from 'node:fs'; | |
| import { configuration } from '@/configuration'; | ||
| import { logger } from '@/ui/logger'; | ||
| import { projectPath } from '@/projectPath'; | ||
| import { readClaudeSettings, type ClaudeSettings } from './claudeSettings'; | ||
| import { readClaudeSettingsAsync, type ClaudeSettings } from './claudeSettings'; | ||
| import { isBun } from '@/utils/runtime'; | ||
|
|
||
| export interface GenerateHookSettingsOptions { | ||
|
|
@@ -25,11 +25,14 @@ export interface GenerateHookSettingsOptions { | |
|
|
||
| /** | ||
| * Generate a temporary settings file with SessionStart hook configuration | ||
| * | ||
| * | ||
| * Uses async file I/O with timeout to read base settings, preventing | ||
| * indefinite hangs on slow or inaccessible filesystems. | ||
| * | ||
| * @param port - The port where Happy server is listening | ||
| * @returns Path to the generated settings file | ||
| */ | ||
| export function generateHookSettingsFile(port: number, options: GenerateHookSettingsOptions = {}): string { | ||
| export async function generateHookSettingsFile(port: number, options: GenerateHookSettingsOptions = {}): Promise<string> { | ||
|
Contributor
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. changing this to async breaks the existing caller at // runClaude.ts line 513 (not updated in this PR):
const hookSettingsPath = generateHookSettingsFile(hookServer.port, {needs to be: const hookSettingsPath = await generateHookSettingsFile(hookServer.port, {
Contributor
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. tests in lines 26, 38, 65, and 102 all need:
|
||
| const hooksDir = join(configuration.happyHomeDir, 'tmp', 'hooks'); | ||
| mkdirSync(hooksDir, { recursive: true }); | ||
|
|
||
|
|
@@ -78,7 +81,7 @@ export function generateHookSettingsFile(port: number, options: GenerateHookSett | |
| ]; | ||
| } | ||
|
|
||
| const baseSettings: ClaudeSettings = readClaudeSettings(options.claudeConfigDir) ?? {}; | ||
| const baseSettings: ClaudeSettings = await readClaudeSettingsAsync(options.claudeConfigDir) ?? {}; | ||
| const baseHooks = | ||
| baseSettings && typeof baseSettings === 'object' && baseSettings.hooks && typeof baseSettings.hooks === 'object' | ||
| ? (baseSettings.hooks as Record<string, unknown>) | ||
|
|
@@ -124,7 +127,7 @@ export function generateHookSettingsFile(port: number, options: GenerateHookSett | |
|
|
||
| /** | ||
| * Clean up the temporary hook settings file | ||
| * | ||
| * | ||
| * @param filepath - Path to the settings file to remove | ||
| */ | ||
| export function cleanupHookSettingsFile(filepath: string): void { | ||
|
|
||
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.
existsSync()is still synchronous and could block on slow filesystems (same issue asreadFileSync). consider usingfs.promises.access()with the abort signal instead