Files
PaperClipAI/server/src
calvindomenicoandPaperclip 92e3ad1de9 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>
2026-11-23 20:26:57 -06:00
..
…
…
…
…
…