Skip to content

Kiloclaw tracked image tag#2942

Merged
St0rmz1 merged 4 commits intomainfrom
kiloclaw-tracked-image-tag
Apr 30, 2026
Merged

Kiloclaw tracked image tag#2942
St0rmz1 merged 4 commits intomainfrom
kiloclaw-tracked-image-tag

Conversation

@St0rmz1
Copy link
Copy Markdown
Contributor

@St0rmz1 St0rmz1 commented Apr 29, 2026

Summary

Adds a nullable tracked_image_tag column to kiloclaw_instances. The Durable Object alarm reconciler writes the column on each tick. This is the schema groundwork for an upcoming admin tool that filters instance populations by current running version, planned as Phase 1.5.2 in plans/kiloclaw-forced-upgrades.md.

The Durable Object remains the source of truth for the running image tag. The Postgres column is a denormalized read cache so admin tooling can query instances by version using SQL. The alarm write happens via ctx.waitUntil so a Postgres failure cannot block reconciliation. The UPDATE uses IS DISTINCT FROM in the WHERE clause, which makes Postgres skip the row entirely when the value already matches. That keeps vacuum pressure low on idle fleets.

After deploy, the active fleet populates within roughly 30 minutes worst case (the longest alarm interval). New rows populate on first alarm.

This change also updates services/kiloclaw/AGENTS.md to acknowledge that the Worker writes Postgres in two narrow exception paths: destroy finalization (already in place) and this denormalized operational metadata column. The previous invariant text claimed Next.js was the sole writer, which had not been accurate since the destroy path landed.

Verification

  • Generated the migration via pnpm drizzle generate and verified it is additive only (nullable column plus a partial index).
  • Applied locally via pnpm drizzle migrate.
  • Restarted the local kiloclaw Worker, triggered a redeploy on the running development instance, waited for the next alarm tick, and confirmed SELECT tracked_image_tag FROM kiloclaw_instances returned the expected value.
  • pnpm run format:check passes.
  • pnpm run lint and pnpm run typecheck show no new errors in touched files. The errors that remain are in unrelated areas (services/gastown/container/* for lint, apps/mobile and services/kiloclaw/src/northflank for typecheck) and were already failing on main.
  • packages/db/src/schema.test.ts passes (6 of 6).

Visual Changes

N/A

Reviewer Notes

Schema change is additive. After this lands, the active fleet self populates tracked_image_tag over the next alarm cycle (5 minutes for running instances, up to 30 minutes for idle ones). The bulk version change UI consumes this column in a subsequent PR (Phase 1.5.2 in plans/kiloclaw-forced-upgrades.md).

@@ -0,0 +1,2 @@
ALTER TABLE "kiloclaw_instances" ADD COLUMN "tracked_image_tag" text;--> statement-breakpoint
CREATE INDEX "IDX_kiloclaw_instances_tracked_image_tag" ON "kiloclaw_instances" USING btree ("tracked_image_tag") WHERE "kiloclaw_instances"."destroyed_at" is null; No newline at end of file
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: Build this index concurrently

kiloclaw_instances is already populated, and a plain CREATE INDEX takes a write-blocking lock until the index build finishes. Use a concurrent index build (or another safe migration path) so instance lifecycle writes are not blocked during deployment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Based on my tests, index creation took less than 1 second. Only 1 table is locked. Requests are queued. I feel like this is not a huge concern.

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.

also relatively speaking a pretty small table. we'll have less than 75k record in it.

@kilo-code-bot
Copy link
Copy Markdown
Contributor

kilo-code-bot Bot commented Apr 29, 2026

Code Review Summary

Status: 1 Issue Found | Recommendation: Address before merge

Overview

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

WARNING

File Line Issue
packages/db/src/migrations/0107_classy_ultimo.sql 2 CREATE INDEX on populated kiloclaw_instances should use a non-blocking migration path such as CONCURRENTLY.
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
N/A N/A N/A
Files Reviewed (9 files)
  • packages/db/src/migrations/0107_classy_ultimo.sql - 1 issue
  • packages/db/src/migrations/meta/0107_snapshot.json - 0 issues
  • packages/db/src/migrations/meta/_journal.json - 0 issues
  • packages/db/src/schema.ts - 0 issues
  • services/kiloclaw/AGENTS.md - 0 issues
  • services/kiloclaw/src/db/index.ts - 0 issues
  • services/kiloclaw/src/durable-objects/kiloclaw-instance.test.ts - 0 issues
  • services/kiloclaw/src/durable-objects/kiloclaw-instance/index.ts - 0 issues
  • services/kiloclaw/src/durable-objects/kiloclaw-instance/postgres.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by gpt-5.5-2026-04-23 · 1,663,022 tokens

…e-tag

Resolves conflict in services/kiloclaw/src/durable-objects/kiloclaw-instance/index.ts:
both branches added imports near each other (this branch: syncTrackedImageTagToPostgresHelper
from ./postgres; main: lifecycle-push imports from PR #2915). Took both.
Test file auto-merged.
@St0rmz1 St0rmz1 merged commit 3a01549 into main Apr 30, 2026
34 checks passed
@St0rmz1 St0rmz1 deleted the kiloclaw-tracked-image-tag branch April 30, 2026 14:52
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.

2 participants