mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
fix(onboarding): start an agent-targeted sign-in only on a settled, prepared draft (#23383)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Onboarding signs the first agent in to Claude or Codex through a plugin-managed execution environment that is prepared for the agent (#23312) > - Each change to the setup draft, such as switching between Claude and OpenAI, makes Core prepare the environment again before it accepts a sign-in > - The wizard remembered that the environment had been prepared once, so it started the new sign-in during that preparation > - Core refused it with `login_agent_unavailable`, and the sign-in card showed only "Sign-in didn't finish" > - This pull request starts a sign-in only when the draft has settled on the current choice and is prepared, and shows Core's error on the card > - The benefit is that switching the sign-in source works, without an added wait ## Linked Issues or Issue Description Refs #23312 and #23315. **What happened?** In onboarding with a plugin-managed execution environment as the default, a user picked Claude, then switched to OpenAI. Every sign-in start after the switch returned `400 login_agent_unavailable`: Core refused the agent as the sign-in target. The card showed "Sign-in didn't finish. Try signing in again." **What did you expect to happen?** The OpenAI sign-in starts as soon as the environment is prepared for the new choice. **Steps to reproduce** 1. Make a plugin-managed execution environment that prepares an environment per agent the instance default. 2. Start onboarding, name the agent, and choose Claude with a subscription. 3. When the Claude sign-in shows, choose OpenAI. 4. See the sign-in fail with the message above. ## What Changed - The sign-in readiness hook takes `settled` and `holdKey`. A sign-in starts only when the agent has settled on the current choice and the environment is prepared for it. Readiness is held per agent, environment and sign-in source, so a source switch waits for the real preparation, and a sign-in already on screen stays on screen. - Onboarding treats the setup draft as settled when its saved harness (and model, when one is set) matches the selection. Each draft save puts the saved agent in the query cache at once, and readiness polls every 500 ms instead of every second. - The new-agent flow treats its draft as settled when no environment save is in flight, and polls a preparing draft every 500 ms. - Both sign-in panels show Core's start error for any sign-in that targets an agent, not only for one that Core selects automatically. ## Verification - `pnpm typecheck` in `ui/`: no errors. - The sign-in readiness helper and hook suites, the `AgentProviderConnection` suites and the `AgentConfigForm` render suite in `ui/`: 23 tests pass. A new hook test covers a switch from Claude to OpenAI and back while the environment is prepared again. - `PAPERCLIP_PLAYWRIGHT_CHANNEL=chrome npx playwright test --config tests/e2e/playwright.config.ts tests/e2e/onboarding-early-setup.spec.ts tests/e2e/onboarding.spec.ts -g "naming step creates|create-company path"`: 2 tests pass. - I reproduced the failure on a staging instance from the network log. I did not repeat the sign-in on a staging instance with this change. ## Risks - A change to the draft after a sign-in started can still make Core refuse the login lease when it acquires it. The card then shows Core's error and the usual retry. - Readiness polling is now twice as frequent while an environment is prepared. It stops when the environment is ready. - No migration and no API change. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), with extended thinking and tool use (code search, shell, tests, browser network inspection) in Claude Code. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [x] All Paperclip CI gates are green - [x] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
37da976b8c
commit
51541be36f
5 files changed
+42
-14
No files matched your search
@@ -3296,7 +3296,7 @@ function DisplayedCodeLoginPanel({
|
|||||||
<ProviderSubscriptionCard
|
<ProviderSubscriptionCard
|
||||||
loading={retryLogin.isPending || (!prompt && !failure)}
|
loading={retryLogin.isPending || (!prompt && !failure)}
|
||||||
failure={failure}
|
failure={failure}
|
||||||
failureMessage={automaticComputer ? startError ?? undefined : undefined}
|
failureMessage={requiresAgent ? startError ?? undefined : undefined}
|
||||||
onRetry={!onRetryReady && retryReady ? retryAction : undefined}
|
onRetry={!onRetryReady && retryReady ? retryAction : undefined}
|
||||||
onRefresh={!retryLogin.isPending && !startLogin.isPending ? retryAction : undefined}
|
onRefresh={!retryLogin.isPending && !startLogin.isPending ? retryAction : undefined}
|
||||||
providerName={connectSourceName(adapterType)}
|
providerName={connectSourceName(adapterType)}
|
||||||
@@ -4138,8 +4138,8 @@ function SubmittedBrowserCodeLoginPanel({
|
|||||||
const failure = !retryLogin.isPending && onboardingFailed
|
const failure = !retryLogin.isPending && onboardingFailed
|
||||||
? timedOut || status === "timed_out" ? "expired" : "failed"
|
? timedOut || status === "timed_out" ? "expired" : "failed"
|
||||||
: undefined;
|
: undefined;
|
||||||
const onboardingFailureMessage = automaticComputer
|
const onboardingFailureMessage = requiresAgent && startError
|
||||||
? startError ?? undefined
|
? startError
|
||||||
: submittedAttemptFailed && failure === "failed"
|
: submittedAttemptFailed && failure === "failed"
|
||||||
? "That code wasn’t accepted. Copy the full code from Claude (including any # part) or retry sign-in."
|
? "That code wasn’t accepted. Copy the full code from Claude (including any # part) or retry sign-in."
|
||||||
: undefined;
|
: undefined;
|
||||||
|
|||||||
@@ -1166,6 +1166,9 @@ function OnboardingWizardInner({
|
|||||||
loginProviderSupportsPty,
|
loginProviderSupportsPty,
|
||||||
);
|
);
|
||||||
const loginRequiresAgent = canShowAdapterLogin && environmentLoginRequiresAgent(resolvedLoginEnvironment);
|
const loginRequiresAgent = canShowAdapterLogin && environmentLoginRequiresAgent(resolvedLoginEnvironment);
|
||||||
|
const agentSettledOnChoice = (agent: Pick<Agent, "adapterType" | "adapterConfig">) =>
|
||||||
|
agentHarnessType(agent.adapterType, agent.adapterConfig) === adapterType
|
||||||
|
&& (!model.trim() || agent.adapterConfig?.model === model.trim());
|
||||||
const loginAgentId = createdAgentId ?? setupAgentId;
|
const loginAgentId = createdAgentId ?? setupAgentId;
|
||||||
const loginAgentQuery = useQuery({
|
const loginAgentQuery = useQuery({
|
||||||
queryKey: queryKeys.agents.detail(loginAgentId ?? "none"),
|
queryKey: queryKeys.agents.detail(loginAgentId ?? "none"),
|
||||||
@@ -1176,16 +1179,20 @@ function OnboardingWizardInner({
|
|||||||
const agent = query.state.data;
|
const agent = query.state.data;
|
||||||
if (query.state.status === "error") return false;
|
if (query.state.status === "error") return false;
|
||||||
const instanceDefault = instanceSettingsForLogin?.defaultEnvironmentId ?? null;
|
const instanceDefault = instanceSettingsForLogin?.defaultEnvironmentId ?? null;
|
||||||
return agent && (agent.lifecycleError || agentComputerHostsLogin(agent, resolvedLoginEnvironmentId, instanceDefault)
|
return agent && (agent.lifecycleError || (agentSettledOnChoice(agent)
|
||||||
|| agentComputerAwaitsHire(agent, resolvedLoginEnvironmentId, instanceDefault)) ? false : 1000;
|
&& (agentComputerHostsLogin(agent, resolvedLoginEnvironmentId, instanceDefault)
|
||||||
|
|| agentComputerAwaitsHire(agent, resolvedLoginEnvironmentId, instanceDefault)))) ? false : 500;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const loginAgent = loginAgentQuery.data?.id === loginAgentId ? loginAgentQuery.data : null;
|
const loginAgent = loginAgentQuery.data?.id === loginAgentId ? loginAgentQuery.data : null;
|
||||||
|
const loginAgentSettled = Boolean(loginAgent && agentSettledOnChoice(loginAgent));
|
||||||
const loginComputer = useAgentComputerLogin({
|
const loginComputer = useAgentComputerLogin({
|
||||||
required: loginRequiresAgent,
|
required: loginRequiresAgent,
|
||||||
agent: loginAgent,
|
agent: loginAgent,
|
||||||
environmentId: resolvedLoginEnvironmentId,
|
environmentId: resolvedLoginEnvironmentId,
|
||||||
instanceDefaultEnvironmentId: instanceSettingsForLogin?.defaultEnvironmentId ?? null,
|
instanceDefaultEnvironmentId: instanceSettingsForLogin?.defaultEnvironmentId ?? null,
|
||||||
|
settled: loginAgentSettled,
|
||||||
|
holdKey: adapterType,
|
||||||
});
|
});
|
||||||
const loginComputerReady = loginComputer.ready;
|
const loginComputerReady = loginComputer.ready;
|
||||||
const loginOnOwnComputer = loginRequiresAgent && loginComputer.ownComputer;
|
const loginOnOwnComputer = loginRequiresAgent && loginComputer.ownComputer;
|
||||||
@@ -2352,7 +2359,10 @@ function OnboardingWizardInner({
|
|||||||
const save = () => {
|
const save = () => {
|
||||||
setupSave.current = setupSave.current.catch(() => {}).then(async () => {
|
setupSave.current = setupSave.current.catch(() => {}).then(async () => {
|
||||||
if (!stillTheSameCompany(companyId) || hiringAgentRef.current !== null) return;
|
if (!stillTheSameCompany(companyId) || hiringAgentRef.current !== null) return;
|
||||||
await agentsApi.update(id, JSON.parse(setupSnapshot), companyId);
|
const saved = await agentsApi.update(id, JSON.parse(setupSnapshot), companyId);
|
||||||
|
if (!stillTheSameCompany(companyId)) return;
|
||||||
|
await queryClient.cancelQueries({ queryKey: queryKeys.agents.detail(id) });
|
||||||
|
queryClient.setQueryData(queryKeys.agents.detail(id), saved);
|
||||||
});
|
});
|
||||||
void setupSave.current.catch(cause => {
|
void setupSave.current.catch(cause => {
|
||||||
if (stillTheSameCompany(companyId)) setError(cause instanceof Error ? cause.message : "Could not save agent setup.");
|
if (stillTheSameCompany(companyId)) setError(cause instanceof Error ? cause.message : "Could not save agent setup.");
|
||||||
|
|||||||
@@ -214,7 +214,7 @@ function Setup({
|
|||||||
const agent = query.state.data;
|
const agent = query.state.data;
|
||||||
if (!agent || agent.lifecycleError) return false;
|
if (!agent || agent.lifecycleError) return false;
|
||||||
return (agent.pauseReason === "setup" && ["preparing", "pausing"].includes(agent.lifecycleState ?? ""))
|
return (agent.pauseReason === "setup" && ["preparing", "pausing"].includes(agent.lifecycleState ?? ""))
|
||||||
|| (screen === "saved" && !isDot && ["preparing", "verifying", "resuming", "pausing"].includes(agent.lifecycleState ?? "")) ? 1000 : false;
|
|| (screen === "saved" && !isDot && ["preparing", "verifying", "resuming", "pausing"].includes(agent.lifecycleState ?? "")) ? 500 : false;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const created =
|
const created =
|
||||||
@@ -378,6 +378,8 @@ function Setup({
|
|||||||
agent: created,
|
agent: created,
|
||||||
environmentId,
|
environmentId,
|
||||||
instanceDefaultEnvironmentId: settings.data?.defaultEnvironmentId ?? null,
|
instanceDefaultEnvironmentId: settings.data?.defaultEnvironmentId ?? null,
|
||||||
|
settled: !environmentSaving,
|
||||||
|
holdKey: connectionAdapter ?? adapterType,
|
||||||
});
|
});
|
||||||
const envKey =
|
const envKey =
|
||||||
isKimi ? "KIMI_API_KEY" : SETUP_CREDENTIAL_KEYS[adapterType] ?? providerKeys[provider] ?? "API_KEY";
|
isKimi ? "KIMI_API_KEY" : SETUP_CREDENTIAL_KEYS[adapterType] ?? providerKeys[provider] ?? "API_KEY";
|
||||||
|
|||||||
@@ -23,8 +23,9 @@ function Probe(props: Parameters<typeof useAgentComputerLogin>[0]) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function render(agent: Agent) {
|
function render(agent: Agent, { settled = true, holdKey = "claude_local" } = {}) {
|
||||||
flushSync(() => root.render(<Probe required agent={agent} environmentId={computer} instanceDefaultEnvironmentId={null} />));
|
flushSync(() => root.render(<Probe required agent={agent} environmentId={computer} instanceDefaultEnvironmentId={null}
|
||||||
|
settled={settled} holdKey={holdKey} />));
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -51,6 +52,19 @@ describe("useAgentComputerLogin", () => {
|
|||||||
expect(login).toEqual({ ready: false, ownComputer: false });
|
expect(login).toEqual({ ready: false, ownComputer: false });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("waits for the draft to settle on a newly chosen source before starting another sign-in", () => {
|
||||||
|
render(draft("verifying"));
|
||||||
|
expect(login).toEqual({ ready: true, ownComputer: true });
|
||||||
|
render(draft("verifying"), { settled: false, holdKey: "codex_local" });
|
||||||
|
expect(login).toEqual({ ready: false, ownComputer: false });
|
||||||
|
render(draft("preparing"), { holdKey: "codex_local" });
|
||||||
|
expect(login).toEqual({ ready: false, ownComputer: false });
|
||||||
|
render(draft("preparing"), { holdKey: "claude_local" });
|
||||||
|
expect(login).toEqual({ ready: false, ownComputer: false });
|
||||||
|
render(draft("verifying"), { holdKey: "claude_local" });
|
||||||
|
expect(login).toEqual({ ready: true, ownComputer: true });
|
||||||
|
});
|
||||||
|
|
||||||
it("does not wait for a draft held until its hire is approved", () => {
|
it("does not wait for a draft held until its hire is approved", () => {
|
||||||
render(draft("paused"));
|
render(draft("paused"));
|
||||||
expect(login).toEqual({ ready: true, ownComputer: false });
|
expect(login).toEqual({ ready: true, ownComputer: false });
|
||||||
|
|||||||
@@ -36,16 +36,18 @@ export function useAgentComputerLogin(input: {
|
|||||||
agent: LoginComputerAgent | null | undefined;
|
agent: LoginComputerAgent | null | undefined;
|
||||||
environmentId: string | null;
|
environmentId: string | null;
|
||||||
instanceDefaultEnvironmentId: string | null;
|
instanceDefaultEnvironmentId: string | null;
|
||||||
|
settled: boolean;
|
||||||
|
holdKey: string;
|
||||||
}): { ready: boolean; ownComputer: boolean } {
|
}): { ready: boolean; ownComputer: boolean } {
|
||||||
const { required, agent, environmentId, instanceDefaultEnvironmentId } = input;
|
const { required, agent, environmentId, instanceDefaultEnvironmentId, settled, holdKey } = input;
|
||||||
const hosts = Boolean(required && agent && agentComputerHostsLogin(agent, environmentId, instanceDefaultEnvironmentId));
|
const hosts = Boolean(required && agent && settled && agentComputerHostsLogin(agent, environmentId, instanceDefaultEnvironmentId));
|
||||||
const key = required && agent ? JSON.stringify([agent.id, environmentId]) : null;
|
const key = required && agent ? JSON.stringify([agent.id, environmentId, holdKey]) : null;
|
||||||
const [prepared, setPrepared] = useState<string | null>(null);
|
const [prepared, setPrepared] = useState<string | null>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (hosts && key) setPrepared(key);
|
setPrepared(current => current === key ? current : hosts && key ? key : null);
|
||||||
}, [hosts, key]);
|
}, [hosts, key]);
|
||||||
if (!required) return { ready: true, ownComputer: false };
|
if (!required) return { ready: true, ownComputer: false };
|
||||||
if (hosts || (key !== null && prepared === key)) return { ready: true, ownComputer: true };
|
if (hosts || (key !== null && prepared === key)) return { ready: true, ownComputer: true };
|
||||||
if (agent && agentComputerAwaitsHire(agent, environmentId, instanceDefaultEnvironmentId)) return { ready: true, ownComputer: false };
|
if (agent && settled && agentComputerAwaitsHire(agent, environmentId, instanceDefaultEnvironmentId)) return { ready: true, ownComputer: false };
|
||||||
return { ready: false, ownComputer: false };
|
return { ready: false, ownComputer: false };
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user