Files
PaperClipAI/server
DottaandPaperclip 9911b7052f Expose continuation retry keys and preserve account-repair resumes (#22046)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - Runner gives agents a tool to report work and wait for a later
check.
> - That tool requires a stable retry key for each explicit wait.
> - Codex can hide the wait fields when it renders our nested schema.
> - Hidden fields make a correct report harder to construct.
> - This pull request changes the provider schema structure and
preserves its rules.
> - Agents can see the required fields before they submit a report.

## Linked Issues or Issue Description

**What happened?**

The completion tool appears in Codex code mode with `continuation?:
unknown`. An agent can omit the required retry key and receive a
rejected report. The top-level schema was fixed in #21398. The nested
continuation still uses the same problematic structure.

**Expected behavior**

Codex must show the required `kind`, `summary`, and `idempotencyKey`
fields. Invalid reports must still fail validation.

**Steps to reproduce**

Render `PRP_COMPLETION_RESULT_PROVIDER_INPUT_SCHEMA` with the public
Codex code-mode renderer at `b271854568d6c9282e999d6f36e5e85f447d027d`.
Its `render_map` function processes `allOf` before sibling properties.
The conditional-only branch renders as `unknown` and hides those
properties.

Source:
https://github.com/openai/codex/blob/b271854568d6c9282e999d6f36e5e85f447d027d/codex-rs/code-mode-protocol/src/json_schema_types.rs#L127

**Paperclip version or commit**

Baseline: `01451fae5b25f784956e9932f12031dc194ac247`.

The first complete CI browser attempt also exposed an intermittent
account-repair race. Repair restores the task and resolves its recovery
action, then a sweep can reclassify the same old failure and block it
again before the queued reply starts. The repair in this PR honors that
exact persisted resolution while holding the existing task lock. A later
failed run still escalates.

## What Changed

- Express the single provider continuation condition as direct `if` and
`then` fields. This is equivalent to its previous `allOf` wrapper.
- Keep the canonical output schema unchanged. Keep required retry keys
and case handoff IDs.
- Add a discovery guard, a 60-case provider/canonical validation
comparison, and authenticated HTTP bridge checks.

### Hypothesis and thesis for a fix

The nested `allOf` hides fields in the tested Codex renderer. The
equivalent direct condition lets that renderer reach the object fields.
This belongs in the existing provider compatibility schema. It changes
no controller policy, company access, saved state, or retry identity.
The experiment proves field visibility. It does not prove which renderer
served a historical request or measure model omission rates.

- Honor a resolved/restored configuration recovery for the same company,
task and failed run before re-escalating. Dispatch checks and recovery
for new failures remain intact.
- Add a PostgreSQL regression covering repeat sweeps, a new failure
identity, an unresolved recovery, and another task's repair. This
belongs in the existing locked escalation function; no new state or
subsystem is introduced. `service.ts` was already over 1,000 lines.

- Define the handoff condition once and explicitly compose both
canonical and provider schemas from it, removing the implicit
one-element `allOf` assumption raised in review.

## Verification

- Built and ran the exact pinned public Codex renderer in a disposable
Rust crate. The complete baseline schema renders `continuation?:
unknown`. The changed schema renders a nullable object with required
`kind`, `summary`, and `idempotencyKey` fields.
- The new discovery regression fails on the baseline. The same test
passes with the fix.
- Runner: `pnpm exec vitest run src/contracts/completion-result.test.ts
src/contracts/tool-input-variants.test.ts
src/contracts/provider-tool-schema-shape.test.ts
src/drivers/runner-tool-bridge.schemas.test.ts
src/drivers/runner-tool-bridge.continuation.test.ts` — 48 tests pass.
- Runner: `pnpm exec tsc -p tsconfig.json` and `node
scripts/generate-semantic-contracts.mjs --check` pass.
- Server: the selected `task-monitor.integration.test.ts` test for
unfinished monitor waits passes with embedded PostgreSQL. It rejects an
unscheduled wait and accepts the saved monitor.
- Server: the selected `issue-monitor-scheduler.test.ts` recovery test
passes with embedded PostgreSQL. It checks persistence, same-key replay,
and one scheduled wake. The fixture's successor run fails its separate
responsible-user setup. This is not proof of successful successor
execution.
- HTTP bridge handler is simulated. It verifies rejection before
dispatch, valid monitor/response-wake/handoff reports, retry identity,
and authentication.
- Recovery regression: baseline 1 failed / 3 passed (the restored task
was blocked again); unchanged test after the fix 4 passed. Together with
recovery state-read tests: 7 passed. Existing configuration-recovery
selection: 4 passed, 108 deselected.
- Final completion schema and authenticated HTTP bridge selection: 33
passed.
- Local real browser journey with disposable embedded PostgreSQL and
ACP/provider fixtures: baseline repeat5 produced 2 failures / 3 passes,
matching CI. Fixed repeat5: 5 passed in 1.8 minutes. The test
independently checks exactly one successful successor, stored connection
binding and persisted reply after reload.
- No full local suite, deployed recovery, or probabilistic model result
is claimed. Fresh CI and review are required for the updated head.

- Review follow-up: 48 focused schema/discovery/HTTP tests pass; `node
scripts/generate-semantic-contracts.mjs --check` passes. Fresh CI/review
required after the refactor.

## Risks

Low runtime risk. The accepted input rules are unchanged. A provider
that handles direct conditionals differently could expose a
compatibility issue. The canonical validator still enforces the output
contract. No migration or saved-session reset is needed. Previously
saved state keeps the same format. Recovery now honors existing
resolved/restored actions only for the exact failed source run, so a new
configuration failure remains eligible for escalation. Company, task,
ownership and dispatch checks remain in force.

## Model Used

OpenAI GPT-6 Codex agent, with reasoning, tool use, and code execution.
The runtime did not expose a more specific model ID.

## 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>
2026-11-17 14:23:19 -06:00
..