Skip to content

Move githubCache out of the durable state file into a quit-time sidecar - #7101

Merged
nwparker merged 2 commits into
mainfrom
nwparker/github-cache-sidecar
Jul 2, 2026
Merged

nwparker merged 2 commits into
mainfrom
nwparker/github-cache-sidecar

Conversation

@nwparker

@nwparker nwparker commented Jul 2, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up to #7092: githubCache was the last remaining non-user-driven writer of orca-data.json.

Problem

Every PR/issue poll restamps fetchedAt even when the fetched data is unchanged, which defeats #7092's content-hash guard by construction: ~100KB of refetchable, 5-minute-TTL cache rewrote the entire 1.6MB durable state file once per refresh cycle (~every 2 minutes with visible PRs), forever.

Fix — the "unobservable" variant

  • The cache is memory-only during the session: setGitHubCache no longer schedules saves, and both the durable payload and the content hash omit the field (getDurableState()), so cache refreshes can never touch orca-data.json again.
  • At flush() time (app quit, updater quit, window reload, agent-auth restart) it's snapshotted best-effort to a sidecar orca-github-cache.json (tmp+rename, dirty-gated, no backups, failures swallowed) and loaded opportunistically at startup — so PR/issue badges still paint instantly on the next launch. There is no user-observable behavior change short of a hard crash, and even then the cost is one cold badge paint of refetchable data.
  • Migration: a legacy in-file cache is used as this session's seed (and marked dirty so the first flush writes the sidecar), then stripped from the durable file by the next write. Downgrades simply recreate the key; the next upgrade strips it again — bounded ping-pong, no data loss possible.

Result

orca-data.json writes are now purely user/session-action-driven, and the file shrinks ~100KB. Renderer, web (localStorage-based), and mobile (meta.linkedPR fallback) consumers are untouched — verified by call-site audit.

Review

Independent adversarial review verified six invariants (no durable writer can reinclude the key — including the offline CLI round-trip and pre-upgrade backup restores; hash/payload consistency; migration & ping-pong bounds; sidecar dirty-flag lifecycle across all flush call sites; consumer tolerance; type-safety through zod-failure/backup-recursion paths). Its one finding — sidecar validation accepted null/array pr/issue shapes, which could crash mobile PR grouping on a corrupt sidecar — is fixed in the second commit. 329 persistence tests pass (3 new: no-rewrite-on-refresh, flush-snapshot + restart seeding, legacy strip).

Made with Orca 🐋

nwparker and others added 2 commits July 2, 2026 02:40
Every PR/issue poll restamps fetchedAt even when nothing changed, which
defeated the content-hash write guard by construction: ~100KB of
refetchable 5-min-TTL cache rewrote the whole 1.6MB orca-data.json once
per refresh cycle - the last remaining non-user-driven writer.

The cache is now memory-only during the session (setGitHubCache no
longer schedules a save; the durable payload and state hash both omit
it) and is snapshotted best-effort to orca-github-cache.json at flush
(quit/reload), so PR/issue badges still paint instantly on next launch.
A legacy in-file cache is used as the seed and stripped by the next
durable write; downgrades just recreate the key, which the next upgrade
strips again. Sidecar loss costs nothing - the data is refetchable.

Co-authored-by: Orca <[email protected]>
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 <[email protected]>
@nwparker
nwparker merged commit 3ba3630 into main Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 7ab42298-8094-4d75-9717-327f78d53d83

📥 Commits

Reviewing files that changed from the base of the PR and between e3f99a7 and ff165af.

📒 Files selected for processing (2)
  • src/main/persistence.test.ts
  • src/main/persistence.ts

📝 Walkthrough

Walkthrough

The persistence layer now stores GitHub cache data (githubCache) in a dedicated sidecar file (orca-github-cache.json) instead of embedding it in the primary orca-data.json state file. New helpers resolve the sidecar path and load/validate its snapshot. Store.load() migrates legacy in-file cache data when present or seeds from the sidecar. A getDurableState() helper excludes githubCache from hash computation and on-disk payload serialization, ensuring cache refreshes don't rewrite the durable state file. setGitHubCache() now only updates in-memory state and marks a dirty flag, while flush() performs an atomic sidecar write when needed. New tests cover these behaviors.

Changes

Cohort / File(s) Summary
Sidecar persistence — src/main/persistence.ts Added getGithubCacheFile(), readGithubCacheSnapshot(), githubCacheDirty flag, getDurableState() helper; updated load(), computeStateHash(), disk write payload, setGitHubCache(), and flush() to route cache writes through a sidecar file.
Sidecar persistence tests — src/main/persistence.test.ts Added tests verifying durable state file stability, sidecar write/reload, and legacy in-file cache migration/removal.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant Store
  participant DurableStateFile as orca-data.json
  participant SidecarFile as orca-github-cache.json

  Caller->>Store: setGitHubCache(data)
  Store->>Store: update in-memory githubCache
  Store->>Store: set githubCacheDirty = true

  Caller->>Store: flush()
  Store->>Store: getDurableState() (excludes githubCache)
  Store->>DurableStateFile: write durable payload (unchanged if only cache changed)
  alt githubCacheDirty
    Store->>SidecarFile: writeGithubCacheSnapshotSync() (tmp+rename)
    Store->>Store: githubCacheDirty = false
  end

  Caller->>Store: new Store / load()
  Store->>DurableStateFile: read state
  alt legacy in-file githubCache present
    Store->>Store: seed githubCache from legacy data, mark loadNeedsSave
  else
    Store->>SidecarFile: readGithubCacheSnapshot()
    SidecarFile-->>Store: cache snapshot
    Store->>Store: seed githubCache from sidecar
  end
Loading

Related issues: None found.

Related PRs: None found.

Suggested labels: persistence, github-cache

Suggested reviewers: None identified from the provided context.

Poem: A rabbit hops with cache in paw, into a sidecar file it saw. The main state stays untouched and neat, while GitHub data finds its own seat. Flush by flush, atomic and light, the cache and state now sleep well at night. 🐇📁

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

enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…ar (stablyai#7101)

* Move githubCache out of the durable state file into a quit-time sidecar

Every PR/issue poll restamps fetchedAt even when nothing changed, which
defeated the content-hash write guard by construction: ~100KB of
refetchable 5-min-TTL cache rewrote the whole 1.6MB orca-data.json once
per refresh cycle - the last remaining non-user-driven writer.

The cache is now memory-only during the session (setGitHubCache no
longer schedules a save; the durable payload and state hash both omit
it) and is snapshotted best-effort to orca-github-cache.json at flush
(quit/reload), so PR/issue badges still paint instantly on next launch.
A legacy in-file cache is used as the seed and stripped by the next
durable write; downgrades just recreate the key, which the next upgrade
strips again. Sidecar loss costs nothing - the data is refetchable.

Co-authored-by: Orca <[email protected]>

* 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 <[email protected]>

---------

Co-authored-by: Orca <[email protected]>
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