Skip to content

feat(db): add cli_session_pull_requests side table + migration#2872

Merged
kilo-code-bot[bot] merged 1 commit intoconvoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/headfrom
convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/gt/toast/b7954dba
Apr 28, 2026
Merged

feat(db): add cli_session_pull_requests side table + migration#2872
kilo-code-bot[bot] merged 1 commit intoconvoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/headfrom
convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/gt/toast/b7954dba

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot Bot commented Apr 28, 2026

Summary

  • Adds new cli_session_pull_requests side table (session_id PK, FK to cli_sessions_v2.session_id ON DELETE CASCADE) with columns for PR URL, number, state, title, head SHA, and sync timestamps.
  • Adds non-unique indexes on pr_state and pr_number for future query patterns.
  • Adds two additive indexes to cli_sessions_v2: a (git_url, git_branch) index for webhook lookup (bead 2) and a unique index on session_id needed to support the FK target.
  • Generated migration 0106_gorgeous_iron_patriot.sql via drizzle-kit. Statements were reordered so the unique index is created before the FK references it (PostgreSQL requires the referenced column to be unique when the FK is added).

Bead 0 of 5 in the 'Associated PR for cloud-agent-next session' convoy. Schema + migration only; consumers land in later beads.

Verification

  • Ran POSTGRES_URL=... pnpm drizzle generate — produces no further diff after the edits.
  • pnpm --filter @kilocode/db typecheck passes.
  • pnpm --filter web typecheck passes.
  • No container runtime available in this environment, so the migration SQL was inspected manually rather than applied; the CREATE UNIQUE INDEX on cli_sessions_v2.session_id is emitted before the ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY so the FK target is present when PostgreSQL creates the constraint.

Visual Changes

N/A — schema-only change.

Reviewer Notes

  • FK target requirement: cli_sessions_v2 has a composite PK (session_id, kilo_user_id), so session_id alone is not unique out of the box. To satisfy the bead's session_id references cli_sessions_v2(session_id) spec, a unique index UQ_cli_sessions_v2_session_id is added. If there are existing rows where the same session_id is shared across users, this migration will fail — worth a quick spot check before merge, but the practice in the codebase (e.g. code-reviews-router.ts looks up kilo_user_id from session_id alone) already implies uniqueness.
  • Migration reorder: drizzle-kit emitted the CREATE INDEX statement after the FK. I reordered the generated SQL so the unique index comes first; the snapshot and journal are unchanged. If the team prefers strict codegen-only migrations, the alternative is to split this into two migrations, but a single reordered file keeps the feature atomic.
  • No runtime code changes anywhere; downstream beads (2, 3, 4) will consume this table.

…tracking

Adds a new side table to store GitHub PR metadata associated with
cloud-agent-next sessions. Keeping this separate from cli_sessions_v2
avoids adding 6 sparse nullable columns to an already-wide table and
allows webhook-driven PR writes to evolve independently.

Also adds indexes on cli_sessions_v2 needed by upcoming beads:
- (git_url, git_branch) for webhook session lookup
- unique on session_id to support the FK from the new side table

Bead b7954dba — convoy dbccdbdf.
@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot Bot commented Apr 28, 2026

Refinery code review passed.

Checked:

  • Migration ordering: CREATE UNIQUE INDEX on cli_sessions_v2.session_id is correctly emitted before the FK constraint that references it. PG would otherwise reject the FK.
  • Schema consistency: new table uses the repo's standard $onUpdateFn(() => sql\now()`)idiom, nullable/NOT-NULL choices match the bead spec, and the cascade delete lines up withcli_sessions_v2being retained (not deleted) on user soft-delete — so nosoftDeleteUser` update is needed.
  • No PII added — PR title/url/sha are public GitHub data, not user PII. GDPR rule N/A.
  • Typecheck and drizzle generate idempotence per the PR description.

One real caveat (author already flagged this in Reviewer Notes and I agree with the risk framing): the new UQ_cli_sessions_v2_session_id unique index narrows the effective data invariant. cli_sessions_v2 has composite PK (session_id, kilo_user_id) and session-ingest/src/routes/api.ts:46-48 explicitly does onConflictDoNothing({ target: [session_id, kilo_user_id] }) — meaning two different users submitting the same session_id is currently allowed. Format is ses_ + 26 chars so collisions are astronomically unlikely in practice, but the migration will fail if prod has any such row pair. Worth a quick SELECT session_id, COUNT(*) FROM cli_sessions_v2 GROUP BY session_id HAVING COUNT(*) > 1 LIMIT 1 before merge to confirm zero collisions.

A strictly-cleaner alternative would have been a composite FK (session_id, kilo_user_id) → cli_sessions_v2(session_id, kilo_user_id), at the cost of denormalizing kilo_user_id into the side table. The chosen approach is reasonable for a 1:1 side table and matches the bead's literal spec; just wanted to surface the tradeoff.

Migration SQL was manually reordered (drizzle-kit emitted FK before index). This is noted by the author and is required for correctness; AGENTS.md's 'never hand-edit migration SQL' rule is in tension with 'generated migration fails' reality here — the reorder is defensible but a team lead may want to bless this precedent.

Comment thread packages/db/src/migrations/0106_gorgeous_iron_patriot.sql
@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot Bot commented Apr 28, 2026

Code Review Summary

Status: 1 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
packages/db/src/migrations/0106_gorgeous_iron_patriot.sql 1 Builds indexes on existing cli_sessions_v2 without CONCURRENTLY, which can block writes during deploy.
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 (2 files)
  • packages/db/src/migrations/0106_gorgeous_iron_patriot.sql - 1 issue
  • packages/db/src/schema.ts - 0 issues

Reviewed by gpt-5.5-2026-04-23 · 831,878 tokens

@kilo-code-bot kilo-code-bot Bot merged commit 25bf277 into convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head Apr 28, 2026
2 checks passed
@kilo-code-bot kilo-code-bot Bot deleted the convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/gt/toast/b7954dba branch April 28, 2026 21:32
kilo-code-bot Bot added a commit that referenced this pull request Apr 29, 2026
feat(db): add cli_session_pull_requests side table for associated PR tracking

Adds a new side table to store GitHub PR metadata associated with
cloud-agent-next sessions. Keeping this separate from cli_sessions_v2
avoids adding 6 sparse nullable columns to an already-wide table and
allows webhook-driven PR writes to evolve independently.

Also adds indexes on cli_sessions_v2 needed by upcoming beads:
- (git_url, git_branch) for webhook session lookup
- unique on session_id to support the FK from the new side table

Bead b7954dba — convoy dbccdbdf.

Co-authored-by: Toast (gastown) <Toast@gastown.local>
kilo-code-bot Bot added a commit that referenced this pull request Apr 30, 2026
feat(db): add cli_session_pull_requests side table for associated PR tracking

Adds a new side table to store GitHub PR metadata associated with
cloud-agent-next sessions. Keeping this separate from cli_sessions_v2
avoids adding 6 sparse nullable columns to an already-wide table and
allows webhook-driven PR writes to evolve independently.

Also adds indexes on cli_sessions_v2 needed by upcoming beads:
- (git_url, git_branch) for webhook session lookup
- unique on session_id to support the FK from the new side table

Bead b7954dba — convoy dbccdbdf.

Co-authored-by: Toast (gastown) <Toast@gastown.local>
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.

0 participants