Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Fix: Deleted/stale channels keep showing in Group Settings
Background
A Discord channel that was deleted on the platform still appears in the Web UI Group Settings → Groups list. Investigation shows this is a shared-core gap, not a Discord-only bug.
Data flow today (core/chat_discovery.py):
- On
refresh_platform()(Rescan), live channels are fetched via_fetch_platform_channels(). Every returned id goes intoseen_idsand is upserted withvisibility_status = "visible"(lines 469–498). _mark_not_returned()(lines 740–769) walks the persistedscopesfor that platform and, for any row not inseen_ids, soft-marks itvisibility_status = "not_returned"pluslast_missing_at. Rows are never physically deleted.channels_response()(lines 585–648) callslist_chats(..., include_not_returned=True)and_filter_response_chats(). That filter only dropsnot_returnedwhenrequire_member=True, which is Slack-with-membership only. For Discord and Lark (require_member=False)not_returnedrows are returned verbatim.- The UI (
ui/src/components/steps/ChannelList.tsx) never readsvisibility_status; its "Show inactive" toggle filters byconfig.enabled(enabled/disabled), not by platform existence. So deleted channels always show and there is no way to remove them.
Per-platform audit:
| Platform | Live list API | Pagination handled | 429/backoff | _mark_not_returned |
Deleted-still-shows |
|---|---|---|---|---|---|
| Slack | users_conversations / conversations_list |
yes (cursor loop) | yes (5x backoff) | yes, require_member gated |
yes |
| Discord | GET /guilds/{id}/channels (+ guild list) |
channels: single call (complete); guild list users/@me/guilds not paginated |
no | yes (require_member=False) |
yes |
| Lark/Feishu | GET /im/v1/chats |
yes (page_token, max_pages=50 cap → truncated) |
no | yes (require_member=False) |
yes |
| Telegram | none (passive, message-driven) | n/a | n/a | never called | yes (cannot auto-detect deletion) |
| none (no channel concept) | n/a | n/a | n/a | n/a (UI short-circuits) |
Key correctness coupling: hiding not_returned is only safe if we never
_mark_not_returned on an incomplete fetch (transient 429, truncated page).
_mark_not_returned already runs only after a fetch that did not raise — but it
runs inside the same transaction that has already upserted the seen rows, so a
fetch that succeeds but is partial (Lark truncated) will still mark the unseen
(but actually-live) rows not_returned. So P0 (hide) and P1 (never false-mark)
must ship together.
Note: Discord's per-guild channel fetch (GET /guilds/{id}/channels) returns the
whole channel set in one call, and _fetch_platform_channels for Discord already
requires a guild_id. The paginated users/@me/guilds endpoint is only used by
the setup-wizard guild picker and has no effect on _mark_not_returned
correctness — it is a UX item, not a P1 correctness item.
Goal
- Deleted/inaccessible channels stop appearing in the Groups list by default (the reported bug), across all active-refresh platforms (Slack, Discord, Lark).
- Users can still review and manually remove stale entries (covers Telegram / WeChat and any soft-marked row), with a clear visual state.
- Eliminate false
not_returnedmarking caused by partial/rate-limited fetches.
Non-goals: redesigning discovery; automatic background physical deletion (left as an explicit, optional follow-up); changing the meaning of the existing "Show inactive" (enabled/disabled) toggle.
Solution
P0 — Hide not_returned from the Groups list by default (root-cause)
Backend (core/chat_discovery.py):
- Add
include_not_returned: bool = Falseparameter tochannels_response().all_chatskeepslist_chats(..., include_not_returned=True)unchanged (it must stay the full inventory for accurate counts). Apply the filter only to the returnedchatsview — extend_filter_response_chats()to dropvisibility_status == not_returnedwheneverinclude_not_returnedisFalse(for all platforms, not justrequire_member). This is the central, platform- agnostic fix, so every active-refresh platform inherits it. _summary()derives counts from the unfilteredall_chats:discovered_count = len(all_chats)(unchanged) and a newnot_returned_count = len([c for c in all_chats if c.visibility_status == VISIBILITY_NOT_RETURNED])— no extra DB query.- Fix the refresh-trigger guard at
channels_response()line ~623. Today it isforce or not chats or cache_requires_refresh. After P0,chatsexcludesnot_returned, so an install whose channels were all deleted would havechats == []on every request and re-refresh on every load (bypassing the TTL, which only lives insiderefresh_platform). Replace thenot chatssignal with a "never successfully fetched" signal:force or state.last_success_at is None or cache_requires_refresh. The backgroundshould_refresh()/_schedule_refreshpath (line ~635) already handles staleness via TTL and is unchanged. - Keep the existing
require_member+not_returnedcheck in_filter_response_chats()as defense-in-depth (harmless once the new default filter is in place; protects callers that pass an unfiltered list). - API surface:
vibe/api.pylist_channels/discord_list_channels/lark_*/telegram_list_chatsand the UI endpoint gain an opt-ininclude_not_returned(defaultFalse) so a power-user view can still fetch stale rows for review/removal.
UI (ui/src/components/steps/ChannelList.tsx):
- By default render only channels the backend returns (now excludes
not_returned). No behavior change needed if backend defaults to hiding. - Add a small affordance ("N unavailable — review") that, when toggled, requests
include_not_returned=trueand renders those rows with a distinct "Unavailable / removed on platform" badge derived fromvisibility_status(+metadata.last_missing_at), visually separate from Enabled/Disabled.
P0b — Manual remove (physical delete of a scope)
- New API + UI action to permanently delete a discovered scope (the
scopesrow plus itsscope_settings). Reuses the existing scope-id helpers; add a focuseddelete_scope()in the discovery/store layer. - This is the only deletion path that also works for Telegram (no live list) and is the user-facing escape hatch. Confirm-before-delete in UI.
- FK note:
scope_settings.scope_idisON DELETE CASCADEandscopes.parent_scope_idisON DELETE SET NULL(storage/models.py). SQLite enforces cascade only whenPRAGMA foreign_keys = ON.delete_scope()must therefore explicitly delete thescope_settingsrow(s) first (do not rely on the pragma), then thescopesrow. Deleting a guild-type scope nulls theparent_scope_idof its child channel scopes (SET NULL) — correct behavior.
P1 — Never false-mark on incomplete fetches (robustness)
The single safety-critical change here is: refresh_platform() must skip
_mark_not_returned() when the fetch was incomplete, while still upserting the
rows it did get. Because both the foreground and background (_schedule_refresh)
paths call refresh_platform(), changing it there covers both.
core/chat_discovery.py:
- Extend
_fetch_platform_channels()return fromtuple[list[dict], str | None]totuple[list[dict], str | None, bool]where the new bool isfetch_complete. Update the single destructure at line ~454 (rows, refreshed_parent = ...). Values: SlackTrue(cursor loop exhausts), DiscordTrue(single complete call), Larknot result.get("truncated", False). - In
refresh_platform(), guard the_mark_not_returned(...)call (line ~499) onfetch_complete; when incomplete, log and skip marking (rows still upserted).
vibe/api.py:
- Lark (highest priority): the
truncatedflag already exists in thelark_list_chats_livereturn dict (line ~9148);_fetch_platform_channelsjust readsresult.get("truncated", False). Add 429/5xx retry/backoff to the Lark fetch so transient limits don't surface as partial success. - Discord (hygiene, lower priority): add 429/5xx retry with backoff to
_discord_api_get/_discord_api_get_async(honorRetry-After), mirroring the Slack helper. Per-guild channel fetch rarely hits 429; this is defensive.
(users/@me/guilds pagination is a UX item — see P4 below — not part of this
correctness fix.)
P2 — Optional auto-GC (follow-up, gated on P1)
- Physically delete rows that have been
not_returnedfor a grace window (e.g. ≥ N consecutive successful refreshes or ≥ X days vialast_missing_at), configurable and off by default. Documented as a separate PR; not implemented in this change unless review requests it.
P3 — Telegram / WeChat
- Telegram: no server list to diff, so deletion cannot be auto-detected. Rely on P0b manual remove; optionally surface a "last seen" staleness hint. No auto-marking.
- WeChat: unchanged (no channel concept; UI already short-circuits).
P4 — Discord guild-list pagination (UX, separate follow-up)
- Paginate
users/@me/guildswith theaftercursor indiscord_list_guilds*so the setup-wizard guild picker is complete for bots in >100–200 guilds. This does not affect_mark_not_returnedcorrectness and is out of scope for the primary fix; documented here so it is not lost.
Testing
- Unit (
tests/): extend chat_discovery tests with a hermetic SQLitedb_pathto assert:- a row marked
not_returnedis excluded fromchannels_response()by default and included wheninclude_not_returned=True; _summary()still counts it underdiscovered_count+ newnot_returned_count;- a truncated/partial fetch upserts seen rows but does not mark missing rows
not_returned— covering both the foregroundrefresh_platform()call and the background_schedule_refresh()→refresh_platform()path (mock a truncated Lark result in each); - after P0, an install whose channels are all
not_returneddoes not trigger a refresh on everychannels_response()call (assert thelast_success_at-based guard, notnot chats); delete_scope()removes the scope and itsscope_settings(assert the explicit child-delete works regardless of the SQLite FK pragma).
- a row marked
- API: unit-test Discord 429 retry and guild-list pagination, and Lark
truncatedpropagation, with mocked HTTP (no live calls; keep hermetic per CLAUDE.md). - UI:
cd ui && npm run build; add/extend a ChannelList test if a pattern exists for the unavailable-rows view. - Manual: Incus regression for cross-platform sanity (Slack/Discord/Lark) per CLAUDE.md, after CI-style local checks.
Rollout / risk
- Behavior change: deleted channels disappear from the default list. Mitigated by the opt-in "unavailable" view + manual remove, and by P1 preventing false hides.
- No destructive DB migration; soft-mark semantics preserved. Physical deletion only via explicit user action (P0b) or optional P2.
- Scope of this PR: P0 + P0b + P1 (+ tests). P2 is a documented follow-up.
TODO
- P0:
include_not_returnedparam onchannels_response(defaultFalse); keepall_chatsunfiltered, filter onlychatsvia_filter_response_chats; addnot_returned_countto_summary; fix refresh-trigger guard to usestate.last_success_at is Noneinstead ofnot chats; thread the opt-in throughvibe/api.py+ UI endpoint. - P0b:
delete_scope()store helper (explicitscope_settingsdelete thenscopes) + API endpoint + UI remove action with confirm. - P1:
_fetch_platform_channelsreturnsfetch_complete(3-tuple), update destructure at line ~454;refresh_platformskips_mark_not_returnedwhen incomplete (covers foreground + background paths); Larktruncatedpropagation + Lark 429 retry; Discord 429 retry (hygiene). - UI: unavailable-rows view + badge from
visibility_status/last_missing_at. - i18n: add new UI strings to
ui/src/i18n/en.jsonandui/src/i18n/zh.json. - Tests: chat_discovery unit (filter default, summary counts, refresh-guard,
truncation skip in fore+background, delete_scope), API retry/truncation unit,
cd ui && npm run build. - Update user docs for the unavailable/remove behavior.
- P4 (separate follow-up):
users/@me/guildscursor pagination for the guild picker.