mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 14:35:17 +01:00
Merge commit '8cd2d6a73d2097253dd329f55b637e12b20361c6' into codex/photon-managed-lock-policy
* commit '8cd2d6a73d2097253dd329f55b637e12b20361c6': docs(skills): add aggregate-bound, lost-runner, and bug-class lessons to fix-failed-paperclip-run (#21745) fix(comments): keep saved authorization cards from blocking replies (#21744) fix(server): wake a delivery task unscoped when it cannot apply settled hints (#21686) refactor: split the runner-e2e and restart-chaos READMEs into a runbook and a catalog (#21743)
This commit is contained in:
commit
6386390f05
23 files changed
+5216
-4965
No files matched your search
@@ -121,6 +121,12 @@ export function createDeliveryWorkCoordinator(input: {
|
||||
dirty = true;
|
||||
if (!running) schedule(task.coalesceMs ?? 0);
|
||||
}
|
||||
function applySettled(hints?: ReadonlySet<string>) {
|
||||
for (const attempt of hints === undefined ? [undefined] : [hints, undefined]) {
|
||||
try { task.onSettled?.(attempt); return; }
|
||||
catch (error) { process.emitWarning(`Delivery settlement could not be applied for ${queue}: ${String(error)}`); }
|
||||
}
|
||||
}
|
||||
const unsubscribe = subscribeDatabaseWork(input.owner, queue, (event, hints) => {
|
||||
if (workerStopped) return;
|
||||
if (databaseWorkPending(input.owner, queue)) {
|
||||
@@ -129,7 +135,7 @@ export function createDeliveryWorkCoordinator(input: {
|
||||
// replaces this deadline with an immediate wake on the normal path.
|
||||
if (!running) schedule(task.retryMs);
|
||||
}
|
||||
if (event === "settled") { task.onSettled?.(hints); wake(); }
|
||||
if (event === "settled") { applySettled(hints); wake(); }
|
||||
});
|
||||
const worker = { wake, async stop() {
|
||||
workerStopped = true;
|
||||
|
||||
@@ -107,6 +107,9 @@ import {
|
||||
requestCheckboxConfirmationPayloadSchema,
|
||||
requestCheckboxConfirmationResultSchema,
|
||||
requestConfirmationPayloadSchema,
|
||||
requestConfirmationCustomTargetSchema,
|
||||
requestConfirmationIssueAttachmentTargetSchema,
|
||||
requestConfirmationIssueDocumentTargetSchema,
|
||||
requestConfirmationResultSchema,
|
||||
requestItemVerdictsPayloadSchema,
|
||||
requestItemVerdictsResultSchema,
|
||||
@@ -117,6 +120,7 @@ import {
|
||||
withdrawIssueThreadInteractionSchema,
|
||||
} from "@paperclipai/shared";
|
||||
import { z } from "zod";
|
||||
import { logger } from "../middleware/logger.js";
|
||||
import { conflict, forbidden, notFound, unprocessable } from "../errors.js";
|
||||
import { getTelemetryClient } from "../telemetry.js";
|
||||
import { authorizationService } from "./authorization.js";
|
||||
@@ -703,6 +707,21 @@ function parseStoredInteractionResult<S extends z.ZodTypeAny>(
|
||||
return null;
|
||||
}
|
||||
|
||||
// Older internal writers persisted custom identity and display text without the
|
||||
// input length limits. Read those exact values across upgrades; never truncate
|
||||
// an identity or relax target types, URLs, revisions, or resolution authority.
|
||||
// New writes still use the strict shared payload schema.
|
||||
const storedRequestConfirmationPayloadSchema = requestConfirmationPayloadSchema.extend({
|
||||
target: z.discriminatedUnion("type", [
|
||||
requestConfirmationIssueDocumentTargetSchema,
|
||||
requestConfirmationIssueAttachmentTargetSchema,
|
||||
requestConfirmationCustomTargetSchema.extend({
|
||||
key: z.string().trim().min(1),
|
||||
label: z.string().trim().min(1).nullable().optional(),
|
||||
}),
|
||||
]).nullable().optional(),
|
||||
});
|
||||
|
||||
function hydrateInteraction(
|
||||
row: IssueThreadInteractionRow,
|
||||
): IssueThreadInteraction {
|
||||
@@ -774,7 +793,7 @@ function hydrateInteraction(
|
||||
),
|
||||
} satisfies AskUserQuestionsInteraction;
|
||||
case "request_confirmation": {
|
||||
const payload = requestConfirmationPayloadSchema.parse(row.payload);
|
||||
const payload = storedRequestConfirmationPayloadSchema.parse(row.payload);
|
||||
return {
|
||||
...base,
|
||||
kind: "request_confirmation",
|
||||
@@ -824,6 +843,23 @@ function hydrateInteraction(
|
||||
}
|
||||
}
|
||||
|
||||
function interactionForCommentSupersession(row: IssueThreadInteractionRow) {
|
||||
try {
|
||||
return hydrateInteraction(row) as UserCommentSupersedableInteraction;
|
||||
} catch (error) {
|
||||
if (!(error instanceof z.ZodError)) throw error;
|
||||
// The comment is useful even when a saved request cannot be decoded. Keep
|
||||
// that gate pending, refuse its normal resolution, and report only schema
|
||||
// locations, never payload/credential values. Valid siblings still expire.
|
||||
logger.warn({
|
||||
companyId: row.companyId, issueId: row.issueId, interactionId: row.id,
|
||||
kind: row.kind,
|
||||
validationIssues: error.issues.map(issue => ({ code: issue.code, path: issue.path })),
|
||||
}, "Saved interaction is invalid; leaving it pending while saving a comment");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async function touchIssue(db: IssueTouchDb, issueId: string, companyId: string) {
|
||||
await db.transaction(async tx => {
|
||||
await notifyStatusCardIssueChange(tx, companyId);
|
||||
@@ -4962,10 +4998,9 @@ export function issueThreadInteractionService(
|
||||
const superseded = rows.filter((row) => {
|
||||
if (row.kind === "ask_user_questions" && scope?.conversationAgentId && scope.conversationUserId) return false;
|
||||
if (!isUserCommentSupersedableKind(row.kind)) return false;
|
||||
const interaction = hydrateInteraction(
|
||||
row,
|
||||
) as UserCommentSupersedableInteraction;
|
||||
const interaction = interactionForCommentSupersession(row);
|
||||
return (
|
||||
interaction !== null &&
|
||||
shouldSupersedeInteractionOnUserComment(interaction) &&
|
||||
isCommentAtOrAfterInteraction({
|
||||
commentCreatedAt: comment.createdAt,
|
||||
@@ -5071,9 +5106,8 @@ export function issueThreadInteractionService(
|
||||
>();
|
||||
for (const row of rows) {
|
||||
if (!isUserCommentSupersedableKind(row.kind)) continue;
|
||||
const interaction = hydrateInteraction(
|
||||
row,
|
||||
) as UserCommentSupersedableInteraction;
|
||||
const interaction = interactionForCommentSupersession(row);
|
||||
if (!interaction) continue;
|
||||
if (!shouldSupersedeInteractionOnUserComment(interaction)) continue;
|
||||
|
||||
const supersedingComment = comments.find((comment) =>
|
||||
|
||||
@@ -75,6 +75,7 @@ import {
|
||||
} from "./mcp-tasks.js";
|
||||
import { logger } from "../middleware/logger.js";
|
||||
import { getAppDefinitionForApplicationKey, isConnectorFeatureEnabled } from "@paperclipai/shared";
|
||||
import { requestConfirmationPayloadSchema } from "@paperclipai/shared";
|
||||
import { instanceSettingsService } from "./instance-settings.js";
|
||||
import { redactSensitiveText } from "../redaction.js";
|
||||
import { spawn } from "node:child_process";
|
||||
@@ -4797,7 +4798,7 @@ export function createToolGatewayService(
|
||||
.limit(1);
|
||||
const href = `/${company?.issuePrefix ?? ""}/apps/${connection.id}/permissions`;
|
||||
const idempotencyKey = `connection-authorization:${connection.id}:${userId}`;
|
||||
const payload = {
|
||||
const payload = requestConfirmationPayloadSchema.parse({
|
||||
version: 1 as const,
|
||||
prompt:
|
||||
grantKind === "organization"
|
||||
@@ -4814,12 +4815,12 @@ export function createToolGatewayService(
|
||||
: "This run needs your personal authorization. Paperclip will not use another user's identity.",
|
||||
target: {
|
||||
type: "custom" as const,
|
||||
key: `connection:${connection.uid}:user:${userId}`,
|
||||
key: `connection-authorization:${createHash("sha256").update(idempotencyKey).digest("hex")}`,
|
||||
revisionId: connection.updatedAt.toISOString(),
|
||||
label: `Connect ${connection.name}`,
|
||||
label: `Connect ${connection.name}`.slice(0, 120),
|
||||
href,
|
||||
},
|
||||
};
|
||||
});
|
||||
const [existing] = await db
|
||||
.select({ id: issueThreadInteractions.id })
|
||||
.from(issueThreadInteractions)
|
||||
|
||||
Reference in new issue
Block a user