feat(recents): add tasks from manual routine runs to Recents (#23675)

## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - The sidebar Recents list shows the tasks from a person's own recent
activity
> - A person can run a routine manually with "Run now", and the run
creates a task
> - That task does not show in Recents, and opening it does not keep it
there, because Recents only admits tasks under the Mine participation
rule. This also affects every routine, channel, and agent-created task
that a person opens
> - The Mine rule keeps these tasks out of Mine on purpose, so we must
not change that rule
> - This pull request adds a separate Recents eligibility flag. It also
admits tasks that the viewer opened and tasks from manual routine runs
that the viewer started. The UI records the new task in Recents when the
run starts
> - The benefit is that people can find the task they just started from
the sidebar at once, and Mine stays unchanged

## Linked Issues or Issue Description

**Is your feature request related to a problem? Please describe.**
When I run a routine manually and it creates a task, the task is not in
my Recents list. I must go to the routine or the task list to find it.

**Describe the solution you'd like**
When I run a routine manually and a task is created, add that task to my
Recents list automatically, even if I did not open it.

Also, a task that a routine creates does not show in Recents even after
I open it.

**Additional context**
Mine must continue to keep routine tasks out by default, including
routines that a person starts manually (see `doc/PRODUCT.md`).

## What Changed

- `server/src/services/issue-summaries.ts`: navigation summaries return
a new `isRecentEligibleForMe` flag. It is true when one of these
conditions is true:
  - The viewer participates under the Mine rule.
- The viewer opened the task. The check is the viewer's
`issue_read_states` row, which is unique on company, issue, and user.
- The viewer started the manual routine run that created the task. The
check is a `routine_runs` row found through the indexed
`linked_issue_id`, with `source = 'manual'` and the same ID as the
issue's `originRunId`. The issue `createdByUserId` must be the viewer,
with no creating agent.
  `isParticipantForMe`, Mine, and unread state do not change.
- `packages/shared`: add `isRecentEligibleForMe` to `IssueSummary`.
- `ui/src/hooks/useRecentTasks.ts`: Recents uses `isRecentEligibleForMe`
(with a fallback to `isParticipantForMe` for older cached summaries) to
show, keep, and prune entries.
- `ui/src/lib/recent-tasks.ts`: add `recordStartedRoutineRunTask`. It
puts the run's task at the top of Recents. The summary fetch then
supplies the title and status and confirms eligibility.
- New `useRecordRoutineRunInRecents` hook. All five "Run now" paths call
it on success: Routines (both list variants), Routine detail, Execution
workspace detail, and the Responsibility screen.
- `tests/runner-e2e/source-sdk-public-inputs.json`: refresh the pin for
`packages/shared/src/types/issue.ts`.
- `doc/PRODUCT.md`: document the Recents behavior.

## Verification

- `cd ui && npx vitest run src/hooks/useRecentTasks.test.tsx`: 29
passed. The new test "shows a task from the viewer's manual routine run
at the top before it is opened" fails on the old hook (red) and passes
with the change (green). Other new tests cover a run that the server
does not confirm (for example, a coalesced run) and a repeat run for a
task that is already in Recents.
- `cd server && npx vitest run
src/__tests__/issue-summaries-routes.test.ts` (embedded Postgres): 24
passed. One new test checks that a manual run by the viewer is
Recents-eligible but not a Mine participant, and that runs by another
person and scheduled runs are not eligible. Another new test checks that
a routine task the viewer opened is Recents-eligible, and that a task
opened only by another person is not. That test fails on the previous
service code (red) and passes with the change (green).
- `ui` typecheck: no errors in changed files. (Errors exist only in
ungenerated Storybook feature-map indexes, which this change does not
touch.)
- The full `server` typecheck was killed by the local memory limit. CI
covers it.
- Manual check: run a routine with "Run now", then look at sidebar
Recents. The new task shows at the top before you open it. Mine does not
show it.

## Risks

- Low risk. No schema change and no migration.
- The summaries query adds two `EXISTS` subqueries per requested task.
Both use indexes (the read-state unique index and
`routine_runs_linked_issue_idx`). The request is bounded by
`ISSUE_SUMMARIES_MAX_IDS`.
- Behavior change: Recents now keeps tasks that the person opened, also
when the task is automatic work. Old local Recents entries for automatic
tasks that the person read can come back.
- If a manual run coalesces into an existing task that the viewer did
not start, the entry is pruned after the summary read. That task does
not show in Recents.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), via Claude Code with tool use
(shell, file edit, test runs).

## 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
- [ ] 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)
- [ ] 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
- [ ] I will address all Greptile and reviewer comments before
requesting merge

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: devinfoley <139239+devinfoley@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-12-03 20:54:26 -08:00
1 parent b93527b632
commit bca282e587
16 files changed
+292 -20

No files matched your search

@@ -6,7 +6,7 @@ import { drizzle } from "drizzle-orm/postgres-js";
import * as schema from "@paperclipai/db/schema/index";
import { afterAll, beforeAll, expect, it, vi } from "vitest";
import {
activityLog, agents, chatConversations, chatEndpoints, companyMemberships, heartbeatRuns, issueComments, issueInboxArchives, issueReadStates, issueRelations, issues, issueThreadInteractions, toolApplications, toolConnections,
activityLog, agents, chatConversations, chatEndpoints, companyMemberships, heartbeatRuns, issueComments, issueInboxArchives, issueReadStates, issueRelations, issues, issueThreadInteractions, routineRuns, routines, toolApplications, toolConnections,
} from "@paperclipai/db";
import { ISSUE_SUMMARIES_MAX_IDS } from "@paperclipai/shared";
import { issueRoutes } from "../routes/issues.js";
@@ -86,6 +86,52 @@ describeEmbeddedPostgres("bounded issue summaries", () => {
expect(res.body.every((row: { isParticipantForMe: unknown }) => typeof row.isParticipantForMe === "boolean")).toBe(true);
});
it("admits a task from the viewer's own manual routine run to Recents without Mine participation", async () => {
const f = await fixture();
const user = f.actor.userId!;
const [routine] = await ctx.db.insert(routines).values({ companyId: f.companyId, title: "Daily scan" }).returning();
const runs = await ctx.db.insert(routineRuns).values(["manual", "manual", "schedule"].map(source => ({
companyId: f.companyId, routineId: routine!.id, source,
}))).returning();
const names = ["mine", "someone-else", "scheduled", "manual-task"];
const rows = await ctx.db.insert(issues).values(names.map((title, index) => ({
companyId: f.companyId, title,
originKind: title === "manual-task" ? "manual" : "routine_execution",
originRunId: title === "manual-task" ? null : runs[Math.min(index, 2)]!.id,
createdByUserId: title === "someone-else" ? "other-user" : title === "scheduled" ? null : user,
responsibleUserId: user,
}))).returning();
// A run links the task it created, as the routine service records it.
for (const row of rows.filter(row => row.originRunId)) {
await ctx.db.update(routineRuns).set({ linkedIssueId: row.id }).where(eq(routineRuns.id, row.originRunId!));
}
const res = await request(app(f.actor)).get(url(f.companyId)).query({ ids: rows.map(row => row.id).join(","), navigation: "true" }).expect(200);
const byTitle = new Map(res.body.map((row: { title: string }) => [row.title, row]));
// Mine keeps routine work out, including runs the person starts manually.
expect(byTitle.get("mine")).toMatchObject({ isParticipantForMe: false, isRecentEligibleForMe: true });
expect(byTitle.get("someone-else")).toMatchObject({ isParticipantForMe: false, isRecentEligibleForMe: false });
expect(byTitle.get("scheduled")).toMatchObject({ isParticipantForMe: false, isRecentEligibleForMe: false });
expect(byTitle.get("manual-task")).toMatchObject({ isParticipantForMe: true, isRecentEligibleForMe: true });
});
it("admits a routine task the viewer opened to Recents without Mine participation", async () => {
const f = await fixture();
const user = f.actor.userId!;
const rows = await ctx.db.insert(issues).values(["opened", "opened-by-other", "never-opened"].map(title => ({
companyId: f.companyId, title, originKind: "routine_execution", responsibleUserId: user,
}))).returning();
const id = (name: string) => rows.find(row => row.title === name)!.id;
await ctx.db.insert(issueReadStates).values([
{ companyId: f.companyId, issueId: id("opened"), userId: user },
{ companyId: f.companyId, issueId: id("opened-by-other"), userId: "other-user" },
]);
const res = await request(app(f.actor)).get(url(f.companyId)).query({ ids: rows.map(row => row.id).join(","), navigation: "true" }).expect(200);
const byTitle = new Map(res.body.map((row: { title: string }) => [row.title, row]));
expect(byTitle.get("opened")).toMatchObject({ isParticipantForMe: false, isRecentEligibleForMe: true });
expect(byTitle.get("opened-by-other")).toMatchObject({ isParticipantForMe: false, isRecentEligibleForMe: false });
expect(byTitle.get("never-opened")).toMatchObject({ isParticipantForMe: false, isRecentEligibleForMe: false });
});
it("matches the inbox unread predicate across participation, request, withdrawal and read histories", async () => {
const f = await fixture();
const user = f.actor.userId!;
+23 -4
View File
@@ -1,6 +1,6 @@
import { issueDisplayStatusSql } from "./issue-display-status.js";
import { and, eq, inArray, isNull, sql, type SQL } from "drizzle-orm";
import { activityLog, issueComments, issueReadStates, issueThreadInteractions, issues, type Db } from "@paperclipai/db";
import { activityLog, issueComments, issueReadStates, issueThreadInteractions, issues, routineRuns, type Db } from "@paperclipai/db";
import { ISSUE_SUMMARIES_MAX_IDS } from "@paperclipai/shared";
import { directHumanCommentCondition } from "./issue-participation.js";
import { inboxVisibleForUserCondition, mineParticipationIssueIds, unreadForUserCondition } from "./issues.js";
@@ -62,7 +62,7 @@ export async function listIssueNavigationState(
// MATERIALIZED prevents PostgreSQL from repeating privacy and viewer facts
// across the task-state and child-count branches of the final union.
const rows = await db.execute<{
kind: string; id: string; unread: boolean; participant: boolean; archived: boolean; total: number; unread_count: number;
kind: string; id: string; unread: boolean; participant: boolean; recent_activity: boolean; archived: boolean; total: number; unread_count: number;
}>(sql`
with navigation_candidates as materialized (
select ${issues.id}, ${issues.parentId}, ${issues.conversationAgentId},
@@ -123,11 +123,29 @@ export async function listIssueNavigationState(
select issues.id, issues.parent_id, issues.conversation_agent_id, coalesce(${unread}, false) as unread
from navigation_facts as issues
)
select 'task' as kind, c.id, coalesce(s.unread, false) as unread, p.id is not null as participant, c.archived, 0 as total, 0 as unread_count
select 'task' as kind, c.id, coalesce(s.unread, false) as unread, p.id is not null as participant,
-- Recent personal activity that is not Mine participation: the viewer
-- opened the task (it has their read state), or started the manual
-- routine run that created it.
(exists (
select 1 from ${issueReadStates}
where ${issueReadStates.companyId} = ${companyId} and ${issueReadStates.issueId} = c.id
and ${issueReadStates.userId} = ${userId}
) or exists (
-- The linked-issue index bounds this lookup; the origin-run check keeps
-- only the run that created the task, not later runs coalesced into it.
select 1 from ${issues} join ${routineRuns}
on ${routineRuns.linkedIssueId} = ${issues.id} and ${routineRuns.companyId} = ${companyId}
and ${routineRuns.id}::text = ${issues.originRunId}
where ${issues.id} = c.id and ${issues.companyId} = ${companyId}
and ${issues.createdByUserId} = ${userId} and ${issues.createdByAgentId} is null
and ${routineRuns.source} = 'manual'
)) as recent_activity,
c.archived, 0 as total, 0 as unread_count
from navigation_candidates c left join navigation_state s on s.id = c.id
left join navigation_participants p on p.id = c.id where c.id in (${requested})
union all
select 'children', c.parent_id, false, false, false, count(*)::int, count(*) filter (where s.unread)::int
select 'children', c.parent_id, false, false, false, false, count(*)::int, count(*) filter (where s.unread)::int
from navigation_candidates c left join navigation_state s on s.id = c.id
where c.parent_id in (${requested}) and c.conversation_agent_id is null group by c.parent_id
`);
@@ -135,6 +153,7 @@ export async function listIssueNavigationState(
const children = new Map(rows.filter(row => row.kind === "children").map(row => [row.id, row]));
return new Map(ids.map(id => [id, {
isParticipantForMe: tasks.get(id)?.participant ?? false,
isRecentEligibleForMe: Boolean(tasks.get(id)?.participant || tasks.get(id)?.recent_activity),
isUnreadForMe: tasks.get(id)?.unread ?? false,
isArchivedForMe: tasks.get(id)?.archived ?? false,
subtaskCount: children.get(id)?.total ?? 0,