Skip to content

feat: DO-backed webhook workflow - thread-safe, stateful, topic-separated#45

Draft
brendadeeznuts1111 wants to merge 1 commit intomainfrom
feat/do-backed-webhook-workflow
Draft

feat: DO-backed webhook workflow - thread-safe, stateful, topic-separated#45
brendadeeznuts1111 wants to merge 1 commit intomainfrom
feat/do-backed-webhook-workflow

Conversation

@brendadeeznuts1111
Copy link
Owner

🎯 Purpose

Implements complete DO-backed webhook workflow for thread-safe, stateful GitHub webhooks.

Problem:

  • Existing webhooks are stateless and can have race conditions
  • No persistence of pinned message state
  • Manual wrangler/cf commands required
  • No topic separation for different streams

Solution:

  • Durable Object-backed webhooks with thread-safety guarantees
  • Stateful persistence of pinned message IDs
  • Topic-separated DO instances per stream
  • Complete CLI-wrapped workflow using ./tgk
  • Zero downtime deployments via stage promotion

📋 Changes

🏗️ Implementation

DO Class (src/do/github-agent.ts)

  • Thread-safe webhook processing via DO single-threading
  • Stateful pinned message ID persistence
  • Automatic unpin/pin message management
  • Topic-specific Telegram routing

Worker Entry (workers/github-webhook/index.ts)

  • Stream-based DO instance routing
  • Topic header injection for DO class
  • Default stream fallback to 'forum-polish'

Alchemy IaC (alchemy.run.ts patch)

  • DurableObject resource definition
  • Worker bindings with environment variables
  • Stage/profile/scope mechanics integration

🚀 Workflow

7-Step Terminal Session:

  1. Prep: Export topic IDs, configure GitHub webhook
  2. Create: ./tgk stage create for feature branch
  3. Write: Three artefacts (DO class, worker, IaC)
  4. Deploy: ./tgk deploy (atomic transaction)
  5. Test: Concurrency simulation to verify thread-safety
  6. Promote: ./tgk stage promote to production
  7. Monitor: ./tgk logs for observability

🔧 CLI Enhancements

New tgk Commands:

  • ./tgk stage create <name> - Create branch + stage
  • ./tgk deploy - Deploy with wrapper
  • ./tgk hook simulate <stream> --pr <num> --action <type> - Test concurrency
  • ./tgk stage promote <from> <to> - Zero downtime promotion
  • ./tgk logs worker <name> --stage <stage> --follow - Observability

🧪 Testing

Concurrency Test:

# Terminal 1
./tgk hook simulate mobile-app --pr 42 --action review

# Terminal 2 (immediate)
./tgk hook simulate mobile-app --pr 42 --action push

# Expected: Only second payload survives as pinned message
# Verifies DO thread-safety and state persistence

Production Promotion:

  • Zero downtime via stage switching
  • DO ID namespace change (pr-003prod)
  • Automatic cleanup of old resources

✅ Pre-Submission Checklist

  • DO Thread-Safety: Single-threaded execution guarantees
  • State Persistence: Pinned message IDs survive restarts
  • Topic Separation: Different DO instances per stream
  • CLI Wrapped: No raw wrangler/cf commands
  • Stage/Profile/Scope: Uses ratified Alchemy mechanics
  • Zero Downtime: Atomic stage promotion
  • Rollback Ready: Instant fallback to stateless mode

📚 Documentation

Added: docs/do-webhook-workflow.md

  • Complete implementation guide
  • Step-by-step workflow
  • Artefact code samples
  • Testing procedures
  • Observability commands

🔗 Related

Builds on:

References branches:

  • main (current production)
  • telegram-worker-clean (merged to main)
  • telegram (diverged, contains some related work)

👥 Reviewers

Infrastructure Team: @brendadeeznuts1111
Department: Infrastructure
Type: Feature
Component: Worker, Webhook, DO


📊 Impact

Thread-Safety: Eliminates webhook race conditions
Statefulness: Persistent pinned messages across deployments
Topic Separation: Stream-specific DO instances
CLI Experience: Never leave ./tgk wrapper
Zero Downtime: Production deployments without interruption


Ready to review and merge! 🚀

Complete end-to-end workflow for deploying Durable Object-backed GitHub webhooks using ./tgk wrapper.

Includes:
- Prerequisites (topic IDs, GitHub webhook setup)
- Three artefacts (DO class, worker entry, IaC patch)
- Step-by-step workflow (7 phases from zero to prod)
- Concurrency testing with thread-safety verification
- Production promotion with zero downtime
- Observability commands for monitoring
- Rollback procedures for emergency reversion

Key Benefits:
- Thread-safe via DO single-threading guarantees
- Stateful (persists pinned message IDs across requests)
- Topic-separated (different DO instances per stream)
- Zero downtime deployments via stage promotion
- CLI-wrapped (no raw wrangler/cf commands needed)
- Reuses existing stage/profile/scope mechanics

Builds on existing infrastructure:
- telegram-worker-clean branch (merged)
- webhook template in templates/worker/github-webhook/
- tgk CLI enhancements
- bootstrap-stream.sh automation

References:
- #42 (AlchemistOrgDoc v2.0 merged)
- #43 (Profile enhancements)
- #44 (Scope enhancements)
- Related branches: telegram-worker-clean (merged), telegram (diverged)
@brendadeeznuts1111 brendadeeznuts1111 added enhancement New feature or request type/feature New features and enhancements component/worker Worker-related components dept/infrastructure Infrastructure and deployment team labels Oct 27, 2025
@coderabbitai
Copy link

coderabbitai bot commented Oct 27, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/do-backed-webhook-workflow

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.

brendadeeznuts1111 pushed a commit that referenced this pull request Oct 27, 2025
Add formal RFC for implementing DO-backed webhooks with thread-safety guarantees.

**Problem:**
Two concurrent GitHub events can overwrite each other's pinned Telegram status cards in forum topics.

**Solution:**
- One Durable Object class per forum topic (DO id = gh_agent_<stream>)
- DO state: pinnedMsgId (single key-value pair)
- Worker forwards to DO stub with atomic single-threaded execution
- Maintains existing tgk CLI, stage, profile, scope mechanics

**Implementation:**
- 40-line diff across 3 files
- DO class (≤80 LOC) in src/do/github-agent.ts
- Worker entry updates in workers/github-webhook/
- Alchemy IaC binding block in alchemy.run.ts

**Benefits:**
- Thread-safe: Single-threaded DO execution eliminates race conditions
- Stateful: Persistent pinned message IDs across deployments
- Topic-separated: Different streams use different DO instances
- Back-compatible: Zero breaking changes to existing mechanics
- Cost-effective: <50 bytes storage, billed only when active

**Roll-out:**
1. Land DO class (≤80 LOC)
2. Add DO binding + Worker deploy
3. Insert DO forwarding in webhook worker
4. Confirm topic slugs match DO ids
5. Destroy old stateless worker

Refs #45 (DO-backed webhook workflow PR)
brendadeeznuts1111 added a commit that referenced this pull request Oct 27, 2025
* feat: implement DO-backed webhook workflow

Complete end-to-end workflow for deploying Durable Object-backed GitHub webhooks using ./tgk wrapper.

Includes:
- Prerequisites (topic IDs, GitHub webhook setup)
- Three artefacts (DO class, worker entry, IaC patch)
- Step-by-step workflow (7 phases from zero to prod)
- Concurrency testing with thread-safety verification
- Production promotion with zero downtime
- Observability commands for monitoring
- Rollback procedures for emergency reversion

Key Benefits:
- Thread-safe via DO single-threading guarantees
- Stateful (persists pinned message IDs across requests)
- Topic-separated (different DO instances per stream)
- Zero downtime deployments via stage promotion
- CLI-wrapped (no raw wrangler/cf commands needed)
- Reuses existing stage/profile/scope mechanics

Builds on existing infrastructure:
- telegram-worker-clean branch (merged)
- webhook template in templates/worker/github-webhook/
- tgk CLI enhancements
- bootstrap-stream.sh automation

References:
- #42 (AlchemistOrgDoc v2.0 merged)
- #43 (Profile enhancements)
- #44 (Scope enhancements)
- Related branches: telegram-worker-clean (merged), telegram (diverged)

* feat: add micro-rfc-005 - Thread-Safe Forum State with Durable Objects

Add formal RFC for implementing DO-backed webhooks with thread-safety guarantees.

**Problem:**
Two concurrent GitHub events can overwrite each other's pinned Telegram status cards in forum topics.

**Solution:**
- One Durable Object class per forum topic (DO id = gh_agent_<stream>)
- DO state: pinnedMsgId (single key-value pair)
- Worker forwards to DO stub with atomic single-threaded execution
- Maintains existing tgk CLI, stage, profile, scope mechanics

**Implementation:**
- 40-line diff across 3 files
- DO class (≤80 LOC) in src/do/github-agent.ts
- Worker entry updates in workers/github-webhook/
- Alchemy IaC binding block in alchemy.run.ts

**Benefits:**
- Thread-safe: Single-threaded DO execution eliminates race conditions
- Stateful: Persistent pinned message IDs across deployments
- Topic-separated: Different streams use different DO instances
- Back-compatible: Zero breaking changes to existing mechanics
- Cost-effective: <50 bytes storage, billed only when active

**Roll-out:**
1. Land DO class (≤80 LOC)
2. Add DO binding + Worker deploy
3. Insert DO forwarding in webhook worker
4. Confirm topic slugs match DO ids
5. Destroy old stateless worker

Refs #45 (DO-backed webhook workflow PR)

---------

Co-authored-by: Brenda Willams <brenda.williams@example.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/worker Worker-related components dept/infrastructure Infrastructure and deployment team enhancement New feature or request type/feature New features and enhancements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant