From 6e596cd63e75cbf1ca3f3abb42c3c58ce87278ef Mon Sep 17 00:00:00 2001 From: Cato <41178744+catomean@users.noreply.github.com> Date: Fri, 25 Sep 2026 08:56:15 -0700 Subject: [PATCH] fix(orangecat): order actor status by attention before the 25-project cap (#916) The cap took the first 25 projects in list order, so an account with 37 projects never showed OrangeCat's Cat its own `orangecat` project. Sort by what needs the owner (blocked on them, new feedback, working, queued, linked, live) and cut after. Stable: ties keep list order. Co-authored-by: Claude Opus 5.5 (1M context) --- scripts/test/orangecat-actor-status.ts | 34 +++++++++++++++++++ .../integrations/orangecat-actor-status.ts | 27 ++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/scripts/test/orangecat-actor-status.ts b/scripts/test/orangecat-actor-status.ts index cb8a3af37..5884d0e42 100644 --- a/scripts/test/orangecat-actor-status.ts +++ b/scripts/test/orangecat-actor-status.ts @@ -106,6 +106,40 @@ async function main(): Promise { assert.equal(many.length, ACTOR_STATUS_MAX_PROJECTS); console.log(" ✓ capped at 25 projects"); + // The cap keeps what needs the person, not the first 25 in list order: an + // account with 37 projects never showed OrangeCat its own `orangecat` project. + const crowd = Array.from({ length: 30 }, (_, i) => ({ + id: `c${i}`, + name: `C${i}`, + liveUrl: null, + entityProjectId: null, + })); + const ordered = shapeActorStatus({ + ...base, + projects: crowd, + states: [ + { + projectKey: "c29", + agentRunning: false, + sessionStatus: "ready", + sessionBlockReason: "awaiting_user", + promptQueue: [], + currentPromptLabel: null, + }, + ], + outcomes: new Map(), + feedback: [], + links: [{ projectId: "c28", entityType: "project", entityId: "oc-9" }], + }); + assert.equal(ordered.length, ACTOR_STATUS_MAX_PROJECTS); + assert.equal(ordered[0].id, "c29", "a project waiting on its owner leads, even from position 30"); + assert.ok( + ordered.some((p) => p.id === "c28"), + "a project linked to OrangeCat survives the cap", + ); + assert.equal(ordered[2].id, "c0", "the rest keep their list order"); + console.log(" ✓ ordered by attention before the cap"); + const now = Date.parse("2026-09-24T12:00:00Z"); assert.ok(isFreshIssuedAt("2026-09-24T11:57:00Z", now)); assert.ok(isFreshIssuedAt("2026-09-24T12:02:00Z", now), "small clock skew ahead is fine"); diff --git a/src/lib/integrations/orangecat-actor-status.ts b/src/lib/integrations/orangecat-actor-status.ts index a49c36f1f..6f8c39b5b 100644 --- a/src/lib/integrations/orangecat-actor-status.ts +++ b/src/lib/integrations/orangecat-actor-status.ts @@ -73,7 +73,7 @@ export function shapeActorStatus(input: ActorStatusInput): ActorProjectStatus[] // entities.id), which user_projects carries as entityProjectId. const feedbackByEntity = new Map(input.feedback.map((f) => [f.projectId, f])); - return input.projects.slice(0, ACTOR_STATUS_MAX_PROJECTS).map((p) => { + const shaped = input.projects.map((p) => { const s = stateByKey.get(p.name.toLowerCase()); const blockReason = s?.sessionBlockReason ?? null; const status: ActorProjectState = blockReason @@ -98,4 +98,29 @@ export function shapeActorStatus(input: ActorStatusInput): ActorProjectStatus[] .map((l) => ({ entityType: l.entityType, entityId: l.entityId })), }; }); + + // Cut to the cap only AFTER ordering by what needs the person. The cap used + // to take the first 25 in list order, so an account with 37 projects never + // showed OrangeCat's Cat its own `orangecat` project — the list order said + // nothing about which ones mattered. Stable sort: ties keep list order. + return shaped + .map((project, index) => ({ project, index })) + .sort((a, b) => attention(b.project) - attention(a.project) || a.index - b.index) + .slice(0, ACTOR_STATUS_MAX_PROJECTS) + .map(({ project }) => project); +} + +/** + * How much a project needs its owner right now — waiting on them first, then + * new visitor feedback, then work in motion, then projects that exist in the + * world (linked to OrangeCat, or live), then the rest. + */ +export function attention(p: ActorProjectStatus): number { + if (p.status === "blocked") return p.blockReason === "awaiting_user" ? 100 : 80; + if (p.feedback.new > 0) return 60 + Math.min(p.feedback.new, 19); + if (p.status === "working") return 50; + if (p.queueDepth > 0) return 40; + if (p.orangecat.length > 0) return 30; + if (p.liveUrl) return 20; + return 0; }