Skip to content

AI Fix for Issue #99: Refactor: Add automatic token refresh to git push operations to prevent auth failures - #100

Merged
integry merged 1 commit into
mainfrom
ai-fix/99-refactor-add-automatic-to-20251007-1159-claude-sonnet-4-5-20250929-j4o
Oct 7, 2025
Merged

integry merged 1 commit into
mainfrom
ai-fix/99-refactor-add-automatic-to-20251007-1159-claude-sonnet-4-5-20250929-j4o

Conversation

@propr-dev

@propr-dev propr-dev Bot commented Oct 7, 2025

Copy link
Copy Markdown
Contributor

AI Implementation Summary

Closes #99

Model Used: claude-sonnet-4-5-20250929
Status: ✅ Implementation Completed
Branch: ai-fix/99-refactor-add-automatic-to-20251007-1159-claude-sonnet-4-5-20250929-j4o
Commits: ✅ Changes committed (f591bfc)


🤖 AI Processing Completed

Execution Details:

Summary:

Summary

I've successfully implemented the automatic token refresh mechanism for git push operations in src/git/repoManager.js. The changes follow the exact specifications from the issue:

Changes made:

  1. Added import (line 8): Imported getAuthenticatedOctokit from ../auth/githubAuth.js

  2. Refactored pushBranch function (lines 1497-1578):

    • Extracted the push logic into a local performPush helper function that accepts a token parameter
    • Moved the git instance initialization outside performPush so it can be shared
    • Simplified the main function to remove the complex retry wrapper with tokenRefreshFn
  3. Implemented automatic retry logic:

    • The main try/catch block now attempts the initial push with the provided authToken
    • On authentication failure (detecting "Authentication failed" or "Invalid username or token" in error message), it automatically:
      • Logs the detection of the authentication error
      • Calls getAuthenticatedOctokit() to get a fresh Octokit instance
      • Retrieves a new token via .auth({ type: "installation" })
      • Retries the push operation with the fresh token
      • Logs success or failure appropriately
    • Non-authentication errors are immediately re-thrown

This implementation makes the git push operation more robust by handling token expiration transparently, which resolves the issue where long-running jobs (particularly during the AI execution phase) cause the initial 1-hour token to expire before the final push operation.

Claude Code Results:

  • Turns Used: 17
  • Cost: $unknown
  • Session ID: 21c60cb0-dfd9-489e-bb10-825ee3197cf6

📁 Detailed Logs:
Execution logs generated:

  • Conversation: 17 messages
  • Session: 21c60cb0-dfd9-489e-bb10-825ee3197cf6
  • Raw Output: 124,599 characters

Log files stored at:

  • conversation: /tmp/claude-logs/issue-99-2025-10-07T12-01-09-923Z-conversation.json
  • output: /tmp/claude-logs/issue-99-2025-10-07T12-01-09-923Z-output.txt
💬 Latest Conversation Messages
ASSISTANT: [content unavailable]

ASSISTANT: ## Summary

I've successfully implemented the automatic token refresh mechanism for git push operations in `src/git/repoManager.js`. The changes follow the exact specifications from the issue:

**Chan...


Powered by Claude Code v1.0.0


This PR was created automatically by Claude Code after processing issue #99.

… git push

Implemented by Claude Code using claude-sonnet-4-5-20250929 model.

Implementation completed successfully.
@integry
integry merged commit 897e219 into main Oct 7, 2025
@integry
integry deleted the ai-fix/99-refactor-add-automatic-to-20251007-1159-claude-sonnet-4-5-20250929-j4o branch June 16, 2026 10:53
propr-dev Bot pushed a commit that referenced this pull request Nov 17, 2026
…doesn't yet include the PR that just merged, the epic body now looks that PR up on its own before deciding which closed issues to drop. A closed issue whose alternate PR merged keeps its list entry and its `Fixes` line, so the body matches the progress count again.

I fixed F3. When GitHub's list of PRs into the epic branch doesn't yet include the PR that just merged, the epic body now looks that PR up on its own before deciding which closed issues to drop. A closed issue whose alternate PR merged keeps its list entry and its `Fixes` line, so the body matches the progress count again.

**The fix**
- I added `withTriggeringChildEvidence` in `packages/core/src/webhook/epicMergeProgress.ts`. If the merging PR is missing from the list, or its row lacks the merge or the branch name, it reads that PR with the same `readMergedChild` call the progress update uses. A PR that turns out to have merged into a different branch isn't added.
- `loadEpicBodyIssueNumbers` in `packages/core/src/webhook/epicPRBody.ts` now uses it, which covers both callers: creating the epic PR and rewriting its body.
- If the read can't confirm the merge, the body is built from the list as before rather than failing. The progress update still throws and retries in that case, as it did before.

**Tests** (`test/epicMergeProgressHandler.test.ts`)
- There are two new tests, one for creation and one for rewriting. In both, #101 is closed, its linked PR #202 was abandoned, and #203 from `101/codex-second` merges while the list doesn't include it yet. Each test checks that #203 was read on its own and that the body keeps `- #101`, `Fixes #101` and `Fixes #100` but still leaves out #102.
- With the fix taken out, both new tests fail. With it, the handler suite passes 57/57.
- `test/epicMergeProgress.test.ts` (75/75) and `packages/core/test/pullRequestStatusEpicSync.test.ts` (37/37) also pass. ESLint with zero warnings passes on the two changed source files, and `tsc --noEmit` passes for `packages/core`.

**Found separately, not changed:** the title a new epic PR starts with is worked out from the plan and the merging PR's number only, without its branch. In the same scenario it could start at a lower count, for example `0/1` instead of `1/2`. The code comment says the status sync corrects the title afterwards, so the wrong count should only last until that sync runs. This behaviour already existed on `main` and is outside F3, so I left it alone.

No preview was made, because the change only affects text written to GitHub.

PR: #3612
Comment by: @propr-ultrafix (ID: 0)
Model: Claude Opus 5.5
integry pushed a commit that referenced this pull request Nov 17, 2026
…the progress comment, the ready comment and the title agree (#3612)

* Epic progress now counts plan issues only. The progress comment, the ready comment, the final-merge comment, the status line and the title all use one computation, so they show the same N and M. All the affected test files pass, and lint and typecheck pass on the changed source files.

The count (`computeEpicMergeProgress`, now in `packages/core/src/webhook/epicProgressCount.ts`)
- M is the plan issues that weren't closed without a merge. N is how many of them are merged into the epic branch.
- An issue counts as merged if its status is merged, its linked PR merged, or a PR from a branch named after it (`3594/…` or `3594-…`) merged.
- A PR without a plan issue changes neither number but is still listed under "Merged child PRs". Two PRs for one issue count it once. A branch from another epic (`3589-epic-…`) isn't counted as a PR for the issue its name starts with.
- An issue closed as not planned (status closed) drops out of M, as closed issues already did.
- An epic with no plan still counts its PRs, and its comments say "pull requests" instead of "issues".

Behaviour changes to be aware of
- An open human PR into the epic branch no longer holds back the "ready for final merge" comment.
- To match branches to issues, the PR list now records the source branch for merged and closed PRs too, not only open ones.

Comments
- The progress comment now reads `N of M issues merged` instead of "N out of M PRs merged".
- The ready comment shows the same line and says `All N issues have been merged…`. The final-merge comment uses the same wording.
- Once the epic PR is merged, the progress comment drops the bar and percentage. It shows ✅ if every issue merged; otherwise it says how many issues weren't merged before the epic PR merged. This removes the "⏳ 75%" next to "merged" seen on #3456.

Epic body
- The issue list and `Fixes #` lines leave out issues whose plan status is closed, and issues GitHub reports as closed `not_planned` or `duplicate`.
- This takes effect the next time the body is rewritten, which happens when a child PR merges; closing an issue alone doesn't trigger it. That logic moved to the new `packages/core/src/webhook/epicPRBody.ts`. Both changed files had gone past the 400-line lint limit, which is why this and the count module were split out.

Tests (regression tests as the issue asked)
- `test/epicMergeProgress.test.ts` (71 pass), `test/epicMergeProgressHandler.test.ts` (53 pass) and `packages/core/test/pullRequestStatusEpicSync.test.ts` (35 pass).
- New tests cover:
  - an extra human PR, both merged and open, in the count, the ready comment and the status line
  - two PRs for one issue, including the case where the merged one isn't the linked one
  - an issue closed as not planned, in the count and in the body's `Fixes` lines
  - the merged epic's final progress comment and final report
- Existing assertions were updated to the new wording. In the status sync tests, open PRs from non-plan branches used to raise the total (for example "1 of 14"); those now expect "1 of 3".

I also updated `docs/docs/features/work-splitting.md`, `docs/docs/features/pr-status.md` and added a Fixed entry to `CHANGELOG.md`. No preview was made: the change is GitHub comment and title text, not app UI.

* feat(ai): I fixed F1 and F2. The affected suites pass, and every new regression test fails when run against the code before the fix.

I fixed F1 and F2. The affected suites pass, and every new regression test fails when run against the code before the fix.

**F1: a closed issue whose work merged now stays in the epic body**
- I moved the "this issue's work is merged" rule into one shared function, `epicIssuesWithMergedWork` in `epicProgressCount.ts`. An issue counts as merged if its status is merged, its linked PR merged, or a PR from a branch named after it merged. The progress count uses it too, so the count and the body can't disagree.
- The body filter `epicBodyIssueNumbers` now drops a closed issue only when it has no merged work. Issues GitHub closed as not planned or as duplicates are still dropped.
- A new `loadEpicBodyIssueNumbers` reads the PRs into the epic branch so the filter can see that merged work. Both places that write the body, creating the epic PR and rewriting its body after a merge, now use it. It only reads the PR list when a plan issue is closed.
- New tests in `test/epicMergeProgressHandler.test.ts` cover the case from the finding, for both creating and rewriting the body: issue #101's linked PR #202 is closed without merging, then an alternate PR #203 from `101/…` merges. #101 keeps its list entry and its `Fixes` line, and an issue closed with no merged work is still left out. I also added a count test for the same case.

**F2: a planned epic no longer falls back to counting PRs**
- `computeEpicMergeProgress` now counts PRs only when no plan was passed at all. A plan whose issues were all filtered out, for example because they shipped through an earlier epic, gives 0 of 0 issues instead of counting a human PR as 1 of 1.
- Both callers already passed nothing for "no plan" and a list for "plan", so neither needed changing.
- New tests:
  - **Count:** an empty plan list gives 0 of 0, with no switch to "pull requests".
  - **Progress comment:** a successor epic whose plan issues all shipped through the previous epic, with a human PR merged afterwards. Both the open-epic and merged-epic paths count 0 of 0, and no comment says "pull requests".
  - **Status line:** the same successor case, in `pullRequestStatusEpicSync.test.ts`. The status line and title no longer show "1 of 1 issues merged".

**Checks**

| Suite | Passed | Failed |
|---|---|---|
| `test/epicMergeProgress.test.ts` | 75 | 0 |
| `test/epicMergeProgressHandler.test.ts` | 55 | 0 |
| `test/epicMergeProgressRetry.test.ts` | 21 | 0 |
| `test/taskIntentWithdrawal.test.ts` | 169 | 0 |
| `test/intentWithdrawalWebhook.test.ts` | 36 | 0 |
| `packages/core/test/pullRequestStatusEpicSync.test.ts` | 37 | 0 |
| `packages/core/test/pullRequestStatusEpic.test.ts` | 24 | 0 |
| `packages/core/test/pullRequestStatusEpicChildReads.test.ts` | 6 | 0 |
| `packages/core/test/epicQueueBlockedHead.test.ts` | 14 | 0 |

- Typecheck for `packages/core` and lint with zero warnings allowed on the three changed source files are both clean.
- The lint config doesn't cover these test files: ESLint skips them with "file ignored" warnings rather than linting them.
- The docs and CHANGELOG already say issues "closed without a merge" are left out, which matches the corrected behaviour, so I didn't change them.
- No preview: nothing in the app's UI changed.

I found nothing else outside F1 and F2 that needed fixing.

PR: #3612
Comment by: @propr-ultrafix (ID: 0)
Model: Claude Opus 5.5

* feat(ai): I fixed F3. When GitHub's list of PRs into the epic branch doesn't yet include the PR that just merged, the epic body now looks that PR up on its own before deciding which closed issues to drop. A closed issue whose alternate PR merged keeps its list entry and its `Fixes` line, so the body matches the progress count again.

I fixed F3. When GitHub's list of PRs into the epic branch doesn't yet include the PR that just merged, the epic body now looks that PR up on its own before deciding which closed issues to drop. A closed issue whose alternate PR merged keeps its list entry and its `Fixes` line, so the body matches the progress count again.

**The fix**
- I added `withTriggeringChildEvidence` in `packages/core/src/webhook/epicMergeProgress.ts`. If the merging PR is missing from the list, or its row lacks the merge or the branch name, it reads that PR with the same `readMergedChild` call the progress update uses. A PR that turns out to have merged into a different branch isn't added.
- `loadEpicBodyIssueNumbers` in `packages/core/src/webhook/epicPRBody.ts` now uses it, which covers both callers: creating the epic PR and rewriting its body.
- If the read can't confirm the merge, the body is built from the list as before rather than failing. The progress update still throws and retries in that case, as it did before.

**Tests** (`test/epicMergeProgressHandler.test.ts`)
- There are two new tests, one for creation and one for rewriting. In both, #101 is closed, its linked PR #202 was abandoned, and #203 from `101/codex-second` merges while the list doesn't include it yet. Each test checks that #203 was read on its own and that the body keeps `- #101`, `Fixes #101` and `Fixes #100` but still leaves out #102.
- With the fix taken out, both new tests fail. With it, the handler suite passes 57/57.
- `test/epicMergeProgress.test.ts` (75/75) and `packages/core/test/pullRequestStatusEpicSync.test.ts` (37/37) also pass. ESLint with zero warnings passes on the two changed source files, and `tsc --noEmit` passes for `packages/core`.

**Found separately, not changed:** the title a new epic PR starts with is worked out from the plan and the merging PR's number only, without its branch. In the same scenario it could start at a lower count, for example `0/1` instead of `1/2`. The code comment says the status sync corrects the title afterwards, so the wrong count should only last until that sync runs. This behaviour already existed on `main` and is outside F3, so I left it alone.

No preview was made, because the change only affects text written to GitHub.

PR: #3612
Comment by: @propr-ultrafix (ID: 0)
Model: Claude Opus 5.5

* feat(ai): I fixed F4. A merged PR from an issue branch that only begins like an epic branch, such as `101-epic-progress-count-plan`, now counts toward its plan issue, and the epic body keeps that issue's list entry and `Fixes #101` line.

I fixed F4. A merged PR from an issue branch that only begins like an epic branch, such as `101-epic-progress-count-plan`, now counts toward its plan issue, and the epic body keeps that issue's list entry and `Fixes #101` line.

**Fix** (`packages/core/src/webhook/epicProgressCount.ts`)
- `epicChildBranchIssue` now uses the repository's real `EPIC_BRANCH_PATTERN` from `services/epicPRService.ts` (`{id}-epic-{word}-{word}-{rand}`). The prefix-only `EPIC_HEAD_PATTERN` (`/^\d+-epic-/`) is gone.
- Only actual epic branches, like `101-epic-other-plan-abc`, are now kept from being matched to an issue.

**Other code with the same assumption**
- Both places that turn a branch name into a plan issue go through `epicChildBranchIssue`, so both are fixed:
  - the count and body path, through `epicIssuesWithMergedWork`, which `computeEpicMergeProgress` and `loadEpicBodyIssueNumbers` both use.
  - the status-line child-to-issue mapping in `pullRequestStatusEpicFacts.ts`.
- That status-line file already checked for other epic branches with `EPIC_BRANCH_PATTERN`, so the two checks now agree.
- No other prefix-only epic check exists in the PR's changes.
- Recovering the merge evidence of a PR that GitHub's list doesn't show yet sends the branch through the same function, so that path is fixed too.

**Regression tests**
- `test/epicMergeProgress.test.ts`: `epicChildBranchIssue('101-epic-progress-count-plan')` returns 101, while an actual epic branch returns null. A closed #101 whose alternate PR #203 merged from that branch counts 2 of 2 with nothing excluded.
- `test/epicMergeProgressHandler.test.ts`: the two existing tests for an alternate PR's body now also run with the `101-epic-progress-count-plan` branch. One covers PRs already in GitHub's list and one covers a merge the list doesn't show yet, each for both creating and rewriting the body. All of them check for `- #101: Issue` and `Fixes #101`.

**Verification**
- Test results:
  - `test/epicMergeProgress.test.ts`: 76 of 76 pass.
  - `test/epicMergeProgressHandler.test.ts`: 61 of 61 pass.
  - `packages/core/test/pullRequestStatusEpicSync.test.ts`: 37 of 37 pass.
- With the old regex put back temporarily, all 5 new cases fail: 1 in the count tests and 4 in the body tests.
- Core `tsc --noEmit` and core ESLint (`--max-warnings 0`) on the changed source file both pass.
- The root ESLint config skips these test files, so they weren't linted.

I made no visual preview, since this changes GitHub comment and body text, not the app's UI.

PR: #3612
Comment by: @propr-ultrafix (ID: 0)
Model: Claude Opus 5.5

* feat(ai): I fixed F5. A later epic on the same branch now drops an issue that a previous epic already shipped, even when the PR that shipped it is an alternate PR from the issue's branch and the issue's linked PR is still open. In that case the later epic used to show "0 of 1 issues merged" for work that had already shipped, and could never become ready.

I fixed F5. A later epic on the same branch now drops an issue that a previous epic already shipped, even when the PR that shipped it is an alternate PR from the issue's branch and the issue's linked PR is still open. In that case the later epic used to show "0 of 1 issues merged" for work that had already shipped, and could never become ready.

**Change**
- **New helper:** `epicIssuesShippedBefore` in `packages/core/src/webhook/epicProgressCount.ts`. It lists the plan issues that a previous epic already shipped. It matches a shipped PR to an issue the same way the progress count does: either the PR is the issue's linked PR, or it comes from a branch named for the issue (`101/…` or `101-…`).
- **Both progress paths now use it** instead of checking only `issue.pr_number`:
  - the progress comments, via `reportablePlanIssues` in `epicMergeProgress.ts`
  - the status line and title, via `loadEpicStatusFacts` in `pullRequestStatusEpicFacts.ts`
- **Lint:** adding this to `updateEpicMergeProgress` pushed it over the complexity limit, so the lookup now happens inside `reportablePlanIssues` instead.

**Tests**
- **New regressions:** each sets up the case from the finding. Issue #101's linked PR is still open, and an alternate PR from its branch merged before the previous epic. A human PR and a PR for a second issue merge after it. The new tests check:
  - in `test/epicMergeProgress.test.ts`, with the trigger being a child PR merge and with the epic itself merged: the count is 1 of 1, and the ready comment (or, once the epic merged, the final-merge comment) is posted.
  - in `packages/core/test/pullRequestStatusEpicSync.test.ts`: the status line reads `✅ 1 of 1 issues merged` and the title shows `1/1`.
- **Negative check:** all three new tests fail when run against the source files from before this change.
- **Suites:** `test/epicMergeProgress.test.ts` (78 pass), `test/epicMergeProgressHandler.test.ts` (61 pass) and `pullRequestStatusEpicSync.test.ts` (38 pass) all pass. ESLint with zero warnings and `tsc --noEmit` pass in `packages/core`.

**Also found, not changed:**
- **Plural on the status line:** it reads "1 of 1 issues merged" where the progress comment would say "issue". The comment uses `progressNoun` to pick the word, but the status line always prints "issues". That is outside F5, so the new test accepts either form.
- **Epic body:** the issue list and `Fixes` lines don't drop issues that a previous epic shipped, by either kind of PR. They never checked for this, so it isn't the defect F5 describes.

No preview was made: the change only affects GitHub comment, status-line and title text.

PR: #3612
Comment by: @propr-ultrafix (ID: 0)
Model: Claude Opus 5.5

---------

Co-authored-by: propr-dev[bot] <1316198+propr-dev[bot]@users.noreply.github.com>
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.

Refactor: Add automatic token refresh to git push operations to prevent auth failures

2 participants