Skip to content

feat(cloud-agent): PR tracking for cloud-agent sessions#2903

Open
kilo-code-bot[bot] wants to merge 6 commits intomainfrom
convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head
Open

feat(cloud-agent): PR tracking for cloud-agent sessions#2903
kilo-code-bot[bot] wants to merge 6 commits intomainfrom
convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

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

Summary

Adds infrastructure to associate a GitHub pull request with a cloud-agent-next CLI session.

  • New cli_session_pull_requests side table (PK = session_id, FK → cli_sessions_v2.session_id with ON DELETE CASCADE) storing PR number, url, state, title, head sha, and last-synced timestamp.
  • Required unique index UQ_cli_sessions_v2_session_id on cli_sessions_v2.session_id so the FK has a unique target (the base table uses a composite PK (session_id, kilo_user_id)).
  • New composite index on (git_url, git_branch) to support branch → session lookups.
  • New fetchPullRequestForBranch helper in the GitHub adapter that looks up the most relevant PR for a (owner, repo, branch) triple via an installation token. Prefers open PRs, maps merged_at"merged" state, returns null on 404, and throws a dedicated GitHubRateLimitError (carrying resetAt) for rate/secondary-rate-limit responses while passing through genuine 403 permission failures unchanged.
  • Mock adapter in apps/web/src/tests/setup/__mocks__/ updated to mirror the new export surface.

Verification

  • verified locally

Visual Changes

Screenshot 2026-05-06 at 22 52 17

@kilo-code-bot kilo-code-bot Bot force-pushed the convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head branch from 3e32e34 to cb82fe9 Compare April 29, 2026 14:07
Comment thread packages/db/src/migrations/0109_rare_vin_gonzales.sql Outdated
Comment thread packages/db/src/migrations/0107_dashing_mockingbird.sql Outdated
@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot Bot commented Apr 29, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (6 files)
  • apps/web/src/components/cloud-agent-next/hooks/useSidebarSessions.ts
  • apps/web/src/components/cloud-agent-next/utils/github-pr-link.ts
  • apps/web/src/lib/integrations/platforms/github/batch-review-decisions.ts
  • apps/web/src/lib/integrations/platforms/github/batch-review-decisions.test.ts
  • apps/web/src/routers/cli-sessions-v2-router.test.ts
  • apps/web/src/routers/cli-sessions-v2-router.ts

Reviewed by gpt-5.5-2026-04-23 · 15,408,229 tokens

Comment thread apps/web/src/routers/cli-sessions-v2-router.ts
kilo-code-bot Bot pushed a commit that referenced this pull request Apr 29, 2026
- Add associatedPr to mobile FetchedSessionData so mobile-session-manager
  matches the shared type definition. This unblocks the CI typecheck
  failure on apps/mobile.

- refreshAssociatedPullRequest: move ensureOrganizationAccess BEFORE
  the throttle short-circuit for org-scoped sessions. Previously a
  removed org member with a stale cli_sessions_v2 row could receive
  cached PR metadata via the throttle path without a current
  membership check. Adds a regression test covering the fresh-sentinel
  case where the throttle previously would have bypassed the check.

- upsertCliSessionPullRequestsFromWebhook: introduce
  WebhookInstallationOwner and require the caller (webhook router) to
  pass the integration owner. The session SELECT now constrains by
  organization_id OR kilo_user_id so a webhook from one tenant's
  installation cannot upsert PR metadata onto a session owned by
  another tenant that happens to share the same (git_url, git_branch).
  Adds cross-tenant isolation tests for both org and user ownership,
  including the slow-path normalization branch.
kilo-code-bot Bot pushed a commit that referenced this pull request Apr 30, 2026
- Add associatedPr to mobile FetchedSessionData so mobile-session-manager
  matches the shared type definition. This unblocks the CI typecheck
  failure on apps/mobile.

- refreshAssociatedPullRequest: move ensureOrganizationAccess BEFORE
  the throttle short-circuit for org-scoped sessions. Previously a
  removed org member with a stale cli_sessions_v2 row could receive
  cached PR metadata via the throttle path without a current
  membership check. Adds a regression test covering the fresh-sentinel
  case where the throttle previously would have bypassed the check.

- upsertCliSessionPullRequestsFromWebhook: introduce
  WebhookInstallationOwner and require the caller (webhook router) to
  pass the integration owner. The session SELECT now constrains by
  organization_id OR kilo_user_id so a webhook from one tenant's
  installation cannot upsert PR metadata onto a session owned by
  another tenant that happens to share the same (git_url, git_branch).
  Adds cross-tenant isolation tests for both org and user ownership,
  including the slow-path normalization branch.
@kilo-code-bot kilo-code-bot Bot force-pushed the convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head branch from 124c0b4 to 084f755 Compare April 30, 2026 19:12
@eshurakov eshurakov force-pushed the convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head branch 3 times, most recently from f317c03 to 969f7c8 Compare May 5, 2026 14:17
Comment thread packages/db/src/migrations/0110_stormy_marauders.sql Outdated
Comment thread services/session-ingest/src/queue-consumer.ts
@eshurakov eshurakov force-pushed the convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head branch 2 times, most recently from 4a65ead to 2785dfc Compare May 6, 2026 19:46
Comment thread apps/web/src/routers/cli-sessions-v2-router.ts
@eshurakov eshurakov changed the title feat(cloud-agent): associated PR tracking for cloud-agent-next sessions feat(cloud-agent): PR tracking for cloud-agent sessions May 6, 2026
Comment thread apps/web/src/components/cloud-agent-next/hooks/useSidebarSessions.ts Outdated
Comment thread apps/web/src/components/cloud-agent-next/utils/github-pr-link.ts Outdated
Comment thread apps/web/src/routers/cli-sessions-v2-router.ts
Comment thread apps/web/src/lib/integrations/platforms/github/adapter.ts
@alex-alecu
Copy link
Copy Markdown
Contributor

@eshurakov please check this thread Kilo-Org/kilocode#9418 (comment)

Do you think we should re-use some logic from backend or that it's better to have it separate?

@eshurakov eshurakov force-pushed the convoy/associated-pr-for-cloud-agent-next-sessi/dbccdbdf/head branch from 5f882d2 to 2d23c9c Compare May 7, 2026 08:07
Comment thread apps/web/src/lib/integrations/platforms/github/webhook-handler.ts
…tched query

Webhooks now flag review_decision_pending=true instead of fetching the
GraphQL reviewDecision inline. The next sidebar list call kicks off a
background batch that claims pending rows, fetches all decisions in one
aliased GraphQL request, and writes results back.
Comment thread apps/web/src/routers/cli-sessions-v2-router.ts Outdated
eshurakov added 3 commits May 7, 2026 13:10
- Update fetch-pull-request-review-decision.test.ts mock to match the
  batched aliased GraphQL query format (`data.data.pr0`) after the
  refactor to `fetchBatchedReviewDecisions`. Fixes the failing CI test.
- Re-verify org membership in `getWithRuntimeState` before returning
  cached PR metadata. A stale `cli_sessions_v2` row with a matching
  `kilo_user_id` is not proof of current org access; removed members
  must not receive cached PR metadata. Mirrors the check already
  present in `refreshAssociatedPullRequest`.
When the refresh path persists a sentinel row because GitHub returned no
PR for a branch, the old code set `review_decision_pending = true`
unconditionally. The batch review-decision worker filters out rows
without `pr_number` and never clears the pending flag, so it would
re-claim the same sentinel every two minutes forever.

Only mark pending when there is actually a PR whose review decision we
still need to fetch.
…s in flight

Expose review_decision_pending on associatedPr so the sidebar list query
can poll every 5s while any row is awaiting an async review decision
fetch, then stop once the batch flushes. Also abandon claimed rows in
the batch worker when there is no GitHub integration or no actionable
PR, so the pending flag can never hang forever and force the client to
poll indefinitely.
@eshurakov
Copy link
Copy Markdown
Contributor

@alex-alecu By reuse you mean the cli and agent manager would get the status from the backend? Or to reuse the actual code?

Backend code is quite different in this case as we rely mostly on webhooks and process (for now) only cloud agent sessions. We're also limited by integration added to the kilo with only repositories that user picked.

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.

3 participants