fix: guard session_ids with optional chaining to prevent crash
boulderState?.session_ids.includes() only guards boulderState, not session_ids. If boulder.json is corrupted or missing the field, session_ids is undefined and .includes() crashes silently, losing subagent results. Changes: - readBoulderState: validate parsed JSON is object, default session_ids to [] - atlas hook line 427: boulderState?.session_ids?.includes - atlas hook line 655: boulderState?.session_ids?.includes - prometheus-md-only line 93: boulderState?.session_ids?.includes - appendSessionId: guard with ?. and initialize to [] if missing Fixes #1672
This commit is contained in:
@@ -22,7 +22,14 @@ export function readBoulderState(directory: string): BoulderState | null {
|
||||
|
||||
try {
|
||||
const content = readFileSync(filePath, "utf-8")
|
||||
return JSON.parse(content) as BoulderState
|
||||
const parsed = JSON.parse(content)
|
||||
if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
|
||||
return null
|
||||
}
|
||||
if (!Array.isArray(parsed.session_ids)) {
|
||||
parsed.session_ids = []
|
||||
}
|
||||
return parsed as BoulderState
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
@@ -48,7 +55,10 @@ export function appendSessionId(directory: string, sessionId: string): BoulderSt
|
||||
const state = readBoulderState(directory)
|
||||
if (!state) return null
|
||||
|
||||
if (!state.session_ids.includes(sessionId)) {
|
||||
if (!state.session_ids?.includes(sessionId)) {
|
||||
if (!Array.isArray(state.session_ids)) {
|
||||
state.session_ids = []
|
||||
}
|
||||
state.session_ids.push(sessionId)
|
||||
if (writeBoulderState(directory, state)) {
|
||||
return state
|
||||
|
||||
Reference in New Issue
Block a user