mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-01 18:07:00 +01:00
Speed up GitHub setup verification and clear stale ping waits
This commit is contained in:
1 parent
d2f5a7832f
commit
454e6b1c64
5 files changed
+160
-39
No files matched your search
@@ -183,6 +183,34 @@ GitHub signature verification, and deduplication across push and polling.
|
||||
Localhost and self-hosted instances can continue using outbound polling.
|
||||
This is a deferred improvement; do not implement it in the current setup work.
|
||||
|
||||
## Live setup finding: slow repository verification (2026-10-08)
|
||||
|
||||
The personal-account Animal Bot Man setup received a verified signed ping at
|
||||
10:31:10 UTC. Its wizard still showed the previous ping-wait response while
|
||||
connection verification checked 86 enabled repositories, once in progress and
|
||||
again under the credential lease before activation. The next setup response
|
||||
completed at 10:32:03 UTC; missing HTTPS was not the cause.
|
||||
|
||||
Verify explicit enabled repository IDs in batches within GitHub's 500-ID limit,
|
||||
preserving the final check under the activation lease. Never request an unscoped
|
||||
token or pass these verification tokens to agents. A failed batch remains
|
||||
unverified. As soon as endpoint polling observes signed delivery, replace the
|
||||
old ping-wait message with App/repository verification progress. Keep the same
|
||||
App, vault, agent, and GitHub-selected repository access.
|
||||
|
||||
Focused tests cover 86- and 501-repository verification, disabled selections,
|
||||
revoked access, and the UI receipt arriving ahead of a full progress response.
|
||||
The existing draft reached connected without a new App or credential entry.
|
||||
After restarting the preserved test drive with the fix, this same App's full
|
||||
progress verification returned connected in 2.74 seconds, with all 86 repository
|
||||
checks passing and the configuration still at revision 1. Server/UI typecheck
|
||||
and builds, 24 focused backend tests, 19 wizard UI tests, and token gates pass.
|
||||
Connection completion remains separate from proving a model or review run.
|
||||
|
||||
[GitHub's installation-token documentation](https://docs.github.com/en/apps/creating-github-apps/authenticating-with-a-github-app/generating-an-installation-access-token-for-a-github-app)
|
||||
specifies the 500-repository limit and prohibits granting access beyond the
|
||||
installation's authorized repositories.
|
||||
|
||||
## Prior findings retained
|
||||
|
||||
Earlier setup research found repeated interviews, missing manager APIs, tunnel
|
||||
|
||||
@@ -3497,6 +3497,49 @@ describeEmbeddedPostgres("chat channel control-plane integration", () => {
|
||||
detail: expect.stringContaining("Restore installation access"),
|
||||
});
|
||||
});
|
||||
it.each([86, 501])("verifies %i enabled repositories in bounded token batches", async (count) => {
|
||||
const f = await reviewBotFixture();
|
||||
const permissions = { contents: "read", issues: "write", metadata: "read", pull_requests: "write", checks: "write" };
|
||||
f.setAppAccess({ permissions, events: ["pull_request", "issue_comment", "pull_request_review_comment"] });
|
||||
const [first] = await db.select().from(chatEndpointResources)
|
||||
.where(eq(chatEndpointResources.endpointId, f.endpoint.id));
|
||||
const ids = [Number(first.metadata!.providerRepositoryId)];
|
||||
await db.insert(chatEndpointResources).values(Array.from({ length: count - 1 }, (_, index) => {
|
||||
const repositoryId = 100_000 + index;
|
||||
ids.push(repositoryId);
|
||||
return { ...first, id: randomUUID(), providerResourceId: `paperclipai/repo-${index}`,
|
||||
label: `paperclipai/repo-${index}`, enabled: true, availability: "available" as const,
|
||||
metadata: { ...first.metadata, providerRepositoryId: repositoryId } };
|
||||
}));
|
||||
// A saved narrower selection must never be included just because it is
|
||||
// present in the installation inventory.
|
||||
await db.insert(chatEndpointResources).values({ ...first, id: randomUUID(),
|
||||
providerResourceId: "paperclipai/disabled", label: "paperclipai/disabled", enabled: false,
|
||||
metadata: { ...first.metadata, providerRepositoryId: 999_999 } });
|
||||
const batches: number[][] = [];
|
||||
let revoked = false;
|
||||
f.setSupplementalProviderFetch(async (input, init) => {
|
||||
if (String(input).endsWith("/app/installations/2468"))
|
||||
return Response.json({ permissions, suspended_at: null });
|
||||
if (String(input).endsWith("/access_tokens")) {
|
||||
const body = JSON.parse(String(init?.body));
|
||||
expect(body.permissions).toEqual(permissions);
|
||||
expect(body.repository_ids.length).toBeGreaterThan(0);
|
||||
expect(body.repository_ids.length).toBeLessThanOrEqual(500);
|
||||
batches.push(body.repository_ids);
|
||||
return revoked ? new Response("", { status: 403 }) : Response.json({ token: "test-installation-token" });
|
||||
}
|
||||
return undefined;
|
||||
});
|
||||
const verified = await f.management.verification(f.endpoint.id);
|
||||
expect(verified.checks.find((check) => check.key === "repositories")?.ok).toBe(true);
|
||||
expect(batches).toHaveLength(Math.ceil(count / 500));
|
||||
expect(batches.flat().sort((a, b) => a - b)).toEqual(ids.sort((a, b) => a - b));
|
||||
revoked = true;
|
||||
const denied = await f.management.verification(f.endpoint.id);
|
||||
expect(denied.connectionReady).toBe(false);
|
||||
expect(denied.checks.find((check) => check.key === "repositories")?.ok).toBe(false);
|
||||
});
|
||||
it("requires every essential GitHub tool and rejects Contents write during verification", async () => {
|
||||
const f = await reviewBotFixture();
|
||||
let contents = "read";
|
||||
|
||||
@@ -423,44 +423,52 @@ export function githubChatManagementService(db: Db, fetchImpl = fetch) {
|
||||
const inaccessible: string[] = [];
|
||||
// Ask GitHub to authorize the selected repository IDs now. A cached
|
||||
// inventory alone cannot prove access after an installation is changed.
|
||||
for (let offset = 0; offset < resources.length; offset += 4) {
|
||||
await Promise.all(
|
||||
resources.slice(offset, offset + 4).map(async (resource) => {
|
||||
const repositoryId = String(
|
||||
resource.metadata?.providerRepositoryId ?? "",
|
||||
);
|
||||
try {
|
||||
if (
|
||||
!permissionsOk ||
|
||||
resource.availability !== "available" ||
|
||||
!/^[1-9][0-9]*$/.test(repositoryId) ||
|
||||
!Number.isSafeInteger(Number(repositoryId))
|
||||
)
|
||||
throw new Error("Unavailable repository");
|
||||
const issued = await githubBotRequest<{ token?: string }>(
|
||||
fetchImpl,
|
||||
credentials.appJwt,
|
||||
`/app/installations/${credentials.credentials.installationId}/access_tokens`,
|
||||
{
|
||||
method: "POST",
|
||||
body: {
|
||||
repository_ids: [Number(repositoryId)],
|
||||
permissions: {
|
||||
contents: "read",
|
||||
metadata: "read",
|
||||
issues: "write",
|
||||
pull_requests: "write",
|
||||
checks: "write",
|
||||
},
|
||||
},
|
||||
const verifiable = resources.filter((resource) => {
|
||||
const repositoryId = String(resource.metadata?.providerRepositoryId ?? "");
|
||||
if (
|
||||
!permissionsOk ||
|
||||
resource.availability !== "available" ||
|
||||
!/^[1-9][0-9]*$/.test(repositoryId) ||
|
||||
!Number.isSafeInteger(Number(repositoryId))
|
||||
) {
|
||||
inaccessible.push(resource.label ?? resource.providerResourceId);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
// GitHub authorizes up to 500 explicit IDs in one scoped token request.
|
||||
// Keep these tokens inside verification; task credentials remain scoped
|
||||
// separately. Never omit repository_ids, which would request all access.
|
||||
for (let offset = 0; offset < verifiable.length; offset += 500) {
|
||||
const batch = verifiable.slice(offset, offset + 500);
|
||||
try {
|
||||
const issued = await githubBotRequest<{ token?: string }>(
|
||||
fetchImpl,
|
||||
credentials.appJwt,
|
||||
`/app/installations/${credentials.credentials.installationId}/access_tokens`,
|
||||
{
|
||||
method: "POST",
|
||||
body: {
|
||||
repository_ids: batch.map((resource) =>
|
||||
Number(resource.metadata!.providerRepositoryId),
|
||||
),
|
||||
permissions: {
|
||||
contents: "read",
|
||||
metadata: "read",
|
||||
issues: "write",
|
||||
pull_requests: "write",
|
||||
checks: "write",
|
||||
},
|
||||
);
|
||||
if (!issued.token) throw new Error("Missing installation token");
|
||||
} catch {
|
||||
inaccessible.push(resource.label ?? resource.providerResourceId);
|
||||
}
|
||||
}),
|
||||
);
|
||||
},
|
||||
},
|
||||
);
|
||||
if (!issued.token) throw new Error("Missing installation token");
|
||||
} catch {
|
||||
// A rejected batch is unverified; do not activate from cached access.
|
||||
inaccessible.push(
|
||||
...batch.map((resource) => resource.label ?? resource.providerResourceId),
|
||||
);
|
||||
}
|
||||
}
|
||||
checks.push({
|
||||
key: "repositories",
|
||||
|
||||
@@ -207,6 +207,36 @@ describe("GitHub App wizard", () => {
|
||||
expect(container.textContent).toContain("continue automatically");
|
||||
expect(githubChatApi.registration).not.toHaveBeenCalled();
|
||||
});
|
||||
it("replaces a stale ping wait as soon as signed delivery arrives", async () => {
|
||||
vi.mocked(githubChatApi.advance).mockResolvedValue({
|
||||
endpointId: "draft-1",
|
||||
state: "verify",
|
||||
message: "Waiting for GitHub to verify webhook delivery…",
|
||||
verification: {
|
||||
ready: false,
|
||||
checks: [{ key: "webhook", label: "Signed delivery", ok: false,
|
||||
detail: "Keep this page open until the signed ping arrives." }],
|
||||
},
|
||||
});
|
||||
await render("resume=draft-1");
|
||||
expect(container.textContent).toContain("Waiting for GitHub");
|
||||
// Endpoint polling observes the receipt while full access verification is
|
||||
// still in flight. The previous progress response must not mislead users.
|
||||
await act(async () => {
|
||||
client.setQueryData(["github-setup", "draft-1"], {
|
||||
...fixture.endpoint,
|
||||
setup: { ...fixture.endpoint.setup, webhookVerifiedAt: "2026-10-08T10:31:10Z" },
|
||||
});
|
||||
});
|
||||
await settle();
|
||||
expect(container.querySelector('[role="status"]')?.textContent).toContain(
|
||||
"GitHub delivery verified. Checking App and repository access",
|
||||
);
|
||||
expect(container.textContent).not.toContain("Waiting for GitHub");
|
||||
expect(container.textContent).not.toContain("until the signed ping arrives");
|
||||
expect(container.textContent).not.toContain("GitHub connected");
|
||||
expect(githubChatApi.registration).not.toHaveBeenCalled();
|
||||
});
|
||||
it("reconnects the same App using vaulted credentials without requiring another paste", async () => {
|
||||
fixture.endpoint.status = "attention";
|
||||
fixture.endpoint.botExternalId = "1234";
|
||||
|
||||
@@ -137,6 +137,12 @@ export function GitHubChatSetup() {
|
||||
(agent) => agent.id === (bot?.assignedAgentId ?? agentId),
|
||||
);
|
||||
const state = identityOnly ? undefined : progress.data;
|
||||
const deliveryVerifiedWhileChecking =
|
||||
state?.state === "verify" &&
|
||||
!!bot?.setup?.webhookVerifiedAt &&
|
||||
state.verification?.checks.some(
|
||||
(check) => !check.ok && ["webhook", "delivery"].includes(check.key),
|
||||
);
|
||||
const existingIdentityMethod =
|
||||
identityOnly || state?.identityMethod === "existing_connection";
|
||||
const connected = state?.state === "connected" && !existing;
|
||||
@@ -604,10 +610,16 @@ export function GitHubChatSetup() {
|
||||
) : state?.state === "verify" ? (
|
||||
<>
|
||||
<p role="status" className="text-sm text-muted-foreground">
|
||||
{state.message ?? "Checking GitHub access…"}
|
||||
{deliveryVerifiedWhileChecking
|
||||
? "GitHub delivery verified. Checking App and repository access…"
|
||||
: state.message ?? "Checking GitHub access…"}
|
||||
</p>
|
||||
{state.verification?.checks
|
||||
.filter((check) => !check.ok)
|
||||
.filter(
|
||||
(check) =>
|
||||
!check.ok &&
|
||||
!(deliveryVerifiedWhileChecking && ["webhook", "delivery"].includes(check.key)),
|
||||
)
|
||||
.map((check) => (
|
||||
<p key={check.key} className="text-sm">
|
||||
{check.detail}
|
||||
|
||||
Reference in new issue
Block a user