Skip to content

Commit 589f032

Browse files
author
Agent on behalf of user jgstern
committed
Merge pull request 'feat: add local PR queue for offline resilience' (#181) from jgstern-agent/feat/auto-pr-queue into dev
2 parents 0e0fe13 + 0f73566 commit 589f032

3 files changed

Lines changed: 650 additions & 131 deletions

File tree

AGENTS.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,18 @@ Run these checks before starting any new feature or task:
3636
# 1. Ensure no auto-pr is in flight (manual PRs don't create this file)
3737
test -f .git/PR_PENDING && echo "STOP: auto-pr awaiting merge" && exit 1
3838

39-
# 2. Sync with dev and main
39+
# 2. Flush any queued PRs if remote is available
40+
./scripts/auto-pr list # Check if any PRs are queued
41+
./scripts/auto-pr flush # Push them if remote is back
42+
43+
# 3. Sync with dev and main
4044
git checkout main && git pull origin main
4145
git checkout dev && git pull origin dev
4246

43-
# 3. Check current progress
47+
# 4. Check current progress
4448
cat STATUS.md
4549

46-
# 4. Create feature branch
50+
# 5. Create feature branch
4751
git checkout -b <author>/feat/<short-name>
4852
```
4953

@@ -83,6 +87,19 @@ git commit -s -m "feat: description"
8387
- Before starting new work: `test -f .git/PR_PENDING && echo "WAIT"`
8488
- If file exists, wait for `auto-pr` to complete before starting unrelated work.
8589
- Manual PRs do not create this gate; use `./scripts/ci-debug status` to check CI.
90+
- **vPR Queue (offline resilience):**
91+
- When remote is unavailable, `auto-pr` queues as a vPR (virtual PR) in `.git/PR_QUEUE`.
92+
- vPRs form a linear chain: each new vPR branches from the previous one.
93+
- Flush pushes ALL vPRs as a single atomic PR (no race conditions with other contributors).
94+
- Commands:
95+
- `./scripts/auto-pr list` — Show queued vPRs
96+
- `./scripts/auto-pr status` — Show queue status and next steps
97+
- `./scripts/auto-pr flush` — Push all vPRs as single PR
98+
- To add more changes while queue is non-empty:
99+
```bash
100+
tip=$(./scripts/auto-pr status | grep "Queue tip" | awk '{print $3}')
101+
git checkout -b author/feat/next-change "$tip"
102+
```
86103
- **Fixing Build:** If `dev` breaks, **revert first**, then fix.
87104
- **Fast Feedback:** During development, run only relevant tests (e.g., `pytest tests/test_cli.py`) to move fast.
88105

CONTRIBUTING.md

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ If you prefer manual control without installing CLI tools like `tea`:
2626
2. **Push via AGit:**
2727
```bash
2828
# Replace 'feature-branch' with your actual branch name
29-
git push origin HEAD:refs/for/main/feature-branch \
29+
git push origin HEAD:refs/for/dev/feature-branch \
3030
-o title="feat: description" \
3131
-o description="Extended details..."
3232
```
@@ -44,11 +44,13 @@ The `scripts/auto-pr` script automates the entire PR lifecycle: push, CI polling
4444

4545
### What it does
4646

47-
1. **Push** — Pushes your branch using Forgejo's AGit workflow (`refs/for/main/<branch>`)
47+
1. **Push** — Pushes your branch using Forgejo's AGit workflow (`refs/for/dev/<branch>`)
4848
2. **Create PR** — The push automatically creates a PR on Codeberg
4949
3. **Poll CI** — Waits for CI status checks to complete (polls every 10 seconds)
5050
4. **Merge** — Automatically merges when CI passes
51-
5. **Cleanup** — Switches back to `main`, pulls, and deletes the local feature branch
51+
5. **Cleanup** — Switches back to `dev`, pulls, and deletes the local feature branch
52+
53+
If the remote is unavailable (503 errors, network issues), the PR is **queued locally** and can be pushed later with `./scripts/auto-pr flush`.
5254

5355
### Requirements
5456

@@ -66,8 +68,8 @@ FORGEJO_TOKEN=your_token_here
6668
```
6769

6870
**Prerequisites:**
69-
- Must be on a feature branch (not `main`)
70-
- Branch must have commits ahead of `main`
71+
- Must be on a feature branch (not `main` or `dev`)
72+
- Branch must have commits ahead of `dev`
7173
- `python3`, `curl`, and `git` must be available
7274

7375
### Usage
@@ -81,6 +83,11 @@ FORGEJO_TOKEN=your_token_here
8183

8284
# Custom title and description
8385
./scripts/auto-pr "feat: add new feature" "Detailed description here"
86+
87+
# Queue management (when remote is unavailable)
88+
./scripts/auto-pr list # Show queued PRs
89+
./scripts/auto-pr flush # Push queued PRs when remote is back
90+
./scripts/auto-pr --help # Show all options
8491
```
8592

8693
### The PR_PENDING Gate (for AI agents)
@@ -97,18 +104,34 @@ The file is automatically removed when the PR is merged.
97104
### Workflow Example
98105

99106
```bash
100-
# 1. Make changes on main
101-
git add . && git commit -s -m "feat: my change"
107+
# 1. Start from dev
108+
git checkout dev && git pull
102109

103-
# 2. Create a feature branch (auto-pr requires this)
110+
# 2. Create a feature branch
104111
git checkout -b my-feature
105112

106-
# 3. Run auto-pr
113+
# 3. Make changes and commit
114+
git add . && git commit -s -m "feat: my change"
115+
116+
# 4. Run auto-pr
107117
./scripts/auto-pr
108118

109-
# 4. Script handles everything, you end up back on main with changes merged
119+
# 5. Script handles everything, you end up back on dev with changes merged
110120
```
111121

122+
### Offline Resilience (vPR Queue)
123+
124+
When Codeberg is unavailable, `auto-pr` automatically:
125+
1. Retries up to 3 times with 10-second delays
126+
2. If still failing, queues as a **vPR (virtual PR)** in `.git/PR_QUEUE`
127+
3. Exits cleanly so you can continue working
128+
129+
**vPR workflow:**
130+
- vPRs form a linear chain (each branches from the previous)
131+
- To add more changes: `git checkout -b new-branch $(./scripts/auto-pr status | grep tip | awk '{print $3}')`
132+
- When Codeberg is back: `./scripts/auto-pr flush`
133+
- Flush pushes ALL vPRs as a **single atomic PR** (individual commits preserved)
134+
112135
### Troubleshooting
113136

114137
| Error | Cause | Solution |
@@ -118,13 +141,14 @@ git checkout -b my-feature
118141
| `Could not find open PR` | API timing issue | Wait and retry, or check Codeberg UI |
119142
| `CI Failed` | Tests/linting failed | Fix issues, amend commit, re-run |
120143
| `Merge failed` | Conflicts or permissions | Check PR on Codeberg for details |
144+
| `PR queued locally` | Remote unavailable | Run `./scripts/auto-pr flush` when remote is back |
121145

122146
### How AGit Works
123147

124148
This script uses Forgejo's AGit flow, which creates PRs via specially-formatted push refs:
125149

126150
```bash
127-
git push origin HEAD:refs/for/main/<branch-name> -o title="..." -o description="..."
151+
git push origin HEAD:refs/for/dev/<branch-name> -o title="..." -o description="..."
128152
```
129153

130154
This is different from GitHub's flow where you push a branch and then create a PR separately. With AGit, the push *is* the PR creation.

0 commit comments

Comments
 (0)