Files
PaperClipAI/packages/shared/src
brendanmatthewjones-cmykandPaperclip f78519ebb8 Clarify unavailable run context for issue writes (#19788)
## Thinking Path

> - Paperclip manages AI agents and their work.
> - The issue API attributes agent writes to a heartbeat run.
> - A valid run with no source issue and an unavailable run are
different denial cases.
> - The old response used one code and could tell an agent to resend a
header that was already present.
> - This pull request gives an unavailable or mismatched run its own
denial code.
> - The response tells the agent to inspect the run and stop affected
writes.
> - The benefit is a clear audit boundary and a useful recovery
instruction.

## Linked Issues or Issue Description

Refs #18450. Related PRs #18743 and #18275 address run context copy and
checkout binding.

**What happened?**

An agent issue write with a supplied run ID can fail when the run row is
absent, in another company, or owned by another agent. The API returned
the same denial as a run without a source issue. The response could tell
the agent to resend a header it already sent.

**Expected behavior**

The API returns a distinct 403 denial for an unavailable or mismatched
run. The response tells the agent to check the run lookup, stop affected
writes, and report the result. A run with no source issue keeps its
separate denial.

**Steps to reproduce**

1. Send an agent issue write with a run ID that has no matching run row
for that agent and company.
2. Observe the denial code and response text before and after this
change.
3. Send a write from a registered run with no source issue and confirm
that it keeps the separate run-context-required code.

**Paperclip version or commit**

Base behavior: `a708a133363a73bd6ad0491cf38dbddfd54c180e`. This PR is
based on a newer `master` commit with unchanged base blobs in the four
affected files.

**Deployment mode**

Agent issue writes in local and self-hosted deployments. No live
installation was tested.

## What Changed

- Add `issue_write_run_context_unavailable` to the shared denial
contract.
- Return that code when the supplied run is absent, belongs to another
company, or belongs to another agent.
- Clarify the separate denial text for a run that has no source issue.
- Add focused shared and server regression tests.

## Verification

- The reviewed four-file patch has SHA256
`d90722aef44d211d57a728e40d435ea4d2b5b15fa9271d9aceab6f254a18e4c7` as a
binary Git diff against its original base.
- Each changed blob in this PR matches the reviewed local commit byte
for byte. The newer base has the same four pre-change blobs.
- `pnpm --filter @paperclipai/shared exec vitest run
src/issue-write-denial.test.ts` passed locally.
- `pnpm --filter @paperclipai/server exec vitest run
src/__tests__/cross-issue-influence-limit.test.ts` passed locally.
- `pnpm --filter @paperclipai/shared typecheck` passed locally.
- `git diff --check` passed. Node 22.23.1 emitted an engine warning
because the repository requests Node 24.11.0 or newer.
- Full CI and Greptile review are pending. No live runtime verification
was performed.

## Risks

- Clients that branch on denial codes will see a new code for
unavailable or mismatched runs.
- The status remains 403. This change does not grant issue write scope
or alter the cross-issue limit.
- A run lookup may return 403 or 404 for reasons other than missing
registration. The response does not treat that result as proof that the
run is absent.
- Rollback: revert this commit. No database migration or configuration
change is required.

## Model Used

- OpenAI GPT-6 Codex assisted with source acceptance and PR preparation.
The exact serving model ID and context window were not exposed in this
run. Reasoning, shell, and GitHub tools were used.
- The reviewed source candidate was AI assisted. Its original model ID
was not recorded with the review evidence.

## 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

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-12-05 03:45:03 -08:00
..