mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-29 23:56:43 +01:00
fix(inbox): keep other users’ failed runs out of Mine (#14572)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The Mine inbox shows work that needs the current user. > - Failed-run rows used the latest run for every agent in the company. > - A failure from another user therefore appeared in Mine and its badge. > - Run list responses also omitted the responsible user needed to filter these rows. > - This pull request uses run ownership for personal failure routing. > - Users see their own failures and can still inspect company failures in All. ## Linked Issues or Issue Description **What happened?** An agent run started for one user failed. Its row and failure badge appeared in another user's Mine inbox. **Expected behavior** Mine and its badge include failed runs for the current responsible user. Other users' failures remain available in All and run details. **Steps to reproduce** 1. Use a company with two human users. 2. Create a failed or timed-out run attributed to the first user. 3. Open Mine as the second user. Before this fix, the failed run appears there and increases the badge. **Paperclip version or commit** Reproduced in regression tests on master at `24beb0057`. **Deployment mode** Authenticated deployment with multiple users. Tests also cover the local single-user board. Related prior work: #933 addressed inbox dismissal and badge consistency. No duplicate ownership fix was found. ## What Changed - Return `responsibleUserId` in normal and summary run lists. - Share one ownership rule across both inbox versions and client/server badges. - Select the latest run per agent before applying the ownership filter. This prevents old failures from resurfacing on shared agents. - Keep unattributed historical failures in the local board's Mine view. Hide them from authenticated users with no matching owner. - Keep company health alerts outside the personal badge, consistent with the client. - Document the routing contract and add page, badge, and database regression coverage. ## Verification - Red: the new badge cases failed with three company failures instead of one personal failure; eight Mine page cases failed across both inbox versions. - Green: 113 focused tests pass in `ui/src/lib/inbox.test.ts`, `ui/src/pages/Inbox.test.tsx`, `server/src/__tests__/heartbeat-list.test.ts`, and `server/src/__tests__/inbox-dismissals.test.ts`. - `pnpm check:token-gates` passes. - Agent calls on behalf of a user have two additional red-to-green API regressions. - Full `pnpm -r typecheck` and `pnpm build` pass. Server typecheck also passes after the agent-call fix. - All CI test shards and browser tests pass on `243bfa681`. The duplicate local `pnpm test:run` was stopped after the CI test lanes completed; it did not finish locally. ## Risks - Authenticated users no longer receive unattributed legacy failures in Mine. Those failures remain visible in All. - The server badge no longer counts company health alerts, matching the existing client badge. - No migration, run state, retry behavior, or company access rules change. ## Model Used - OpenAI GPT-6 through Codex, with reasoning, terminal execution, and browser tools. The exact deployment variant and context window size are not exposed in this session. ## 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 --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
24beb00575
commit
7636966452
14 files changed
+158
-28
No files matched your search
@@ -145,7 +145,7 @@ describeEmbeddedPostgres("heartbeat list", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("returns summary list rows without heavy run detail fields", async () => {
|
||||
it.each([false, true])("preserves run ownership in list rows (summary=%s)", async (summary) => {
|
||||
const companyId = randomUUID();
|
||||
const agentId = randomUUID();
|
||||
const issueId = randomUUID();
|
||||
@@ -176,6 +176,7 @@ describeEmbeddedPostgres("heartbeat list", () => {
|
||||
agentId,
|
||||
invocationSource: "assignment",
|
||||
status: "failed",
|
||||
responsibleUserId: "run-owner",
|
||||
error: "Failed after doing useful work",
|
||||
usageJson: {
|
||||
provider: "openai",
|
||||
@@ -199,7 +200,7 @@ describeEmbeddedPostgres("heartbeat list", () => {
|
||||
},
|
||||
});
|
||||
|
||||
const runs = await heartbeatService(db).list(companyId, undefined, 5, { summary: true });
|
||||
const runs = await heartbeatService(db).list(companyId, undefined, 5, { summary });
|
||||
|
||||
expect(runs).toHaveLength(1);
|
||||
expect(runs[0]).toMatchObject({
|
||||
@@ -207,16 +208,19 @@ describeEmbeddedPostgres("heartbeat list", () => {
|
||||
companyId,
|
||||
agentId,
|
||||
status: "failed",
|
||||
responsibleUserId: "run-owner",
|
||||
error: "Failed after doing useful work",
|
||||
usageJson: null,
|
||||
resultJson: null,
|
||||
sessionIdBefore: null,
|
||||
sessionIdAfter: null,
|
||||
logStore: null,
|
||||
logRef: null,
|
||||
logSha256: null,
|
||||
externalRunId: null,
|
||||
processPid: null,
|
||||
...(summary ? {
|
||||
usageJson: null,
|
||||
resultJson: null,
|
||||
sessionIdBefore: null,
|
||||
sessionIdAfter: null,
|
||||
logStore: null,
|
||||
logRef: null,
|
||||
logSha256: null,
|
||||
externalRunId: null,
|
||||
processPid: null,
|
||||
} : {}),
|
||||
contextSnapshot: {
|
||||
issueId,
|
||||
wakeReason: "issue_assigned",
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
import { errorHandler } from "../middleware/index.js";
|
||||
import { inboxDismissalRoutes } from "../routes/inbox-dismissals.js";
|
||||
import { inboxDismissalService } from "../services/inbox-dismissals.ts";
|
||||
import { sidebarBadgeRoutes } from "../routes/sidebar-badges.js";
|
||||
import { sidebarBadgeService } from "../services/sidebar-badges.ts";
|
||||
|
||||
const embeddedPostgresSupport = await getEmbeddedPostgresTestSupport();
|
||||
@@ -59,6 +60,46 @@ describeEmbeddedPostgres("inbox dismissals", () => {
|
||||
await tempDb?.cleanup();
|
||||
});
|
||||
|
||||
it.each([
|
||||
{ userId: "user-1", expected: 1 },
|
||||
{ userId: "user-2", expected: 1 },
|
||||
{ userId: "uninvolved-user", expected: 0 },
|
||||
{ userId: "local-board", expected: 1 },
|
||||
{ userId: "user-1", actorType: "agent", expected: 1 },
|
||||
{ userId: null, actorType: "agent", expected: 0 },
|
||||
])("scopes failed-run badges to $userId (actor=$actorType)", async ({ userId, actorType, expected }) => {
|
||||
const companyId = randomUUID();
|
||||
await db.insert(companies).values({ id: companyId, name: "Paperclip", issuePrefix: "PAP" });
|
||||
for (const responsibleUserId of ["user-1", "user-2", null]) {
|
||||
const agentId = randomUUID();
|
||||
await db.insert(agents).values({ id: agentId, companyId, name: "Agent", role: "engineer", status: "error" });
|
||||
await db.insert(heartbeatRuns).values({
|
||||
companyId, agentId, responsibleUserId, invocationSource: "manual",
|
||||
status: responsibleUserId === "user-2" ? "timed_out" : "failed",
|
||||
});
|
||||
}
|
||||
// Pick the latest run before filtering by user, so a shared agent cannot
|
||||
// resurrect this user's older failure after somebody else's success.
|
||||
const sharedAgentId = randomUUID();
|
||||
await db.insert(agents).values({ id: sharedAgentId, companyId, name: "Shared", role: "engineer" });
|
||||
await db.insert(heartbeatRuns).values([
|
||||
{ companyId, agentId: sharedAgentId, responsibleUserId: "user-1", invocationSource: "manual", status: "failed", createdAt: new Date("2026-03-11T01:00:00Z") },
|
||||
{ companyId, agentId: sharedAgentId, responsibleUserId: "user-2", invocationSource: "manual", status: "succeeded", createdAt: new Date("2026-03-11T02:00:00Z") },
|
||||
]);
|
||||
const app = express();
|
||||
app.use((req, _res, next) => {
|
||||
req.actor = actorType === "agent"
|
||||
? { type: "agent", source: "agent_jwt", agentId: sharedAgentId, companyId, onBehalfOfUserId: userId, onBehalfOfMemberships: [{ companyId, membershipRole: "member", status: "active" }] }
|
||||
: { type: "board", source: userId === "local-board" ? "local_implicit" : "session", userId: userId!, companyIds: [companyId], isInstanceAdmin: true };
|
||||
next();
|
||||
});
|
||||
app.use("/api", sidebarBadgeRoutes(db));
|
||||
app.use(errorHandler);
|
||||
const response = await request(app).get(`/api/companies/${companyId}/sidebar-badges`).expect(200);
|
||||
expect(response.body.failedRuns).toBe(expected);
|
||||
expect(response.body.inbox).toBe(expected);
|
||||
});
|
||||
|
||||
it("upserts a single dismissal record per user and inbox item key", async () => {
|
||||
const companyId = randomUUID();
|
||||
const userId = "board-user";
|
||||
|
||||
@@ -4,7 +4,6 @@ import { and, eq } from "drizzle-orm";
|
||||
import { inboxDismissals, joinRequests } from "@paperclipai/db";
|
||||
import { sidebarBadgeService } from "../services/sidebar-badges.js";
|
||||
import { accessService } from "../services/access.js";
|
||||
import { dashboardService } from "../services/dashboard.js";
|
||||
import { collapseDuplicatePendingHumanJoinRequests } from "../lib/join-request-dedupe.js";
|
||||
import { assertCompanyAccess } from "./authz.js";
|
||||
|
||||
@@ -28,7 +27,6 @@ export function sidebarBadgeRoutes(db: Db) {
|
||||
const router = Router();
|
||||
const svc = sidebarBadgeService(db);
|
||||
const access = accessService(db);
|
||||
const dashboard = dashboardService(db);
|
||||
|
||||
router.get("/companies/:companyId/sidebar-badges", async (req, res) => {
|
||||
const companyId = req.params.companyId as string;
|
||||
@@ -78,16 +76,14 @@ export function sidebarBadgeRoutes(db: Db) {
|
||||
.then(buildDismissedAtByKey)
|
||||
: new Map<string, number>();
|
||||
|
||||
// Company health alerts belong in All, not the personal inbox badge.
|
||||
const badges = await svc.get(companyId, {
|
||||
currentUserId: req.actor.type === "board"
|
||||
? req.actor.userId ?? null
|
||||
: req.actor.onBehalfOfUserId ?? null,
|
||||
dismissals: dismissedAtByKey,
|
||||
joinRequests: visibleJoinRequests,
|
||||
});
|
||||
const summary = await dashboard.summary(companyId);
|
||||
const hasFailedRuns = badges.failedRuns > 0;
|
||||
const alertsCount =
|
||||
(summary.agents.error > 0 && !hasFailedRuns ? 1 : 0) +
|
||||
(summary.costs.monthBudgetCents > 0 && summary.costs.monthUtilizationPercent >= 80 ? 1 : 0);
|
||||
badges.inbox = badges.failedRuns + alertsCount + badges.joinRequests + badges.approvals;
|
||||
|
||||
res.json(badges);
|
||||
});
|
||||
|
||||
@@ -3311,6 +3311,7 @@ const heartbeatRunProcessGroupIdColumn =
|
||||
|
||||
const heartbeatRunListColumns = {
|
||||
id: heartbeatRuns.id,
|
||||
responsibleUserId: heartbeatRuns.responsibleUserId,
|
||||
companyId: heartbeatRuns.companyId,
|
||||
agentId: heartbeatRuns.agentId,
|
||||
invocationSource: heartbeatRuns.invocationSource,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { and, desc, eq, inArray, not } from "drizzle-orm";
|
||||
import type { Db } from "@paperclipai/db";
|
||||
import { agents, approvals, heartbeatRuns } from "@paperclipai/db";
|
||||
import type { SidebarBadges } from "@paperclipai/shared";
|
||||
import { isHeartbeatRunVisibleInMine, type SidebarBadges } from "@paperclipai/shared";
|
||||
|
||||
const ACTIONABLE_APPROVAL_STATUSES = ["pending", "revision_requested"];
|
||||
const FAILED_HEARTBEAT_STATUSES = ["failed", "timed_out"];
|
||||
@@ -27,6 +27,7 @@ export function sidebarBadgeService(db: Db) {
|
||||
get: async (
|
||||
companyId: string,
|
||||
extra?: {
|
||||
currentUserId?: string | null;
|
||||
dismissals?: ReadonlyMap<string, number>;
|
||||
joinRequests?: Array<{ id: string; updatedAt: Date | string | null; createdAt: Date | string }>;
|
||||
unreadTouchedIssues?: number;
|
||||
@@ -49,6 +50,7 @@ export function sidebarBadgeService(db: Db) {
|
||||
.selectDistinctOn([heartbeatRuns.agentId], {
|
||||
id: heartbeatRuns.id,
|
||||
runStatus: heartbeatRuns.status,
|
||||
responsibleUserId: heartbeatRuns.responsibleUserId,
|
||||
createdAt: heartbeatRuns.createdAt,
|
||||
})
|
||||
.from(heartbeatRuns)
|
||||
@@ -64,6 +66,7 @@ export function sidebarBadgeService(db: Db) {
|
||||
|
||||
const failedRuns = latestRunByAgent.filter((row) =>
|
||||
FAILED_HEARTBEAT_STATUSES.includes(row.runStatus)
|
||||
&& (extra?.currentUserId === undefined || isHeartbeatRunVisibleInMine(row, extra.currentUserId))
|
||||
&& !isDismissed(extra?.dismissals ?? new Map(), `run:${row.id}`, row.createdAt),
|
||||
).length;
|
||||
|
||||
|
||||
Reference in new issue
Block a user