Skip to content

Commit 427f563

Browse files
d-csclaude
andcommitted
fix(webapp): make buffer fallback reachable on PG-miss in routeOperationsToRun
Follow-up to the Devin review on PR #3756. updateMetadataService.call resolves with undefined (not a throw) when the target run isn't in PG, so the previous `if (!error) return;` treated PG-miss as success and the buffer fallback below was unreachable. Capture the result too and fall through only on PG-applied; PG-miss now proceeds to the buffer fallback alongside the PG-threw path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bb21c85 commit 427f563

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

apps/webapp/app/routes/api.v1.runs.$runId.metadata.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,28 @@ async function routeOperationsToRun(
8080
// AuthenticatedEnvironment so we don't have to recover the unsafe
8181
// `as unknown` cast that the previous narrowed `{ id, organizationId }`
8282
// signature forced on us.
83-
const [error] = await tryCatch(
83+
//
84+
// Two non-success outcomes from `call`:
85+
// * throws — PG threw (e.g. "Cannot update metadata for a completed
86+
// run", or a transient PG outage).
87+
// * resolves with undefined — PG row didn't exist (the target may be
88+
// buffered, not yet materialised).
89+
// Either way we want to try the buffer fallback below; treating the
90+
// undefined-return as success would make the fallback unreachable.
91+
const [error, result] = await tryCatch(
8492
updateMetadataService.call(targetRunId, { operations }, env)
8593
);
86-
if (!error) return;
87-
88-
// PG service threw — commonly "Cannot update metadata for a completed
89-
// run", but it could also be a transient PG failure. Parent/root ops
90-
// are auxiliary (the caller's primary mutation already landed); stay
91-
// best-effort and don't surface this to the caller — but warn so a
92-
// genuine PG outage on these ops isn't invisible.
93-
logger.warn("metadata route: parent/root PG op failed", {
94-
targetRunId,
95-
error: error instanceof Error ? error.message : String(error),
96-
});
94+
if (!error && result !== undefined) return;
95+
96+
if (error) {
97+
// PG threw — auxiliary op, stay best-effort and don't surface this
98+
// to the caller (the caller's primary mutation already landed). But
99+
// warn so a genuine PG outage on these ops isn't invisible.
100+
logger.warn("metadata route: parent/root PG op failed", {
101+
targetRunId,
102+
error: error instanceof Error ? error.message : String(error),
103+
});
104+
}
97105

98106
// Buffer fallback only makes sense for friendlyId-keyed entries. The
99107
// PG-side parent/root IDs are internal cuids; the buffer keys entries

0 commit comments

Comments
 (0)