Autonomous Durable Objects debugger. Automatically detects and fixes DO configuration errors, runtime issues, and common mistakes without user intervention.
Automates debugging of Durable Objects by detecting configuration errors, runtime issues, and code problems, then applying fixes automatically.
/plugin marketplace add secondsky/claude-skills/plugin install cloudflare-durable-objects@claude-skillsAutonomous agent that detects, diagnoses, and fixes Durable Objects issues automatically. Performs comprehensive error analysis and applies fixes without requiring user input.
This agent should be used when:
Keywords: debug, error, fix, broken, not working, failing, deployment failed, migration error, binding error
Scan project for DO-related configuration and code:
# Find wrangler.jsonc
find . -name "wrangler.jsonc" -type f
# Find DO class files
find src -name "*.ts" -type f | xargs grep -l "extends DurableObject"
If wrangler.jsonc not found:
/do-setup command first# Check JSON validity (strip comments)
grep -v '^\s*//' wrangler.jsonc | jq '.' 2>&1
If JSON invalid:
# Use skill's validation script
./scripts/validate-do-config.sh 2>&1
Parse output for errors and warnings:
Deep analysis of wrangler.jsonc DO configuration:
Read wrangler.jsonc and parse:
grep -v '^\s*//' wrangler.jsonc | jq '{
bindings: .durable_objects.bindings,
migrations: .migrations
}'
Extract:
Error 1: Missing Bindings
Check if durable_objects.bindings exists:
jq '.durable_objects.bindings // empty' wrangler.jsonc
If empty or missing:
"durable_objects": {
"bindings": []
}
Error 2: Missing Migrations
Check if migrations array exists:
jq '.migrations // empty' wrangler.jsonc
If empty or missing:
Error 3: Binding Without Migration
For each binding, check if class exists in migrations:
# Get binding class names
jq -r '.durable_objects.bindings[]?.class_name' wrangler.jsonc
# Get migration class names
jq -r '.migrations[]? | .new_sqlite_classes[]?, .new_classes[]?' wrangler.jsonc
Compare lists - if binding class not in migrations:
Error 4: Duplicate Binding Names
Check for duplicate binding names:
jq -r '.durable_objects.bindings[]?.name' wrangler.jsonc | sort | uniq -d
If duplicates found:
Error 5: Invalid Binding Name
Check binding name format (should be SCREAMING_SNAKE_CASE):
jq -r '.durable_objects.bindings[]?.name' wrangler.jsonc
If not matching ^[A-Z_]+$:
Analyze DO class implementations:
Search for DO class definitions:
# Find all files with DurableObject classes
grep -r "extends DurableObject" src/ --include="*.ts" -l
# Extract class names
grep -r "export class.*extends DurableObject" src/ --include="*.ts" -o
Extract:
For each class referenced in bindings, verify it's exported:
Error 6: Class Not Exported
# Check if class is exported
grep "export class MyDO extends DurableObject" src/index.ts
If not found:
export class MyDO extends DurableObject { ... }
// Or re-export from another file:
export { MyDO } from "./MyDO";
Error 7: Class Export in Wrong File
Check main entry point (from wrangler.jsonc):
# Get main file
MAIN_FILE=$(jq -r '.main // "src/index.ts"' wrangler.jsonc)
# Check if class exported in main file
grep "export.*MyDO" "$MAIN_FILE"
If not found:
Read DO class constructor for common issues:
# Extract constructor code
grep -A 30 "constructor(ctx: DurableObjectState" src/MyDO.ts
Error 8: Missing super() Call
Check for super(ctx, env) in constructor:
// Search for super call
grep "super(ctx, env)" src/MyDO.ts
If not found:
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env); // ← Add this
}
Error 9: Heavy Constructor Work
Check for common blocking operations in constructor (not in blockConcurrencyWhile):
# Look for await outside blockConcurrencyWhile
grep -A 5 "constructor(" src/MyDO.ts | grep "await" | grep -v "blockConcurrencyWhile"
If found:
constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
this.ctx.blockConcurrencyWhile(async () => {
// Move async initialization here
});
}
Error 10: SQL Syntax Errors
Search for SQL queries and validate syntax:
grep -r "storage.sql.exec" src/ -A 3
Common issues:
If found:
Error 11: Transaction Nesting
Check for nested transactions (not supported):
# Look for multiple BEGIN TRANSACTION
grep -r "BEGIN TRANSACTION" src/
If found multiple in same function:
Error 12: setTimeout in DO
Search for setTimeout/setInterval usage:
grep -r "setTimeout\|setInterval" src/ --include="*.ts"
If found in DO class:
// Remove setTimeout
setTimeout(() => { ... }, 5000);
// Replace with alarm
await this.ctx.storage.setAlarm(Date.now() + 5000);
Error 13: Outgoing WebSocket
Check for outgoing WebSocket connections:
grep -r "new WebSocket(" src/
If found in DO:
Validate migration structure:
Extract all migration tags:
jq -r '.migrations[]?.tag' wrangler.jsonc
Error 14: Duplicate Migration Tags
Check for duplicates:
jq -r '.migrations[]?.tag' wrangler.jsonc | sort | uniq -d
If duplicates found:
Error 15: Missing Migration Tags
Check if all migrations have tags:
jq '.migrations[] | select(.tag == null)' wrangler.jsonc
If found:
tag fieldCheck for correct migration field usage:
Error 16: Using new_classes for SQL Storage
If DO uses SQL but migration uses new_classes:
# Check for new_classes (old KV syntax)
jq '.migrations[] | select(.new_classes != null)' wrangler.jsonc
If found and code uses SQL storage:
{
"tag": "v1",
"new_sqlite_classes": ["MyDO"] // ← Changed from new_classes
}
Check TypeScript setup for DOs:
Check if @cloudflare/workers-types is installed:
# Check package.json
jq '.devDependencies."@cloudflare/workers-types"' package.json
If missing:
npm install -D @cloudflare/workers-types@latest
Search for Env interface definition:
grep -r "interface Env" src/ --include="*.ts"
Verify all DO bindings are in Env:
interface Env {
MY_DO: DurableObjectNamespace<MyDO>; // Check this exists
}
If binding missing from Env:
Systematically apply all identified fixes:
Order fixes by criticality:
Critical (prevents deployment):
High (causes runtime errors):
Medium (performance issues):
Low (warnings):
For each fix, apply changes:
Fix Configuration Files (wrangler.jsonc)
Use Edit tool to update:
// Read current config
const config = await readFile('wrangler.jsonc');
// Parse (strip comments)
const json = parseJSON(stripComments(config));
// Apply fix (e.g., add migration)
if (!json.migrations) {
json.migrations = [];
}
json.migrations.push({
tag: "v1",
new_sqlite_classes: ["MyDO"]
});
// Write back
await writeFile('wrangler.jsonc', JSON.stringify(json, null, 2));
Fix Code Files (DO classes)
Use Edit tool to update:
// Example: Add missing super() call
const oldCode = `constructor(ctx: DurableObjectState, env: Env) {
this.ctx = ctx;`;
const newCode = `constructor(ctx: DurableObjectState, env: Env) {
super(ctx, env);
this.ctx = ctx;`;
await editFile('src/MyDO.ts', oldCode, newCode);
Create Missing Files
Use Write tool if files missing:
// Example: Create missing Env interface file
const envTypes = `interface Env {
MY_DO: DurableObjectNamespace<MyDO>;
}`;
await writeFile('src/types.ts', envTypes);
After applying fixes, re-run validation:
# Validate configuration
./scripts/validate-do-config.sh
# Check TypeScript compilation
npx tsc --noEmit
If validation passes:
If validation fails:
Test fixes locally before deployment:
# Start local dev server
wrangler dev &
DEV_PID=$!
# Wait for startup
sleep 5
# Test DO creation
curl "http://localhost:8787?id=test-123"
# Check exit code
if [ $? -eq 0 ]; then
echo "✅ Local test passed"
else
echo "❌ Local test failed"
fi
# Stop dev server
kill $DEV_PID
# Try deployment (dry run if available)
wrangler deploy --dry-run 2>&1
If dry run succeeds:
wrangler deployIf dry run fails:
Provide structured output with clear sections:
🔍 Durable Objects Diagnostic Complete
Issues Found: 8
Issues Fixed: 8
Status: ✅ All issues resolved
Fixes Applied:
──────────────
1. ✅ Added missing migration for class 'MyDO'
File: wrangler.jsonc
Change: Added v1 migration with new_sqlite_classes
2. ✅ Added missing super() call in constructor
File: src/MyDO.ts:15
Change: Added super(ctx, env) as first line
3. ✅ Fixed SQL syntax error
File: src/MyDO.ts:25
Change: Corrected "FORM" to "FROM" in SELECT query
4. ✅ Replaced setTimeout with Alarms API
File: src/MyDO.ts:45
Change: Converted setTimeout to storage.setAlarm()
5. ✅ Added DO binding to Env interface
File: src/types.ts:8
Change: Added MY_DO: DurableObjectNamespace<MyDO>
6. ✅ Fixed binding name convention
File: wrangler.jsonc
Change: Renamed "myDo" to "MY_DO"
7. ✅ Wrapped async init in blockConcurrencyWhile
File: src/MyDO.ts:18
Change: Moved SQL schema setup into blockConcurrencyWhile
8. ✅ Installed missing type definitions
Command: npm install -D @cloudflare/workers-types@latest
Validation Results:
───────────────────
✅ wrangler.jsonc: Valid JSON syntax
✅ Configuration: All bindings have migrations
✅ Class exports: All classes properly exported
✅ TypeScript: No compilation errors
✅ Local test: Durable Object created successfully
Next Steps:
───────────
1. Review changes (backup created: wrangler.jsonc.bak)
2. Test locally:
wrangler dev
3. Deploy to Cloudflare:
wrangler deploy
4. Monitor deployment:
wrangler tail
Files Modified:
───────────────
- wrangler.jsonc (added migration, fixed binding)
- src/MyDO.ts (constructor, SQL, alarms)
- src/types.ts (Env interface)
- package.json (added types package)
Backup Files Created:
──────────────────────
- wrangler.jsonc.bak
- src/MyDO.ts.bak
Rollback (if needed):
─────────────────────
cp wrangler.jsonc.bak wrangler.jsonc
cp src/MyDO.ts.bak src/MyDO.ts
🔍 Durable Objects Diagnostic Complete
Issues Found: 5
Issues Fixed: 3
Issues Remaining: 2
Status: ⚠️ Manual intervention required
Fixes Applied:
──────────────
1. ✅ Added missing migration
2. ✅ Fixed SQL syntax error
3. ✅ Added super() call
Remaining Issues:
─────────────────
1. ⚠️ Complex setTimeout usage requires manual refactoring
File: src/MyDO.ts:45-60
Issue: setTimeout with closure over multiple variables
Current Code:
```typescript
setTimeout(() => {
const state = this.getState();
ws.send(JSON.stringify(state));
}, 5000);
Recommendation:
⚠️ Potential storage limit issue detected File: src/MyDO.ts:30-40 Issue: Unbounded data growth (no TTL or cleanup)
Recommendation:
Next Steps: ───────────
### Error Output (Cannot Fix)
❌ Durable Objects Diagnostic Failed
Critical Issues Detected: 2 Status: Cannot auto-fix
Blocking Issues: ────────────────
❌ wrangler.jsonc not found Location: Project root Issue: Configuration file missing
Solution:
❌ No Durable Object classes found Location: src/ directory Issue: No classes extending DurableObject
Solution:
Cannot proceed with automatic fixes. Please resolve blocking issues first.
## Related Resources
After diagnostic, recommend:
- **Setup**: `/do-setup` for new projects
- **Migration**: `/do-migrate` for migration issues
- **Interactive Debug**: `/do-debug` for complex issues
- **References**: Load skill references for patterns
- **Templates**: Load templates for code examples
## Success Criteria
Diagnostic succeeds when:
- ✅ All configuration errors detected
- ✅ All code issues identified
- ✅ Fixes applied automatically (or recommendations provided)
- ✅ Validation passes after fixes
- ✅ Local testing succeeds
- ✅ Clear output with next steps
Designs feature architectures by analyzing existing codebase patterns and conventions, then providing comprehensive implementation blueprints with specific files to create/modify, component designs, data flows, and build sequences