mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-04 04:29:01 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - In the `free_inference_1` onboarding flow, `OnboardingWizard` skips
Step 4 ("Connect a model") and hires the first agent directly on starter
inference when the user submits Step 3.
> - However, Step 3's early-setup effect still auto-created a
provisional `General` draft agent (`pauseReason: "setup"`, `adapterType:
"process"`) as soon as Step 3 mounted, even though Step 4 login is never
used in `free_inference_1`.
> - If the user reloaded or navigated to the Dashboard before submitting
Step 3, that orphaned `pauseReason: "setup"` draft prevented onboarding
from re-opening and caused `Dashboard.tsx` to show "All agents in this
organization are paused — nothing will run."
> - This pull request skips Step 3 early-setup draft creation while
`free_inference_1` is active (or while the onboarding variant/status
queries are still pending) and filters out unfinished `pauseReason:
"setup"` drafts and terminated agents in
`Dashboard.derivePausedAgentBanner` and `hasNoAgents`.
> - The benefit is a clean `free_inference_1` onboarding experience with
no orphaned paused drafts and accurate Dashboard empty-state banners.
## Linked Issues or Issue Description
**Subsystem affected**
`ui/` — React + Vite board UI
**Problem or motivation**
When a Cloud workspace is assigned to `free_inference_1`, opening Step 3
of `OnboardingWizard` immediately created an unfinished `General` draft
agent (`pauseReason: "setup"`, `adapterType: "process"`) meant only for
Step 4 provider login. Navigating to `/dashboard` before clicking "Start
chatting" left that orphaned draft in place and triggered the "All
agents in this organization are paused — nothing will run." warning
banner.
**Proposed solution**
- Add `shouldSkipEarlyOnboardingSetupDraft` in
`ui/src/lib/cloud-trial-gate.ts` and gate `OnboardingWizard`'s Step 3
early-setup effect on `!shouldSkipEarlyOnboardingSetupDraft({
isFreeInferenceOnboarding, onboardingVariantPending })`.
- Update `derivePausedAgentBanner` and `hasNoAgents` in
`ui/src/pages/Dashboard.tsx` to ignore unfinished `pauseReason: "setup"`
drafts and `terminated` agents.
- Add unit tests in `ui/src/pages/Dashboard.test.ts` and
`ui/src/components/CloudTrialGate.test.tsx`.
**Alternatives considered**
- Deleting the setup draft on wizard unmount was ruled out because
browser reloads or tab closes do not reliably run unmount cleanup, and
`free_inference_1` never needs a Step 3 setup draft in the first place.
## What Changed
- `ui/src/lib/cloud-trial-gate.ts`: Added
`shouldSkipEarlyOnboardingSetupDraft`.
- `ui/src/components/OnboardingWizard.tsx`: Tracked
`onboardingVariantPending` (`onboardingSessionPending` /
`cloudTrialStatusPending`) and gated the Step 3 early-setup draft
creation effect so `free_inference_1` never creates a provisional
`General` (`pauseReason: "setup"`) draft.
- `ui/src/pages/Dashboard.tsx`: Excluded `pauseReason: "setup"` drafts
and `terminated` agents from `derivePausedAgentBanner` and
`hasNoAgents`.
- `ui/src/pages/Dashboard.test.ts` &
`ui/src/components/CloudTrialGate.test.tsx`: Added unit test coverage.
## Verification
- `pnpm --filter @paperclipai/ui typecheck` (0 errors)
- `pnpm exec vitest run ui/src/pages/Dashboard.test.ts
ui/src/components/CloudTrialGate.test.tsx
ui/src/lib/onboarding-auto-open.test.ts` (24/24 passed)
## Risks
- Low risk: `baseline` onboarding behavior is unchanged once
`onboardingSession` resolves (a cached session query already loaded by
the app shell), and `Dashboard` still shows the all-paused banner
whenever real hired agents are paused.
## Model Used
- Google Gemini (Antigravity agentic coding environment with tool use
and local Vitest + TypeScript verification)
## 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
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge
---------
Co-authored-by: Paperclip <noreply@paperclip.ing>
121 lines
5.2 KiB
TypeScript
121 lines
5.2 KiB
TypeScript
import type { Agent, CompactIssue, IssueSummary } from "@paperclipai/shared";
|
|
import { describe, expect, it } from "vitest";
|
|
import { derivePausedAgentBanner, recentTaskIndexRows, withTaskSummaries } from "./Dashboard";
|
|
|
|
function agent(overrides: Partial<Agent>): Agent {
|
|
return {
|
|
id: "agent-1",
|
|
name: "Agent",
|
|
status: "idle",
|
|
pauseReason: null,
|
|
...overrides,
|
|
} as unknown as Agent;
|
|
}
|
|
|
|
describe("derivePausedAgentBanner", () => {
|
|
it("returns null with no agents loaded or an empty company", () => {
|
|
expect(derivePausedAgentBanner(undefined)).toBeNull();
|
|
expect(derivePausedAgentBanner([])).toBeNull();
|
|
});
|
|
|
|
it("prefers the imported banner and lists only import-paused agents", () => {
|
|
const banner = derivePausedAgentBanner([
|
|
agent({ id: "a", status: "paused", pauseReason: "import" }),
|
|
agent({ id: "b", status: "paused", pauseReason: "manual" }),
|
|
agent({ id: "c", status: "idle" }),
|
|
]);
|
|
expect(banner).toEqual({ kind: "imported", pausedImportedAgentIds: ["a"] });
|
|
});
|
|
|
|
it("falls back to the all-paused banner when no import pauses exist", () => {
|
|
const banner = derivePausedAgentBanner([
|
|
agent({ id: "a", status: "paused", pauseReason: "manual" }),
|
|
agent({ id: "b", status: "paused", pauseReason: "system" }),
|
|
]);
|
|
expect(banner).toEqual({ kind: "all-paused" });
|
|
});
|
|
|
|
it("shows nothing while at least one agent can run and none are import-paused", () => {
|
|
const banner = derivePausedAgentBanner([
|
|
agent({ id: "a", status: "paused", pauseReason: "manual" }),
|
|
agent({ id: "b", status: "idle" }),
|
|
]);
|
|
expect(banner).toBeNull();
|
|
});
|
|
|
|
it("ignores unfinished onboarding setup drafts and terminated agents", () => {
|
|
expect(
|
|
derivePausedAgentBanner([
|
|
agent({ id: "setup-1", status: "paused", pauseReason: "setup" }),
|
|
]),
|
|
).toBeNull();
|
|
expect(
|
|
derivePausedAgentBanner([
|
|
agent({ id: "setup-1", status: "paused", pauseReason: "setup" }),
|
|
agent({ id: "term-1", status: "terminated", pauseReason: null }),
|
|
]),
|
|
).toBeNull();
|
|
});
|
|
|
|
it("handles a large mixed-agent organization within a bounded linear property-read budget", () => {
|
|
const TOTAL = 500;
|
|
const MAX_READS = TOTAL * 6;
|
|
let reads = 0;
|
|
|
|
const rawAgents: Agent[] = Array.from({ length: TOTAL }, (_, index) => {
|
|
if (index % 10 === 0) return agent({ id: `setup-${index}`, status: "paused", pauseReason: "setup" });
|
|
if (index % 10 === 1) return agent({ id: `term-${index}`, status: "terminated", pauseReason: null });
|
|
return agent({ id: `paused-${index}`, status: "paused", pauseReason: "manual" });
|
|
});
|
|
|
|
const countedAgents = rawAgents.map(
|
|
(entry) =>
|
|
new Proxy(entry, {
|
|
get(target, prop, receiver) {
|
|
reads += 1;
|
|
if (reads > MAX_READS) {
|
|
throw new Error(`derivePausedAgentBanner exceeded property read budget (${reads} > ${MAX_READS})`);
|
|
}
|
|
return Reflect.get(target, prop, receiver);
|
|
},
|
|
}),
|
|
);
|
|
|
|
expect(derivePausedAgentBanner(countedAgents)).toEqual({ kind: "all-paused" });
|
|
expect(reads).toBeLessThanOrEqual(MAX_READS);
|
|
});
|
|
});
|
|
|
|
describe("dashboard recent tasks from the task index", () => {
|
|
const row = (id: string, updatedAt: string): CompactIssue =>
|
|
({ id, identifier: id.toUpperCase(), title: id, status: "blocked", updatedAt, assigneeAgentId: "agent-1" }) as unknown as CompactIssue;
|
|
|
|
it("keeps the ten most recently updated tasks, newest first", () => {
|
|
const rows = Array.from({ length: 14 }, (_, index) => row(`t${index}`, new Date(Date.UTC(2026, 10, 1 + index)).toISOString()));
|
|
expect(recentTaskIndexRows(rows.reverse()).map(issue => issue.id)).toEqual(
|
|
["t13", "t12", "t11", "t10", "t9", "t8", "t7", "t6", "t5", "t4"]);
|
|
});
|
|
|
|
it("reads each task's update time once, in one pass over a large company", () => {
|
|
let reads = 0;
|
|
const rows = Array.from({ length: 5_000 }, (_, index) => {
|
|
const at = new Date(Date.UTC(2026, 0, 1) + ((index * 7919) % 5_000) * 60_000).toISOString();
|
|
return Object.defineProperty({ id: `t${index}` }, "updatedAt", { get: () => { reads += 1; return at; } }) as unknown as CompactIssue;
|
|
});
|
|
const recent = recentTaskIndexRows(rows);
|
|
expect(reads).toBe(5_000);
|
|
const sorted = [...rows].sort((a, b) => Date.parse(String(b.updatedAt)) - Date.parse(String(a.updatedAt))).slice(0, 10);
|
|
expect(recent.map(issue => issue.id)).toEqual(sorted.map(issue => issue.id));
|
|
});
|
|
|
|
it("takes the status glyph fields from the task summary and the rest from the index row", () => {
|
|
const summary = { id: "t1", displayStatus: "in_queue", externalConversationState: "waiting",
|
|
blockerAttention: { state: "covered" } } as unknown as IssueSummary;
|
|
const [merged] = withTaskSummaries([row("t1", "2026-11-01T00:00:00.000Z")], [summary]);
|
|
expect(merged).toMatchObject({ id: "t1", title: "t1", assigneeAgentId: "agent-1", displayStatus: "in_queue",
|
|
externalConversationState: "waiting", blockerAttention: { state: "covered" } });
|
|
const [plain] = withTaskSummaries([row("t2", "2026-11-01T00:00:00.000Z")], undefined);
|
|
expect(plain).not.toHaveProperty("displayStatus");
|
|
});
|
|
});
|