Skip to content

feat(review-fix): confirm fix sessions before starting them - #8499

Merged
iscekic merged 3 commits into
mainfrom
drain/review-fix-session-confirmation
Oct 24, 2026
Merged

iscekic merged 3 commits into
mainfrom
drain/review-fix-session-confirmation

Conversation

@iscekic

@iscekic iscekic commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Evidence

Evidence: demonstrated — a local dev-stack rerun at this head exercised the confirmation step, an accepted submission that ran the server-side review-comment selection, and the per-actor cap; session rows and Redis counters were read back in the running database and cache.

What changes

  • apps/web/src/app/cloud-agent-fork/review/[reviewId]/route.ts: GET renders the confirmation step for the review, and POST prepares the fix session only for a same-origin submission of that page's form. The session start runs after the review read proves access, after the per-actor session start cap, and after the server-side review-comment selection. Both responses stay on the app origin (relative Location, no-store).
  • New apps/web/src/app/cloud-agent-fork/review/[reviewId]/confirm/page.tsx: the confirmation page. It requires a session (sign-in returns to this page), explains what the session will do, and posts the form to the route.
  • apps/web/src/lib/code-reviews/core/session-start-rate-limit.ts: the Redis fixed-window session start cap extracted from review-md/route.ts. That route keeps its key and limits (review-md-conversion, 30/hour); fix sessions use a review-fix-session bucket with REVIEW_FIX_SESSION_RATE_LIMIT / REVIEW_FIX_SESSION_RATE_WINDOW_SECONDS (30/hour).
  • Tests: route.test.ts covers the confirmation step, the app-origin requirement, the cap (including that it runs only after access is proven and before comment selection), the sign-in callback path, and the selected-comment prompt on both personal and organization starts. confirm/page.test.ts covers the invalid id redirect, the sign-in callback, the form target, and the capped message.

This branch was merged with main, so the fix session uses selectFixReviewCommentsForReview and builds its prompt from the resolved comments exactly as the sibling fix-review flow does.

Verification

Rerun on a fresh work VM at this head (f48527155e): dev stack with Postgres and Redis, nextjs on :3000, the cloud-agent-next worker on :8794, one seeded fake account plus a code review row owned by it, a linked GitHub app integration, and a local stand-in for the provider API the selection reads (installation token, review comments, review threads, collaborator permission). Each request was made over HTTP with a real signed-in session cookie.

Step Observed
Review link, no session 302 -> /cloud-agent-fork/review/<id>/confirm; no session row
Review link, signed in 302 -> the same confirmation path; no session row
Confirmation page, signed in 200, heading Start a fix session, submit button Start fix session, form action /cloud-agent-fork/review/<id>
Confirmation page, no session 307 -> /users/sign_in?callbackPath=%2Fcloud-agent-fork%2Freview%2F<id>%2Fconfirm
Submission with no origin signal 303 -> .../confirm?error=invalid_origin; no session row
Submission with a foreign origin 303 -> .../confirm?error=invalid_origin; no session row
Submission without a session 302 -> /users/sign_in?callbackPath=...; no session row
Account without access to the review 302 -> /code-reviews?error=access_denied; no session row, no counter for the review owner, no provider request
Submission by the review owner from the app origin 303 -> /cloud/chat?sessionId=ses_...; one new session row
Provider requests during that submission installation token, review comments, review threads, collaborator permission — in that order, exactly once each
Prompt forwarded to the worker contains the PR URL, repository, pull request number, branch, the selected comment id and its body; autoInitiate set
Per-actor cap at its limit 303 -> .../confirm?error=rate_limited; no session row and no provider request; the counter advanced once
Capped confirmation page alert text You have started several fix sessions in the last hour. Try again later.
Conversion route, request not originated by the app 302 -> /code-reviews?error=invalid_conversion_request
Conversion route, direct navigation passed the origin gate and its own review-md-conversion counter, which is separate from the fix-session counter
Invalid review id on the route and the page 302 and 307 -> /code-reviews?error=invalid_review_id

Unit checks: pnpm exec jest --runInBand src/app/cloud-agent-fork in apps/web passes (3 suites, 40 tests); the changed files pass the root oxlint config.

No screenshots were published: this VM's agent reads pages as text, so I could not inspect image pixels or metadata before publishing. The rendered text above was read from the live DOM.

Production prerequisites

None. The cap reuses the existing Redis client and adds no environment variable, secret, binding, migration, or external configuration.

Proxy answers

The owner's proxy gave these answers in the owner's place.

  1. Question: Session start gating for the posted review-comment link.
    Answer: Uniform confirmation page (Recommended)
    Confidence: 0.55 · Precedent: Speed and least work: replace old paths instead of keeping them alongside; session ad6a3f589364 "alongside? why not instead?"
  2. Question: Where the confirmation step lives.
    Answer: New in-app page (Recommended)
    Confidence: 0.70 · Precedent: UX and design quality: hold all UI work to the best-in-class standard within the design system; session df491946927a accepted "Improve within the design system"
  3. Question: How the per-actor session cap is shared with the REVIEW.md conversion route.
    Answer: Shared helper, per-flow buckets (Recommended)
    Confidence: 0.60 · Precedent: Engineering conventions: extract shared code into an internal library; session 5d8113f51c48 "extract any common code to an internal library"

The review fix link now opens a confirmation page on the Kilo origin, and the
session is prepared from that page's form submission. The submission's origin is
validated before the review is read and before a session is prepared.

The per-actor session start cap moves out of the REVIEW.md conversion route into
lib/code-reviews/core/session-start-rate-limit, and the fix route applies it
after the review read proves access. Each flow keeps its own bucket; a capped
reader lands back on the confirmation page with an explanation.
@iscekic iscekic added drain Work item from the findings drain janitor:trust Janitor finding: trust boundary hardening labels Oct 21, 2026
@kilo-code-bot

kilo-code-bot Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The three prior suggestions are fixed at HEAD 2a93790: the POST origin check now accepts only Sec-Fetch-Site: same-origin, a rejected submission returns to the confirmation page with ?error=invalid_origin and renders an explanation, and the billing copy now attributes organization reviews to the organization balance. No new issues in the incremental diff.

Assumptions: [INFERENCE] Tests were not executed in this environment; verification relies on the PR's reported jest/typecheck/lint run and on reading the changed lines and their full file context. The invalid_origin message asks the reader to reload, which a client that never sends Origin or Sec-Fetch-Site cannot satisfy, but the page still offers cancellation, so this was not raised as a finding.

Files Reviewed (7 files)
  • apps/web/src/app/cloud-agent-fork/review-md/route.ts
  • apps/web/src/app/cloud-agent-fork/review/[reviewId]/confirm/page.test.ts
  • apps/web/src/app/cloud-agent-fork/review/[reviewId]/confirm/page.tsx
  • apps/web/src/app/cloud-agent-fork/review/[reviewId]/route.test.ts
  • apps/web/src/app/cloud-agent-fork/review/[reviewId]/route.ts
  • apps/web/src/lib/code-reviews/core/constants.ts
  • apps/web/src/lib/code-reviews/core/session-start-rate-limit.ts
Previous Review Summary (commit d561419)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit d561419)

Status: 3 Issues Found | Recommendation: Address before merge

Executive Summary

The confirmation gate, origin check, and per-actor session cap are correctly ordered and access-gated; the remaining findings are hardening and copy accuracy around the new POST origin check and the confirmation page.

Assumptions: [INFERENCE] Tests were not executed in this environment; verification relies on the PR's reported jest/typecheck/lint run. Parallel observation outside this diff: review-md/route.ts still starts a credit-spending session from a plain GET, so the confirmation pattern added here is not yet applied to that sibling flow.

Overview

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

SUGGESTION

File Line Issue
apps/web/src/app/cloud-agent-fork/review/[reviewId]/route.ts 73 POST accepts Sec-Fetch-Site: same-site, which spans sibling subdomains, on a credit-spending mutation
apps/web/src/app/cloud-agent-fork/review/[reviewId]/route.ts 94 Origin rejection bounces back to the confirmation page with no error, so blocked readers get no feedback
apps/web/src/app/cloud-agent-fork/review/[reviewId]/confirm/page.tsx 36 Copy says the session uses "your" credits, but organization reviews spend the organization's balance
Files Reviewed (7 files)
  • apps/web/src/app/cloud-agent-fork/review-md/route.ts - 0 issues
  • apps/web/src/app/cloud-agent-fork/review/[reviewId]/confirm/page.test.ts - 0 issues
  • apps/web/src/app/cloud-agent-fork/review/[reviewId]/confirm/page.tsx - 1 issue
  • apps/web/src/app/cloud-agent-fork/review/[reviewId]/route.test.ts - 0 issues
  • apps/web/src/app/cloud-agent-fork/review/[reviewId]/route.ts - 2 issues
  • apps/web/src/lib/code-reviews/core/constants.ts - 0 issues
  • apps/web/src/lib/code-reviews/core/session-start-rate-limit.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-flash-latest · Input: 38K · Output: 3.4K · Cached: 248.2K

Review guidance: REVIEW.md from base branch main

@iscekic

iscekic commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

bot: The review fix link renders this confirmation page on the local dev stack, and the session starts from its button.

Confirmation page with the Start fix session button

- Accept only `same-origin` from `Sec-Fetch-Site` when `Origin` is absent.
- Explain a rejected submission on the confirmation page instead of returning
  the reader there unchanged.
- Word the credits sentence for organization reviews.
@iscekic

iscekic commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

bot: The confirmation page after the copy update, on the local dev stack.

Confirmation page with the Start fix session button

@iscekic

iscekic commented Oct 21, 2026

Copy link
Copy Markdown
Collaborator Author

bot: The later capture (02) supersedes the earlier screenshot (01): it shows the current confirmation page copy.

@iscekic iscekic added the merge:human Substantive functional risk requires human review. label Oct 21, 2026
@iscekic
iscekic enabled auto-merge October 21, 2026 20:41
@iscekic
iscekic disabled auto-merge October 22, 2026 13:08
@iscekic iscekic added the intent:ok Janitor change confirmed as a real bug fix, not intended behavior label Oct 23, 2026
@iscekic iscekic added merge:blocked:insufficient-e2e Verification does not cover the change needs:prod-action Prod prerequisite (env var, secret, firewall rule, config) needed before merge and removed merge:blocked:insufficient-e2e Verification does not cover the change needs:prod-action Prod prerequisite (env var, secret, firewall rule, config) needed before merge labels Oct 23, 2026
@iscekic

iscekic commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator Author

Changes requested: merge main into the branch. #8223 merged into main and changed apps/web/src/app/cloud-agent-fork/review/[reviewId]/route.ts and its route.test.ts, so both files now conflict. Keep #8223's server-side comment selection, and apply this PR's confirm-then-POST flow on top of it. Re-run the route tests on the merged tree.

@iscekic iscekic added merge:human Substantive functional risk requires human review. and removed merge:human Substantive functional risk requires human review. labels Oct 24, 2026
@iscekic

iscekic commented Oct 24, 2026

Copy link
Copy Markdown
Collaborator Author

bot: Merged main into drain/review-fix-session-confirmation (merge commit f485271). The conflict in apps/web/src/app/cloud-agent-fork/review/[reviewId]/route.ts and its route.test.ts is resolved by keeping the server-side comment selection from #8223 (selectFixReviewCommentsForReview) inside the confirm-then-POST flow: the GET redirects to the confirmation page, the POST enforces the origin signal and the per-actor cap before prepareSession, and the prompt is assembled from the server-selected comments with the omitted count and a nonce.

Route tests rerun on the merged tree (apps/web, jest --runInBand src/app/cloud-agent-fork against a migrated local Postgres): 3 suites, 40 tests pass. CI on the merged head is green.

@iscekic
iscekic added this pull request to the merge queue Oct 24, 2026
Merged via the queue into main with commit bf62dc0 Oct 24, 2026
86 checks passed
@iscekic
iscekic deleted the drain/review-fix-session-confirmation branch October 24, 2026 21:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drain Work item from the findings drain intent:ok Janitor change confirmed as a real bug fix, not intended behavior janitor:trust Janitor finding: trust boundary hardening merge:human Substantive functional risk requires human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants