Commit Graph
3 Commits
Author SHA1 Message Date
34f8d25089 fix(github): expose review finding categories (#18429)
## Thinking Path

> - Paperclip manages AI agents and their work.
> - GitHub review bots submit structured assessments through task-bound
tools.
> - Each repository can set its own finding categories.
> - The schema accepts a string, but the server rejects values outside
the saved review policy.
> - Review instructions did not list the accepted values. The error did
not list them either.
> - This change gives agents the values before submission and keeps
server validation.

## Linked Issues or Issue Description

**What happened?**
Review submissions failed with an unknown finding category. The agent
corrected the assessment before publication. The sampled trace has two
rejections followed by a processed review. Historical tool inputs are
null. Authorized diagnostic inspection found no saved raw provider trace
for the representative run. The exact rejected values remain unknown.

**Expected behavior**
Agents can find the accepted categories before submission. Unknown
values still fail validation.

**Steps to reproduce**
Set a custom finding category. Start a review. Submit a different
category. Before this change, the instructions and error do not list the
accepted value.

## What Changed

- List configured categories in manual and automatic review
instructions.
- Return categories from the saved assessment policy in `begin_review`.
- Describe the dynamic constraint in the shared discovery schema. Keep
custom categories valid.
- List accepted values in category errors. Keep authorization and
publication checks.
- Add contract and database integration tests. Update documentation and
access maps.

### Hypothesis and thesis for a fix

The missing category guidance can cause avoidable submission retries. A
model can also ignore the policy returned by metadata reads; the
historical inputs do not establish which occurred. The repair belongs to
the GitHub review contract. Use the saved policy categories at review
start, explain the constraint, and retain server rejection. A fixed
global enum would reject valid custom categories.

## Verification

- Baseline `f1d7808`: two new contract assertions failed for missing
category guidance and error detail. The same assertions pass after the
change.
- `pnpm exec vitest run
server/src/services/chat-github-review-policy.test.ts
server/src/services/chat-github-tools.test.ts`: 41 passed.
- `pnpm exec vitest run
server/src/__tests__/chat-channels.integration.test.ts -t 'returns
snapshot finding categories'`: 1 passed. Real PostgreSQL and service
code; simulated GitHub HTTP. Checks policy changes, rejection before
publication, accepted custom category persistence, and processed
publication.
- `node scripts/check-maps.mjs`: passed. Structural evidence only.
- Shared TypeScript check passed. Server TypeScript checking was killed
by the 8 GiB memory limit, including a separate retry after the other
checks stopped.
- Full typecheck and build could not complete: `cargo` is absent. Full
tests were stopped after concurrent checks exhausted memory. CI must
supply the full checks.
- Follow-up compiler repair: the unchanged baseline reproduces TS2352 in
the category discovery test. Runtime matchers replace the unsafe schema
cast. They retain both guidance and custom-category assertions. The
repair is commit `0dcb94c676`, with current master merged at
`14d7052854`. The final head is
`c46b8f35add9255fc71be294d27f5a7865bcb47f`; the remaining code-comment
review finding was removed and resolved.
- Final-head CI: all gates pass, with no failed or pending checks.
Greptile gives this head 5/5 with no outstanding findings; the only
inline thread is resolved. The workspace test shard passed on one
bounded rerun after an earlier CLI child-server readiness timeout; no
code change was made for that rerun.
- The review host passed full recursive typecheck and build after the
compiler repair and master integration. Fresh database rechecks hit the
host PostgreSQL semaphore limit. The full local test command hit a
pre-existing chat line-selection failure before assertions. These local
limits do not replace the passing final-head CI evidence.
- No live model or GitHub publication at the changed revision. No
deployment or merge.

## Risks

- Instructions add policy text. An agent can still ignore it.
- Existing bot catalogs get the schema description when tools are
synchronized. Trusted review instructions and `begin_review` also expose
categories.
- The service test uses simulated GitHub HTTP. It does not prove that
deployed agents avoid retries.

## Model Used

The original worker used OpenAI `gpt-6.1-sol` through Codex with
reasoning, tool use, and code execution. A later Codex review repaired
the test compiler error. That review runtime exposes GPT-6 but no exact
snapshot or context-window size.

## 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: devinfoley <139239+devinfoley@users.noreply.github.com>
Co-authored-by: Paperclip <noreply@paperclip.ing>
Co-authored-by: Dotta <bippadotta@protonmail.com>
Co-authored-by: cryppadotta <34892728+cryppadotta@users.noreply.github.com>
2026-10-31 22:06:32 -05:00
DottaandPaperclip 5c807d11fa fix(github): prevent duplicate review score headings (#18321)
Clarify the shared GitHub review submission contract for new and existing bots.
Remove copied score headings while preserving the structured score and saved assessment.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-10-30 10:19:31 -05:00
ee29e2850d fix: keep GitHub guest provenance from failing tool discovery (#17340)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Agents reach their tools through the MCP tool gateway. Every run
starts with `tools/list`.
> - Tool discovery runs a GitHub guest sponsor probe
(`githubGuestBotConnectionForSession`) before it lists any connection.
> - The probe walked the run's identity chain before it knew whether the
task had a guest sponsored GitHub message at all.
> - When agent A works a task and the task is reassigned to agent B, B's
run chain continues A's run. The chain walk refuses with a plain
`HttpError`. The gateway returns 403 for `tools/list` with no audit
record. B loses every tool, built-in and connected, even when the
company has no GitHub endpoint.
> - This pull request makes the probe look up guest sponsored GitHub
messages for the task and agent first. When there are none, the probe
answers `null` and does not consult provenance.
> - The benefit is that a reassigned or continued task keeps its tools,
while a guest sponsored task still refuses a broken chain.

## Linked Issues or Issue Description

Fixes #17307

**What happened?**

`tools/list` on the MCP gateway returned `403 {"error":"Chat tools
cannot be inherited by another task"}` for every run whose identity
chain contained a run of another agent or another task. No audit event
was recorded. The agent received no tools at all, including unrelated
MCP connections. The company had no GitHub chat endpoint.

**Expected behavior**

A run on a task with no GitHub guest sponsor lists its tools. The guest
probe only decides whether the run must be limited to the sponsoring
bot's connection. When the task has no guest sponsored GitHub message,
the answer is "no sponsor" and discovery continues.

**Steps to reproduce**

1. Let agent A run on a task. The run gets an accepted identity context.
2. Reassign the task to agent B and let B run. B's identity context has
A's context as parent.
3. Call `tools/list` for B's run. Before this change the gateway returns
403 with the message above. The same happens when the parent context
belongs to a run on another task (see #17307).

**Call path**

`handleMcpGatewayProtocol` → `listToolsForNamedGateway` →
`listToolsForContext` → `buildToolsForContext` →
`connectionToolsForContext` → `githubGuestBotConnectionForSession` →
`chatRunSourceMessageId`, which throws `forbidden(...)`. The error is an
`HttpError`, not a `ToolGatewayHttpError`, so the route sends it as a
bare 403 and the discovery audit never runs.

**Paperclip version or commit**

`d69631b01b9c658f80bf8bed389863dce82643e1` (image `sha-d69631b`),
Docker, authenticated mode with PostgreSQL.

## What Changed

- `server/src/services/chat-github-tools.ts`:
`githubGuestBotConnectionForSession` first selects the inbound GitHub
message links on the task whose delivery carries `githubAuthority.guest
= true`, for endpoints assigned to the session agent. When there are
none it returns `null` without reading the run or its provenance chain.
When there are some, it verifies provenance as before and returns the
connection of the link that matches the verified source message.
- `server/src/services/chat-channels/run-origin.ts` is unchanged. The
cross-agent and cross-task refusals stay in place for Slack authority,
GitHub reviews and response comments, and for guest sponsored tasks.
- New test `server/src/services/chat-github-tools.test.ts` (embedded
PostgreSQL, same pattern as `run-origin.test.ts`):
- a run whose chain continues another agent, or another task, with no
guest message → `null` (fails before this change with the 403 above,
passes after);
- a guest sponsored task whose chain continues another agent → still
rejects with status 403;
- a run sponsored by a GitHub guest → returns the bot connection; the
same run with `guest: false` → `null`.

## Verification

- `pnpm --filter @paperclipai/server exec vitest run
src/services/chat-github-tools.test.ts`: 2 failed / 3 passed before the
fix, 5 passed after.
- `pnpm --filter @paperclipai/server exec vitest run
src/services/chat-channels/run-origin.test.ts
src/services/chat-github-tools.test.ts`: all passed.
- `pnpm --filter @paperclipai/plugin-sdk ensure-build-deps && pnpm
--filter @paperclipai/server exec tsc --noEmit`: clean.
- Manual: with a patched image, a run on a task that was reassigned
between two agents receives its full tool list through `tools/list` and
a `discovery` audit event is written. Before the patch the same kind of
run received the 403 and no audit event.

## Risks

- Low risk. The probe's result is unchanged for every session where it
returned a value before. The only behavior change is for sessions that
previously threw: when the task has no guest sponsored GitHub message,
they now get `null`, which is the value the old code could only have
returned for them anyway, because the final match also required a guest
link on this task for this agent.
- One extra query per discovery on guest sponsored tasks. On every other
session the run and provenance queries are skipped.

## Model Used

- Claude (Anthropic), Claude Code agent session; model id
`claude-fable-5-1`, extended thinking, tool use (shell, git, vitest with
embedded PostgreSQL).

## 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
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [x] I will address all Greptile and reviewer comments before
requesting merge

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

https://claude.ai/code/session_01LoF4rrmx35JJqbhEpaLQ9Q

---------

Co-authored-by: Ingvar Petrov <ip@protrener.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-23 20:06:16 -07:00