Skip to content

Commit 9cc05cc

Browse files
fix(pr): prevent parallel main refreshes from colliding (#134014)
* fix: restore gateway recovery fixture lint and types Preserve the recovery coverage added in #134165 while using the actual WebSocket dependency and authored SecretRef fixture boundary. Co-authored-by: Shakker <[email protected]> * fix(pr): prevent parallel main refreshes from colliding * test(pr): observe private main refresh checkpoints * fix: authenticate CI checkout and lazy blob fetches * fix: prepare immutable reader history during CI checkout * fix(ci): declare historical reader selector entry point * test: include historical prerequisite in routing expectations * perf(anthropic): defer auth and catalog runtime imports Keep provider descriptors synchronous without importing credential stores, external auth discovery, or live catalog transport during registration. Load those implementations only when the existing asynchronous setup, doctor, usage, and catalog hooks need them. Expose the existing lightweight API-key descriptor factory through provider-entry while preserving the shipped auth SDK helpers and their synchronous contracts. The unchanged fresh-process registry proof retains its original timeout and verifies scoped failover without global activation. * test(ui): await agent menu lifecycle before keyboard navigation Wait for opening focus initialization and visible popup retirement before exercising selection and typing ownership. Preserve the existing focus, selected-agent, and composer assertions without changing product behavior or timeouts. * fix(ci): prepare Testbox against the checked-out merge base * docs(plugins): use public provider auth import in tutorial --------- Co-authored-by: Shakker <[email protected]>
1 parent 00d542d commit 9cc05cc

29 files changed

Lines changed: 1369 additions & 380 deletions

‎.github/actions/git-owner/owner.py‎

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import base64
2+
import json
13
import os
24
import re
35
import runpy
@@ -14,6 +16,7 @@
1416
cancelled = 0
1517
closed = False
1618
git = shutil.which("git")
19+
checkout_environment = {}
1720

1821

1922
def cancel(signum, _frame):
@@ -199,6 +202,23 @@ def scan_error(error):
199202
return locks
200203

201204

205+
def git_auth_environment(remote, token):
206+
# Git's promisor fetch inherits this process-only config from checkout.
207+
# Reject redirects: http.<url> matching does not re-scope redirected requests.
208+
count = int(os.environ.get("GIT_CONFIG_COUNT", "0"))
209+
if count < 0:
210+
raise ValueError("Invalid Git environment configuration count")
211+
header = f"http.{remote}.extraheader"
212+
authorization = base64.b64encode(f"x-access-token:{token}".encode()).decode()
213+
settings = [(header, ""), (header, f"AUTHORIZATION: basic {authorization}"),
214+
(f"http.{remote}.followRedirects", "false")]
215+
environment = {"GIT_CONFIG_COUNT": str(count + len(settings)), "GIT_TERMINAL_PROMPT": "0"}
216+
for index, (key, value) in enumerate(settings, count):
217+
environment[f"GIT_CONFIG_KEY_{index}"] = key
218+
environment[f"GIT_CONFIG_VALUE_{index}"] = value
219+
return environment
220+
221+
202222
def run_git(directory, *arguments, timeout=None, stdout=None, stderr=None, env=None,
203223
reclaim_locks=False):
204224
global closed
@@ -216,8 +236,10 @@ def run_git(directory, *arguments, timeout=None, stdout=None, stderr=None, env=N
216236
timed_out = False
217237
deadline = time.monotonic() + timeout if timeout is not None else None
218238
try:
239+
environment = ({**os.environ, **checkout_environment, **(env or {})}
240+
if checkout_environment or env is not None else None)
219241
options = {"stdin": subprocess.DEVNULL, "stdout": stdout, "stderr": stderr,
220-
"env": {**os.environ, **env} if env is not None else None}
242+
"env": environment}
221243
if os.name == "nt":
222244
job = create_job(None, None)
223245
limits = ExtendedLimits()
@@ -341,6 +363,14 @@ def fetch_ref(value):
341363

342364
def checkout():
343365
check_cancelled()
366+
prerequisites = json.loads(os.environ.get("CHECKOUT_GIT_COMMITS_JSON", "null")) if kind == "linux-node" else None
367+
if prerequisites is None:
368+
prerequisites = []
369+
if not isinstance(prerequisites, list) or any(
370+
not isinstance(commit, str) or not re.fullmatch("[0-9a-f]{40}", commit)
371+
for commit in prerequisites
372+
):
373+
raise ValueError("Invalid immutable test prerequisite commits")
344374
if reset:
345375
os.makedirs(workspace, exist_ok=True)
346376
# Every earlier Git group has been drained before deleting its workspace.
@@ -360,6 +390,9 @@ def checkout():
360390
base = os.environ.get("CHECKOUT_BASE_SHA") if kind == "linux-node" else None
361391
if base:
362392
refs.append(f"+{base}:refs/remotes/origin/ci-ratchet-base")
393+
# Fetch full reader objects with the authenticated checkout, before its
394+
# credential scope ends and test workers create historical worktrees.
395+
refs.extend(prerequisites)
363396
fetch(workspace, *refs, prune=True, max_attempts=1 if reset else 3,
364397
retry_codes=(124, 137) if kind == "skills" else ())
365398
run_git(workspace, "checkout", *(["--force"] if reset else []), "--detach",
@@ -422,29 +455,37 @@ def main():
422455
raise SystemExit(0)
423456
workspace = os.environ["GITHUB_WORKSPACE"]
424457
remote = f"https://github.com/{os.environ['CHECKOUT_REPO']}.git"
458+
# The workflow's token is repository-bound; never lend it to a sibling checkout.
459+
token = os.environ.pop("CHECKOUT_TOKEN", "")
460+
if token and os.environ["CHECKOUT_REPO"] == os.environ.get("GITHUB_REPOSITORY"):
461+
checkout_environment.update(git_auth_environment(remote, token))
462+
del token
425463
if kind == "clawhub":
426464
workspace = os.path.join(workspace, "clawhub-source")
427465
reset = kind in ("linux-node", "android", "clawhub")
428466
label = "ClawHub checkout" if kind == "clawhub" else "checkout"
429467
started_at = time.monotonic()
430-
for attempt in range(1, 6 if reset else 2):
431-
try:
432-
checkout()
433-
if reset:
434-
print(f"{label} attempt {attempt}/5 succeeded", flush=True)
435-
if kind == "clawhub":
436-
print(f"{label} completed in {int(time.monotonic() - started_at)}s", flush=True)
437-
raise SystemExit(0)
438-
except (FetchTimeout, GitFailure) as error:
439-
# Only command failures are retryable. Ownership/inspection errors
440-
# escape to the fail-closed boundary below, never workspace deletion.
441-
check_cancelled()
442-
if not reset:
443-
raise SystemExit(124 if isinstance(error, FetchTimeout) else error.code)
444-
print(f"{label} attempt {attempt}/5 failed", flush=True)
445-
backoff(attempt * 5)
446-
print(f"{label} failed after 5 attempts", file=sys.stderr)
447-
raise SystemExit(1)
468+
try:
469+
for attempt in range(1, 6 if reset else 2):
470+
try:
471+
checkout()
472+
if reset:
473+
print(f"{label} attempt {attempt}/5 succeeded", flush=True)
474+
if kind == "clawhub":
475+
print(f"{label} completed in {int(time.monotonic() - started_at)}s", flush=True)
476+
raise SystemExit(0)
477+
except (FetchTimeout, GitFailure) as error:
478+
# Only command failures are retryable. Ownership/inspection errors
479+
# escape to the fail-closed boundary below, never workspace deletion.
480+
check_cancelled()
481+
if not reset:
482+
raise SystemExit(124 if isinstance(error, FetchTimeout) else error.code)
483+
print(f"{label} attempt {attempt}/5 failed", flush=True)
484+
backoff(attempt * 5)
485+
print(f"{label} failed after 5 attempts", file=sys.stderr)
486+
raise SystemExit(1)
487+
finally:
488+
checkout_environment.clear()
448489

449490

450491
if __name__ == "__main__":
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"outboundMessageTerminalReader": {
3+
"commit": "5dc4cf602bc5e263e83cd16a12bb1e100544f4c3",
4+
"file": "src/audit/message-delivery-progress-store.test.ts",
5+
"configs": [
6+
"test/vitest/vitest.unit-src.config.ts",
7+
"test/vitest/vitest.full-core-unit-src.config.ts"
8+
]
9+
}
10+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { existsSync } from "node:fs";
2+
import { matchesGlob } from "node:path";
3+
import prerequisites from "./test-prerequisites.json" with { type: "json" };
4+
5+
// The trusted workflow owns immutable history; selected targets only decide
6+
// which readers run. Do not make credential-free test workers fetch it later.
7+
export function resolveTestGitCommits(shard) {
8+
const plans = shard.groups ?? [shard];
9+
return Object.values(prerequisites)
10+
.filter(
11+
({ file, configs }) =>
12+
existsSync(file) &&
13+
plans.some((plan) => {
14+
const patterns = plan.targets ?? plan.includePatterns;
15+
return patterns
16+
? patterns.some((pattern) => matchesGlob(file, pattern))
17+
: plan.configs?.some((config) => configs.includes(config));
18+
}),
19+
)
20+
.map(({ commit }) => commit);
21+
}

‎.github/workflows/ci-build-artifacts-testbox.yml‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,26 @@ jobs:
155155
packages/*/dist/
156156
key: ${{ runner.os }}-dist-build-v2-${{ github.sha }}
157157

158+
- name: Resolve PR Testbox base
159+
if: github.event_name == 'pull_request'
160+
id: testbox-base
161+
shell: bash
162+
env:
163+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
164+
run: |
165+
# The shallow merge checkout already contains its actual base parent.
166+
base="$(node scripts/lib/merge-head-diff-base.mjs --base "$BASE_SHA" --head HEAD --prefer-first-parent)"
167+
echo "sha=$base" >> "$GITHUB_OUTPUT"
158168
- name: Ensure Testbox base commit
159169
if: github.event_name == 'pull_request'
160170
uses: ./.github/actions/ensure-base-commit
161171
with:
162-
base-sha: ${{ github.event.pull_request.base.sha }}
172+
base-sha: ${{ steps.testbox-base.outputs.sha }}
163173
fetch-ref: ${{ github.event.pull_request.base.ref }}
164174
- name: Prepare Testbox shell
165175
uses: ./.github/actions/prepare-testbox-shell
166176
with:
167-
base-ref: ${{ github.event.pull_request.base.sha || 'refs/remotes/origin/main' }}
177+
base-ref: ${{ steps.testbox-base.outputs.sha || 'refs/remotes/origin/main' }}
168178

169179
- name: Hydrate Testbox provider env helper
170180
shell: bash

‎.github/workflows/ci-check-arm-testbox.yml‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,16 +62,26 @@ jobs:
6262
cache-mode: restore
6363
install-bun: "false"
6464
install-trufflehog: "true"
65+
- name: Resolve PR Testbox base
66+
if: github.event_name == 'pull_request'
67+
id: testbox-base
68+
shell: bash
69+
env:
70+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
71+
run: |
72+
# The shallow merge checkout already contains its actual base parent.
73+
base="$(node scripts/lib/merge-head-diff-base.mjs --base "$BASE_SHA" --head HEAD --prefer-first-parent)"
74+
echo "sha=$base" >> "$GITHUB_OUTPUT"
6575
- name: Ensure Testbox base commit
6676
if: github.event_name == 'pull_request'
6777
uses: ./.github/actions/ensure-base-commit
6878
with:
69-
base-sha: ${{ github.event.pull_request.base.sha }}
79+
base-sha: ${{ steps.testbox-base.outputs.sha }}
7080
fetch-ref: ${{ github.event.pull_request.base.ref }}
7181
- name: Prepare Testbox shell
7282
uses: ./.github/actions/prepare-testbox-shell
7383
with:
74-
base-ref: ${{ github.event.pull_request.base.sha || 'refs/remotes/origin/main' }}
84+
base-ref: ${{ steps.testbox-base.outputs.sha || 'refs/remotes/origin/main' }}
7585

7686
- name: Hydrate Testbox provider env helper
7787
shell: bash

‎.github/workflows/ci-check-testbox.yml‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,26 @@ jobs:
5757
install-trufflehog: "true"
5858
# Testbox hydration uses the ordinary pnpm store cache. Canonical CI
5959
# owns the exact dependency archive and never delegates here.
60+
- name: Resolve PR Testbox base
61+
if: github.event_name == 'pull_request'
62+
id: testbox-base
63+
shell: bash
64+
env:
65+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
66+
run: |
67+
# The shallow merge checkout already contains its actual base parent.
68+
base="$(node scripts/lib/merge-head-diff-base.mjs --base "$BASE_SHA" --head HEAD --prefer-first-parent)"
69+
echo "sha=$base" >> "$GITHUB_OUTPUT"
6070
- name: Ensure Testbox base commit
6171
if: github.event_name == 'pull_request'
6272
uses: ./.github/actions/ensure-base-commit
6373
with:
64-
base-sha: ${{ github.event.pull_request.base.sha }}
74+
base-sha: ${{ steps.testbox-base.outputs.sha }}
6575
fetch-ref: ${{ github.event.pull_request.base.ref }}
6676
- name: Prepare Testbox shell
6777
uses: ./.github/actions/prepare-testbox-shell
6878
with:
69-
base-ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.sha || 'HEAD' }}
79+
base-ref: ${{ steps.testbox-base.outputs.sha || 'HEAD' }}
7080

7181
- name: Hydrate Testbox provider env helper
7282
shell: bash

0 commit comments

Comments
 (0)