mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 07:27:13 +01:00
Fix plugin SDK issues.list double-applying offset/limit (#16327)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Plugins get a scoped host SDK (`ctx.issues.list`, etc.) so they can read company data without full server access > - The `issues.list` handler already asks the issue service to paginate at the SQL level, but then re-slices the already-paginated result a second time with the same offset/limit > - That means any page past the first (`offset >= limit`) always returns `[]`, silently — a plugin paginating a large company's issues loses every row past page 0 > - This pull request removes the redundant second windowing step so `issues.list` paginates correctly on every page > - The benefit is that plugins (e.g. a Home Assistant integration scanning >200 issues) stop silently losing data past page 1 ## Linked Issues or Issue Description Fixes #16290. Related prior art: #14654 attempted nearly the same fix on 2026-09-30 but was withdrawn by its own author minutes later as an accidental branch push, never reviewed. #14673 (nagoodman) is an active, independently-equivalent fix open since 2026-09-30 — see the maintainer-review coordination note below. ## What Changed - Removed the redundant `applyWindow` re-slice in the plugin-SDK `issues.list` handler (`server/src/services/plugin-host-services.ts`); the normalized `limit`/`offset` now pass straight into the `issues.list(companyId, …)` service call, which already paginates at the SQL level. - Added an explicit `limit === 0` short-circuit to `[]`: the service's own clamp is `Math.max(1, floor(limit))`, so passing `0` straight through would otherwise incorrectly yield 1 row instead of 0. - **Follow-up fix (2026-10-16, per reviewer feedback from @BichengWang):** the `limit === 0` short-circuit originally returned before `issues.list` ran at all, which skipped that service's filter validation (e.g. a malformed `assigneeAgentId` silently returned `[]` instead of the expected 422). Fixed by always running the query (floored to `limit: 1` when the caller asked for `0`) and discarding the rows only after it succeeds, so validation errors still surface. Added a regression test for the malformed zero-limit case. - Confirmed the no-limit case is unaffected: the query path skips `.limit()` entirely when `limit === undefined`, matching the prior "no limit → return all from offset" behavior. - Audited every other `applyWindow` call site in the same file (`companies.list`, `projects.list`, `agents.list`, `goals.list`): none forward `params` into their underlying service call, so `applyWindow` is their only windowing step — no double-apply there. Only `issues.list` had the bug. ## Maintainer review coordination @BichengWang flagged (2026-10-16) that #14673 is an active, independently-equivalent fix for the same bug that already preserves the zero-limit validation path this PR initially missed. Both PRs now cover the same ground; whichever lands first should supersede the other. No preference from us — happy to close this one if a maintainer prefers #14673. ## Verification - New regression test in `server/src/__tests__/plugin-orchestration-apis.test.ts`: seeds 5 issues and asserts 3 full pages — including page 2 (`offset=4`) — return their expected slices instead of `[]`, plus `limit=0` and past-the-end cases, plus (new) a malformed-filter-at-zero-limit case that must still reject with 422. - Run locally with `pnpm exec vitest run --project @paperclipai/server server/src/__tests__/plugin-orchestration-apis.test.ts`. ### Local verification - Commit: `9d776d12a` (rebased on current `origin/master`) - Negative control: reverted just the service-file fix, kept the new test — confirms it fails (`[]` returned instead of rejecting) without the fix, passes with it. - tier1/tier2 gate: in progress on this commit as of 2026-10-16T16:xx UTC; will update once it reports pass/fail. - Previous head `6a0279174`: tier1+tier2 both GATE PASSED, live GitHub 56/56 checks green, Greptile 5/5. - Not run locally: docker-context, e2e (no Docker/Chrome on host) ## Risks - Behavior-only change to one plugin-SDK list handler; no schema or migration changes. Low risk. - Revert is a clean single-commit revert of this PR. ## Model Used Claude (Claude Agent SDK), Sonnet 5 (`claude-sonnet-5`), agentic tool use with repository read/write and test execution. ## 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 (#14654 withdrawn, #14673 active/overlapping) - [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 (none needed — internal plugin-SDK behavior, no user-facing docs reference this handler) - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green (re-gating after the follow-up fix; previous head was 56/56) - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups (re-review pending on the new commit) - [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
d2bdad4ae5
commit
92e3ad1de9
2 files changed
+41
-4
No files matched your search
@@ -158,6 +158,39 @@ describeEmbeddedPostgres("plugin orchestration APIs", () => {
|
||||
return root;
|
||||
}
|
||||
|
||||
it("pages plugin issues past the first page instead of silently returning an empty tail", async () => {
|
||||
const { companyId } = await seedCompanyAndAgent();
|
||||
const services = buildHostServices(db, "plugin-record-id", "paperclip.missions", createEventBusStub());
|
||||
for (let index = 0; index < 5; index += 1) {
|
||||
await services.issues.create({
|
||||
companyId,
|
||||
title: `Issue ${index}`,
|
||||
originKind: "plugin:paperclip.missions:page",
|
||||
});
|
||||
}
|
||||
|
||||
const params = { companyId, originKind: "plugin:paperclip.missions:page" };
|
||||
const all = await services.issues.list(params);
|
||||
expect(all).toHaveLength(5);
|
||||
|
||||
const page0 = await services.issues.list({ ...params, limit: 2, offset: 0 });
|
||||
const page1 = await services.issues.list({ ...params, limit: 2, offset: 2 });
|
||||
const page2 = await services.issues.list({ ...params, limit: 2, offset: 4 });
|
||||
expect(page0).toEqual(all.slice(0, 2));
|
||||
expect(page1).toEqual(all.slice(2, 4));
|
||||
expect(page2).toEqual(all.slice(4, 5));
|
||||
|
||||
expect(await services.issues.list({ ...params, limit: 0 })).toEqual([]);
|
||||
expect(await services.issues.list({ ...params, limit: 1, offset: 5 })).toEqual([]);
|
||||
|
||||
await expect(
|
||||
services.issues.list({ ...params, limit: 0, assigneeAgentId: "invalid-id" }),
|
||||
).rejects.toThrow("assigneeAgentId must be a UUID or 'null'");
|
||||
await expect(
|
||||
services.issues.list({ ...params, limit: 1, assigneeAgentId: "invalid-id" }),
|
||||
).rejects.toThrow("assigneeAgentId must be a UUID or 'null'");
|
||||
});
|
||||
|
||||
it("returns plugin-safe execution workspace metadata scoped to the company", async () => {
|
||||
const { companyId } = await seedCompanyAndAgent();
|
||||
const otherCompanyId = randomUUID();
|
||||
|
||||
@@ -2125,10 +2125,14 @@ export function buildHostServices(
|
||||
// Push the non-member visibility predicate into the list query so private
|
||||
// issues are filtered at the SQL layer before they can reach a plugin.
|
||||
const readCondition = await issueReadSqlCondition(db, pluginIssuePrivacyActor);
|
||||
return applyWindow(
|
||||
(await issues.list(companyId, { ...(params as any), readCondition })) as Issue[],
|
||||
params,
|
||||
);
|
||||
const limit = parseWindowValue(params.limit);
|
||||
const queried = (await issues.list(companyId, {
|
||||
...(params as any),
|
||||
readCondition,
|
||||
limit: limit === 0 ? 1 : limit ?? undefined,
|
||||
offset: parseWindowValue(params.offset) ?? 0,
|
||||
})) as Issue[];
|
||||
return limit === 0 ? [] : queried;
|
||||
},
|
||||
async get(params) {
|
||||
const companyId = ensureCompanyId(params.companyId);
|
||||
|
||||
Reference in new issue
Block a user