[Gastown] Phase 2: Town config, integrations, multi-polecat, refinery, molecules, convoys, escalations#389
Conversation
Code Review SummaryStatus: 2 Issues Found | Recommendation: Address before merge Overview
Issue Details (click to expand)CRITICAL
WARNING
Previously Reported Issues (addressed in follow-up commits)The following issues were reported in earlier review rounds and have been addressed:
Files Reviewed (38 files)
|
411c167 to
f99bbef
Compare
…escalation timing, polecat cap - Pass refinery system prompt via systemPromptOverride instead of discarding it and falling back to the generic systemPromptForRole - Preserve masked env var values on save: server-side check replaces ****-prefixed values with the stored original instead of overwriting - Fix re-escalation timing: each bump now requires (N+1) * threshold age, so bumps are spaced 4h apart instead of all firing in ~9min - countAgentsByRole now excludes dead/failed agents so the polecat cap isn't permanently exhausted by terminated polecats
| ${user_rigs.columns.name}, | ||
| ${user_rigs.columns.git_url}, | ||
| ${user_rigs.columns.default_branch}, | ||
| ${user_rigs.columns.platform_integration_id}, |
There was a problem hiding this comment.
[CRITICAL]: Missing ALTER TABLE ADD COLUMN migration for platform_integration_id
initializeDatabase() only runs CREATE TABLE IF NOT EXISTS, which is a no-op for existing DOs that already have the user_rigs table. The new platform_integration_id column won't exist in those tables, so this INSERT will fail with a SQLite error (table user_rigs has no column named platform_integration_id) when an existing user tries to create a rig.
Add a migration step in initializeDatabase() after the CREATE TABLE:
// Migration: add platform_integration_id column for existing tables
try {
query(this.sql, `ALTER TABLE "user_rigs" ADD COLUMN "platform_integration_id" text`, []);
} catch {
// Column already exists — ignore
}| source_rig_id: `text not null`, | ||
| source_agent_id: `text`, | ||
| severity: `text not null check(severity in ('low', 'medium', 'high'))`, | ||
| severity: `text not null check(severity in ('low', 'medium', 'high', 'critical'))`, |
There was a problem hiding this comment.
[WARNING]: CHECK constraint change won't apply to existing DOs — re-escalation to 'critical' will fail
The CREATE TABLE IF NOT EXISTS won't update the CHECK constraint on existing Town DO tables. The old constraint check(severity in ('low', 'medium', 'high')) will reject 'critical' values. Since Town.do.ts now bumps severity to 'critical' via SEVERITY_ORDER = ['low', 'medium', 'high', 'critical'], the UPDATE will fail with a CHECK constraint violation on existing DOs.
SQLite doesn't support ALTER TABLE ... ALTER COLUMN to change CHECK constraints. Options:
- Drop and recreate the table (data loss unless migrated)
- Use
PRAGMA writable_schema(fragile) - Remove the CHECK constraint from the schema entirely and rely on Zod validation at the application layer (simplest, since the Zod
EscalationSeverityenum already validates)
Summary
Implements all 7 Phase 2 issues from #204 in a single branch.
Issues Addressed
[Gastown] PR 10.5: Town Configuration — Environment Variables & Settings #385 — Town Configuration:
TownConfigtype with env vars, git auth tokens, default model, max polecats, refinery gates. Settings page at/gastown/[townId]/settings. Config inheritance flows through Rig DO dispatch path into agent env vars.[Gastown] PR 10.6: Integrations-Based Repo Connection #386 — Integrations-Based Repo Connection:
CreateRigDialognow usesRepositoryComboboxto pick repos from connected GitHub/GitLab integrations (with manual URL fallback).platform_integration_idstored on rigs.[Gastown] PR 10: Multiple Polecats per Rig #216 — Multiple Polecats per Rig: 20-name pool (Toast, Maple, Birch, Shadow, Copper...), configurable concurrency cap (default 5), branch isolation with bead ID prefix (
gt/toast/abc12345). Dashboard auto-refresh on agents (5s) and beads (8s).[Gastown] PR 12: Refinery Agent #218 — Refinery Agent: AI-powered merge review with quality gate execution, code review, and rework request flow via
gt_mail_send. Falls back to deterministic merge when no gates configured. Newrefinery-system.prompt.ts.[Gastown] PR 13: Molecule/Formula System #219 — Molecule/Formula System: Multi-step durable workflows.
createMolecule(),getMoleculeCurrentStep(),advanceMoleculeStep()in Rig DO.gt_mol_currentandgt_mol_advanceplugin tools. Auto-completion on final step.[Gastown] PR 14: Convoy Lifecycle #220 — Convoy Lifecycle: HTTP handlers for convoy CRUD. Rig DO notifies Town DO when a convoy-tracked bead closes, enabling automatic landing detection.
[Gastown] PR 15: Escalation System #221 — Escalation System:
criticalseverity added. Auto-re-escalation bumps severity after 4h unacknowledged (up to 3 times), notifies Mayor. Acknowledge flow and list/filter endpoints.Bug Fixes
git credential-storein agent worktrees so polecats can push to remotes using tokens from town configNew Files
cloudflare-gastown/src/handlers/town-config.handler.tscloudflare-gastown/src/handlers/rig-molecules.handler.tscloudflare-gastown/src/handlers/town-convoys.handler.tscloudflare-gastown/src/handlers/town-escalations.handler.tscloudflare-gastown/src/prompts/refinery-system.prompt.tssrc/app/(app)/gastown/[townId]/settings/page.tsxsrc/app/(app)/gastown/[townId]/settings/TownSettingsPageClient.tsxCloses #385, #386, #216, #218, #219, #220, #221