Reject null/array pr-issue shapes when reading the github cache sidecar

A corrupt-but-valid-JSON sidecar ({"pr":null}) would seed
state.githubCache.pr = null and crash mobile worktree.ps PR grouping
until the renderer's first cache save repaired it.

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
Neil
2026-07-02 02:50:34 -07:00
co-authored by Orca
parent 05fdd91169
commit ff165afc5f
+5 -4
View File
@@ -338,11 +338,12 @@ function getGithubCacheFile(): string {
function readGithubCacheSnapshot(): PersistedState['githubCache'] | null {
try {
const parsed = JSON.parse(readFileSync(getGithubCacheFile(), 'utf-8')) as unknown
const isPlainRecord = (value: unknown): value is Record<string, unknown> =>
typeof value === 'object' && value !== null && !Array.isArray(value)
if (
parsed &&
typeof parsed === 'object' &&
typeof (parsed as { pr?: unknown }).pr === 'object' &&
typeof (parsed as { issue?: unknown }).issue === 'object'
isPlainRecord(parsed) &&
isPlainRecord((parsed as { pr?: unknown }).pr) &&
isPlainRecord((parsed as { issue?: unknown }).issue)
) {
return parsed as PersistedState['githubCache']
}