Skip to content

feat(wasteland): Phase 1 — Wasteland Infrastructure (Issue #1810)#1974

Open
jrf0110 wants to merge 15 commits intowasteland-stagingfrom
convoy/phase-1-wasteland-infrastructure-issue-1/a69010dc/head
Open

feat(wasteland): Phase 1 — Wasteland Infrastructure (Issue #1810)#1974
jrf0110 wants to merge 15 commits intowasteland-stagingfrom
convoy/phase-1-wasteland-infrastructure-issue-1/a69010dc/head

Conversation

@jrf0110
Copy link
Copy Markdown
Contributor

@jrf0110 jrf0110 commented Apr 3, 2026

Summary

Phase 1 Wasteland Infrastructure — all 7 convoy beads completed, reviewed, and rework addressed. This PR lands the full cloudflare-wasteland/ package scaffold and core infrastructure:

  • Scaffolded cloudflare-wasteland/ package with wrangler.jsonc, package.json, tsconfig, worker skeleton
  • Added WastelandContainerDO — per-wasteland Container class with wl CLI env injection
  • Added WastelandDO — metadata storage (wasteland_config, wasteland_credentials, wasteland_members tables), credential CRUD, alarm skeleton
  • Added AES-256-GCM crypto utilities for encrypting DoltHub tokens at rest
  • Added Container Dockerfile and control server for wl CLI operations (browse, claim, done, post, sync, join, status)
  • Wired up Kilo auth middleware and route stubs for Phase 2/3

Verification

  • All 7 convoy beads closed successfully
  • All code reviews passed (refinery approved)
  • All rework feedback addressed and re-reviewed
  • Branch exists on remote with all commits intact

Visual Changes

N/A

Reviewer Notes

This is a convoy landing PR — no code was modified in this PR itself. The branch contains the accumulated work of 7 independently reviewed and approved beads from the Phase 1 convoy (a69010dc). Phases 2-4 build on top of this foundation.

jrf0110 added 9 commits March 31, 2026 23:15
Create the WastelandContainerDO Durable Object modeled after
TownContainerDO. Manages container lifecycle for the wl CLI,
with WASTELAND_API_URL and KILO_API_URL env vars, plus persistent
env var storage for credentials like DOLTHUB_TOKEN.

Also scaffolds cloudflare-wasteland package with:
- worker-configuration.d.ts (Env type with WASTELAND_CONTAINER binding)
- tsconfig.json
- package.json
- pnpm-workspace.yaml entry
…bles, and alarm skeleton

Create the WastelandDO Durable Object at cloudflare-wasteland/src/dos/Wasteland.do.ts
with SQLite tables for configuration, encrypted credentials, and member registry.

Package structure:
- db/tables/ — Zod-backed table definitions (wasteland_config, wasteland_credentials,
  wasteland_members) using getTableFromZodSchema pattern
- dos/wasteland/ — Sub-modules (config.ts, credentials.ts, members.ts) with plain
  functions accepting SqlStorage, per AGENTS.md conventions
- dos/Wasteland.do.ts — DO class with RPC methods, constructor table init via
  blockConcurrencyWhile, and alarm skeleton for periodic sync
- util/ — query.util.ts and table.ts copied from cloudflare-gastown

All sub-modules use the type-safe query() helper, table interpolators for column
references, and Zod Record schemas for result parsing. TypeScript compiles cleanly.
…c/gt/toast/c1453d94' into convoy/phase-1-wasteland-infrastructure-issue-1/a69010dc/head
Add container infrastructure for WastelandContainerDO:
- Dockerfile and Dockerfile.dev based on debian:bookworm-slim with wl CLI and Bun
- Control server (Bun HTTP) with endpoints for all wl operations:
  browse, claim, done, post, sync, join, status, and health
- Mutation serialization via mutex to protect local working copy
- Post-mutation verification to detect no-op mutations
- DOLTHUB_TOKEN header auth on all wl endpoints
- 60s CLI timeout, structured JSON logging, periodic heartbeat
- Zod schema validation on all request bodies and CLI output
…ation tests

Replace WastelandDO stub with full implementation backed by SQLite
storage. Add 42 integration tests covering WastelandDO CRUD lifecycle,
member management, credential storage, connected towns, wanted board
cache, WastelandRegistryDO operations (including countAll with Zod
parse), full lifecycle with registry integration, HTTP health endpoints,
CORS verification, and tRPC authorization. All code uses Zod for IO
boundary validation with no 'as' casts per project coding standards.
…d integration tests

# Conflicts:
#	cloudflare-wasteland/src/dos/WastelandDO.stub.ts
#	cloudflare-wasteland/src/dos/WastelandRegistry.do.ts
WastelandRegistryRecord,
} from '../db/tables/wasteland-registry.table';

const CountResult = z.object({ cnt: z.coerce.number() });
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: Duplicate CountResult declaration blocks compilation

This file already declares CountResult on the next line, so adding a second const here produces a duplicate identifier error and the worker will not build.

/* sql */ `
INSERT OR REPLACE INTO ${wasteland_connected_towns} (
${wasteland_connected_towns.columns.town_id},
${wasteland_connected_towns.columns.town_name},
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: Connected-town rows no longer match the API contract

connectKiloTown still calls stub.connectTown(input.townId, ctx.userId), and RpcConnectedTownOutput still requires wasteland_id and connected_by. Persisting town_name here means we store the caller's user id in this column and return a row that cannot satisfy the tRPC output schema, so connectKiloTown and listConnectedTowns will fail at runtime.

export function createTableWastelandMembers(): string {
return getCreateTableQueryFromTable(wasteland_members, {
member_id: `text primary key`,
user_id: `text not null`,
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: Membership rows can be duplicated for the same user

The router looks members up by user_id (getMember(ctx.userId) and the auto-register path in connectKiloTown), but this schema only keys rows by member_id while addMember() always inserts a new row. The same user can be added multiple times, which makes getMember() ambiguous and exposes duplicate owners/maintainers in listMembers().

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot bot commented Apr 3, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 1
WARNING 1
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

CRITICAL

File Line Issue
cloudflare-wasteland/src/dos/wasteland/connected-towns.ts 34 Connected-town rows now store town_name, but the caller still passes ctx.userId and the unchanged RPC schema still expects wasteland_id and connected_by, so connect/list town RPCs will fail schema validation at runtime.

WARNING

File Line Issue
cloudflare-wasteland/src/db/tables/wasteland-members.table.ts 19 user_id is not unique even though membership lookups are by user_id, so the same user can be inserted multiple times and produce ambiguous member state.
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
cloudflare-wasteland/src/trpc/router.ts 529 connectKiloTown still calls stub.connectTown(input.townId, ctx.userId), which no longer matches the new connected-town storage shape.
cloudflare-wasteland/src/trpc/schemas.ts 63 ConnectedTownOutput still requires wasteland_id and connected_by, but the new DO/table return town_name instead.
cloudflare-wasteland/src/trpc/router.ts 385 updateWastelandConfig updates the per-wasteland DO only; it does not update the registry entry name created at cloudflare-wasteland/src/trpc/router.ts:125, so listWastelands can return stale names.
cloudflare-wasteland/src/trpc/ownership.ts 22 resolveWastelandOwnership still only recognizes direct owners/admins for user-owned wastelands and never checks wasteland_members, so added members cannot use member-scoped procedures like listing members, storing credentials, or browsing the wanted board.
Files Reviewed (10 files)
  • cloudflare-wasteland/src/db/tables/wasteland-members.table.ts - 1 issue
  • cloudflare-wasteland/src/dos/Wasteland.do.ts - 0 issues
  • cloudflare-wasteland/src/dos/WastelandRegistry.do.ts - 0 issues
  • cloudflare-wasteland/src/dos/wasteland/config.ts - 0 issues
  • cloudflare-wasteland/src/dos/wasteland/connected-towns.ts - 1 issue
  • cloudflare-wasteland/src/dos/wasteland/credentials.ts - 0 issues
  • cloudflare-wasteland/src/dos/wasteland/members.ts - 0 issues
  • cloudflare-wasteland/src/trpc/ownership.ts - 0 issues
  • cloudflare-wasteland/src/trpc/router.ts - 0 issues
  • cloudflare-wasteland/src/wasteland.worker.ts - 0 issues

Reviewed by gpt-5.4-20260305 · 238,576 tokens

jrf0110 added 5 commits April 3, 2026 18:35
…c/gt/maple/56ce508b' into convoy/phase-1-wasteland-infrastructure-issue-1/a69010dc/head

# Conflicts:
#	cloudflare-wasteland/package.json
#	cloudflare-wasteland/src/db/tables/wasteland-config.table.ts
#	cloudflare-wasteland/src/db/tables/wasteland-members.table.ts
#	cloudflare-wasteland/tsconfig.json
#	cloudflare-wasteland/worker-configuration.d.ts
#	pnpm-lock.yaml
…c/gt/toast/531855d7' into merge-temp

# Conflicts:
#	cloudflare-wasteland/container/control-server/server.ts
…architecture

Replace WastelandDO.stub.ts with proper Wasteland.do.ts that delegates to
sub-modules per the AGENTS.md conventions. Add connected-towns sub-module,
fix missing getIndexesWastelandMembers export, add trust_level CHECK constraint,
make initializeWasteland/updateConfig/storeCredential return records, add
getMember/updateMember/connectTown/disconnectTown/listConnectedTowns/getWantedBoard/
refreshWantedBoard methods, and switch all imports from stub to Wasteland.do.
/* sql */ `
INSERT OR REPLACE INTO ${wasteland_connected_towns} (
${wasteland_connected_towns.columns.town_id},
${wasteland_connected_towns.columns.town_name},
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: Connected-town rows still do not match the tRPC contract

connectKiloTown still calls this RPC with ctx.userId as the second argument, and ConnectedTownOutput still expects wasteland_id and connected_by. Writing that value into town_name means the DO returns rows that cannot satisfy the schema, so both connectKiloTown and listConnectedTowns will still fail at runtime.

…dDO.stub.ts

- Remove duplicate const CountResult declaration in WastelandRegistry.do.ts (line 10)
  that would cause a SyntaxError at compile/runtime
- Delete WastelandDO.stub.ts which is unused (replaced by Wasteland.do.ts with
  sub-module architecture in commit 603a82a)
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