Skip to content

feat(discord): Supabase-backed trigger storage for pod resilience#368

Merged
JonasJesus42 merged 3 commits intomainfrom
JonasJesus42/supabase-trigger-resilience
Apr 7, 2026
Merged

feat(discord): Supabase-backed trigger storage for pod resilience#368
JonasJesus42 merged 3 commits intomainfrom
JonasJesus42/supabase-trigger-resilience

Conversation

@JonasJesus42
Copy link
Copy Markdown
Contributor

@JonasJesus42 JonasJesus42 commented Apr 7, 2026

Summary

  • Replace LazyStudioKV with SupabaseTriggerStorage: StudioKV depended on expiring mesh tokens (~5 min), causing trigger credentials to be lost on pod restart. The new storage uses static SUPABASE_URL/SUPABASE_ANON_KEY env vars that never expire.
  • Fix onChange config merge: Previously silently dropped configs when connectionId/organizationId/meshUrl were missing. Now merges with existing saved config from Supabase, preventing data loss.
  • Remove DISCORD_BOT_START tool: Bots auto-start from Supabase bootstrap and onChange — no manual start needed.
  • Add trigger credential pre-warming: Logs available trigger credentials on startup for observability.

Pre-deploy requirement

Create new Supabase table before deploying:

CREATE TABLE public.discord_trigger_credentials (
  connection_id TEXT PRIMARY KEY REFERENCES public.discord_connections(connection_id) ON DELETE CASCADE,
  callback_url TEXT NOT NULL,
  callback_token TEXT NOT NULL,
  active_trigger_types TEXT[] NOT NULL DEFAULT '{}',
  created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
  updated_at TIMESTAMPTZ NOT NULL DEFAULT now()
);

Post-deploy action

Users need to re-enable triggers once in Mesh UI so credentials get saved to the new Supabase table. After that, they persist indefinitely across pod restarts.

Test plan

  • Create discord_trigger_credentials table in Supabase
  • Deploy and verify bots auto-start from Supabase bootstrap (no user interaction)
  • Enable a trigger in Mesh UI → verify credentials saved to discord_trigger_credentials → send Discord message → verify trigger fires
  • Kill pod → new pod starts → verify bots reconnect AND triggers still fire
  • Verify DISCORD_BOT_START tool no longer appears in MCP tool list
  • Test onChange with partial data → verify existing config fields are preserved

🤖 Generated with Claude Code


Summary by cubic

Persist Discord trigger credentials in Supabase so triggers survive pod restarts and no longer rely on expiring Mesh tokens. Also shares one Discord client across connections with the same bot token and preserves created_at on credential upserts.

  • New Features

    • Replace StudioKV with Supabase-backed storage (discord_trigger_credentials) using SUPABASE_URL/SUPABASE_ANON_KEY.
    • onChange now merges with saved config to prevent dropped fields when connectionId/organizationId/meshUrl are missing.
    • Remove DISCORD_BOT_START; bots auto-start via Supabase bootstrap and onChange.
    • Pre-warm and log available trigger credentials at startup.
  • Migration

    • Before deploy: create public.discord_trigger_credentials with columns — connection_id PK (FK to public.discord_connections(connection_id) ON DELETE CASCADE), callback_url, callback_token, active_trigger_types TEXT[], created_at, updated_at.
    • After deploy: users must re-enable triggers once in Mesh UI to save credentials into the new table.

Written for commit 4e76cf6. Summary will update on new commits.

StudioKV depended on expiring mesh tokens (~5 min), causing trigger
credentials to be lost on pod restart. This replaces it with
SupabaseTriggerStorage that uses static SUPABASE_URL/SUPABASE_ANON_KEY
env vars (never expire), making triggers fully resilient across restarts.

Also fixes onChange to merge with existing config (prevents silent drops),
removes DISCORD_BOT_START tool (bots auto-start from bootstrap/onChange),
and adds trigger credential pre-warming on startup.

Requires new Supabase table: discord_trigger_credentials

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

1 issue found across 5 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="discord-read/server/lib/supabase-client.ts">

<violation number="1" location="discord-read/server/lib/supabase-client.ts:241">
P2: `created_at` is being overwritten on every upsert, so it no longer represents the original creation time.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

JonasJesus42 and others added 2 commits April 7, 2026 15:39
…oken

Connections with duplicate bot tokens were getting instances with
client=null because bootstrap skipped ensureBotRunning for them.
Now duplicate connections share the Client reference from the primary
connection that started it, so all connections report as running.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
created_at should only be set on first insert (via Supabase DEFAULT).
Omit it from the upsert payload so it preserves the original creation time.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@JonasJesus42 JonasJesus42 merged commit c9adb49 into main Apr 7, 2026
2 checks passed
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