Skip to content

fix(integrations): reload Jira and Linear state files when another process rewrites them - #13125

Closed
tisohjung wants to merge 3 commits into
stablyai:mainfrom
tisohjung:fix/integration-site-file-cache-invalidation
Closed

tisohjung wants to merge 3 commits into
stablyai:mainfrom
tisohjung:fix/integration-site-file-cache-invalidation

Conversation

@tisohjung

@tisohjung tisohjung commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Connect Jira or Linear in one Orca window, and any other Orca running on the same machine keeps saying "not connected" until you restart it. This makes the other one notice.

What Changed

Jira and Linear both memoized their state file — ~/.orca/jira-sites.json and ~/.orca/linear-workspaces.json — on first read and never invalidated it:

function getSiteFile(): JiraSiteFile {
  if (!siteFileLoaded || !cachedSiteFile) {
    cachedSiteFile = readSiteFileFromDisk()
    siteFileLoaded = true
  }
  return cachedSiteFile
}

The cache now carries the file's inode, size, and mtime, and reloads when that stamp moves. Both clients share one createIntegrationStateFileCache() helper instead of the fix being written twice.

Why

That directory is shared by every Orca process on the machine — an installed app beside a dev build, or orca serve beside the desktop app. A process that started before the file existed reports "not connected" for its whole life, including to any paired client reading its connection status.

Writes call invalidate() rather than caching the value they just wrote. Stamping our own write would record whatever is on disk at that instant, so a concurrent writer slipping in between would pin our value under their stamp — permanently stale, because the stamps then agree forever. Reloading costs one read after each write, and writes only happen on connect, disconnect, and site selection.

Tokens already read through to disk on a cache miss, so only the state files needed this.

Linked Issue

No linked issue. This was found while working on #13126 (Jira on mobile), where a stale connection status was one of the candidate explanations for a paired client reporting "not connected". It turned out not to be the cause there, but the staleness is real and reproducible on its own, so it is split out here rather than folded into that PR.

Visual Proof

N/A — this only changes when an existing connection status is recomputed. No UI, layout, or interaction changes.

Testing

Manually verified on macOS with two Orca processes sharing ~/.orca: connecting in one is picked up by the other without a restart.

The bug was originally found the same way round — a desktop process that had started a day before ~/.orca/jira-sites.json first existed still reported no Jira connection, indefinitely.

pnpm test reports failures in 16 files locally. Re-running those files serially leaves 15 passing, and the remaining one (config/scripts/check-root-directory-entries.test.mjs) fails identically on a clean tree with this branch stashed. No Jira, Linear, or integration-cache test fails in either run.

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

10 new tests: 5 on the helper (memoize while unchanged, reload on change, reload when the file appears after an absent first read, reload on removal, and a write landing between the stamp and the read that must self-correct rather than pin), 3 on the Jira client, 2 on Linear. Each was confirmed to fail with the invalidation removed, and the interleaving test was confirmed to fail if get() is reordered to stamp after reading — so they pin the behaviour rather than the implementation.

AI Disclosure

Written with Claude Opus 5 (via Claude Code). Human Review & QA.

Review

Security. Credential handling is unchanged: tokens still load through integration-credential-file, decrypt failures still surface via credentialErrors, and nothing new is written, logged, or widened. The cache now notices a file another process wrote — the same directory and permissions the client already trusted.

Cross-platform. node:fs statSync only; no shell, no path assumptions beyond the existing join(homedir(), '.orca'). stats.ino is a real file index on macOS and Linux; on Windows it can be reported as 0, in which case the stamp degrades to size + mtime, which still detects every write this guards against. Sub-second mtimeMs is available on all three platforms, so a same-second rewrite is still caught.

Remote SSH / backwards compatibility. Each host — native, WSL distro, SSH host, relay — runs its own main process against its own ~/.orca, so the fix applies per host and changes nothing between them. No RPC params, stream frames, or published content change, so there is no wire-compatibility surface and mixed client/host versions are unaffected.

Mobile. No mobile code changes. Paired clients benefit indirectly because jira.status and linear.status stop answering from a stale snapshot.

Performance. One statSync per state-file read, on a local path, in front of calls that are already network-bound. A full re-read still only happens when the file actually changed.

Behaviour change worth noting. A process now observes a disconnect performed elsewhere instead of holding a stale connected view. That is the intended correction, but it does remove the accidental per-process isolation that existed before.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Author

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Added a generic integration state-file cache that detects inode, size, and modification-time changes. The cache supports lazy reads, missing files, reloads, and invalidation. Jira and Linear clients now use the shared cache for site and workspace state. Added tests for external updates, file transitions, memoization, reloads, and invalidation.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 13.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description is detailed and covers the change, rationale, testing, review, and checklist, but it explicitly lacks the required linked issue. Add a valid linked issue under Linked Issue, such as “Fixes #13126” or the correct issue for this change.
✅ Passed checks (3 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the main change: reloading Jira and Linear state files after rewrites by another process.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/integration-state-file-cache.ts (1)

21-30: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Condense the block comment.

Keep only the non-obvious cache rationale. Move deployment examples to documentation if they are needed. As per coding guidelines, “Comments must be concise, limited to non-obvious information, and preferably one line.”

Source: Coding guidelines


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 62c7bd8e-53b1-4113-8f04-76fa4056a6c9

📥 Commits

Reviewing files that changed from the base of the PR and between 0d29497 and febabd6a8b781ab0f94a8fe3e2add0c16e42abe3.

📒 Files selected for processing (6)
  • src/main/integration-state-file-cache.test.ts
  • src/main/integration-state-file-cache.ts
  • src/main/jira/client.test.ts
  • src/main/jira/client.ts
  • src/main/linear/client.test.ts
  • src/main/linear/client.ts

@tisohjung
tisohjung force-pushed the fix/integration-site-file-cache-invalidation branch 2 times, most recently from 8d7be8a to 8450793 Compare August 8, 2026 05:29

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c9080dbd-f9f1-4f9b-ab79-b33fa4c60377

📥 Commits

Reviewing files that changed from the base of the PR and between 8d7be8af981a3a64a2e6268d45bc86668c091ba7 and 845079386b107338685e03d178bc49aa5a6e9335.

📒 Files selected for processing (4)
  • src/main/integration-state-file-cache.test.ts
  • src/main/integration-state-file-cache.ts
  • src/main/jira/client.ts
  • src/main/linear/client.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/main/linear/client.ts
  • src/main/jira/client.ts

…ocess rewrites them

Both clients memoized ~/.orca/{jira-sites,linear-workspaces}.json on first read and
never invalidated, so getStatus() kept answering from a snapshot taken at process
start. Every Orca process on a machine shares that directory — an installed app
beside a dev build, or `orca serve` beside the desktop app — which made a
connection performed in one process invisible to the others until they restarted.

Stamp the cache with the file's inode, size, and mtime and reload when the stamp
moves. Writes record their own stamp so the next read does not bounce straight
back to disk. Tokens already read through to disk on a cache miss, so only the
state files needed this.

The two clients had the same load-once shape, so the logic lands in one
createIntegrationStateFileCache() helper instead of being fixed twice.
@tisohjung
tisohjung force-pushed the fix/integration-site-file-cache-invalidation branch from 8450793 to bc8326a Compare August 8, 2026 05:38
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

…file-cache-invalidation

# Conflicts:
#	src/main/jira/client.ts
#	src/main/linear/client.ts
@nwparker nwparker removed the P1 label Aug 19, 2026
nwparker added a commit that referenced this pull request Oct 14, 2026
Adapt PR #13125 and reuse the existing precise file identity signature for cache invalidation.

Co-authored-by: Minho Yi <[email protected]>
@tisohjung

Copy link
Copy Markdown
Contributor Author

Superseded by #28594, which landed this same fix on 2026-10-14 (commit 5ae088a, co-authored here). Main has since taken it further: the stamp moved to the shared fileStatSignature helper and the cache key now includes the path, and the same pattern was extended to the Jira and Linear token files via integration-token-file-cache.ts. Nothing in this branch is left to merge — every file it touches conflicts with main and resolves to main's version — so closing rather than pushing an empty update.

@tisohjung tisohjung closed this Oct 23, 2026
@tisohjung
tisohjung deleted the fix/integration-site-file-cache-invalidation branch October 23, 2026 09:04
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.

4 participants