mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-24 14:20:12 +01:00
3cd1370141befdb5485578d7e777a1ae26fbf8bb
4
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
3cd1370141 |
fix(github): re-read parked response requests after the settle decision changes (#22710)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Review agents answer GitHub pull requests, and a background sweep settles each request's status comment once its run finishes > - The sweep parks a request it cannot progress yet with a wait key, and a broad rebuild skips it until that key changes > - #22672 changed how requests settle, but requests parked by the older code kept the same key after the deploy > - So the new code never read them: 11 inline "Working on this…" comments stayed open on staging after #22672 deployed > - This pull request puts a decision version at the start of the wait key > - The benefit is that a deploy which changes the settle decision re-reads every parked request once, so old stuck comments settle ## Linked Issues or Issue Description Refs #22672 **Describe the bug** After #22672 deployed to staging, 5 of 16 stuck inline "Working on this…" review comments settled, but 11 did not. Their tasks had no new activity, so their wait keys did not change, and the sweep kept skipping them. **Steps to reproduce** 1. A request is parked by the terminal response sweep with a wait key from older code. 2. Deploy code that changes when such a request settles. 3. Nothing on the task changes, so the key stays the same and the request is never read again. **Expected behavior** A deploy that changes the settle decision re-reads every parked request once. ## What Changed - `GITHUB_TERMINAL_RESPONSE_DECISION_VERSION` ("v2") now starts the terminal sweep's wait key. Keys written before this change never match, so each parked request is read once by the current decision. - New test: requests parked with the old key, whose own run finished before a newer run, are all settled after the sweep starts. ## Verification - `reads requests parked by an older decision once after a deploy`: red without the version (0 of 120 acknowledged), green with it (120 of 120). - `server/src/services/chat-channels/github/` tests: 65 passed. - After deploy: the 11 open "Working on this…" comments on staging-reviewed PRs should settle within a sweep pass. ## Risks - One extra read of every parked request right after deploy (one batched page read per 100 rows, then they park again under the new key). Low risk. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code 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 - [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 - [ ] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
8ce422e45d |
fix(github): keep published reviews and settle every status comment (#22672)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Review agents answer GitHub pull requests through one shared main PR comment and one comment per inline request > - Paperclip writes status notices into these comments: "Work is paused", "This turn ended without publishing a final response", "Working on this…" > - On recent PRs these notices replaced finished reviews, and many never changed again, even after the task was done > - People then see a stale status instead of the review, and work that waits on the review slows down > - This pull request keeps published reviews in place and makes every status comment settle > - The benefit is that the PR always shows the latest real review, and no placeholder stays open after the task is idle ## Linked Issues or Issue Description **Describe the bug** Review bot comments on GitHub pull requests show "Work is paused. Your request is saved." or "This turn ended without publishing a final response." after the review finished. The comment never updates. Inline replies stay at "Working on this…". **Steps to reproduce** 1. A review agent publishes a review in the main PR comment. 2. Two more review requests arrive. The task becomes blocked for a short time, or the run for a request ends without a reply. 3. The main PR comment now shows the status notice. The review is gone. 4. Separately: request A's run ends and request B's run starts a few seconds later. A's inline comment stays "Working on this…" forever. **Expected behavior** A status notice for one request never replaces a published review in the shared main PR comment. Every request comment settles once the run that woke for it is finished and the task is idle. **Evidence** GitHub edit history shows the overwrite on all six settled stuck comments across #22528, #22591, #22611, #22626 (two bots) and #22635. Example: on #22626 the "Ponytail Paperclip Review — 3/5" body was replaced by "Work is paused" at 14:28 and again at 14:56; Feynman's reply was replaced and then patched nine times in four minutes. The task ran 15 back-to-back runs about 3 seconds apart, so the old "latest run only" check never matched the earlier requests. ## What Changed - `writeGitHubResponseComment` takes a `status` flag. In the shared main PR comment, a status notice never replaces a published reply or a newer response. That request settles as final against the existing comment (`published_response_kept` / `status_superseded`) instead of throwing and retrying. - Status notices carry a `paperclip-response-kind:status` marker. Known status texts posted before this change count as status too, so a later status may still replace them. - `readGitHubResponseRun` / `readGitHubResponseRuns` return `finishedRequestRunId`: the latest finished run that woke for the request. It is part of the same statement, so the batched sweep keeps its statement budget. - `githubResponseExecution` settles a request from that run once the task's latest run is finished, the latest run belongs to another request, and the task is not blocked. - `processTerminalResponses` selects a request when any finished run woke for it, not only the latest run. ## Verification - New red/green integration tests in `server/src/__tests__/chat-channels.integration.test.ts`: - `keeps the published review in the main GitHub PR comment when a later request has only a status: ended_without_reply / paused` (red before: body became the status text) - `settles a GitHub working comment whose run finished just before another request's run started` (red before: body stayed "Working on this…") - Updated older tests that asserted the old rule (status replaces the review) to assert the review stays and the request settles final. - `response-run-state.test.ts` equivalence reference now also computes the finished request run; passes over the randomized fixture. - `terminal-response-work.test.ts` statement budget passes (the first fallback did one query per row; it now reads in the same statement). - Local: all GitHub tests in the integration file passed (536) before the batching refactor; after it, the targeted tests plus `server/src/services/chat-channels/github/` and related files pass (438). `tsc --noEmit` for server is clean. CI covers the full suite. ## Risks - Behavior change: when a newer request is paused or ends without a reply, the main PR comment keeps the earlier review instead of showing the status. The status stays visible in the Paperclip task. - A request whose run finished without a reply now settles to "ended without publishing a final response" once the task is idle, even if a later continuation run covered it in another thread. - No migration. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and code 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 - [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 - [ ] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> |
||
|
|
f4f4902707 |
perf(chat): read the run state of a GitHub response sweep page in one batch (#21711)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The GitHub chat channel has two sweeps for request response
comments: the acknowledgement sweep (`acknowledgement-work.ts`) and the
terminal-response sweep (`terminal-response-work.ts`). Each reads pages
of up to 100 requests.
> - For each loaded request, both sweeps call `readGitHubResponseRun`
one row at a time. That is one latest-run statement, plus the run
identity context read and the message link read of
`chatRunSourceMessageId`. A page of 100 requests costs about 300
statements.
> - On paperclip.staging, those two provenance reads ran at about 13/s
each. #21705 stops the idle backlog from being reloaded. This PR makes
the reads that remain cost a constant number of statements per page.
> - The per-row read also had a failure mode. A 403 from one run's
provenance check aborted the acknowledgement sweep's whole page, so no
request of that company was acknowledged until the 403 went away.
> - This pull request adds a batched `readGitHubResponseRuns` and uses
it once per page in both sweeps.
> - The benefit is a constant number of statements per page, and a
provenance failure that affects only its own request.
## Linked Issues or Issue Description
Refs #21705 (the same sweeps; that PR stops reloading requests that
cannot progress).
No issue exists. This describes the problem with the fields of
`.github/ISSUE_TEMPLATE/bug_report.yml`.
**What happened?**
On paperclip.staging (2026-11-15, about 01:45–02:25Z),
`provenanceReads.context` (`select … from run_identity_contexts where id
= $1 and run_id = $2 and company_id = $3 and status = $4 limit $5`) ran
at 13.37/s, and `provenanceReads.link` (`select
chat_conversations.issue_id, chat_endpoints.provider from
chat_message_links join … where chat_message_links.company_id = $3 and
comment_id = $4 …`) ran at 13.20/s. Both GitHub response sweeps reach
them through `readGitHubResponseRun` → `chatRunSourceMessageId(db, run,
{ provider: "github" })`, once for each loaded row. `load()` costs one
page read plus three statements per row. `check()` read the run state
twice for each due request (before and after the acknowledgement).
In the acknowledgement sweep, a 403 from `chatRunSourceMessageId` (for
example, a run whose identity context is no longer accepted) threw out
of `entry()` and aborted the whole page. The terminal sweep already kept
such a row due, so the acknowledgement owner could revoke it.
**Expected behavior**
A page of requests costs a constant number of statements. A failure for
one run affects only the requests of that run.
**Steps to reproduce**
1. Create 120 GitHub response requests on 30 tasks. Give each task an
ended run with an accepted identity context.
2. Register the terminal-response sweep. On master, the first pass costs
one page read plus three statements per row.
3. Mark the requests `received`, revoke one run's identity context, and
register the acknowledgement sweep. On master, the load fails with a
403, and none of the 150 requests is acknowledged.
**Paperclip version or commit**
master at
|
||
|
|
ea8c734cb9 |
fix(chat): park GitHub terminal responses that wait for a newer run or task change (#21705)
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - The GitHub chat channel posts one App-owned response comment per
accepted request. The terminal-response sweep
(`terminal-response-work.ts`) finds processed, non-final responses whose
task's latest run has ended, and asks the acknowledgement owner to post
the final text.
> - On paperclip.staging, 1,557 processed `github_response_comment` rows
are not final. None changed in the last 5 minutes, and the oldest dates
from 2026-10-28. The sweep reads all of them again on each company-wide
rebuild (every 30 s per company), with one page read plus three
statements per row. Two of those statements run at about 13/s each in
`pg_stat_statements`.
> - The sweep cannot make progress on these rows. Their task's latest
run ended without owning the request (a later request started it), or
the pause is already shown. Nothing that the decision reads changes
until a new run starts, the task status changes, or the row changes.
> - This pull request records that wait on the row and skips it on broad
rebuilds until one of those inputs changes.
> - The benefit is that an idle backlog costs one page read per rebuild
instead of about three statements per row, and no request loses a path
to settle.
## Linked Issues or Issue Description
No issue exists. This describes the problem with the fields of
`.github/ISSUE_TEMPLATE/bug_report.yml`.
**What happened?**
On paperclip.staging (2026-11-15, about 01:45–02:25Z), two single-row
statements ran at nearly the same rate:
- `select id, run_id, company_id, status, responsible_user_id,
message_id, parent_context_id from run_identity_contexts where id = $1
and run_id = $2 and company_id = $3 and status = $4 limit $5` at
13.37/s.
- `select chat_conversations.issue_id, chat_endpoints.provider from
chat_message_links join chat_conversations … join chat_endpoints … where
chat_message_links.company_id = $3 and comment_id = $4 …` at 13.20/s.
They are `provenanceReads.context` and `provenanceReads.link` in
`run-origin.ts`. The terminal-response sweep reaches them through
`readGitHubResponseRun` for each row it loads.
The backlog of `github_response_comment` actions on staging:
- `processed`, `delivery_id` set, `result.final` not `true`: 1,557 rows
(the terminal sweep's set). None updated in the last 5 minutes. The
oldest `updated_at` is 2026-10-28.
- `result.code` of those rows: null 1,387, `acknowledgement_unconfirmed`
150, `acknowledgement_superseded` 20.
- The acknowledgement set (`received`, or `failed` and retryable) is
empty.
- Other rows: processed and final 6,645, failed and not retryable 265,
cancelled 116.
**Root cause**
`entry()` returns `null` ("nothing to post now") when
`githubResponseExecution` has no body. That happens when the task's
latest run has ended but does not own the request and the task is not
blocked. It also happens when the task is blocked and the row already
shows this pause (`pausedVersion` matches). The page query still selects
these rows, because the latest run has ended (or the task is blocked)
and the row is not final. Nothing records the decision, so each
company-wide rebuild reads every row again: `readGitHubResponseRun` (one
statement) plus `chatRunSourceMessageId` (the context and link reads)
for each row. The codes do not matter. `acknowledgement_unconfirmed` is
a retry code that a later successful acknowledgement keeps, and
`acknowledgement_superseded` marks a request whose shared PR comment has
a newer version. All three groups wait for the same thing: a newer run
that owns the request, or a task status change.
**Expected behavior**
A response that cannot progress costs nothing until the run, the task or
the response changes. A response that can progress settles as before.
**Steps to reproduce**
1. Create a GitHub endpoint and a task with several processed, non-final
response comments (codes null, `acknowledgement_unconfirmed`,
`acknowledgement_superseded`).
2. Give the task a newer ended run whose identity context names a later
request, so the run does not own the older requests.
3. Register the terminal-response sweep and send a company-wide hint
every 30 s.
4. On master, each rebuild reads every row again with about three
statements per row and writes nothing.
**Paperclip version or commit**
master at
|