Skip to content

fix(platform): self-heal integration installed flag on credential activation#1593

Merged
larryro merged 1 commit into
mainfrom
fix/integration-installed-self-heal
Apr 21, 2026
Merged

fix(platform): self-heal integration installed flag on credential activation#1593
larryro merged 1 commit into
mainfrom
fix/integration-installed-self-heal

Conversation

@larryro
Copy link
Copy Markdown
Collaborator

@larryro larryro commented Apr 21, 2026

Summary

  • Settings → Integrations shows Tavily as Connected (green badge driven by cred.isActive), but the chat composer + menu gates Deep research and Web search on installed && isActive, so they show Requires Tavily. The two surfaces can disagree when the tracked seed file (examples/integrations/tavily/config.json) gets reverted to installed: false by a git checkout while the DB credential row stays active. Once in that state, the UI has no path to re-run installIntegration (the save/test flow only installs when no credential row exists yet).
  • Self-heal at the two write sites that flip isActive: truetest_connection.ts and oauth2_token_exchange.ts — by calling a new idempotent internal action ensureInstalledInternal in file_actions.ts that rewrites config.json with installed: true when it's missing.
  • Invalidate the ['config', 'integrations'] TanStack cache after a successful test in useTestIntegration, so the composer picks up the healed flag without a page refresh.
  • Debug console.log on the self-heal path for log-based verification (can swap to createDebugLog('DEBUG_INTEGRATIONS', ...) later if noise is a concern).

Why not the alternatives

  • Tighten the "Connected" badge to installed && isActive — regresses the user's current UX (they already see Tavily as Connected), and doesn't actually unblock them.
  • Relax the composer to isActive only — the engine/runtime (listForExecution, start_workflow_from_file) still filters by installed: true, so the capability would fail silently at execution time.
  • One-off migration — heavier than a demo-stage fix, and the write-site heal covers all affected users on their next save.

Test plan

  • Reproduce the bug: with Tavily already connected, git checkout -- examples/integrations/tavily/config.json to flip the seed back to installed: false; confirm composer shows Requires Tavily on Web search / Deep research while Settings → Integrations still shows Connected.
  • With this PR, open Settings → Integrations → Tavily → click Test connection.
  • examples/integrations/tavily/config.json on disk now has "installed": true.
  • Composer + menu shows Web search and Deep research without the Requires Tavily hint (no page refresh needed).
  • Confirm Convex logs show [Integrations] ensureInstalledInternal: done (slug=tavily changed=true) on the first heal and changed=false on a subsequent test.
  • Repeat with an OAuth2 integration (e.g. Gmail) to cover oauth2_token_exchange.ts.
  • Regression: with installed: true already on disk, Test connection is a no-op for the file — no spurious git status churn.
  • npx tsc --noEmit from services/platform/ and npm run lint --workspace=@tale/platform are clean.

Summary by CodeRabbit

  • Bug Fixes

    • Improved integration installation state synchronization following OAuth activation and connection testing.
    • Added automatic verification to ensure integration configuration consistency after credential updates.
  • Refactor

    • Optimized integration configuration and credential management workflows for enhanced reliability.

…ivation

When a tracked seed integration config (e.g. examples/integrations/tavily/config.json)
gets reverted to installed:false by a git checkout while its DB credential row stays
active, the composer readiness gate (installed && isActive) disagrees with the
"Connected" badge (isActive only), so users see "Requires Tavily" on Web search /
Deep research even though Settings shows Tavily Connected.

Fix at the two write sites that flip isActive:true — test_connection and
oauth2_token_exchange — by calling a new idempotent ensureInstalledInternal action
that rewrites config.json with installed:true. Also invalidate the
['config','integrations'] TanStack cache after a successful test so the composer
picks up the healed flag without a page refresh.

Debug console.log on the self-heal path for log-based verification.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ca8046d4-a80b-4145-989d-3c84ffdc58a3

📥 Commits

Reviewing files that changed from the base of the PR and between 8e4b6ab and c50a07e.

📒 Files selected for processing (4)
  • services/platform/app/features/settings/integrations/hooks/actions.ts
  • services/platform/convex/integrations/file_actions.ts
  • services/platform/convex/integrations/oauth2_token_exchange.ts
  • services/platform/convex/integrations/test_connection.ts

📝 Walkthrough

Walkthrough

This PR modifies the integration activation flow across client and backend layers. It adds React Query cache invalidation to the client-side useTestIntegration hook by overriding its mutateAsync method. On the backend, installIntegration is refactored to delegate the installed flag update to a new writeInstalledFlag helper. A new internal action ensureInstalledInternal is introduced to synchronize the integration's installed state idempotently. The OAuth2 callback and test connection handlers now call this action post-activation to ensure state consistency, with logging of whether changes occurred.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main purpose of the PR: self-healing the integration installed flag when credentials are activated. It directly reflects the core changes across multiple files that ensure config.installed is synchronized when credentials become active.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/integration-installed-self-heal

Comment @coderabbitai help to get the list of available commands and usage tips.

@larryro larryro merged commit e0d46f0 into main Apr 21, 2026
15 checks passed
@larryro larryro deleted the fix/integration-installed-self-heal branch April 21, 2026 11:31
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