mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-30 21:38:42 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Paperclip posts system comments when automatic run recovery cannot continue > - These comments currently mix the main event with recovery identifiers and routing details > - The task chat shell also renders these comments as large raw text blocks > - Operators need a short explanation first and inspectable evidence on demand > - This pull request emits structured recovery notices and renders them as compact humanized rows > - The benefit is a quieter task thread that keeps the full recovery evidence available ## Linked Issues or Issue Description Related prior extraction source: #11070. This pull request replaces only its structured recovery notice slice with a focused branch based on current master. **What existing behavior does this improve?** Paperclip recovery escalations and the experimental task chat system-comment renderer. **Current behavior** Recovery escalation comments put action identifiers, owner details, run details, and failure codes into the visible markdown body. The task chat shell renders the complete system comment as a large text block. **Proposed behavior** The server emits a short system notice with typed metadata sections. The task chat shell classifies known recovery families and renders one compact row. An operator can expand the row to inspect the full body and metadata. **Reason and benefit** The main thread stays readable during repeated recovery activity. Typed links and evidence remain available without exposing raw failure text in the default view. **Breaking changes** The visible recovery comment body is shorter. Recovery action deduplication now reads the structured metadata and still recognizes legacy body markers. No API schema or database migration changes. ## What Changed - Emit stranded recovery escalations with `system_notice` presentation and typed recovery, owner, run, and failure-code metadata. - Share bounded metadata row builders across recovery notice producers and preserve legacy deduplication compatibility. - Humanize known recovery notice families and render compact expandable task-chat rows. - Route system-authored comments ahead of derived agent authorship so recovery notices do not appear as agent bubbles. - Add focused server and UI regression coverage. ## Verification - `pnpm check:token-gates` — 3/3 clean. - `pnpm --filter @paperclipai/server typecheck` — passed. - `pnpm --filter @paperclipai/ui typecheck` — passed. - `pnpm --filter @paperclipai/shared typecheck` — passed. - `pnpm --filter @paperclipai/shared exec vitest run src/validators/issue.test.ts` — 32 tests passed. - `pnpm --filter @paperclipai/server exec vitest run src/services/recovery/stranded-notice.test.ts src/__tests__/issue-recovery-actions.test.ts` — 57 tests passed. - `pnpm --filter @paperclipai/server exec vitest run src/services/recovery/successful-run-handoff.test.ts src/services/recovery/stranded-notice.test.ts` — 39 tests passed. - `pnpm --filter @paperclipai/server exec vitest run src/__tests__/heartbeat-process-recovery.test.ts -t 'escalates an exhausted failed successful-run handoff without using generic continuation recovery first|escalates an exhausted successful handoff run that still leaves no disposition'` — 2 tests passed. - `pnpm --filter @paperclipai/server exec vitest run src/__tests__/heartbeat-process-recovery.test.ts -t 'blocks assigned todo work after the one automatic dispatch recovery was already used'` — passed. - `pnpm --filter @paperclipai/ui exec vitest run src/lib/system-notice-humanizer.test.ts src/components/task-chat/TaskChatSystemNotice.test.tsx src/components/task-chat/task-chat-adapter.test.ts` — 15 tests passed. - Storybook visual baselines were not updated because this chat-shell path has no affected snapshot baseline. Focused rendering tests and token gates cover this change. ## Risks - Consumers that parse recovery action identifiers from comment markdown must move to structured metadata. Server deduplication remains backward compatible with legacy comments. - The humanizer uses stable recovery-family phrases. Unknown notices use a generic truncated first-sentence fallback. - The UI changes only the experimental task chat presentation. The stored comment body and expanded metadata remain available. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - OpenAI Codex with GPT-5, reasoning mode, repository tools, shell execution, and GitHub integration. The runtime did not expose a 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: Paperclip <noreply@paperclip.ing>
101 lines
4.5 KiB
TypeScript
101 lines
4.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { humanizeSystemNotice } from "./system-notice-humanizer";
|
|
|
|
describe("humanizeSystemNotice", () => {
|
|
it("uses presentation title and tone when present", () => {
|
|
const result = humanizeSystemNotice({
|
|
body: "Paperclip automatically retried dispatch but it still has no live execution path.",
|
|
presentation: {
|
|
kind: "system_notice",
|
|
tone: "danger",
|
|
title: "Run recovery exhausted",
|
|
detailsDefaultOpen: false,
|
|
},
|
|
});
|
|
expect(result).toEqual({ title: "Run recovery exhausted", tone: "danger" });
|
|
});
|
|
|
|
it("classifies claude_auth_required retry failures", () => {
|
|
const result = humanizeSystemNotice({
|
|
body:
|
|
"Paperclip automatically retried continuation for this assigned `in_progress` issue during terminal run " +
|
|
"recovery, but it still has no live execution path. Latest retry failure: `claude_auth_required` - adapter " +
|
|
"handshake failed. Moving it to `blocked` so it is visible for intervention.",
|
|
});
|
|
expect(result.title).toBe("Task paused — Claude needs re-authentication");
|
|
expect(result.tone).toBe("warning");
|
|
});
|
|
|
|
it("classifies configuration_incomplete failures", () => {
|
|
const result = humanizeSystemNotice({
|
|
body:
|
|
"Paperclip stopped before dispatching the adapter because required secret/env bindings are missing. " +
|
|
"Latest retry failure: `configuration_incomplete`. Moving it to `blocked` with a source-scoped recovery action.",
|
|
});
|
|
expect(result.title).toBe("Task paused — a secret/config binding is missing");
|
|
expect(result.tone).toBe("warning");
|
|
});
|
|
|
|
it("classifies missing secret bindings even without a failure code", () => {
|
|
const result = humanizeSystemNotice({
|
|
body:
|
|
"Paperclip stopped before dispatching the adapter because required secret/env bindings are missing. " +
|
|
"Moving it to `blocked` so an operator can bind the missing secret(s).",
|
|
});
|
|
expect(result.title).toBe("Task paused — a secret/config binding is missing");
|
|
});
|
|
|
|
it("classifies workspace validation failures", () => {
|
|
const result = humanizeSystemNotice({
|
|
body:
|
|
"Paperclip stopped before launching the local adapter because the issue workspace failed validation. " +
|
|
"This prevents git-sensitive adapters from running in an unrelated fallback cwd.",
|
|
});
|
|
expect(result.title).toBe("Task paused — workspace problem");
|
|
expect(result.tone).toBe("warning");
|
|
});
|
|
|
|
it("names the recovery owner from the markdown link for generic no-live-execution-path notices", () => {
|
|
const result = humanizeSystemNotice({
|
|
body:
|
|
"Paperclip automatically retried dispatch for this assigned `todo` issue during terminal run recovery, " +
|
|
"but it still has no live execution path. Moving it to `blocked` so it is visible for intervention.\n\n" +
|
|
"- Recovery action: `ra-123`\n" +
|
|
"- Recovery owner: [Dana the Manager](/PAP/agents/agent-9)\n" +
|
|
"- Next action: the recovery owner should restore a live execution path.",
|
|
});
|
|
expect(result.title).toBe("Task paused — waiting on Dana the Manager");
|
|
expect(result.tone).toBe("warning");
|
|
});
|
|
|
|
it("still humanizes no-live-execution-path notices without an owner link", () => {
|
|
const result = humanizeSystemNotice({
|
|
body:
|
|
"Paperclip automatically retried dispatch, but it still has no live execution path. " +
|
|
"Moving it to `blocked` so it is visible for intervention.",
|
|
});
|
|
expect(result.title).toBe("Task paused — waiting on a recovery owner");
|
|
});
|
|
|
|
it("falls back to System update plus a truncated first sentence", () => {
|
|
const longFirstSentence =
|
|
"The heartbeat scheduler observed an unusual condition while reconciling this issue's run ledger against the " +
|
|
"control plane state and recorded the discrepancy for later review.";
|
|
const result = humanizeSystemNotice({ body: `${longFirstSentence} Second sentence here.` });
|
|
expect(result.title).toBe("System update");
|
|
expect(result.tone).toBe("neutral");
|
|
expect(result.detail).toBeDefined();
|
|
expect(result.detail!.length).toBeLessThanOrEqual(80);
|
|
expect(result.detail!.endsWith("…")).toBe(true);
|
|
});
|
|
|
|
it("keeps a short first sentence untruncated in the fallback detail", () => {
|
|
const result = humanizeSystemNotice({ body: "Run rescheduled. More context follows." });
|
|
expect(result).toEqual({
|
|
title: "System update",
|
|
tone: "neutral",
|
|
detail: "Run rescheduled.",
|
|
});
|
|
});
|
|
});
|