mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-04 21:21:27 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work.
> - Product journeys observe native tasks until their useful result is
complete.
> - A native session can time out while the server schedules an
exact-session retry.
> - The run status is temporarily failed while its retry remains
scheduled.
> - The observer currently grades that temporary state as a final
failure.
> - This pull request keeps observing a bound scheduled retry within the
original deadline.
> - The benefit is a grade based on the completed task, with terminal
failures and work limits preserved.
## Linked Issues or Issue Description
**What happened?**
A build-and-revise task prepared its ZIP, then hit a five-minute native
session timeout. The API reported agent-owned exact-session recovery on
the same run with one of three attempts used and a retry scheduled
before the campaign deadline. The journey raised `agent_run_failed`
before that retry could occur.
**Expected behavior**
Observe a proven scheduled retry on the same run within the original
deadline. Require a later successful run and the existing independent
artifact checks. A pending retry cannot pass the journey.
**Steps to reproduce**
Run the new agent-recovery regression against the previous observer. A
realistic failed native run with a scheduled retry fails immediately.
The corrected observer sees the same run succeed and still fails
terminal, exhausted, foreign and late recovery states.
**Paperclip version or commit**
Reproduced from 28aa32e7d7. Affected
source files were unchanged on current master before publication. The
documentation incorporates current master changes.
**Deployment mode**
Credential-free task-observer calibration on Linux. The observed hosted
failure supplied the original diagnosis. No full-stack staging recovery
pass is claimed.
## What Changed
- Pass the original campaign deadline to agent task validation.
- Reuse the existing native recovery predicate after company, task,
agent, environment and model checks.
- Accept older API projections that omit a successor when no successor
exists. Continue to reject an actual successor.
- Require succeeded or explicitly checked cancelled runs for settlement.
Never settle a failed recovery snapshot.
- Add controlled success, deadline and negative recovery tests. Preserve
the original budgets and run limits.
## Verification
- Red: three new recovery checks failed against the previous observer:
premature terminal grading, premature settlement and the wrong deadline
failure.
- Green: 194 tests pass across agent-recovery, agent-evidence and
onboarding-first-task.
- Local test-project typecheck could not complete: the host killed the
compiler with SIGKILL. `pnpm verify --explain` could not select checks
because the managed Git storage guard rejects `git ls-files`. Neither
attempt is a pass.
- Review follow-up at `b2957a3112df1cbcce80bba441cc0415bed1f86c`: the
shared task read now waits for pending recovery before it reaches any
consumer. This covers Plan revision, Plan approval, protected-action
decisions, replies and artifact reads. Four journey regression checks
fail before this gate and pass after it. All 202 focused recovery,
agent-evidence, onboarding and Plan checks pass. Fresh CI and review on
this head are pending. No new paid test, protected pin update or staging
deployment was made.
## Risks
- Waiting requires an explicit native retry projection, a matching
cause, agent ownership, remaining attempts and a retry time inside the
existing deadline. Other failures still stop immediately.
- Older projections omit the optional successor field. The compatibility
change accepts only null or absent values.
- No provider timeout or runtime recovery policy changes. A full
authorized staging run must still prove acceptance.
## Model Used
OpenAI GPT-6 through Codex, with reasoning, source editing, shell tools
and Chromium. The runtime does not expose a more specific model
revision.
## 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>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
64 lines
4.3 KiB
TypeScript
64 lines
4.3 KiB
TypeScript
type RecordValue = Record<string, unknown>;
|
|
const object = (value: unknown): RecordValue => value !== null && typeof value === "object" && !Array.isArray(value)
|
|
? value as RecordValue : {};
|
|
const nativeRecoveryTerminalCauses = new Set([
|
|
"native_provider_runtime_missing", "native_provider_model_rejected", "native_provider_approval_required",
|
|
"native_event_replay_conflict", "runner_remote_provider_artifact_incompatible",
|
|
"runner_remote_provider_verification_unavailable", "native_provider_terminal_failed",
|
|
"native_current_wake_comments_unread", "native_current_wake_comments_changed_after_read",
|
|
"native_session_cleanup_quarantined", "native_adopted_runner_authentication_timeout", "native_provider_usage_limit",
|
|
"native_permission_declined", "native_session_retry_exhausted",
|
|
]);
|
|
|
|
function hasProviderUsage(value: unknown): boolean {
|
|
if (value == null) return false;
|
|
if (typeof value !== "object" || Array.isArray(value)) return true;
|
|
return Object.entries(value).some(([key, entry]) => {
|
|
if (entry == null) return false;
|
|
if (["inputTokens", "cachedInputTokens", "outputTokens", "totalTokens", "costUsd", "costUsdExact"].includes(key)) return entry !== 0;
|
|
if (key === "accountingReceiptReady") return entry !== true;
|
|
// Assigned before provider dispatch; identifies the accounting scope, not usage.
|
|
if (key === "ledgerScope") return typeof entry !== "object" || Array.isArray(entry);
|
|
return true;
|
|
});
|
|
}
|
|
|
|
export function isPendingNativeRecovery(run: RecordValue, deadlineAt: number): boolean {
|
|
const execution = object(run.execution);
|
|
const finishedAt = typeof run.finishedAt === "string" ? Date.parse(run.finishedAt) : NaN;
|
|
const retryAt = typeof execution.retryAt === "string" ? Date.parse(execution.retryAt) : NaN;
|
|
// Older deployed projections omit the optional successor field when there
|
|
// is no successor. Both forms preserve the exact same-run retry contract.
|
|
return run.runtimeMode === "native" && run.status === "failed" && run.nativePhase === "retryable_failure" &&
|
|
typeof run.errorCode === "string" && run.errorCode.trim().length > 0 && execution.cause === run.errorCode &&
|
|
!nativeRecoveryTerminalCauses.has(run.errorCode) &&
|
|
typeof run.nativeIssueId === "string" && run.nativeIssueId === object(run.contextSnapshot).issueId &&
|
|
(run.issueId == null || run.issueId === run.nativeIssueId) &&
|
|
(execution.phase === "retry_scheduled" || execution.phase === "reconnecting") && execution.recoveryOwner === "agent" &&
|
|
Number.isInteger(execution.attempt) && Number(execution.attempt) >= 1 &&
|
|
execution.maxAttempts === 3 && Number(execution.attempt) < execution.maxAttempts && execution.successorRunId == null &&
|
|
Number.isFinite(finishedAt) && Number.isFinite(retryAt) && Number.isFinite(deadlineAt) &&
|
|
retryAt > finishedAt && retryAt <= deadlineAt;
|
|
}
|
|
|
|
/** Admission may set startedAt before selecting a runtime. Only this explicit
|
|
* control-plane receipt, without contradictory provider evidence, proves no turn
|
|
* ran. A legacy default alone is never proof of either execution or nonexecution. */
|
|
export function isProviderUnstartedWorkspaceDeferral(run: RecordValue): boolean {
|
|
const result = object(run.resultJson);
|
|
const recovery = object(result.executionRecovery);
|
|
const cancellation = object(result.cancellation);
|
|
const profile = object(run.runnerProfileJson);
|
|
return run.status === "cancelled" && run.errorCode === "workspace_busy" &&
|
|
recovery.kind === "workspace_wait" && recovery.providerWorkStarted === false &&
|
|
cancellation.source === "control_plane" && cancellation.expected === true && object(cancellation.initiator).type === "system" &&
|
|
run.runtimeMode === "legacy" && run.runtimeModeResolvedAt === null &&
|
|
["nativeIssueId", "nativeSessionId", "nativePhase", "runnerInstanceId", "processPid", "processGroupId", "processStartedAt",
|
|
"sessionIdAfter", "externalRunId", "exitCode", "signal", "logStore", "logRef", "lastOutputAt", "lastOutputStream"].every(key => run[key] == null) &&
|
|
run.lastOutputSeq === 0 &&
|
|
(run.lastOutputBytes == null || run.lastOutputBytes === 0) &&
|
|
profile.nativeExecutionInput == null && profile.sessionCheckpoint == null &&
|
|
!hasProviderUsage(run.usageJson) && (run.costUsd == null || run.costUsd === 0) &&
|
|
["costUsd", "costUsdExact", "cost_usd", "total_cost_usd"].every(key => result[key] == null || result[key] === 0);
|
|
}
|