Skip to content

fix(tauri): forward hot-instance OAuth deep links#2229

Merged
senamakel merged 3 commits into
tinyhumansai:mainfrom
NgoQuocViet2001:ai/fix-windows-oauth-deeplink
May 19, 2026
Merged

fix(tauri): forward hot-instance OAuth deep links#2229
senamakel merged 3 commits into
tinyhumansai:mainfrom
NgoQuocViet2001:ai/fix-windows-oauth-deeplink

Conversation

@NgoQuocViet2001
Copy link
Copy Markdown
Contributor

@NgoQuocViet2001 NgoQuocViet2001 commented May 19, 2026

Summary

  • Enable the deep-link feature on tauri-plugin-single-instance.
  • Update app/src-tauri/Cargo.lock so the single-instance plugin links against tauri-plugin-deep-link.
  • Document why the feature is required for Windows/Linux second-launch OAuth callback forwarding.

Problem

Closes #2228. On Windows, OAuth completes in the system browser, but when OpenHuman is already running the openhuman://oauth/... second launch only focuses the primary instance. The live renderer never receives the callback, while cold-start and simulated deep links still work.

tauri-plugin-single-instance was installed to prevent secondary CEF launches, but without its deep-link feature the second-launch deep-link payload is not forwarded into the primary app on Windows/Linux.

Validation

  • cargo metadata --manifest-path app/src-tauri/Cargo.toml --format-version 1 --no-deps + assertion that tauri-plugin-single-instance includes deep-link -> passed.
  • cargo fmt --manifest-path app/src-tauri/Cargo.toml -p OpenHuman --check -> passed.
  • git diff --check -> passed.
  • cargo check --manifest-path app/src-tauri/Cargo.toml -> attempted; blocked by local native toolchain gaps unrelated to this change: missing cmake for cef-dll-sys and missing libclang/LIBCLANG_PATH for whisper-rs-sys. Cargo reached dependency resolution and native build scripts before failing.

Duplicate check

Searched existing PRs for #2228, "Windows desktop OAuth callbacks", and single-instance + deep-link feature; no open or recent PR covers this fix. Prior #1510 added the single-instance guard but did not enable the deep-link forwarding feature.

Summary by CodeRabbit

  • New Features
    • Deep-link payload forwarding for second-instance app launches is now supported.
  • Tests
    • Added a regression test to verify the deep-link feature is declared and remains enabled.

Review Change Stack

@NgoQuocViet2001 NgoQuocViet2001 requested a review from a team May 19, 2026 16:01
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ffcc7c44-8cc2-4f3d-b7de-605f4ba5c9c8

📥 Commits

Reviewing files that changed from the base of the PR and between 56bcb9f and 4065975.

📒 Files selected for processing (2)
  • app/src-tauri/Cargo.toml
  • app/src-tauri/src/lib.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/src-tauri/Cargo.toml

📝 Walkthrough

Walkthrough

Enables the deep-link feature for tauri-plugin-single-instance in app/src-tauri/Cargo.toml and adds a regression test that parses that Cargo.toml to assert the dependency includes the "deep-link" feature.

Changes

Deep-link support for OAuth callbacks

Layer / File(s) Summary
Enable deep-link feature on single-instance plugin
app/src-tauri/Cargo.toml
tauri-plugin-single-instance dependency gains features = ["deep-link"] and comments clarifying second-launch deep-link payload forwarding.
Regression test validating Cargo.toml
app/src-tauri/src/lib.rs
Adds single_instance_dep_enables_deep_link_feature test that parses app/src-tauri/Cargo.toml and asserts the tauri-plugin-single-instance dependency includes the "deep-link" feature.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I peeked through Cargo's fold,
Found a flag to make links bold,
Deep links hop to one warm den,
No stray instances again,
OAuth finishes—happy end!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(tauri): forward hot-instance OAuth deep links' directly describes the main change—enabling deep-link feature forwarding in the single-instance plugin to fix OAuth callbacks. It is clear, concise, and accurately reflects the primary objective.
Linked Issues check ✅ Passed The PR enables the deep-link feature on tauri-plugin-single-instance and adds a regression test to verify it, meeting issue #2228's core requirements. Both the Cargo.toml change and the test directly address the root cause of hot-instance OAuth callbacks failing on Windows/Linux.
Out of Scope Changes check ✅ Passed All changes—enabling the deep-link feature, updating Cargo.lock, adding documentation, and the regression test—are directly scoped to fixing the hot-instance OAuth deep-link forwarding issue. No unrelated modifications are present.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

Warning

Review ran into problems

🔥 Problems

Stopped waiting for pipeline failures after 30000ms. One of your pipelines takes longer than our 30000ms fetch window to run, so review may not consider pipeline-failure results for inline comments if any failures occurred after the fetch window. Increase the timeout if you want to wait longer or run a @coderabbit review after the pipeline has finished.


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 and usage tips.

coderabbitai[bot]
coderabbitai Bot previously approved these changes May 19, 2026
Copy link
Copy Markdown
Contributor

@graycyrus graycyrus left a comment

Choose a reason for hiding this comment

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

Nice find — enabling the deep-link feature on tauri-plugin-single-instance is the correct fix, and the inline comment documenting the why is appreciated.

One thing holding this back: issue #2228 acceptance criteria explicitly require regression test coverage and ≥ 80 % diff coverage. The PR currently adds no tests. Since the change is a Cargo feature flag, a lightweight cargo metadata assertion (verifying the feature is present) or an integration-level deep-link forwarding test would satisfy the gate without being heavy.

Otherwise the Cargo.toml + lockfile change itself looks correct — just needs the test coverage to land.

Comment thread app/src-tauri/Cargo.toml
# process exits cleanly after handing its argv to the primary. The `deep-link`
# feature forwards second-launch deep-link payloads to the primary instance on
# Windows/Linux, which is required for hot-instance OAuth callbacks.
tauri-plugin-single-instance = { version = "2", features = ["deep-link"] }
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.

[major] Missing regression test required by #2228 acceptance criteria.

The issue explicitly lists:

  • Regression safety — Unit, integration, or E2E coverage added or updated so the single-instance deep-link wiring is verified.
  • Diff coverage ≥ 80 %

Suggestion: add a build-time assertion that tauri-plugin-single-instance includes the deep-link feature, e.g.:

#[cfg(test)]
#[test]
fn single_instance_has_deep_link_feature() {
    // cargo metadata already verified this in CI validation,
    // but a compiled test catches regressions if someone removes the feature.
    assert!(cfg!(feature = "deep-link") || cfg!(target_os = "macos"),
            "tauri-plugin-single-instance must enable the deep-link feature on Windows/Linux");
}

Alternatively, a CI script assertion using cargo metadata --no-deps works too — the PR's own validation section already describes the command.

senamakel added 2 commits May 19, 2026 14:31
Parses app/src-tauri/Cargo.toml at test time and asserts that the
`tauri-plugin-single-instance` dependency keeps the `deep-link` feature
enabled. Without it, second-launch deep-link payloads are not forwarded
into the primary instance, which silently breaks hot-instance OAuth
callbacks on Windows/Linux (issue tinyhumansai#2228).

Addresses @graycyrus review request on app/src-tauri/Cargo.toml:56.
Comment thread app/src-tauri/Cargo.toml
# process exits cleanly after handing its argv to the primary. The `deep-link`
# feature forwards second-launch deep-link payloads to the primary instance on
# Windows/Linux, which is required for hot-instance OAuth callbacks.
tauri-plugin-single-instance = { version = "2", features = ["deep-link"] }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Added a regression test in 4065975tests::single_instance_dep_enables_deep_link_feature in app/src-tauri/src/lib.rs parses Cargo.toml at test time and asserts the deep-link feature is present on tauri-plugin-single-instance. This fails fast if anyone removes the feature flag in the future (issue #2228 regression safety + diff coverage). I went with a Cargo.toml-parse test rather than the suggested cfg!(feature = "deep-link") form because cfg! checks features of this crate (OpenHuman), not the transitive plugin crate, so it wouldn't actually catch the regression we care about.

@senamakel senamakel merged commit 9566f2c into tinyhumansai:main May 19, 2026
26 of 27 checks passed
@NgoQuocViet2001
Copy link
Copy Markdown
Contributor Author

@graycyrus thanks again for the review. The requested regression coverage was added in 4065975 via tests::single_instance_dep_enables_deep_link_feature, which parses app/src-tauri/Cargo.toml and asserts that tauri-plugin-single-instance keeps the deep-link feature enabled.

I noticed the original review thread may still appear unresolved after merge. If there is anything still missing from the #2228 acceptance criteria, happy to follow up in a separate PR.

senamakel added a commit that referenced this pull request May 20, 2026
…2128)

## Summary

- Centralises OAuth deep-link → channel-badge transitions behind a new
  `useOAuthConnectionListener` hook so every channel panel handles both
  `oauth:success` and `oauth:error` consistently.
- Adds a `clearOtherPendingForChannel` reducer so starting a connect flow on
  one auth mode drops any sibling auth mode that's still mid-`connecting` on
  the same channel.
- Wires `DiscordConfig` and `TelegramConfig` onto the shared hook; future
  channels with an OAuth auth mode inherit correct pending-state transitions
  automatically.
- Covers the new reducer (4 cases) and hook (8 cases) with Vitest.

## Problem

OAuth badges on the channel connection panels could get pinned at
`Connecting` indefinitely (issue #2128):

- `DiscordConfig` had a per-component `oauth:success` listener but no
  `oauth:error` listener — failed OAuth attempts never transitioned the badge
  out of `connecting`.
- `TelegramConfig` had neither — completed *and* failed OAuth attempts left
  the badge pinned.
- Both panels set `connecting` on the chosen auth mode but never cancelled
  any sibling auth mode that was already pending. Triggering a second OAuth
  method on Discord (`OAuth Sign-in` then `Login with OpenHuman`, or the
  reverse) left both methods badged `Connecting` simultaneously.

This is the exact repro from the issue. The same shape was visible across
GitHub/GitLab style multi-method panels because the underlying state model
(`channelConnections`, keyed by `(channel, authMode)`) had no notion of
mutual exclusion.

## Solution

**Shared listener hook** —
[`app/src/hooks/useOAuthConnectionListener.ts`](app/src/hooks/useOAuthConnectionListener.ts)
subscribes to both `oauth:success` and `oauth:error` window events
(dispatched from `utils/desktopDeepLinkListener.ts`), filters by `toolkit` /
`provider` case-insensitively, and dispatches the matching slice action.
Per-channel panels mount it once with `{ channel, authMode }`; cleanup on
unmount is deterministic. New channels with an OAuth auth mode inherit the
behaviour without copying any logic.

**Pending-state cancellation reducer** — `clearOtherPendingForChannel({ channel,
exceptAuthMode })` in `channelConnectionsSlice.ts` walks the auth-mode map
for one channel and transitions every `connecting` row (except the
exception) to `disconnected` with `lastError: undefined`. Cancelled rows go
to `disconnected` rather than `error` so the UI doesn't surface a misleading
failure — the user explicitly switched methods, they didn't experience an
error.

**Per-panel wiring** — `DiscordConfig` and `TelegramConfig` each:

1. Mount `useOAuthConnectionListener({ channel: <name>, authMode: 'oauth' })`
   at the top of the component (replacing the bespoke effect on Discord;
   net-new on Telegram).
2. Dispatch `clearOtherPendingForChannel` at the start of `handleConnect`
   *before* setting their own auth mode to `connecting`.

**Tradeoffs**

- The cancellation transition is `disconnected`, not a new `cancelled` state.
  Adding a dedicated state would expand the `ChannelConnectionStatus` union
  across many call sites for marginal UX value.
- The deep-link CustomEvent payload (`{ integrationId, toolkit }` for
  success, `{ provider, errorCode, message }` for error) is unchanged, so
  no symmetric change in the Tauri-side handler is needed.

## Submission Checklist

- [x] Tests added or updated (happy path + at least one failure / edge case) per [Testing Strategy](../gitbooks/developing/testing-strategy.md#failure-path-requirement) — 12 new Vitest cases (4 reducer + 8 hook) covering success, error, mismatched channel, mismatched provider, missing error message, custom capabilities, unsubscribe on unmount, and three sibling-cancellation shapes.
- [x] **Diff coverage ≥ 80%** — frontend-only change; `pnpm test:coverage` locally over the new files reaches 100% on changed lines (every branch in the hook + reducer is exercised by the suite).
- [x] Coverage matrix updated — `N/A: behaviour-only fix on existing surfaces (channel connection pending state)`.
- [x] All affected feature IDs from the matrix are listed in the PR description under `## Related` — `N/A: no feature ID changes`.
- [x] No new external network dependencies introduced — purely in-app state plumbing.
- [x] Manual smoke checklist updated if this touches release-cut surfaces — `N/A: no release-cut surface touched (channels panel is part of the always-shipped settings UX)`.
- [x] Linked issue closed via `Closes #NNN` in the `## Related` section — see below.

## Impact

- **Desktop only** — no mobile/web/CLI impact. The deep-link event source
  (`desktopDeepLinkListener.ts`) is Tauri-gated; the hook is a no-op outside
  Tauri because no deep-link events fire.
- **No persistence shape change** — `channelConnections` slice schema
  (`SCHEMA_VERSION = 1`) is unchanged. The new reducer only mutates existing
  rows; no migration needed.
- **No security implications** — the listener filters strictly by channel
  identifier and never reads tokens. Existing `[DeepLink][oauth:*]` logs
  remain the canonical diagnostic surface; the hook adds its own
  `channels:oauth-listener` debug namespace per the project's
  verbose-diagnostics rule.

## Related

- Closes: #2128
- Follow-up PR(s)/TODOs: none

## Provider coverage

The issue body mentions Discord, GitHub, and GitLab. The Channels page in this codebase only exposes three multi-method channel-config panels today: `DiscordConfig.tsx`, `TelegramConfig.tsx`, and `WebChannelConfig.tsx` (the last is not OAuth-driven). There is no `GitHubConfig.tsx` / `GitLabConfig.tsx` — verified via `find app/src -name "*Config.tsx"`.

GitHub OAuth does appear elsewhere in the app, but on different state slices that this PR's `channelConnections`-bound hook does not (and should not) touch:

| Surface | File(s) | State path | This PR applies? |
|---|---|---|---|
| App-level sign-in | `BootCheckGate.tsx`, OAuth callback | `deepLinkAuth` slice | No — different slice. App-level OAuth's hot-instance issue is the family fixed by #2228 / #2229. |
| Skill OAuth install | `InstallSkillDialog.tsx`, `services/api/skillsApi.ts` | skills-domain state | No — different surface. |
| Composio integration | `components/composio/TriggerToggles.tsx`, `composio/providerConfigs.tsx` | Composio integration state | No — different surface. |
| **Channel config** (this PR) | `DiscordConfig.tsx`, `TelegramConfig.tsx` | `channelConnections` slice | **Yes — wired.** |

So this PR's `useOAuthConnectionListener` covers every multi-method OAuth panel that actually exists on the Channels surface. The shared hook is also the right shape for any future `GitHubConfig.tsx` / `GitLabConfig.tsx` channel panels — wiring them in becomes a one-line `useOAuthConnectionListener({ channelId, capabilities, ... })` import.

If the stale-`Connecting` symptom also surfaces in the app-level / skills / Composio OAuth flows, those are separate fixes against different state slices and out of scope for this PR — I'm happy to file follow-up issues if any are observed.

---

## AI Authored PR Metadata (required for Codex/Linear PRs)

### Linear Issue
- Key: N/A
- URL: N/A

### Commit & Branch
- Branch: `fix/2128-oauth-badge-pending-state`
- Commit SHA: `2d93f7c0`

### Validation Run
- [x] `pnpm --filter openhuman-app format:check` — `All matched files use Prettier code style!` on the 6 changed files
- [x] `pnpm typecheck` — clean (`tsc --noEmit`)
- [x] Focused tests: `pnpm --filter openhuman-app exec vitest run --config test/vitest.config.ts src/store/__tests__/channelConnectionsSlice.test.ts src/hooks/__tests__/useOAuthConnectionListener.test.tsx src/components/channels/__tests__/DiscordConfig.test.tsx src/components/channels/__tests__/TelegramConfig.test.tsx` → 4 files, 27 tests pass
- [x] Rust fmt/check (if changed): `N/A: no Rust changes`
- [x] Tauri fmt/check (if changed): `N/A: no Tauri shell changes`

### Validation Blocked
- `command:` `git push` pre-push hook (`app:lint:commands-tokens`)
- `error:` `lint:commands-tokens requires ripgrep` — `rg` not installed on the dev environment
- `impact:` zero — the check greps a directory I did not modify (`src/components/commands/`). Pushed with `--no-verify` per the CLAUDE.md guidance for environment-related hook failures unrelated to the diff. Maintainers can re-run on CI to validate.

### Behavior Changes
- Intended behavior change: OAuth badges on channel panels transition out of `connecting` when the OAuth flow completes *or* fails, and starting a new method cancels the previous method's `connecting` row.
- User-visible effect: the reported bug (multiple methods stuck on `Connecting` simultaneously, Telegram OAuth never clearing) goes away. No new UI elements; only badge state transitions are affected.

### Parity Contract
- Legacy behavior preserved: existing `connected` and `error` transitions are unchanged; `disconnectChannelConnection`, `upsertChannelConnection`, `setChannelConnectionStatus` are all untouched. The Discord `oauth:success` path still produces the same final state (`status: 'connected'`, `capabilities: ['read', 'write']`); the inline effect was just refactored behind the shared hook.
- Guard/fallback/dispatch parity checks: hook only reacts when the event's `toolkit` (success) or `provider` (error) field matches the subscribed channel — siblings on other channels, and mismatched dispatches, are no-ops.

### Duplicate / Superseded PR Handling
- Duplicate PR(s): none found. #2170 cross-references #2128 in passing but its title and body close #2141 (channel selector error-status aggregation, a different surface).
- Canonical PR: this one.
- Resolution: N/A.


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Reusable OAuth connection listener to handle OAuth success/error deep-link flows for Discord and Telegram.
  * New action to clear other pending/connecting auth methods for a channel.

* **Bug Fixes**
  * Prevents multiple auth methods from remaining "connecting"; switching stops in-flight polling and clears sibling pending modes.
  * OAuth errors now record meaningful messages and listeners unsubscribe on unmount.

* **Tests**
  * Added tests covering the OAuth listener and pending-clearing reducer behaviors.

<!-- review_stack_entry_start -->

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/tinyhumansai/openhuman/pull/2256?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: sanil-23 <sanil@alphahuman.xyz>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
mtkik pushed a commit to mtkik/openhuman-meet that referenced this pull request May 21, 2026
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
mtkik pushed a commit to mtkik/openhuman-meet that referenced this pull request May 21, 2026
…inyhumansai#2128)

## Summary

- Centralises OAuth deep-link → channel-badge transitions behind a new
  `useOAuthConnectionListener` hook so every channel panel handles both
  `oauth:success` and `oauth:error` consistently.
- Adds a `clearOtherPendingForChannel` reducer so starting a connect flow on
  one auth mode drops any sibling auth mode that's still mid-`connecting` on
  the same channel.
- Wires `DiscordConfig` and `TelegramConfig` onto the shared hook; future
  channels with an OAuth auth mode inherit correct pending-state transitions
  automatically.
- Covers the new reducer (4 cases) and hook (8 cases) with Vitest.

## Problem

OAuth badges on the channel connection panels could get pinned at
`Connecting` indefinitely (issue tinyhumansai#2128):

- `DiscordConfig` had a per-component `oauth:success` listener but no
  `oauth:error` listener — failed OAuth attempts never transitioned the badge
  out of `connecting`.
- `TelegramConfig` had neither — completed *and* failed OAuth attempts left
  the badge pinned.
- Both panels set `connecting` on the chosen auth mode but never cancelled
  any sibling auth mode that was already pending. Triggering a second OAuth
  method on Discord (`OAuth Sign-in` then `Login with OpenHuman`, or the
  reverse) left both methods badged `Connecting` simultaneously.

This is the exact repro from the issue. The same shape was visible across
GitHub/GitLab style multi-method panels because the underlying state model
(`channelConnections`, keyed by `(channel, authMode)`) had no notion of
mutual exclusion.

## Solution

**Shared listener hook** —
[`app/src/hooks/useOAuthConnectionListener.ts`](app/src/hooks/useOAuthConnectionListener.ts)
subscribes to both `oauth:success` and `oauth:error` window events
(dispatched from `utils/desktopDeepLinkListener.ts`), filters by `toolkit` /
`provider` case-insensitively, and dispatches the matching slice action.
Per-channel panels mount it once with `{ channel, authMode }`; cleanup on
unmount is deterministic. New channels with an OAuth auth mode inherit the
behaviour without copying any logic.

**Pending-state cancellation reducer** — `clearOtherPendingForChannel({ channel,
exceptAuthMode })` in `channelConnectionsSlice.ts` walks the auth-mode map
for one channel and transitions every `connecting` row (except the
exception) to `disconnected` with `lastError: undefined`. Cancelled rows go
to `disconnected` rather than `error` so the UI doesn't surface a misleading
failure — the user explicitly switched methods, they didn't experience an
error.

**Per-panel wiring** — `DiscordConfig` and `TelegramConfig` each:

1. Mount `useOAuthConnectionListener({ channel: <name>, authMode: 'oauth' })`
   at the top of the component (replacing the bespoke effect on Discord;
   net-new on Telegram).
2. Dispatch `clearOtherPendingForChannel` at the start of `handleConnect`
   *before* setting their own auth mode to `connecting`.

**Tradeoffs**

- The cancellation transition is `disconnected`, not a new `cancelled` state.
  Adding a dedicated state would expand the `ChannelConnectionStatus` union
  across many call sites for marginal UX value.
- The deep-link CustomEvent payload (`{ integrationId, toolkit }` for
  success, `{ provider, errorCode, message }` for error) is unchanged, so
  no symmetric change in the Tauri-side handler is needed.

## Submission Checklist

- [x] Tests added or updated (happy path + at least one failure / edge case) per [Testing Strategy](../gitbooks/developing/testing-strategy.md#failure-path-requirement) — 12 new Vitest cases (4 reducer + 8 hook) covering success, error, mismatched channel, mismatched provider, missing error message, custom capabilities, unsubscribe on unmount, and three sibling-cancellation shapes.
- [x] **Diff coverage ≥ 80%** — frontend-only change; `pnpm test:coverage` locally over the new files reaches 100% on changed lines (every branch in the hook + reducer is exercised by the suite).
- [x] Coverage matrix updated — `N/A: behaviour-only fix on existing surfaces (channel connection pending state)`.
- [x] All affected feature IDs from the matrix are listed in the PR description under `## Related` — `N/A: no feature ID changes`.
- [x] No new external network dependencies introduced — purely in-app state plumbing.
- [x] Manual smoke checklist updated if this touches release-cut surfaces — `N/A: no release-cut surface touched (channels panel is part of the always-shipped settings UX)`.
- [x] Linked issue closed via `Closes #NNN` in the `## Related` section — see below.

## Impact

- **Desktop only** — no mobile/web/CLI impact. The deep-link event source
  (`desktopDeepLinkListener.ts`) is Tauri-gated; the hook is a no-op outside
  Tauri because no deep-link events fire.
- **No persistence shape change** — `channelConnections` slice schema
  (`SCHEMA_VERSION = 1`) is unchanged. The new reducer only mutates existing
  rows; no migration needed.
- **No security implications** — the listener filters strictly by channel
  identifier and never reads tokens. Existing `[DeepLink][oauth:*]` logs
  remain the canonical diagnostic surface; the hook adds its own
  `channels:oauth-listener` debug namespace per the project's
  verbose-diagnostics rule.

## Related

- Closes: tinyhumansai#2128
- Follow-up PR(s)/TODOs: none

## Provider coverage

The issue body mentions Discord, GitHub, and GitLab. The Channels page in this codebase only exposes three multi-method channel-config panels today: `DiscordConfig.tsx`, `TelegramConfig.tsx`, and `WebChannelConfig.tsx` (the last is not OAuth-driven). There is no `GitHubConfig.tsx` / `GitLabConfig.tsx` — verified via `find app/src -name "*Config.tsx"`.

GitHub OAuth does appear elsewhere in the app, but on different state slices that this PR's `channelConnections`-bound hook does not (and should not) touch:

| Surface | File(s) | State path | This PR applies? |
|---|---|---|---|
| App-level sign-in | `BootCheckGate.tsx`, OAuth callback | `deepLinkAuth` slice | No — different slice. App-level OAuth's hot-instance issue is the family fixed by tinyhumansai#2228 / tinyhumansai#2229. |
| Skill OAuth install | `InstallSkillDialog.tsx`, `services/api/skillsApi.ts` | skills-domain state | No — different surface. |
| Composio integration | `components/composio/TriggerToggles.tsx`, `composio/providerConfigs.tsx` | Composio integration state | No — different surface. |
| **Channel config** (this PR) | `DiscordConfig.tsx`, `TelegramConfig.tsx` | `channelConnections` slice | **Yes — wired.** |

So this PR's `useOAuthConnectionListener` covers every multi-method OAuth panel that actually exists on the Channels surface. The shared hook is also the right shape for any future `GitHubConfig.tsx` / `GitLabConfig.tsx` channel panels — wiring them in becomes a one-line `useOAuthConnectionListener({ channelId, capabilities, ... })` import.

If the stale-`Connecting` symptom also surfaces in the app-level / skills / Composio OAuth flows, those are separate fixes against different state slices and out of scope for this PR — I'm happy to file follow-up issues if any are observed.

---

## AI Authored PR Metadata (required for Codex/Linear PRs)

### Linear Issue
- Key: N/A
- URL: N/A

### Commit & Branch
- Branch: `fix/2128-oauth-badge-pending-state`
- Commit SHA: `2d93f7c0`

### Validation Run
- [x] `pnpm --filter openhuman-app format:check` — `All matched files use Prettier code style!` on the 6 changed files
- [x] `pnpm typecheck` — clean (`tsc --noEmit`)
- [x] Focused tests: `pnpm --filter openhuman-app exec vitest run --config test/vitest.config.ts src/store/__tests__/channelConnectionsSlice.test.ts src/hooks/__tests__/useOAuthConnectionListener.test.tsx src/components/channels/__tests__/DiscordConfig.test.tsx src/components/channels/__tests__/TelegramConfig.test.tsx` → 4 files, 27 tests pass
- [x] Rust fmt/check (if changed): `N/A: no Rust changes`
- [x] Tauri fmt/check (if changed): `N/A: no Tauri shell changes`

### Validation Blocked
- `command:` `git push` pre-push hook (`app:lint:commands-tokens`)
- `error:` `lint:commands-tokens requires ripgrep` — `rg` not installed on the dev environment
- `impact:` zero — the check greps a directory I did not modify (`src/components/commands/`). Pushed with `--no-verify` per the CLAUDE.md guidance for environment-related hook failures unrelated to the diff. Maintainers can re-run on CI to validate.

### Behavior Changes
- Intended behavior change: OAuth badges on channel panels transition out of `connecting` when the OAuth flow completes *or* fails, and starting a new method cancels the previous method's `connecting` row.
- User-visible effect: the reported bug (multiple methods stuck on `Connecting` simultaneously, Telegram OAuth never clearing) goes away. No new UI elements; only badge state transitions are affected.

### Parity Contract
- Legacy behavior preserved: existing `connected` and `error` transitions are unchanged; `disconnectChannelConnection`, `upsertChannelConnection`, `setChannelConnectionStatus` are all untouched. The Discord `oauth:success` path still produces the same final state (`status: 'connected'`, `capabilities: ['read', 'write']`); the inline effect was just refactored behind the shared hook.
- Guard/fallback/dispatch parity checks: hook only reacts when the event's `toolkit` (success) or `provider` (error) field matches the subscribed channel — siblings on other channels, and mismatched dispatches, are no-ops.

### Duplicate / Superseded PR Handling
- Duplicate PR(s): none found. tinyhumansai#2170 cross-references tinyhumansai#2128 in passing but its title and body close tinyhumansai#2141 (channel selector error-status aggregation, a different surface).
- Canonical PR: this one.
- Resolution: N/A.


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Reusable OAuth connection listener to handle OAuth success/error deep-link flows for Discord and Telegram.
  * New action to clear other pending/connecting auth methods for a channel.

* **Bug Fixes**
  * Prevents multiple auth methods from remaining "connecting"; switching stops in-flight polling and clears sibling pending modes.
  * OAuth errors now record meaningful messages and listeners unsubscribe on unmount.

* **Tests**
  * Added tests covering the OAuth listener and pending-clearing reducer behaviors.

<!-- review_stack_entry_start -->

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/tinyhumansai/openhuman/pull/2256?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: sanil-23 <sanil@alphahuman.xyz>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
CodeGhost21 pushed a commit to CodeGhost21/openhuman that referenced this pull request May 22, 2026
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
CodeGhost21 pushed a commit to CodeGhost21/openhuman that referenced this pull request May 22, 2026
…inyhumansai#2128)

## Summary

- Centralises OAuth deep-link → channel-badge transitions behind a new
  `useOAuthConnectionListener` hook so every channel panel handles both
  `oauth:success` and `oauth:error` consistently.
- Adds a `clearOtherPendingForChannel` reducer so starting a connect flow on
  one auth mode drops any sibling auth mode that's still mid-`connecting` on
  the same channel.
- Wires `DiscordConfig` and `TelegramConfig` onto the shared hook; future
  channels with an OAuth auth mode inherit correct pending-state transitions
  automatically.
- Covers the new reducer (4 cases) and hook (8 cases) with Vitest.

## Problem

OAuth badges on the channel connection panels could get pinned at
`Connecting` indefinitely (issue tinyhumansai#2128):

- `DiscordConfig` had a per-component `oauth:success` listener but no
  `oauth:error` listener — failed OAuth attempts never transitioned the badge
  out of `connecting`.
- `TelegramConfig` had neither — completed *and* failed OAuth attempts left
  the badge pinned.
- Both panels set `connecting` on the chosen auth mode but never cancelled
  any sibling auth mode that was already pending. Triggering a second OAuth
  method on Discord (`OAuth Sign-in` then `Login with OpenHuman`, or the
  reverse) left both methods badged `Connecting` simultaneously.

This is the exact repro from the issue. The same shape was visible across
GitHub/GitLab style multi-method panels because the underlying state model
(`channelConnections`, keyed by `(channel, authMode)`) had no notion of
mutual exclusion.

## Solution

**Shared listener hook** —
[`app/src/hooks/useOAuthConnectionListener.ts`](app/src/hooks/useOAuthConnectionListener.ts)
subscribes to both `oauth:success` and `oauth:error` window events
(dispatched from `utils/desktopDeepLinkListener.ts`), filters by `toolkit` /
`provider` case-insensitively, and dispatches the matching slice action.
Per-channel panels mount it once with `{ channel, authMode }`; cleanup on
unmount is deterministic. New channels with an OAuth auth mode inherit the
behaviour without copying any logic.

**Pending-state cancellation reducer** — `clearOtherPendingForChannel({ channel,
exceptAuthMode })` in `channelConnectionsSlice.ts` walks the auth-mode map
for one channel and transitions every `connecting` row (except the
exception) to `disconnected` with `lastError: undefined`. Cancelled rows go
to `disconnected` rather than `error` so the UI doesn't surface a misleading
failure — the user explicitly switched methods, they didn't experience an
error.

**Per-panel wiring** — `DiscordConfig` and `TelegramConfig` each:

1. Mount `useOAuthConnectionListener({ channel: <name>, authMode: 'oauth' })`
   at the top of the component (replacing the bespoke effect on Discord;
   net-new on Telegram).
2. Dispatch `clearOtherPendingForChannel` at the start of `handleConnect`
   *before* setting their own auth mode to `connecting`.

**Tradeoffs**

- The cancellation transition is `disconnected`, not a new `cancelled` state.
  Adding a dedicated state would expand the `ChannelConnectionStatus` union
  across many call sites for marginal UX value.
- The deep-link CustomEvent payload (`{ integrationId, toolkit }` for
  success, `{ provider, errorCode, message }` for error) is unchanged, so
  no symmetric change in the Tauri-side handler is needed.

## Submission Checklist

- [x] Tests added or updated (happy path + at least one failure / edge case) per [Testing Strategy](../gitbooks/developing/testing-strategy.md#failure-path-requirement) — 12 new Vitest cases (4 reducer + 8 hook) covering success, error, mismatched channel, mismatched provider, missing error message, custom capabilities, unsubscribe on unmount, and three sibling-cancellation shapes.
- [x] **Diff coverage ≥ 80%** — frontend-only change; `pnpm test:coverage` locally over the new files reaches 100% on changed lines (every branch in the hook + reducer is exercised by the suite).
- [x] Coverage matrix updated — `N/A: behaviour-only fix on existing surfaces (channel connection pending state)`.
- [x] All affected feature IDs from the matrix are listed in the PR description under `## Related` — `N/A: no feature ID changes`.
- [x] No new external network dependencies introduced — purely in-app state plumbing.
- [x] Manual smoke checklist updated if this touches release-cut surfaces — `N/A: no release-cut surface touched (channels panel is part of the always-shipped settings UX)`.
- [x] Linked issue closed via `Closes #NNN` in the `## Related` section — see below.

## Impact

- **Desktop only** — no mobile/web/CLI impact. The deep-link event source
  (`desktopDeepLinkListener.ts`) is Tauri-gated; the hook is a no-op outside
  Tauri because no deep-link events fire.
- **No persistence shape change** — `channelConnections` slice schema
  (`SCHEMA_VERSION = 1`) is unchanged. The new reducer only mutates existing
  rows; no migration needed.
- **No security implications** — the listener filters strictly by channel
  identifier and never reads tokens. Existing `[DeepLink][oauth:*]` logs
  remain the canonical diagnostic surface; the hook adds its own
  `channels:oauth-listener` debug namespace per the project's
  verbose-diagnostics rule.

## Related

- Closes: tinyhumansai#2128
- Follow-up PR(s)/TODOs: none

## Provider coverage

The issue body mentions Discord, GitHub, and GitLab. The Channels page in this codebase only exposes three multi-method channel-config panels today: `DiscordConfig.tsx`, `TelegramConfig.tsx`, and `WebChannelConfig.tsx` (the last is not OAuth-driven). There is no `GitHubConfig.tsx` / `GitLabConfig.tsx` — verified via `find app/src -name "*Config.tsx"`.

GitHub OAuth does appear elsewhere in the app, but on different state slices that this PR's `channelConnections`-bound hook does not (and should not) touch:

| Surface | File(s) | State path | This PR applies? |
|---|---|---|---|
| App-level sign-in | `BootCheckGate.tsx`, OAuth callback | `deepLinkAuth` slice | No — different slice. App-level OAuth's hot-instance issue is the family fixed by tinyhumansai#2228 / tinyhumansai#2229. |
| Skill OAuth install | `InstallSkillDialog.tsx`, `services/api/skillsApi.ts` | skills-domain state | No — different surface. |
| Composio integration | `components/composio/TriggerToggles.tsx`, `composio/providerConfigs.tsx` | Composio integration state | No — different surface. |
| **Channel config** (this PR) | `DiscordConfig.tsx`, `TelegramConfig.tsx` | `channelConnections` slice | **Yes — wired.** |

So this PR's `useOAuthConnectionListener` covers every multi-method OAuth panel that actually exists on the Channels surface. The shared hook is also the right shape for any future `GitHubConfig.tsx` / `GitLabConfig.tsx` channel panels — wiring them in becomes a one-line `useOAuthConnectionListener({ channelId, capabilities, ... })` import.

If the stale-`Connecting` symptom also surfaces in the app-level / skills / Composio OAuth flows, those are separate fixes against different state slices and out of scope for this PR — I'm happy to file follow-up issues if any are observed.

---

## AI Authored PR Metadata (required for Codex/Linear PRs)

### Linear Issue
- Key: N/A
- URL: N/A

### Commit & Branch
- Branch: `fix/2128-oauth-badge-pending-state`
- Commit SHA: `2d93f7c0`

### Validation Run
- [x] `pnpm --filter openhuman-app format:check` — `All matched files use Prettier code style!` on the 6 changed files
- [x] `pnpm typecheck` — clean (`tsc --noEmit`)
- [x] Focused tests: `pnpm --filter openhuman-app exec vitest run --config test/vitest.config.ts src/store/__tests__/channelConnectionsSlice.test.ts src/hooks/__tests__/useOAuthConnectionListener.test.tsx src/components/channels/__tests__/DiscordConfig.test.tsx src/components/channels/__tests__/TelegramConfig.test.tsx` → 4 files, 27 tests pass
- [x] Rust fmt/check (if changed): `N/A: no Rust changes`
- [x] Tauri fmt/check (if changed): `N/A: no Tauri shell changes`

### Validation Blocked
- `command:` `git push` pre-push hook (`app:lint:commands-tokens`)
- `error:` `lint:commands-tokens requires ripgrep` — `rg` not installed on the dev environment
- `impact:` zero — the check greps a directory I did not modify (`src/components/commands/`). Pushed with `--no-verify` per the CLAUDE.md guidance for environment-related hook failures unrelated to the diff. Maintainers can re-run on CI to validate.

### Behavior Changes
- Intended behavior change: OAuth badges on channel panels transition out of `connecting` when the OAuth flow completes *or* fails, and starting a new method cancels the previous method's `connecting` row.
- User-visible effect: the reported bug (multiple methods stuck on `Connecting` simultaneously, Telegram OAuth never clearing) goes away. No new UI elements; only badge state transitions are affected.

### Parity Contract
- Legacy behavior preserved: existing `connected` and `error` transitions are unchanged; `disconnectChannelConnection`, `upsertChannelConnection`, `setChannelConnectionStatus` are all untouched. The Discord `oauth:success` path still produces the same final state (`status: 'connected'`, `capabilities: ['read', 'write']`); the inline effect was just refactored behind the shared hook.
- Guard/fallback/dispatch parity checks: hook only reacts when the event's `toolkit` (success) or `provider` (error) field matches the subscribed channel — siblings on other channels, and mismatched dispatches, are no-ops.

### Duplicate / Superseded PR Handling
- Duplicate PR(s): none found. tinyhumansai#2170 cross-references tinyhumansai#2128 in passing but its title and body close tinyhumansai#2141 (channel selector error-status aggregation, a different surface).
- Canonical PR: this one.
- Resolution: N/A.


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Reusable OAuth connection listener to handle OAuth success/error deep-link flows for Discord and Telegram.
  * New action to clear other pending/connecting auth methods for a channel.

* **Bug Fixes**
  * Prevents multiple auth methods from remaining "connecting"; switching stops in-flight polling and clears sibling pending modes.
  * OAuth errors now record meaningful messages and listeners unsubscribe on unmount.

* **Tests**
  * Added tests covering the OAuth listener and pending-clearing reducer behaviors.

<!-- review_stack_entry_start -->

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/tinyhumansai/openhuman/pull/2256?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: sanil-23 <sanil@alphahuman.xyz>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
AusAgentSmith pushed a commit to AusAgentSmith/openhuman that referenced this pull request May 23, 2026
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
AusAgentSmith pushed a commit to AusAgentSmith/openhuman that referenced this pull request May 23, 2026
…inyhumansai#2128)

## Summary

- Centralises OAuth deep-link → channel-badge transitions behind a new
  `useOAuthConnectionListener` hook so every channel panel handles both
  `oauth:success` and `oauth:error` consistently.
- Adds a `clearOtherPendingForChannel` reducer so starting a connect flow on
  one auth mode drops any sibling auth mode that's still mid-`connecting` on
  the same channel.
- Wires `DiscordConfig` and `TelegramConfig` onto the shared hook; future
  channels with an OAuth auth mode inherit correct pending-state transitions
  automatically.
- Covers the new reducer (4 cases) and hook (8 cases) with Vitest.

## Problem

OAuth badges on the channel connection panels could get pinned at
`Connecting` indefinitely (issue tinyhumansai#2128):

- `DiscordConfig` had a per-component `oauth:success` listener but no
  `oauth:error` listener — failed OAuth attempts never transitioned the badge
  out of `connecting`.
- `TelegramConfig` had neither — completed *and* failed OAuth attempts left
  the badge pinned.
- Both panels set `connecting` on the chosen auth mode but never cancelled
  any sibling auth mode that was already pending. Triggering a second OAuth
  method on Discord (`OAuth Sign-in` then `Login with OpenHuman`, or the
  reverse) left both methods badged `Connecting` simultaneously.

This is the exact repro from the issue. The same shape was visible across
GitHub/GitLab style multi-method panels because the underlying state model
(`channelConnections`, keyed by `(channel, authMode)`) had no notion of
mutual exclusion.

## Solution

**Shared listener hook** —
[`app/src/hooks/useOAuthConnectionListener.ts`](app/src/hooks/useOAuthConnectionListener.ts)
subscribes to both `oauth:success` and `oauth:error` window events
(dispatched from `utils/desktopDeepLinkListener.ts`), filters by `toolkit` /
`provider` case-insensitively, and dispatches the matching slice action.
Per-channel panels mount it once with `{ channel, authMode }`; cleanup on
unmount is deterministic. New channels with an OAuth auth mode inherit the
behaviour without copying any logic.

**Pending-state cancellation reducer** — `clearOtherPendingForChannel({ channel,
exceptAuthMode })` in `channelConnectionsSlice.ts` walks the auth-mode map
for one channel and transitions every `connecting` row (except the
exception) to `disconnected` with `lastError: undefined`. Cancelled rows go
to `disconnected` rather than `error` so the UI doesn't surface a misleading
failure — the user explicitly switched methods, they didn't experience an
error.

**Per-panel wiring** — `DiscordConfig` and `TelegramConfig` each:

1. Mount `useOAuthConnectionListener({ channel: <name>, authMode: 'oauth' })`
   at the top of the component (replacing the bespoke effect on Discord;
   net-new on Telegram).
2. Dispatch `clearOtherPendingForChannel` at the start of `handleConnect`
   *before* setting their own auth mode to `connecting`.

**Tradeoffs**

- The cancellation transition is `disconnected`, not a new `cancelled` state.
  Adding a dedicated state would expand the `ChannelConnectionStatus` union
  across many call sites for marginal UX value.
- The deep-link CustomEvent payload (`{ integrationId, toolkit }` for
  success, `{ provider, errorCode, message }` for error) is unchanged, so
  no symmetric change in the Tauri-side handler is needed.

## Submission Checklist

- [x] Tests added or updated (happy path + at least one failure / edge case) per [Testing Strategy](../gitbooks/developing/testing-strategy.md#failure-path-requirement) — 12 new Vitest cases (4 reducer + 8 hook) covering success, error, mismatched channel, mismatched provider, missing error message, custom capabilities, unsubscribe on unmount, and three sibling-cancellation shapes.
- [x] **Diff coverage ≥ 80%** — frontend-only change; `pnpm test:coverage` locally over the new files reaches 100% on changed lines (every branch in the hook + reducer is exercised by the suite).
- [x] Coverage matrix updated — `N/A: behaviour-only fix on existing surfaces (channel connection pending state)`.
- [x] All affected feature IDs from the matrix are listed in the PR description under `## Related` — `N/A: no feature ID changes`.
- [x] No new external network dependencies introduced — purely in-app state plumbing.
- [x] Manual smoke checklist updated if this touches release-cut surfaces — `N/A: no release-cut surface touched (channels panel is part of the always-shipped settings UX)`.
- [x] Linked issue closed via `Closes #NNN` in the `## Related` section — see below.

## Impact

- **Desktop only** — no mobile/web/CLI impact. The deep-link event source
  (`desktopDeepLinkListener.ts`) is Tauri-gated; the hook is a no-op outside
  Tauri because no deep-link events fire.
- **No persistence shape change** — `channelConnections` slice schema
  (`SCHEMA_VERSION = 1`) is unchanged. The new reducer only mutates existing
  rows; no migration needed.
- **No security implications** — the listener filters strictly by channel
  identifier and never reads tokens. Existing `[DeepLink][oauth:*]` logs
  remain the canonical diagnostic surface; the hook adds its own
  `channels:oauth-listener` debug namespace per the project's
  verbose-diagnostics rule.

## Related

- Closes: tinyhumansai#2128
- Follow-up PR(s)/TODOs: none

## Provider coverage

The issue body mentions Discord, GitHub, and GitLab. The Channels page in this codebase only exposes three multi-method channel-config panels today: `DiscordConfig.tsx`, `TelegramConfig.tsx`, and `WebChannelConfig.tsx` (the last is not OAuth-driven). There is no `GitHubConfig.tsx` / `GitLabConfig.tsx` — verified via `find app/src -name "*Config.tsx"`.

GitHub OAuth does appear elsewhere in the app, but on different state slices that this PR's `channelConnections`-bound hook does not (and should not) touch:

| Surface | File(s) | State path | This PR applies? |
|---|---|---|---|
| App-level sign-in | `BootCheckGate.tsx`, OAuth callback | `deepLinkAuth` slice | No — different slice. App-level OAuth's hot-instance issue is the family fixed by tinyhumansai#2228 / tinyhumansai#2229. |
| Skill OAuth install | `InstallSkillDialog.tsx`, `services/api/skillsApi.ts` | skills-domain state | No — different surface. |
| Composio integration | `components/composio/TriggerToggles.tsx`, `composio/providerConfigs.tsx` | Composio integration state | No — different surface. |
| **Channel config** (this PR) | `DiscordConfig.tsx`, `TelegramConfig.tsx` | `channelConnections` slice | **Yes — wired.** |

So this PR's `useOAuthConnectionListener` covers every multi-method OAuth panel that actually exists on the Channels surface. The shared hook is also the right shape for any future `GitHubConfig.tsx` / `GitLabConfig.tsx` channel panels — wiring them in becomes a one-line `useOAuthConnectionListener({ channelId, capabilities, ... })` import.

If the stale-`Connecting` symptom also surfaces in the app-level / skills / Composio OAuth flows, those are separate fixes against different state slices and out of scope for this PR — I'm happy to file follow-up issues if any are observed.

---

## AI Authored PR Metadata (required for Codex/Linear PRs)

### Linear Issue
- Key: N/A
- URL: N/A

### Commit & Branch
- Branch: `fix/2128-oauth-badge-pending-state`
- Commit SHA: `2d93f7c0`

### Validation Run
- [x] `pnpm --filter openhuman-app format:check` — `All matched files use Prettier code style!` on the 6 changed files
- [x] `pnpm typecheck` — clean (`tsc --noEmit`)
- [x] Focused tests: `pnpm --filter openhuman-app exec vitest run --config test/vitest.config.ts src/store/__tests__/channelConnectionsSlice.test.ts src/hooks/__tests__/useOAuthConnectionListener.test.tsx src/components/channels/__tests__/DiscordConfig.test.tsx src/components/channels/__tests__/TelegramConfig.test.tsx` → 4 files, 27 tests pass
- [x] Rust fmt/check (if changed): `N/A: no Rust changes`
- [x] Tauri fmt/check (if changed): `N/A: no Tauri shell changes`

### Validation Blocked
- `command:` `git push` pre-push hook (`app:lint:commands-tokens`)
- `error:` `lint:commands-tokens requires ripgrep` — `rg` not installed on the dev environment
- `impact:` zero — the check greps a directory I did not modify (`src/components/commands/`). Pushed with `--no-verify` per the CLAUDE.md guidance for environment-related hook failures unrelated to the diff. Maintainers can re-run on CI to validate.

### Behavior Changes
- Intended behavior change: OAuth badges on channel panels transition out of `connecting` when the OAuth flow completes *or* fails, and starting a new method cancels the previous method's `connecting` row.
- User-visible effect: the reported bug (multiple methods stuck on `Connecting` simultaneously, Telegram OAuth never clearing) goes away. No new UI elements; only badge state transitions are affected.

### Parity Contract
- Legacy behavior preserved: existing `connected` and `error` transitions are unchanged; `disconnectChannelConnection`, `upsertChannelConnection`, `setChannelConnectionStatus` are all untouched. The Discord `oauth:success` path still produces the same final state (`status: 'connected'`, `capabilities: ['read', 'write']`); the inline effect was just refactored behind the shared hook.
- Guard/fallback/dispatch parity checks: hook only reacts when the event's `toolkit` (success) or `provider` (error) field matches the subscribed channel — siblings on other channels, and mismatched dispatches, are no-ops.

### Duplicate / Superseded PR Handling
- Duplicate PR(s): none found. tinyhumansai#2170 cross-references tinyhumansai#2128 in passing but its title and body close tinyhumansai#2141 (channel selector error-status aggregation, a different surface).
- Canonical PR: this one.
- Resolution: N/A.


<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

* **New Features**
  * Reusable OAuth connection listener to handle OAuth success/error deep-link flows for Discord and Telegram.
  * New action to clear other pending/connecting auth methods for a channel.

* **Bug Fixes**
  * Prevents multiple auth methods from remaining "connecting"; switching stops in-flight polling and clears sibling pending modes.
  * OAuth errors now record meaningful messages and listeners unsubscribe on unmount.

* **Tests**
  * Added tests covering the OAuth listener and pending-clearing reducer behaviors.

<!-- review_stack_entry_start -->

[![Review Change Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/tinyhumansai/openhuman/pull/2256?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack)

<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

Co-authored-by: sanil-23 <sanil@alphahuman.xyz>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Steven Enamakel <enamakel@tinyhumans.ai>
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.

Windows desktop OAuth callbacks do not reach the running app instance

3 participants