Harden Copilot error and VFS handling

This commit is contained in:
Siddharth Ganesan
2026-08-14 10:04:33 -07:00
parent 0e78b14d2a
commit a4cdfa0e92
2 changed files with 39 additions and 5 deletions
+22 -1
View File
@@ -20,6 +20,27 @@ export function messageForCopilotApplicationError(
if (classified && classified.code !== 'internal') {
return classified.message
}
trace.getActiveSpan()?.recordException(toError(error))
trace.getActiveSpan()?.recordException(flattenErrorChain(error))
return fallback
}
/**
* Wrapper errors (Drizzle's "Failed query: <sql>") bury the actionable cause —
* the Postgres constraint/violation — in `cause`. Join the chain so the span
* exception carries the part an investigator actually needs.
*/
function flattenErrorChain(error: unknown): Error {
const primary = toError(error)
const parts = [primary.message]
let cursor: unknown = primary.cause
let depth = 0
while (cursor && depth < 4) {
parts.push(toError(cursor).message)
cursor = toError(cursor).cause
depth += 1
}
if (parts.length === 1) return primary
const flattened = new Error(parts.join(' ← '))
flattened.stack = primary.stack
return flattened
}
+17 -4
View File
@@ -1806,11 +1806,24 @@ export class WorkspaceVFS {
})
}
// deployment.json exists for EVERY workflow: "is it deployed?" is a
// question with an answer either way, and a not-found error here was a
// recurring red herring — agents probing an undeployed workflow read a
// failure instead of the fact. Versions stay gated: they genuinely
// don't exist before the first deploy.
this.registerLazy(`${prefix}deployment.json`, async () => {
if (!versionedWorkflowIds.has(wf.id)) {
return JSON.stringify({
deployed: false,
note: 'This workflow has never been deployed.',
})
}
const deploymentData = await this.loadDeployments(wf.id)
return deploymentData
? serializeDeployments(deploymentData)
: JSON.stringify({ deployed: false, note: 'This workflow has never been deployed.' })
})
if (versionedWorkflowIds.has(wf.id)) {
this.registerLazy(`${prefix}deployment.json`, async () => {
const deploymentData = await this.loadDeployments(wf.id)
return deploymentData ? serializeDeployments(deploymentData) : null
})
this.registerLazy(`${prefix}versions.json`, async () => {
const deploymentData = await this.loadDeployments(wf.id)
return deploymentData?.versions && deploymentData.versions.length > 0