• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
project logo

colel

rust-nyc-talk-submissions

https://github.com/colelawrence/rust-nyc-talk-submissions
Public
Like
rust-nyc-talk-submissions
Home
Code
16
.beads
2
.context
4
.github
1
.pi
1
backend
10
docs
3
frontend
3
shared
1
.gitignore
.vtignore
AGENTS.md
BRAND_STYLE_GUIDE.md
README.md
biome.json
deno.json
main.tsx
Environment variables
7
Branches
2
Pull requests
Remixes
1
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
backend
/
autothread
/
README.md
Code
/
backend
/
autothread
/
README.md
Search
1/29/2026
Viewing readonly version of main branch: v162
View latest version
README.md

Autothread Debug Console

A testing and debugging infrastructure for the autothread system that enables rapid iteration in Val Town's deploy-to-prod environment.

Quick Start

  1. Set environment variables:

    ADMIN_TOKEN=your-secret-token
    ENABLE_TEST_API=true
    
  2. Test in sandbox mode (default - no side effects):

    curl -X POST https://your-val.val.run/api/autothread/debug/run \ -H "Authorization: Bearer $ADMIN_TOKEN" \ -H "Content-Type: application/json" \ -d '{"mode": "plan"}'

Concepts

Execution Modes

ModeDiscord WritesDB WritesUse Case
plan❌❌See what would happen without any changes
dry_runβŒβœ…Test DB logic (cursors, claims) without Discord
liveβœ…βœ…Actually create threads

Namespaces

NamespaceTablesUse Case
sandbox*_sandboxTesting - isolated from production
prod*Real data - requires explicit confirmation

Safety Guards

  • Default: mode=plan, namespace=sandbox
  • live + prod requires confirm: "LIVE_PROD"
  • Resetting prod is blocked
  • Caps are enforced server-side (max 3 iterations, 5 threads)

Endpoints

Run Control

POST /run

Trigger an autothread run with custom configuration.

{ "mode": "plan|dry_run|live", "namespace": "sandbox|prod", "enableAI": false, "allowlist": ["channel_id_1", "channel_id_2"], "maxChannels": 1, "maxThreads": 2, "iterations": 1, "durationMs": 10000, "confirm": "LIVE_PROD" // Required for live+prod }

Response includes:

  • result.plannedActions[] - What would/did happen
  • result.events[] - Detailed event log
  • result.threadsCreated, result.errorCount

State Inspection

GET /state?namespace=sandbox

Returns channels, recent processed messages, and today's stats.

GET /runs?namespace=sandbox&limit=10

List recent runs with their status.

GET /runs/:id/events?namespace=sandbox

Get detailed events for a specific run.

State Manipulation

POST /reset

Reset all sandbox state.

{"namespace": "sandbox", "confirm": "RESET_SANDBOX"}

POST /reset-cursor

Reset a channel's last_message_id cursor.

{"namespace": "sandbox", "channelId": "123", "lastMessageId": null}

POST /clear-processed

Clear processed messages with filters.

{"namespace": "sandbox", "channelId": "123", "status": "dry_run"}

Component Testing

GET /discord/channels

Test Discord API connectivity. Returns all guild channels.

GET /discord/messages?channelId=123&limit=20

Fetch messages from a channel.

POST /eval-message

Test gate evaluation on a message.

{"content": "Hello world, this is a test message", "isBot": false}

or

{"channelId": "123", "messageId": "456"}

POST /generate-name

Test deterministic thread naming.

{"content": "This is a long message that will be truncated for the thread name"}

POST /generate-ai-name

Test AI thread naming (requires OPENAI_API_KEY).

{ "content": "Can someone help me with Rust lifetimes?", "context": [ {"author": "alice", "content": "I'm stuck on this borrow checker error"}, {"author": "bob", "content": "What does the error say?"} ] }

Workflow Examples

1. Initial Testing

# See what the system would do curl -X POST .../debug/run -d '{"mode":"plan"}' -H "Authorization: Bearer $TOKEN" # Check planned actions # Look at result.plannedActions

2. Test DB Logic

# Run with DB writes but no Discord curl -X POST .../debug/run -d '{"mode":"dry_run"}' -H "..." # Inspect state curl .../debug/state -H "..." # Reset and try again curl -X POST .../debug/reset -d '{"confirm":"RESET_SANDBOX"}' -H "..."

3. Test Specific Channel

# Get channel IDs curl .../debug/discord/channels -H "..." # Run on specific channel curl -X POST .../debug/run -d '{"allowlist":["123456789"]}' -H "..."

4. Debug Gate Failures

# Why was this message skipped? curl -X POST .../debug/eval-message \ -d '{"channelId":"123","messageId":"456"}' -H "..." # Test with synthetic content curl -X POST .../debug/eval-message \ -d '{"content":"!help","isBot":false}' -H "..." # Will show: "Starts with command prefix (!, /, .)"

5. Test AI Naming

curl -X POST .../debug/generate-ai-name \ -d '{"content":"Question about async/await","context":[{"content":"Previous discussion"}]}' \ -H "..."

Module Structure

backend/autothread/
β”œβ”€β”€ index.ts      # Re-exports
β”œβ”€β”€ types.ts      # Type definitions, config defaults
β”œβ”€β”€ store.ts      # Database operations with namespace support
β”œβ”€β”€ logic.ts      # Core processing logic (gates, AI, threading)
└── runner.ts     # High-level runner used by cron and debug

The cron job (autothread.cron.ts) and debug endpoint (autothread-debug.http.ts) both use the same underlying runAutothread() function, ensuring consistent behavior.

Environment Variables

VariableRequiredDescription
ADMIN_TOKENFor debugBearer token for debug endpoints
ENABLE_TEST_APIFor debugMust be "true" to enable debug
DISCORD_BOT_TOKENYesDiscord bot authentication
DISCORD_GUILD_IDYesGuild to monitor
AUTOTHREAD_DRY_RUNNoCron dry-run mode
AUTOTHREAD_ENABLE_AINoEnable AI naming in cron
AUTOTHREAD_CHANNEL_ALLOWLISTNoComma-separated channel IDs
OPENAI_API_KEYFor AIOpenAI API key (Val Town std lib)
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
Β© 2026 Val Town, Inc.