fix(ci): reset stale PR review context after history changes - #301
Conversation
There was a problem hiding this comment.
Review mode: initial
Findings
-
[MAJOR]
listPullRequestFileswill return an empty array for any PR with files due to incorrect flatMap usage with--paginate --slurp– Thegh api --paginate --slurpflag returns a single flattened JSON array of all items, not an array of per-page arrays. The addedflatMapwithArray.isArraycheck discards every item because each element is an object, not an array.Evidence:
.github/scripts/deepseek-common.mjs:420-424const pages = JSON.parse(raw); return pages.flatMap((page) => (Array.isArray(page) ? page : []));
This breaks the DeepSeek PR review path whenever the PR has at least one file — the file list will be
[], so no file excerpts or patches are included.Suggested fix: Remove the
flatMapand returnJSON.parse(raw)directly:- const pages = JSON.parse(raw); - return pages.flatMap((page) => (Array.isArray(page) ? page : [])); + const pages = JSON.parse(raw); + return Array.isArray(pages) ? pages : [];
-
[MAJOR] Test mock for
listPullRequestFilesdoes not reflect actualgh api --paginate --slurpoutput – The test mocks the command to return'[[{"filename":"first.ts"}],[{"filename":"second.ts"}]]'(an array of arrays), but the real output is'[{"filename":"first.ts"},{"filename":"second.ts"}]'(a flat array). The test passes only because the implementation accidentally flattens array-of-arrays, which is the opposite of real behavior.Evidence:
tests/deepseek-common.test.ts:116-122
Mock returns a nested array, but actualgh api --paginate --slurpreturns a single array.Suggested fix: Update the mock to return a flat array:
- return '[[{"filename":"first.ts"}],[{"filename":"second.ts"}]]'; + return '[{"filename":"first.ts"},{"filename":"second.ts"}]';
And adjust the expectation or the implementation accordingly (the implementation should not use
flatMap— see above). -
[MINOR]
gh pr diff --name-onlyresult is loaded but never used – In.github/prompts/codex-pr-review.mdline 55, the commandgh pr diff "$pr_number" -R "$repo" --name-onlyis run, but the output is not stored in a variable nor referenced later. It wastes an API call.Suggested fix: Remove the line unless it is needed for another purpose.
-
[NIT] In
isLinearReviewUpdate,has_merge_commitfield could beundefinedfor empty commit arrays – Ifcomparisonis provided butcommitsis empty (e.g.,ahead_by=0), the function accessescomparison?.has_merge_commitwhich may beundefined. It will still compare=== false, so it works, but explicit handling would be clearer.Suggested fix: No change needed, but consider adding a guard for clarity.
Summary
- Review mode: initial
- Review policy: advisory — the check reflects automation health/completion only; it does not approve the PR or resolve findings.
- Major issues: The
listPullRequestFilespagination implementation is incorrect and will break the DeepSeek review path. The accompanying test is also wrong. These must be fixed before merging. - Minor: Unused command in prompt.
- Other logic: Ancestry check and context-reset logic appear sound and correctly handle failures by discarding context.
Testing
- New tests for
isLinearReviewUpdateand PR file pagination were added, but the pagination test is invalid due to a mismatched mock. The existing tests for linear update correctness are good. - Suggested tests: Once the pagination bug is fixed, verify that
listPullRequestFilesworks with realghoutput (e.g., by running against a PR with >100 files). Also add a test for theprior_context_discardedandis_follow_up_reviewoutput logic in the workflow.
Open Cowork Bot
|
I verified the pagination findings against the real GitHub CLI/API before changing the implementation, and they are false positives. Using this PR with
The No code change is needed for these findings. The live commands used were: gh api --paginate --slurp "repos/OpenCoworkAI/open-cowork/pulls/301/files?per_page=2"
node --input-type=module -e "import {listPullRequestFiles} from './.github/scripts/deepseek-common.mjs'; console.log(listPullRequestFiles('OpenCoworkAI/open-cowork', '301'))" |
Summary
Why
PR #298 exposed the failure mode: the bot compared diverged heads (
04bcc817...e91a849, 13 ahead / 7 behind) and inherited findings for files that were not in the PR's current seven-file diff. The workflow previously treated any different reviewed SHA as a valid follow-up.The new checks fail closed: old review text and old-head compare data are available only for a verified safe linear update. All other cases reset review context and review the current PR from scratch.
Validation
npx vitest run tests/deepseek-common.test.ts tests/codex-pr-review-context.test.ts(11 tests passed)npm run typechecknpm run lint(0 errors; 8 existing warnings)node --checkfor both changed DeepSeek scriptsgit diff --checkThe review event remains
COMMENT; this PR does not turn advisory findings into a merge gate.