Skip to content

Commit d4bbf42

Browse files
committed
fix(cursor-review): leave a reopened auto-resolved thread for a person; narrow docs
Now the sweep can reply as the poster (the App), its marker reply no longer trips only_poster_spoke the way an approver reply did, so a thread a person unresolved would be re-resolved every round. The pre-resolve re-read now fetches comment bodies and skips any thread already carrying AUTO_RESOLVE_MARKER. Docs: say the App-first precedence covers this workflow's own decide sweep and resolve-below only; cursor-approve's approve-external still resolves as APPROVER_TOKEN. Input description lists the GITHUB_TOKEN fallback.
1 parent 4b1d819 commit d4bbf42

4 files changed

Lines changed: 39 additions & 10 deletions

File tree

‎.github/cursor-review/auto-approve.py‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ def cmd_auto_retry(args) -> int:
13551355
isResolved
13561356
participants: comments(first: 100) {
13571357
totalCount
1358-
nodes { author { __typename login } }
1358+
nodes { author { __typename login } body }
13591359
}
13601360
}
13611361
}
@@ -1506,7 +1506,18 @@ def still_eligible(thread_id: str, poster_login: str) -> bool:
15061506
node = (_graphql(THREAD_RECHECK_QUERY, threadId=thread_id).get("data") or {}).get("node")
15071507
if not isinstance(node, dict):
15081508
raise RuntimeError("thread re-read returned no node")
1509-
return not node.get("isResolved") and only_poster_spoke(node, poster_login)
1509+
return not node.get("isResolved") and only_poster_spoke(node, poster_login) and not already_auto_resolved(node)
1510+
1511+
1512+
def already_auto_resolved(node: dict) -> bool:
1513+
"""True when a comment in the thread carries AUTO_RESOLVE_MARKER: an earlier
1514+
sweep resolved it, so an unresolved thread like this was reopened by a
1515+
person and is theirs. Needed since the sweep can reply AS the poster (the
1516+
App, via RESOLVER_TOKEN or resolve-below's precedence): that reply never
1517+
trips only_poster_spoke the way an approver-authored reply did, and the
1518+
thread would otherwise be re-resolved and re-replied every round."""
1519+
nodes = ((node or {}).get("participants") or {}).get("nodes") or []
1520+
return any(AUTO_RESOLVE_MARKER in ((n or {}).get("body") or "") for n in nodes)
15101521

15111522

15121523
def resolve_eligible_threads(repo: str, pr, poster_login: str, threshold: str, commit_sha: str,

‎.github/cursor-review/tests/test_auto_approve.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2685,6 +2685,18 @@ def fake_gh(args, payload=None):
26852685
mock.patch.object(AA, "emit", lambda *a: None):
26862686
return AA.cmd_resolve_below(args)
26872687

2688+
def test_a_thread_reopened_after_an_auto_resolve_is_left_alone(self):
2689+
# The App's own marker reply does not trip only_poster_spoke, so a
2690+
# person who unresolves the thread must not see it re-resolved (and
2691+
# re-replied) every round.
2692+
t = thread("R", "low", repliers=[POSTER])
2693+
t["participants"]["nodes"][1]["body"] = "Not actioning: Low finding.\n\n" + AA.AUTO_RESOLVE_MARKER
2694+
self.assertEqual(self.run_cmd([t]), 0)
2695+
self.assertEqual([(k, tid) for k, tid, _ in self.mutations], [("recheck", "R")])
2696+
2697+
def test_recheck_query_reads_comment_bodies(self):
2698+
self.assertIn("nodes { author { __typename login } body }", AA.THREAD_RECHECK_QUERY)
2699+
26882700
def test_resolves_low_and_nit_while_a_medium_is_open(self):
26892701
rc = self.run_cmd([thread("M", "medium"), thread("L", "low"), thread("N", "nit")])
26902702
self.assertEqual(rc, 0)

‎.github/workflows/cursor-review.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,9 @@ on:
766766
while the PR carries `needs-human-review` or `skip-cursor-review`.
767767
No effect without `approve_max_severity`, or for an author
768768
`approve_authors` does not list. Resolving needs write access (the
769-
`bot_app_id` App, else APPROVER_TOKEN; the App is preferred because
770-
it posted the threads, and an approver PAT may be refused).
769+
`bot_app_id` App, else APPROVER_TOKEN, else GITHUB_TOKEN; the App is
770+
preferred because it posted the threads, and an approver PAT may be
771+
refused).
771772
type: boolean
772773
required: false
773774
default: false

‎docs/callers/cursor-review.md‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,12 +1026,17 @@ round resolves at most 30 threads and stops after 3 failures in a row (a missing
10261026
permission or a rate limit); the rest wait for the next approving round. The step
10271027
summary logs the resolved / skipped-human / skipped-unbadged /
10281028
skipped-above-threshold / failed / deferred counts. Resolving a thread needs
1029-
**write access** to the repo. Both the approve-time sweep and
1030-
`resolve_below_threshold_on_post` resolve (and reply) as the `bot_app_id` App
1031-
first — it posted the threads — then `APPROVER_TOKEN`, then `GITHUB_TOKEN`; the
1032-
approval itself is still posted as `APPROVER_TOKEN`. The App comes first because
1033-
an approver PAT can approve yet be refused `resolveReviewThread` ("Resource not
1034-
accessible by personal access token"). Without write access the approval still
1029+
**write access** to the repo. This workflow's approve-time sweep (in `Auto-approve
1030+
decision`) and `resolve_below_threshold_on_post` resolve (and reply) as the
1031+
`bot_app_id` App first — it posted the threads — then `APPROVER_TOKEN`, then
1032+
`GITHUB_TOKEN`; the approval itself is still posted as `APPROVER_TOKEN`. The App
1033+
comes first because an approver PAT can approve yet be refused
1034+
`resolveReviewThread` ("Resource not accessible by personal access token").
1035+
Under `defer_approval`, this workflow's decide resolves nothing and the sweep is
1036+
[cursor-approve](cursor-approve.md)'s, which has no App token and still resolves
1037+
as `APPROVER_TOKEN` — pair it with `resolve_below_threshold_on_post` if that
1038+
token cannot resolve. A thread that carries an earlier auto-resolve reply and was
1039+
unresolved since is left for a person. Without write access the approval still
10351040
lands and each resolve logs a warning. Withdrawing an approval later does not unresolve anything.
10361041

10371042
**Resolving them as soon as they are posted (`resolve_below_threshold_on_post`).**

0 commit comments

Comments
 (0)