feat: ao session claim-pr + spawn --claim-pr wiring#101
Conversation
Greptile SummaryThis PR wires up
Confidence Score: 4/5Safe to merge with awareness of one CDC correctness issue in the PR takeover path. During a PR re-claim (takeover), ClaimPRForSession ON CONFLICT DO UPDATE SET only updates session_id, review_decision, and updated_at. If review_decision changed, the pr_cdc_update trigger fires immediately with stale pr_state/ci_state/mergeability, and the correcting event from the subsequent UpsertPR shares the same updated_at. CDC consumers that deduplicate on URL+timestamp could retain the stale snapshot. backend/internal/storage/sqlite/queries/pr.sql and its generated counterpart backend/internal/storage/sqlite/gen/pr.sql.go — ClaimPRForSession ON CONFLICT clause needs pr_state, ci_state, and mergeability added to its SET list. Important Files Changed
Sequence DiagramsequenceDiagram
participant CLI
participant HTTP as HTTP /sessions/{id}/pr/claim
participant Svc as session.Service.ClaimPR
participant SCM as GitHub SCM
participant Store as SQLite Store (ClaimPR tx)
participant CDC as change_log (triggers)
CLI->>HTTP: "POST pr/claim {pr, allowTakeover}"
HTTP->>Svc: ClaimPR(id, ref, opts)
Svc->>Svc: normalizePRRef / requireSameGitHubRepo
Svc->>SCM: FetchPullRequests([ref])
SCM-->>Svc: SCMObservation
Svc->>SCM: FetchReviewThreads(ref)
SCM-->>Svc: review threads
Svc->>Store: ClaimPR(pr, checks, threads, comments, reviewMode, allowTakeover)
Store->>Store: GetPRClaimAndOwner
alt "PR owned by active session and allowTakeover=false"
Store-->>Svc: PRClaimedByActiveSessionError
Svc-->>HTTP: 409 PR_CLAIMED_BY_ACTIVE_SESSION
else
Store->>Store: ClaimPRForSession UPSERT
Store->>CDC: pr_session_cdc_update fires pr_session_changed
Store->>Store: writePRRows UpsertPR + checks + threads
Store->>CDC: pr_cdc_update fires pr_updated
Store-->>Svc: ClaimOutcome
Svc-->>HTTP: ClaimPRResult
HTTP-->>CLI: 200 ClaimPRResponse
end
Reviews (4): Last reviewed commit: "fix: align PR claim branch with latest m..." | Re-trigger Greptile |
125997f to
768fdf1
Compare
|
Stale
Fix: add Once this PR lands |
|
Orphan session on
Two options, leaning toward (a): (a) CLI-side cleanup on claim failure. On a non-fatal claim error, call (b) Server-side combined route. (a) is the smaller fix and matches how the CLI already composes other multi-step flows. Either way, the error message should mention the session id so a user who picks "leave it" can find it later with |
5d4a935 to
06adc2e
Compare
Closes #90
Implements the
ao session claim-pr <session-id> <pr-ref>lifecycle surface plusao spawn --claim-prwiring from the design at/tmp/aa-session-claim-pr-design.md.What changed:
GET /api/v1/sessions/{sessionId}/prandPOST /api/v1/sessions/{sessionId}/pr/claimwith the specified JSON envelopes and error mapping.gh repo view --json url -q .urlshorthand fallback when a project has no stored repo URL.ao session claim-prandao spawn --claim-pr/--no-takeoverCLI flows.0004_pr_session_changed_cdc.sql, wideningchange_log.event_typeand introducing the newpr_session_changedCDC event for PR ownership transfers.Local gate run from
backend/:Intentional omission:
--assign-on-githubremains out of scope per the design.