Skip to content

[Gastown] Phase 2: Town config, integrations, multi-polecat, refinery, molecules, convoys, escalations#389

Merged
jrf0110 merged 3 commits into204-gt-prop-dfrom
phase-2
Feb 20, 2026
Merged

[Gastown] Phase 2: Town config, integrations, multi-polecat, refinery, molecules, convoys, escalations#389
jrf0110 merged 3 commits into204-gt-prop-dfrom
phase-2

Conversation

@jrf0110
Copy link
Copy Markdown
Contributor

@jrf0110 jrf0110 commented Feb 19, 2026

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: TownConfig type 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: CreateRigDialog now uses RepositoryCombobox to pick repos from connected GitHub/GitLab integrations (with manual URL fallback). platform_integration_id stored 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. New refinery-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_current and gt_mol_advance plugin 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: critical severity added. Auto-re-escalation bumps severity after 4h unacknowledged (up to 3 times), notifies Mayor. Acknowledge flow and list/filter endpoints.

Bug Fixes

  • Git push auth: Configures git credential-store in agent worktrees so polecats can push to remotes using tokens from town config
  • Settings link: Added to town overview header

New Files

  • cloudflare-gastown/src/handlers/town-config.handler.ts
  • cloudflare-gastown/src/handlers/rig-molecules.handler.ts
  • cloudflare-gastown/src/handlers/town-convoys.handler.ts
  • cloudflare-gastown/src/handlers/town-escalations.handler.ts
  • cloudflare-gastown/src/prompts/refinery-system.prompt.ts
  • src/app/(app)/gastown/[townId]/settings/page.tsx
  • src/app/(app)/gastown/[townId]/settings/TownSettingsPageClient.tsx

Closes #385, #386, #216, #218, #219, #220, #221

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Feb 19, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
cloudflare-gastown/src/dos/GastownUser.do.ts 144 Missing ALTER TABLE ADD COLUMN migration for platform_integration_id — INSERT will fail on existing DOs

WARNING

File Line Issue
cloudflare-gastown/src/db/tables/town-escalations.table.ts 28 CHECK constraint change won't apply to existing DOs — re-escalation to 'critical' will fail
Previously Reported Issues (addressed in follow-up commits)

The following issues were reported in earlier review rounds and have been addressed:

File Status Issue
cloudflare-gastown/src/dos/Rig.do.ts ✅ Fixed (ec087f0) buildRefinerySystemPrompt result not passed to container
src/app/(app)/gastown/[townId]/settings/TownSettingsPageClient.tsx ✅ Fixed (ec087f0) Masked env var values overwriting secrets on save
cloudflare-gastown/src/dos/Town.do.ts ✅ Fixed (ec087f0) Re-escalation fires all 3 bumps in rapid succession
cloudflare-gastown/src/dos/Rig.do.ts ✅ Fixed (ec087f0) countAgentsByRole counts dead/failed agents toward cap
cloudflare-gastown/src/dos/Rig.do.ts ✅ Fixed (bf5fca4) Missing GITLAB_INSTANCE_URL env var mapping in startMergeInContainer
src/components/gastown/CreateRigDialog.tsx ✅ Fixed (bf5fca4) resolveGitUrl hardcodes gitlab.com
cloudflare-gastown/container/src/agent-runner.ts ✅ Fixed (bf5fca4) Credential file written with default permissions
src/routers/gastown-router.ts ✅ Fixed (e897e2b) Unsafe as cast bypasses type safety
cloudflare-gastown/src/dos/Town.do.ts ✅ Fixed (e897e2b) Env vars merge-only semantics (can't delete)
cloudflare-gastown/container/src/agent-runner.ts ✅ Fixed (e897e2b) .git-credentials inside worktree
cloudflare-gastown/src/gastown.worker.ts ✅ Fixed (e897e2b) Internal endpoint returns raw tokens
cloudflare-gastown/container/src/kilo-server.ts ✅ Fixed Config file written with mode: 0o600
cloudflare-gastown/container/src/agent-runner.ts ✅ Fixed Unused chmod import removed
Files Reviewed (38 files)
  • cloudflare-deploy-infra/dispatcher/worker-configuration.d.ts - 0 issues (formatting only)
  • cloudflare-gastown/container/Dockerfile - 0 issues
  • cloudflare-gastown/container/bun.lock - skipped (generated)
  • cloudflare-gastown/container/package.json - 0 issues
  • cloudflare-gastown/container/plugin/client.ts - 0 issues
  • cloudflare-gastown/container/plugin/index.ts - 0 issues
  • cloudflare-gastown/container/plugin/mayor-tools.ts - 0 issues
  • cloudflare-gastown/container/plugin/package.json - 0 issues
  • cloudflare-gastown/container/plugin/tools.test.ts - 0 issues
  • cloudflare-gastown/container/plugin/tools.ts - 0 issues
  • cloudflare-gastown/container/src/agent-runner.ts - 0 issues (previously reported issues fixed)
  • cloudflare-gastown/container/src/control-server.ts - 0 issues
  • cloudflare-gastown/container/src/git-manager.ts - 0 issues
  • cloudflare-gastown/container/src/kilo-server.ts - 0 issues (previously reported issue fixed)
  • cloudflare-gastown/container/src/process-manager.ts - 0 issues
  • cloudflare-gastown/src/db/tables/town-escalations.table.ts - 1 issue
  • cloudflare-gastown/src/db/tables/user-rigs.table.ts - 0 issues
  • cloudflare-gastown/src/dos/GastownUser.do.ts - 1 issue
  • cloudflare-gastown/src/dos/Mayor.do.ts - 0 issues
  • cloudflare-gastown/src/dos/Rig.do.ts - 0 issues (previously reported issues fixed)
  • cloudflare-gastown/src/dos/Town.do.ts - 0 issues (previously reported issues fixed)
  • cloudflare-gastown/src/gastown.worker.ts - 0 issues
  • cloudflare-gastown/src/handlers/rig-molecules.handler.ts - 0 issues
  • cloudflare-gastown/src/handlers/town-config.handler.ts - 0 issues
  • cloudflare-gastown/src/handlers/town-convoys.handler.ts - 0 issues
  • cloudflare-gastown/src/handlers/town-escalations.handler.ts - 0 issues
  • cloudflare-gastown/src/handlers/towns.handler.ts - 0 issues
  • cloudflare-gastown/src/prompts/refinery-system.prompt.ts - 0 issues
  • cloudflare-gastown/src/types.ts - 0 issues
  • cloudflare-gastown/worker-configuration.d.ts - skipped (generated)
  • plans/gastown-cloud-proposal-d.md - 0 issues
  • src/app/(app)/gastown/[townId]/TownOverviewPageClient.tsx - 0 issues
  • src/app/(app)/gastown/[townId]/rigs/[rigId]/RigDetailPageClient.tsx - 0 issues
  • src/app/(app)/gastown/[townId]/settings/TownSettingsPageClient.tsx - 0 issues (previously reported issue fixed)
  • src/app/(app)/gastown/[townId]/settings/page.tsx - 0 issues
  • src/components/gastown/CreateRigDialog.tsx - 0 issues (previously reported issue fixed)
  • src/lib/gastown/gastown-client.ts - 0 issues
  • src/routers/gastown-router.ts - 0 issues (previously reported issue fixed)

Fix these issues in Kilo Cloud

…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},
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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'))`,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[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:

  1. Drop and recreate the table (data loss unless migrated)
  2. Use PRAGMA writable_schema (fragile)
  3. Remove the CHECK constraint from the schema entirely and rely on Zod validation at the application layer (simplest, since the Zod EscalationSeverity enum already validates)

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