Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(mcp-host): classify every gfsc status in the file reference check
Alfredo Lopezb61286e0fa8d
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.jsonindex b5ed25ca1..c7556a8e4 100644--- a/mcp-host/package-lock.json+++ b/mcp-host/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-mcp-host",- "version": "0.1.453",+ "version": "0.1.454","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-mcp-host",- "version": "0.1.453",+ "version": "0.1.454","license": "SEE LICENSE IN LICENSE","dependencies": {"@anthropic-ai/sdk": "^0.32.0",diff --git a/mcp-host/package.json b/mcp-host/package.jsonindex c4a241cc6..c1799ee55 100644--- a/mcp-host/package.json+++ b/mcp-host/package.json@@ -1,6 +1,6 @@{"name": "clerum-mcp-host",- "version": "0.1.453",+ "version": "0.1.454","description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude","main": "dist/main.js","engines": {diff --git a/mcp-host/src/agent/__tests__/fileReferenceResolver.test.ts b/mcp-host/src/agent/__tests__/fileReferenceResolver.test.tsindex eb40ac0bf..f37a1dc37 100644--- a/mcp-host/src/agent/__tests__/fileReferenceResolver.test.ts+++ b/mcp-host/src/agent/__tests__/fileReferenceResolver.test.ts@@ -174,11 +174,13 @@ describe('parseIncomingFileReferences (#666)', () => {['another resource', `gfs://main/${RID_2}`],])('rejects a gfsUri that names %s', (_label, gfsUri) => {const ref = gfsReference()+ expect(parseIncomingFileReferences([ref], 10)).toMatchObject({ ok: true })const tampered = { ...ref, source: { ...ref.source, gfsUri } }+ // The FileReferenceV1 contract refuses it, before any Host check.expect(parseIncomingFileReferences([tampered], 10)).toMatchObject({ok: false,code: 'FILE_REFERENCE_INVALID',- message: 'The gfsUri of a file reference must name its drive and resourceId.',+ message: 'gfs source gfsUri must name its drive and resourceId',})})@@ -304,14 +306,24 @@ describe('resolveFileReferences (#666)', () => {})})- it('rethrows a gfsc status outside 4xx and 5xx instead of classifying it', async () => {- const error = new GfscHttpError(302, 'moved')- const gfsc = client(() => {- throw error- })- await expect(resolveFileReferences([gfsReference()], gfsc)).rejects.toBe(error)- expect(gfsc.resolve).toHaveBeenCalledTimes(1)- })+ // redirect:'error' turns 301/302/303/307/308 into a TypeError, so these are+ // the 3xx statuses a GfscHttpError can carry. A rethrow would put gfsc's body+ // into the route's 500 answer.+ it.each([300, 304, 305, 306])(+ 'fails contract on a gfsc %i instead of rethrowing it',+ async status => {+ const gfsc = client(() => {+ throw new GfscHttpError(status, 'gfsc body text')+ })+ expect(await resolveFileReferences([gfsReference()], gfsc)).toEqual({+ ok: false,+ failure: 'contract',+ errorClass: 'GfscHttpError',+ status,+ })+ expect(gfsc.resolve).toHaveBeenCalledTimes(1)+ }+ )it('fails transient on a timeout signal', async () => {const gfsc = client(() => {diff --git a/mcp-host/src/agent/fileReferenceResolver.ts b/mcp-host/src/agent/fileReferenceResolver.tsindex 64de9aa70..082a0a961 100644--- a/mcp-host/src/agent/fileReferenceResolver.ts+++ b/mcp-host/src/agent/fileReferenceResolver.ts@@ -110,14 +110,9 @@ export function parseIncomingFileReferences(}const reference = parsed.value// A GFS file is keyed by drive and resource, whatever the version: two- // references to the same file would leave its read pin ambiguous.- let key = reference.id- if (reference.source.kind === 'gfs') {- const rid = normalizeRid(reference.source.resourceId)- if (!rid || reference.source.gfsUri !== `gfs://${reference.source.drive}/${rid}`)- return invalid('The gfsUri of a file reference must name its drive and resourceId.')- key = `${reference.source.drive}/${rid}`- }+ // references to the same file would leave its read pin ambiguous. The+ // contract guarantees gfsUri is gfs://<drive>/<normalized rid>.+ const key = reference.source.kind === 'gfs' ? reference.source.gfsUri : reference.idconst seen = reference.source.kind === 'gfs' ? gfsFiles : idsif (seen.has(key)) return invalid('Each file reference must appear once.')seen.add(key)@@ -187,8 +182,10 @@ function isTokenReadError(error: Error): boolean {}/**- * Maps a failed gfsc `resolve` call that is not an availability. An error- * outside this table is rethrown: it is a defect, not a check result.+ * Maps a failed gfsc `resolve` call that is not an availability. An error of a+ * class outside this table is rethrown: it is a defect, not a check result.+ * Every gfsc status is classified, because a rethrown GfscHttpError would+ * carry gfsc's response body into the route's 500 answer.*/function checkFailure(error: unknown): ResolutionFailure {if (error instanceof GfscHttpError) {@@ -196,9 +193,9 @@ function checkFailure(error: unknown): ResolutionFailure {if (status === 401) return new ResolutionFailure('credentials', 'GfscHttpError', status)if (status === 429 || (status >= 500 && status <= 599))return new ResolutionFailure('transient', 'GfscHttpError', status)- if (status >= 400 && status <= 499)- return new ResolutionFailure('contract', 'GfscHttpError', status)- throw error+ // Any other status, 4xx or the 3xx that redirect:'error' lets through, is+ // one the Host does not understand.+ return new ResolutionFailure('contract', 'GfscHttpError', status)}if (error instanceof Error) {if (error.name === 'AbortError' || error.name === 'TimeoutError')