Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix(cli): invalidate app metadata cache on 422 to clear stale data (#36921)
Xiyuan Chen6ce61eae5945
diff --git a/cli/src/commands/run/app/run.test.ts b/cli/src/commands/run/app/run.test.tsindex efe6a07e801..d0d4586577d 100644--- a/cli/src/commands/run/app/run.test.ts+++ b/cli/src/commands/run/app/run.test.ts@@ -351,6 +351,26 @@ describe('runApp', () => {})})+ it('422 on run: invalidates cache and adds republish hint', async () => {+ const io = bufferStreams()+ const cache = await loadAppInfoCache({ store: getCache(CACHE_APP_INFO) })+ // warm cache with successful run+ await runApp(+ { appId: 'app-1', message: 'hi' },+ { bundle: bundle(), http: testHttpClient(mock.url, 'dfoa_test'), host: mock.url, io, cache },+ )+ expect(cache.get(mock.url, 'app-1')).toBeDefined()++ mock.setScenario('run-422-stale')+ const err = await runApp(+ { appId: 'app-1', message: 'hi' },+ { bundle: bundle(), http: testHttpClient(mock.url, { bearer: 'dfoa_test', retryAttempts: 0 }), host: mock.url, io, cache },+ ).catch((e: unknown) => e)+ expect(err).toMatchObject({ code: 'server_4xx_other', httpStatus: 422 })+ expect((err as { hint?: string }).hint).toMatch(/cache cleared/)+ expect(cache.get(mock.url, 'app-1')).toBeUndefined()+ })+it('workflow: --file overrides same-named key from --inputs (file wins)', async () => {const io = bufferStreams()const cache = await loadAppInfoCache({ store: getCache(CACHE_APP_INFO) })diff --git a/cli/src/commands/run/app/run.ts b/cli/src/commands/run/app/run.tsindex 64bee92f3b3..6dae0e4143a 100644--- a/cli/src/commands/run/app/run.ts+++ b/cli/src/commands/run/app/run.ts@@ -82,6 +82,25 @@ export async function runApp(opts: RunAppOptions, deps: RunAppDeps): Promise<voiconst wsId = resolveWorkspaceId({ flag: opts.workspace, env: env('DIFY_WORKSPACE_ID'), active: deps.active })const apps = new AppsClient(deps.http)const meta = new AppMetaClient({ apps, host: deps.host, cache: deps.cache })++ try {+ await executeRun(opts, deps, meta, wsId)+ }+ catch (err) {+ if (err instanceof BaseError && err.httpStatus === 422) {+ await meta.invalidate(opts.appId)+ throw err.withHint('app metadata cache cleared — if the app was recently republished, run the command again')+ }+ throw err+ }+}++async function executeRun(+ opts: RunAppOptions,+ deps: RunAppDeps,+ meta: AppMetaClient,+ wsId: string,+): Promise<void> {const m = await meta.get(opts.appId, wsId, [FieldInfo])const mode = m.info?.mode ?? ''if (mode === '')diff --git a/cli/test/fixtures/dify-mock/scenarios.ts b/cli/test/fixtures/dify-mock/scenarios.tsindex cfd55f438c9..94bfd1b5c71 100644--- a/cli/test/fixtures/dify-mock/scenarios.ts+++ b/cli/test/fixtures/dify-mock/scenarios.ts@@ -13,6 +13,7 @@ export type Scenario| 'hitl-resume'| 'server-version-empty'| 'server-version-unsupported'+ | 'run-422-stale'export type AccountFixture = {id: stringdiff --git a/cli/test/fixtures/dify-mock/server.ts b/cli/test/fixtures/dify-mock/server.tsindex 59f318e0925..af045087636 100644--- a/cli/test/fixtures/dify-mock/server.ts+++ b/cli/test/fixtures/dify-mock/server.ts@@ -288,6 +288,12 @@ export function buildApp(getScenario: () => Scenario, state?: MockState): Hono {const isAgent = app.is_agent === true || app.mode === 'agent-chat'const query = body.query ?? ''const scenario = getScenario()+ if (scenario === 'run-422-stale') {+ return c.json(+ { error: { code: 'query_not_supported_for_workflow', message: 'query not supported for workflow mode' } },+ { status: 422 },+ )+ }if (scenario === 'stream-error') {const errSse = sseChunks([{ event: 'error', data: { message: 'boom', status: 503 } }])return new Response(errSse, { status: 200, headers: { 'content-type': 'text/event-stream' } })