Skip to content

fix: read a withdrawn bitbucket server approval as withdrawn - #39431

Merged
KiroCrewCaptain merged 1 commit into
mainfrom
fix/21122-bitbucket-withdrawn-approval
Nov 19, 2026
Merged

KiroCrewCaptain merged 1 commit into
mainfrom
fix/21122-bitbucket-withdrawn-approval

Conversation

@bolichen97

@bolichen97 bolichen97 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A Bitbucket Server / Data Center reviewer who withdraws an approval stops reading as approved in the dashboard's pull-request read.

The live run on Bitbucket Data Center 9.4.26 reported in #21122 found it. A reviewer approved a pull request and then withdrew the approval. The instance's own reviewers entry reads approved: false, status: UNAPPROVED, but the reader still returned that reviewer's review row as APPROVED. The raw /activities answer, newest first, was [UNAPPROVED, UPDATED, APPROVED, OPENED].

Why it matters

Anything that reads a Bitbucket Server pull request through the dashboard's /api/source/pull-request payload (an app, an agent) gets a verdict the reviewer has taken back, and the Changes panel's Reviews tab counts it. That can make an unapproved change look approved.

Not a goal

  • Resolved comments and tasks, the merge-conflict read, and the UNKNOWN build state (items 2-4 of the live run). They are things the reader does not read yet, not wrong answers.
  • Reading the pull request's reviewers list, or adding a new review state value.

What changed (motivation → approach → change)

A withdrawn approval drops out of the review rows, so the payload agrees with the instance.

  • Root cause: _comment_rows in dashboard/source_providers/bitbucket_server.py turns the activity stream into rows, oldest first. It maps APPROVED and REVIEWED and skipped UNAPPROVED, so the earlier APPROVED row stayed.
  • Change: an UNAPPROVED activity drops that reviewer's earlier review rows, because after a withdrawal the instance reads the reviewer as having no verdict. A later re-approval adds its own row; other reviewers and all comment rows are untouched.
  • Who withdrew: matched on the account key (user.name, else user.slug), not the display name, because two accounts can share a display name.

Backwards compatibility

Compatible: the payload shape and the set of state values are unchanged; only a review row the instance itself has withdrawn is left out.

Reader: website/src/components/PullRequestPanel.tsx:reviews tab -- entry: chat -- its count is source.comments.length, so a withdrawn approval stops adding to it; test_a_withdrawn_approval_no_longer_reads_as_approved
Reader: website/src/components/CommentThreads.tsx:groupThreads -- entry: chat -- already skips review rows with no body, and Bitbucket Server review rows have none, so the list renders the same
Reader: website/src/app-sdk/PullRequestPanel.tsx -- entry: app -- reads the same /api/source/pull-request payload; the other rows keep their id, kind and state (test asserts every row)
Reader: src/kiro_crew/apps/builtins/auto_improvement/backend/pr_checks.py:_count_unresolved -- entry: app -- counts only resolvable rows, and review rows are resolvable: False

Tests

  • test_a_withdrawn_approval_no_longer_reads_as_approved in test/test_source_providers_bitbucket_server.py serves an activity stream through the real /api/source/pull-request handler and asserts every row's id, kind and state:
    • live: the four rows of the live run as posted (only dates added): no review row is left.
    • withdrawn: the same, plus an added "needs work" by another account with the same display name, which still reads CHANGES_REQUESTED.
    • re-approved: a new approval after the withdrawal yields that APPROVED row.
    • needs-work-withdrawn: a reviewer's "needs work" is dropped by their UNAPPROVED, and their comment row stays.
  • Determinism: the test 20 times at -n0 and 10 times at -n 4 --dist loadgroup --max-worker-restart=2 beside the Gerrit and Jira provider tests, all green; the whole file in a shuffled order (seed 30892, 49 ids) green.

Proof: PROVEN test/test_source_providers_bitbucket_server.py::test_a_withdrawn_approval_no_longer_reads_as_approved[live], test/test_source_providers_bitbucket_server.py::test_a_withdrawn_approval_no_longer_reads_as_approved[withdrawn], test/test_source_providers_bitbucket_server.py::test_a_withdrawn_approval_no_longer_reads_as_approved[re-approved], test/test_source_providers_bitbucket_server.py::test_a_withdrawn_approval_no_longer_reads_as_approved[needs-work-withdrawn] (head 79967bf)

Manual verification

Run on Linux (Ubuntu 24.04, x86_64). No licensed Bitbucket Server / Data Center instance is available there, so the real gateway handler /api/source/pull-request was driven on an aiohttp app, with the instance answered by the test file's _Instance stub serving the reporter's four /activities rows verbatim (ids, accounts, display names).

Before the fix (base reader), the payload's comments:

[reporter] HTTP 200 comments =
[{"id": "322", "kind": "review", "author": "EE Operator", "state": "APPROVED", "threadId": ""}]

After the fix:

[reporter] HTTP 200 comments =
[]

Nearby happy path after the fix: the existing fixture's approval by rev1 (id 903) still reads APPROVED, and inline thread 11 (ids 11 and 12) is unchanged. The whole test file passes (49 tests).

On a live Bitbucket Data Center 9.4.26 instance, the reporter ran the reader at this PR's merge base and at its head (comment): an approval withdrawn by DELETE /approve or by PUT participants with status UNAPPROVED went from one APPROVED row to no review row; approve, withdraw, approve again gave one APPROVED row; another reviewer's kept approval still read APPROVED.

Real-machine verification

Machine: EC2 m7i.2xlarge, Ubuntu 24.04.5 x86_64, 8 vCPU / 32 GiB; about 2 hours, about $0.81 on demand
Before (main c22557c): python3 -m pytest -n0 -s -q -p no:cacheprovider test/test_zz_repro_21122.py (a temporary driver, not committed, that serves the live run's four /activities rows to the real /api/source/pull-request handler) -> comments = [{"id": "322", "kind": "review", "author": "EE Operator", "state": "APPROVED"}]
After (head 79967bf): the same command -> comments = [], and the existing fixture's approval (id 903) still reads APPROVED; test/test_source_providers_bitbucket_server.py 49 passed
Cleanup: instance terminated (describe-instances for it prints [], describe-volumes for it prints []); reached over SSM, no key pair; its security group has no ingress rules and is not one made for this PR

Related Issues

Closes #21122

Sibling sweep

Swept: git grep -nE '"kind": "review"|_github_comment(item, "review")|approv' -- src/kiro_crew/dashboard/source_providers/
Sibling: src/kiro_crew/dashboard/source_providers/github.py -- not affected -- GitHub returns a dismissed review in place with state DISMISSED
Sibling: src/kiro_crew/dashboard/source_providers/gerrit.py -- not affected -- it reads the current Code-Review votes, so a removed vote is 0 and skipped
Sibling: src/kiro_crew/dashboard/source_providers/gitlab.py -- not affected -- it emits no review verdict rows

Pattern harvest

Not generalizable: the defect is one provider's event vocabulary missing its withdrawal event; the other readers build verdicts from a current-state snapshot.

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable) -- N/A, no spec documents Bitbucket Server review rows
  • No secrets, credentials, or internal references in the diff

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 11c3fb8b79dd11ca346f74acbf93fb96e0354d7e touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 11c3fb8b79dd11ca346f74acbf93fb96e0354d7e — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

Nothing blocks. This is a mechanism-level fix with a linked live reproduction (#21122), and a test added here fails on base.

What this change ships

Inventory (3 items) — 3 justified

Intent: a Bitbucket Server reviewer who withdraws an approval stops showing as approved in the pull-request read. This is a FIX.

  1. An approval later withdrawn no longer appears as an APPROVED review row — justified
  2. A "needs work" verdict later withdrawn by the same account is also dropped — justified
  3. A withdrawal matches the reviewer by account key, not display name — justified

[FIRST-PRINCIPLES-REVIEWED] 11c3fb8

Description read

[DESCRIPTION-READ] e74ea47e5d0be902c4d0966cc49a50b390cb22fcc41cbb1f43ada378accafef7

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 11c3fb8b79dd11ca346f74acbf93fb96e0354d7e — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: a withdrawal is now replayed within the activity stream the reader already folds, and it is keyed by the reviewer's account.

Notes

  • The same replay gap stays open for a reviewer who switches from APPROVED to REVIEWED (needs work) with no UNAPPROVED between them. Both rows would still show, so the reader reports two verdicts where the instance holds one. That is outside this PR's goal and belongs in a follow-up that keeps only the latest row per account.

[DESIGN-REVIEWED] 11c3fb8

Description read

[DESCRIPTION-READ] 19252e1e51589e6460be42ca3ebc3482222cfa0b1150d808d0ed38e4cf3f9592

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 11c3fb8b79dd11ca346f74acbf93fb96e0354d7e — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 11c3fb8

Verdict parsed from the review's SHA-scoped output markers for commit 11c3fb8b79dd11ca346f74acbf93fb96e0354d7e.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 11c3fb8b79dd11ca346f74acbf93fb96e0354d7e false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 11c3fb8b79dd11ca346f74acbf93fb96e0354d7e and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 11c3fb8

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 11c3fb8b79dd11ca346f74acbf93fb96e0354d7e false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 19, 2026
@bolichen97
bolichen97 force-pushed the fix/21122-bitbucket-withdrawn-approval branch from 79967bf to d9e1949 Compare November 19, 2026 16:35
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in 108 files this PR's files import or sit beside (src/kiro_crew/dashboard/source_providers/ among them) since this head's CI ran (c22557c -> 5036a64); CI re-running.

The only red on the old head was SAST (Semgrep), cancelled at its 30-minute limit: its diff-only scan compares the merge commit with the merge-base, and a merge-base 1,500+ commits behind main made that 7,560 files instead of this PR's two. The patch is unchanged (range-diff =), and neither changed file moved on main.
[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 19, 2026
The Bitbucket Server reader flattens the pull request's activity stream
into review rows, but mapped only APPROVED and REVIEWED and ignored
UNAPPROVED. A reviewer who approved and then withdrew therefore still
read as APPROVED, while the instance itself reads them as having no
verdict.

When an UNAPPROVED activity arrives, drop that reviewer's earlier review
rows. The reviewer is identified by the account name (else slug), not
the display name, since two accounts can share one. A later re-approval
still yields its own row; other reviewers and comment rows are
untouched. The test serves the activity stream from the live run on
Bitbucket Data Center 9.4.26 reported in #21122, plus the REVIEWED
("needs work") shape that run confirmed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bolichen97
bolichen97 force-pushed the fix/21122-bitbucket-withdrawn-approval branch from d9e1949 to 11c3fb8 Compare November 19, 2026 20:25
@bolichen97

Copy link
Copy Markdown
Contributor Author

Rebased: main moved in .github/workflows/ci.yml, the code-channel bar test suite and src/kiro_crew/apps/builtins/auto_improvement/tests/test_pr_watchers.py, the Windows backend test setup behind this head's reds, not in this PR's files, since this head's CI ran (5036a64 -> be1ce64); CI re-running.

The old head's only reds were three Windows backend shards, each in a test this PR does not touch, and each one's fix has landed on main since the old base:

The patch is unchanged (range-diff =).
[operator: bolichen97]

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Nov 19, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider estimates an 8% chance that this change introduces a defect, within the 12% limit for approving on its own, but it is held at tier pending: being reviewed.

This is a small, targeted fix in _comment_rows. When the reader sees an UNAPPROVED activity, it now drops that account's earlier review rows (APPROVED or CHANGES_REQUESTED). It matches the reviewer by account key (user.name, else user.slug), not by display name. Comment rows, other reviewers' rows and later re-approvals are not affected. Rows are still built oldest first and the cap check is unchanged, so removing rows cannot corrupt the output. The new parametrized test runs requests through the real /api/source/pull-request handler. Its live case fails on base, which returns one APPROVED row, and covers the stated goal. The readers named in the PR only count or render rows and need no change. The payload shape and the set of state values are unchanged. CI is green.

Tier: pending: being reviewed.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 11c3fb8b79 · 78 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I reviewed head 11c3fb8 and traced how the activity stream is folded in _comment_rows. An UNAPPROVED activity now drops only the earlier review rows of the account that withdrew. Accounts are matched by account name or slug, and other reviewers' rows, comment rows and a later re-approval are kept. The provider test file passes on this head (49 tests), and all four cases of the new test fail against the main branch reader, so the test really pins the fix. I found no wrong behaviour, crash or data loss, so nothing blocks.

@KiroCrewCaptain
KiroCrewCaptain merged commit 7b84a16 into main Nov 19, 2026
99 checks passed
@KiroCrewCaptain
KiroCrewCaptain deleted the fix/21122-bitbucket-withdrawn-approval branch November 19, 2026 21:48
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 19, 2026
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.

Bitbucket Server reader: verify against a live Server or Data Center instance

2 participants