From a393db78b40cac03ccc4eeba470e8c5edd21971d Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 13 Mar 2026 14:53:30 -0500 Subject: [PATCH] fix: address greptile follow-up Co-Authored-By: Paperclip --- .../codex-local/src/server/codex-home.ts | 2 +- .../codex-local/src/server/execute.ts | 6 +-- packages/shared/src/validators/agent.ts | 5 ++- server/src/services/issues.ts | 38 ++++++++++--------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/packages/adapters/codex-local/src/server/codex-home.ts b/packages/adapters/codex-local/src/server/codex-home.ts index a182e998..de037d6a 100644 --- a/packages/adapters/codex-local/src/server/codex-home.ts +++ b/packages/adapters/codex-local/src/server/codex-home.ts @@ -11,7 +11,7 @@ function nonEmpty(value: string | undefined): string | null { return typeof value === "string" && value.trim().length > 0 ? value.trim() : null; } -async function pathExists(candidate: string): Promise { +export async function pathExists(candidate: string): Promise { return fs.access(candidate).then(() => true).catch(() => false); } diff --git a/packages/adapters/codex-local/src/server/execute.ts b/packages/adapters/codex-local/src/server/execute.ts index 416f0e8e..d4b3da46 100644 --- a/packages/adapters/codex-local/src/server/execute.ts +++ b/packages/adapters/codex-local/src/server/execute.ts @@ -21,7 +21,7 @@ import { runChildProcess, } from "@paperclipai/adapter-utils/server-utils"; import { parseCodexJsonl, isCodexUnknownSessionError } from "./parse.js"; -import { prepareWorktreeCodexHome, resolveCodexHomeDir } from "./codex-home.js"; +import { pathExists, prepareWorktreeCodexHome, resolveCodexHomeDir } from "./codex-home.js"; const __moduleDir = path.dirname(fileURLToPath(import.meta.url)); const CODEX_ROLLOUT_NOISE_RE = @@ -61,10 +61,6 @@ function resolveCodexBillingType(env: Record): "api" | "subscrip return hasNonEmptyEnvValue(env, "OPENAI_API_KEY") ? "api" : "subscription"; } -async function pathExists(candidate: string): Promise { - return fs.access(candidate).then(() => true).catch(() => false); -} - async function isLikelyPaperclipRepoRoot(candidate: string): Promise { const [hasWorkspace, hasPackageJson, hasServerDir, hasAdapterUtilsDir] = await Promise.all([ pathExists(path.join(candidate, "pnpm-workspace.yaml")), diff --git a/packages/shared/src/validators/agent.ts b/packages/shared/src/validators/agent.ts index dae54754..f703f036 100644 --- a/packages/shared/src/validators/agent.ts +++ b/packages/shared/src/validators/agent.ts @@ -78,7 +78,10 @@ export const wakeAgentSchema = z.object({ reason: z.string().optional().nullable(), payload: z.record(z.unknown()).optional().nullable(), idempotencyKey: z.string().optional().nullable(), - forceFreshSession: z.boolean().optional().default(false), + forceFreshSession: z.preprocess( + (value) => (value === null ? undefined : value), + z.boolean().optional().default(false), + ), }); export type WakeAgent = z.infer; diff --git a/server/src/services/issues.ts b/server/src/services/issues.ts index c42ac02a..ecff7c3c 100644 --- a/server/src/services/issues.ts +++ b/server/src/services/issues.ts @@ -1115,26 +1115,28 @@ export function issueService(db: Db) { }, getCommentCursor: async (issueId: string) => { - const latest = await db - .select({ - latestCommentId: issueComments.id, - latestCommentAt: issueComments.createdAt, - }) - .from(issueComments) - .where(eq(issueComments.issueId, issueId)) - .orderBy(desc(issueComments.createdAt), desc(issueComments.id)) - .limit(1) - .then((rows) => rows[0] ?? null); - - const [{ totalComments }] = await db - .select({ - totalComments: sql`count(*)::int`, - }) - .from(issueComments) - .where(eq(issueComments.issueId, issueId)); + const [latest, countRow] = await Promise.all([ + db + .select({ + latestCommentId: issueComments.id, + latestCommentAt: issueComments.createdAt, + }) + .from(issueComments) + .where(eq(issueComments.issueId, issueId)) + .orderBy(desc(issueComments.createdAt), desc(issueComments.id)) + .limit(1) + .then((rows) => rows[0] ?? null), + db + .select({ + totalComments: sql`count(*)::int`, + }) + .from(issueComments) + .where(eq(issueComments.issueId, issueId)) + .then((rows) => rows[0] ?? null), + ]); return { - totalComments: Number(totalComments ?? 0), + totalComments: Number(countRow?.totalComments ?? 0), latestCommentId: latest?.latestCommentId ?? null, latestCommentAt: latest?.latestCommentAt ?? null, };