Files
PaperClipAI/server/src/services/native-runtime/remote-warm-session-recovery.test.ts
T
DottaandClaude Opus 5.5 11b09b7234 refactor: remove doc/execution-semantics.md and its references (#21699)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Contributors and agents read the docs under `doc/` for background on
run execution
> - `doc/execution-semantics.md` grew to 6,310 lines of per-PR notes
> - It was hard to read and it drifted from the code
> - The code and tests are the source of truth for execution behavior
> - This pull request removes the file and every reference to it
> - The benefit is one less stale document that readers can mistake for
a requirement

## Linked Issues or Issue Description

**Issue type**

Outdated or unclear documentation.

**Where is the issue?**

`doc/execution-semantics.md`, and the docs, rules, skills, maps, code
comments and log text that link to it.

**What's wrong?**

The file is 6,310 lines of notes added one PR at a time. Much of it
repeats or contradicts the code. Readers and agents treat it as a
contract, but the code and tests decide the behavior.

**Suggested fix**

Delete the file. Remove each link to it. Keep the documents that link to
it. Point at code where a pointer is still useful. Do not move the
content to another doc.

Refs #10664 (an open docs PR that edits this file; it becomes obsolete).

## What Changed

- Delete `doc/execution-semantics.md`.
- Remove links and pointers in `doc/PRODUCT.md`,
`doc/LOW-TRUST-PRESETS.md`, `doc/TASK-WATCHDOG.md`,
`doc/composer-stop.md`, `doc/native-workspace-finalization-recovery.md`,
`doc/run-log-events.md`, `doc/runner-internals.md` and
`doc/workspace-repositories.md`.
- `doc/TASK-WATCHDOG.md` now points at
`server/src/modules/active-run-watchdog/` for the silent active-run
watchdog.
- Remove the link in `rules/upgrade-safe-run-state.mdc` and
`maps/feature-map/recovery.md`.
- Update the skills `diagnose-why-work-stopped`,
`fix-failed-paperclip-run` and `terminal-bench-loop`. The
`fix-failed-paperclip-run` skill now points at
`server/src/services/heartbeat/` and `server/src/services/recovery/`.
- Remove the file from the source anchors in `.devin/wiki.json`.
- Remove the doc name from four code comments in `server/` and `ui/`.
- The failed-attachment log message no longer ends with a link to the
removed doc. Two tests now check the message text instead of the link.
- Leave two dated plan files under `doc/plans/` unchanged. They are
history.

## Verification

- `git grep -i execution-semantics` finds no hits outside `doc/plans/`.
- Every relative Markdown link in the changed files resolves.
- `node scripts/check-maps.mjs` passes.
- `node --test .github/scripts/tests/*.test.mjs` passes (808 tests).
- `pnpm verify` was not run locally. The worktree has no `node_modules`.
CI runs the changed Vitest files.

## Risks

- Low risk. Most changes are docs and comments.
- One runtime log line is shorter. It no longer has a link. No logic
changes.
- Open PRs that edit the deleted file, such as #10664, will conflict.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use and
shell access.

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

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-14 20:29:25 -06:00

120 lines
9.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { describeFailedAttachment, describeOwnFailedAttachment, isSettledRemoteWarmControlState, summarizePostTerminalEvents } from "./remote-warm-session-recovery.js";
const identity = { runId: "run", normalizedSessionId: "session", runnerInstanceId: "runner", environmentLeaseId: "lease", turnId: "turn", itemId: "item" };
const terminal = { eventType: "run.terminal", envelope: { ...identity } };
const goal = { schema: "paperclip.session_goal.snapshot.v1", goal: null, workingNow: false };
const notification = { schema: "paperclip.prp.event.v1", eventType: "session.goal.snapshot", runId: identity.runId,
normalizedSessionId: identity.normalizedSessionId, sourceInstanceId: "runner", sourceKind: "runner", payload: goal };
const snapshot = { eventType: "session.goal.snapshot", envelope: { ...identity, payload: notification } };
const notice = { schema: "paperclip.provider.notice.v1", noticeId: "codex-warning", severity: "warning", category: "warning", scope: "turn",
recoverable: true, userActionable: true, summary: "ignored a notification for a settled Codex turn" };
const noticeNotification = { ...notification, eventType: "provider.notice.recorded", payload: notice };
const lateNotice = { eventType: "provider.notice.recorded", envelope: { ...identity, payload: noticeNotification } };
const state = (events: unknown[]) => ({ identity, commands: [{ status: "completed" }], committedEvents: events });
describe("settled remote warm control evidence", () => {
it.each(["paperclip.prp.event.v1", "paperclip.prp.event.v2"])("accepts the terminal and an authenticated %s idle goal-read suffix without changing its order", schema => {
const suffix = { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, schema } } };
const control = state([terminal, suffix]);
expect(isSettledRemoteWarmControlState(control, identity)).toBe(true);
expect(control.committedEvents).toEqual([terminal, suffix]);
expect(isSettledRemoteWarmControlState(state([terminal]), identity)).toBe(true);
});
it.each([
["active goal", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, payload: { ...goal, goal: { status: "active" } } } } }],
["provider work", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, payload: { ...goal, workingNow: true } } } }],
["unauthenticated event type", { ...snapshot, eventType: "unknown" }],
["unknown protocol version", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, schema: "paperclip.prp.event.v3" } } }],
["new turn", { ...snapshot, eventType: "turn.started" }],
["foreign run", { ...snapshot, envelope: { ...snapshot.envelope, runId: "other" } }],
["foreign session", { ...snapshot, envelope: { ...snapshot.envelope, normalizedSessionId: "other" } }],
["foreign source", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, sourceInstanceId: "other" } } }],
["foreign lease", { ...snapshot, envelope: { ...snapshot.envelope, environmentLeaseId: "other" } }],
["foreign notification", { ...snapshot, envelope: { ...snapshot.envelope, payload: { ...notification, runId: "other" } } }],
["missing payload", { ...snapshot, envelope: { ...identity } }],
])("holds a %s suffix", (_name, suffix) => {
expect(isSettledRemoteWarmControlState(state([terminal, suffix]), identity)).toBe(false);
});
it("accepts anything that already happened after the terminal, whatever its severity or type", () => {
const variant = (eventType: string, payload: Record<string, unknown>) =>
({ eventType, envelope: { ...lateNotice.envelope, payload: { ...noticeNotification, eventType, payload } } });
const info = { ...lateNotice, envelope: { ...lateNotice.envelope, payload: { ...noticeNotification, payload: { ...notice, severity: "info" } } } };
expect(isSettledRemoteWarmControlState(state([terminal, lateNotice]), identity)).toBe(true);
expect(isSettledRemoteWarmControlState(state([terminal, lateNotice, snapshot, info]), identity)).toBe(true);
for (const late of [
variant("provider.notice.recorded", { ...notice, severity: "error", recoverable: false }),
variant("harness.diagnostic", { code: "codex_resume_usage_snapshot" }),
variant("usage.reported", { runDelta: { inputTokens: 1 } }),
variant("a.future.event", {}),
]) expect(isSettledRemoteWarmControlState(state([terminal, late]), identity)).toBe(true);
});
it.each(["turn.started", "turn.accepted", "run.attached", "tool.execution.started", "semantic_tool.input", "runtime_request.created"])(
"holds %s after the terminal because work may still be live", eventType => {
const live = { eventType, envelope: { ...lateNotice.envelope, payload: { ...noticeNotification, eventType } } };
expect(isSettledRemoteWarmControlState(state([terminal, lateNotice, live]), identity)).toBe(false);
});
it("reads goal state from both goal events", () => {
const goalEvent = (eventType: string, payload: Record<string, unknown>) =>
({ eventType, envelope: { ...identity, payload: { ...notification, eventType, payload: { ...goal, ...payload } } } });
for (const eventType of ["session.goal.snapshot", "session.goal.updated"]) {
const settled = (payload: Record<string, unknown>) => isSettledRemoteWarmControlState(state([terminal, goalEvent(eventType, payload)]), identity);
expect(settled({ goal: { status: "active" } })).toBe(false);
expect(settled({ goal: { status: "paused" }, workingNow: true })).toBe(false);
expect(settled({ goal: null, workingNow: undefined })).toBe(false);
expect(settled({ goal: { status: "paused" } })).toBe(true);
expect(settled({ goal: { status: "complete" } })).toBe(true);
expect(settled({})).toBe(true);
}
});
it("summarizes post-terminal events for the next run's log", () => {
expect(summarizePostTerminalEvents(state([terminal]))).toBeNull();
expect(summarizePostTerminalEvents(state([terminal, lateNotice, lateNotice, snapshot])))
.toBe("provider.notice.recorded x2, session.goal.snapshot x1");
});
it("explains a failed attachment with its real cause", () => {
const stored = 'native_session_recovery_failed: Error: PRP command run.attach failed: {"commandType":"run.attach","result":{"code":"command_execution_failed","message":"run.attach requires a settled Codex provider session: active_turn"},"status":"failed"}';
const pointer = describeFailedAttachment(stored);
expect(pointer).toContain("run.attach requires a settled Codex provider session: active_turn");
expect(pointer).toContain("A later run may start a new provider thread.");
expect(describeFailedAttachment("run.attach requires the restored Codex provider process")).toContain("restored Codex provider process");
const quoted = `PRP command run.attach failed: ${JSON.stringify({ result: { message: 'run.attach provider is invalid: unknown "value" here' } })}`;
expect(describeFailedAttachment(quoted)).toContain('run.attach provider is invalid: unknown "value" here. A later run');
expect(describeFailedAttachment("Plugin Runner operation failed; reconcile the saved task")).toBeNull();
expect(describeFailedAttachment(null)).toBeNull();
});
it("names the original failure when a same-run retry finds its own failed attachment", () => {
expect(describeOwnFailedAttachment([{ stderrTail: "run.attach requires a settled session: active_turn" }]))
.toBe("runner_state_identity_mismatch: prior_attach_failed: run.attach requires a settled session: active_turn");
expect(describeOwnFailedAttachment([])).toBe("runner_state_identity_mismatch: prior_attach_failed: unknown");
expect(describeOwnFailedAttachment(undefined)).toBe("runner_state_identity_mismatch: prior_attach_failed: unknown");
});
it.each([
["notification type mismatch", { ...lateNotice, envelope: { ...lateNotice.envelope, payload: { ...noticeNotification, eventType: "session.goal.snapshot" } } }],
["foreign notice source", { ...lateNotice, envelope: { ...lateNotice.envelope, payload: { ...noticeNotification, sourceInstanceId: "other" } } }],
["foreign notice lease", { ...lateNotice, envelope: { ...lateNotice.envelope, environmentLeaseId: "other" } }],
["control plane notice source", { ...lateNotice, envelope: { ...lateNotice.envelope, payload: { ...noticeNotification, sourceKind: "control_plane" } } }],
])("holds a %s suffix", (_name, suffix) => {
expect(isSettledRemoteWarmControlState(state([terminal, suffix]), identity)).toBe(false);
});
it("holds new work recorded after a late provider notice", () => {
expect(isSettledRemoteWarmControlState(state([terminal, lateNotice, { ...snapshot, eventType: "turn.started" }]), identity)).toBe(false);
});
it("holds missing terminals, pending commands and mixed core identities", () => {
expect(isSettledRemoteWarmControlState(state([snapshot]), identity)).toBe(false);
expect(isSettledRemoteWarmControlState({ ...state([terminal, snapshot]), commands: [{ status: "dispatched" }] }, identity)).toBe(false);
expect(isSettledRemoteWarmControlState({ ...state([terminal, snapshot]), identity: { ...identity, runnerInstanceId: "other" } }, identity)).toBe(false);
expect(isSettledRemoteWarmControlState(state([{ ...terminal, envelope: { ...identity, runId: "other" } }, snapshot]), identity)).toBe(false);
});
});