Skip to content

fix(aimock): use valid response schema for broken feature-parity fixtures - #3971

Merged
jpr5 merged 1 commit into
mainfrom
fix/aimock-crewai-startup-regression
Apr 16, 2026
Merged

jpr5 merged 1 commit into
mainfrom
fix/aimock-crewai-startup-regression

Conversation

@jpr5

@jpr5 jpr5 commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Five fixtures in showcase/aimock/feature-parity.json used an unrecognized "text" field instead of "content". aimock's /v1/chat/completions handler returns 500 "Fixture response did not match any known type" when the response shape doesn't match its discriminators.
  • CrewAI's ChatWithCrewFlow.__init__ calls generate_input_description_with_ai at module import time. That prompt contains "Reporting Analyst" / "reports" text (derived from the LatestAiDevelopment crew yaml), which substring-matched the broken "report" fixture and produced a 500. CrewAI treated that as InternalServerError, crashing the crewai-crews container before uvicorn could bind a port. Railway healthcheck failed → deployment rolled back to the previous ACTIVE build.
  • Fix: convert the five broken fixtures (plan, steps, mars, dashboard, report) from "text" to "content", and add a targeted fixture that matches CrewAI's exact startup prompt prefix ("Based on the following context, write a concise") so it wins over the generic fixtures.

Root cause

aimock discriminators in helpers.ts only recognize content, toolCalls, error, etc. — never text. Any fixture using "text" silently fell through to the 500 branch. See server.ts:563-663 and helpers.ts:51-80.

The regression window matches — fixtures landed 2026-04-14 12:52 PDT (5ac07d4); Railway aimock picked them up at 2026-04-14T21:57 UTC.

Verification

Red-green reproduced locally against @copilotkit/[email protected]:

PRE-FIX  status: 500
PRE-FIX  body:   {"error":{"message":"Fixture response did not match any known type","type":"server_error"}}

POST-FIX status: 200
POST-FIX body:   {"id":"chatcmpl-...","object":"chat.completion",...,"content":"A short input value used to parameterize the crew's tasks and agents."}

Also verified: the five previously-broken user messages (report, plan, dashboard, mars ... steps, etc.) all return 200 with valid content after the fix.

Follow-up (not in this PR)

CrewAI's blocking LLM call at module import is fragile — any aimock hiccup still crashes the container before it can bind a port. That is upstream behavior (crewai/cli/crew_chat.py:481 generate_input_description_with_ai) and should be tracked as a separate issue.

Test plan

  • Local: red-green confirmed against @copilotkit/[email protected] — 500 pre-fix, 200 post-fix for CrewAI-style startup prompt
  • Local: the five previously-broken fixtures (plan, steps, mars, dashboard, report) now return 200 + valid content
  • Railway: aimock image rebuilds and picks up new fixtures; crewai-crews next deploy reaches ACTIVE

…rewai-crews

The showcase aimock feature-parity fixture had five entries that used the
unrecognized field "text" instead of "content" in the response body.

aimock's /v1/chat/completions handler validates the response shape through
discriminators (isTextResponse, isToolCallResponse, etc.) and when none
match, returns 500 "Fixture response did not match any known type".

When CrewAI's ChatWithCrewFlow.__init__ calls generate_input_description_with_ai,
it sends a prompt containing "Reporting Analyst" / "reports" text (from the
LatestAiDevelopment crew definition). aimock substring-matches this against
the "report" fixture, which had the broken "text" shape, and returned 500.

CrewAI treats that as an InternalServerError, the crewai-crews container
crashes during module import (before uvicorn binds), Railway healthchecks
fail, and the deployment rolls back to the previous ACTIVE build.

Fix:
- Convert the 5 fixtures with "text" (plan, steps, mars, dashboard, report)
  to the valid "content" field so they return 200 OK.
- Add a targeted fixture that matches CrewAI's exact startup prompt prefix
  ("Based on the following context, write a concise") and returns a clean
  text description. This catches generate_input_description_with_ai and
  generate_crew_description_with_ai before they can fall through to the
  more generic fixtures, providing a more predictable response for CrewAI
  startup.

Verified locally against @copilotkit/[email protected]:
- Before: the CrewAI-style prompt returns 500 with the exact error message
  seen in Railway logs.
- After: returns 200 with a valid chat.completion envelope.

Note: CrewAI's blocking LLM call at module import remains fragile (any
aimock hiccup crashes the container before it can bind a port). That is
an upstream issue and will be tracked separately.
@vercel

vercel Bot commented Apr 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
chat-with-your-data Ready Ready Preview, Comment Apr 16, 2026 7:10pm
docs Ready Ready Preview, Comment Apr 16, 2026 7:10pm
form-filling Ready Ready Preview, Comment Apr 16, 2026 7:10pm
research-canvas Ready Ready Preview, Comment Apr 16, 2026 7:10pm
travel Ready Ready Preview, Comment Apr 16, 2026 7:10pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@jpr5
jpr5 merged commit 728363f into main Apr 16, 2026
12 checks passed
@jpr5
jpr5 deleted the fix/aimock-crewai-startup-regression branch April 16, 2026 19:23
jpr5 added a commit that referenced this pull request Apr 16, 2026
Follow-up to #3971. aimock supports fixture schema validation at startup via
--validate-on-load, but it's opt-in. The showcase Dockerfile did not pass
the flag, so fixtures with unrecognized response keys (e.g. "text" instead
of "content") loaded silently and only failed at request time with HTTP 500.
That's what crashed crewai-crews on startup.

Changes:
- showcase/aimock/Dockerfile: pass --validate-on-load so broken fixtures
  fail the container boot, not individual requests.
- showcase/scripts/__tests__/aimock-fixtures.test.ts: new vitest spec that
  loads feature-parity.json and smoke.json via @copilotkit/aimock's
  loadFixtureFile + validateFixtures and asserts zero errors. Runs as part
  of the existing showcase-validate CI workflow.
- showcase/scripts/package.json: add @copilotkit/aimock dependency for the
  validator import.

Verified red-green: with the pre-#3971 broken "text" fixtures, validateFixtures
flags 5 errors; post-#3971 it returns zero. Docker red-green: container with
an intentionally broken fixture fails to start with "Validation failed: 1
error(s)" and non-zero exit.
jpr5 added a commit that referenced this pull request Apr 16, 2026
…3974)

## Summary

CrewAI's `ChatWithCrewFlow.__init__` (invoked from
`ag_ui_crewai.endpoint.add_crewai_crew_fastapi_endpoint` at module
import in `ag-ui-crewai <= 0.1.5`) makes synchronous blocking LLM calls
via `crewai.cli.crew_chat.generate_input_description_with_ai` and
`generate_crew_description_with_ai`. ANY LLM hiccup — aimock regression,
OpenAI outage, network blip, DNS failure — crashes the Python process
BEFORE uvicorn can bind its port, causing Railway/Kubernetes health
checks to fail and deploys to roll back.

This was the direct cause of the crewai-crews Railway crash fixed
server-side in #3971. That fix patched the aimock response schema, but
the underlying fragility in upstream CrewAI / ag-ui-crewai remained — a
future blip would crash us again.

This PR adds a defensive monkey-patch in `agent_server.py` that replaces
both generator functions with static-string returns BEFORE
`ag_ui_crewai` is imported. The AI-generated descriptions are only
surfaced in the CrewAI chat UI (which the CopilotKit runtime does not
use), so static defaults are functionally equivalent for our showcase.

Upstream issue filed: crewAIInc/crewAI#5510

The long-term fix is deferred construction in `ag-ui-crewai`, which has
landed on ag-ui `main` but is not yet released. Remove this shim once
`ag-ui-crewai > 0.1.5` ships.

## Why a monkey-patch and not lazy-init

`add_crewai_crew_fastapi_endpoint` is the entry point and internally
constructs `ChatWithCrewFlow(crew)` synchronously in `ag-ui-crewai <=
0.1.5`. Deferring that call would require either vendoring the endpoint
function or reimplementing it. The monkey-patch is two lines and removes
cleanly when the upstream fix ships.

## Test plan

Verified locally via Docker build + run with an intentionally broken LLM
endpoint (`OPENAI_BASE_URL=http://invalid-host/v1`):

**Unhardened (negative control):**

```
File "/app/agent_server.py", line 27, in <module>
    add_crewai_crew_fastapi_endpoint(app, LatestAiDevelopment(), "/")
  File ".../ag_ui_crewai/endpoint.py", line 250, in add_crewai_crew_fastapi_endpoint
    add_crewai_flow_fastapi_endpoint(app, ChatWithCrewFlow(crew=crew), path)
  File ".../ag_ui_crewai/crews.py", line 56, in __init__
    self.crew_chat_inputs = crew_chat_generate_crew_chat_inputs(...)
  File ".../crewai/cli/crew_chat.py", line 387, in generate_crew_chat_inputs
    description = generate_input_description_with_ai(input_name, crew, chat_llm)
  File ".../crewai/cli/crew_chat.py", line 481, in generate_input_description_with_ai
    response = chat_llm.call(...)
APIError
```

Container exits with code 1, never binds a port.

**Hardened (this PR):**

```
INFO:     Started server process [7]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
```

`curl http://localhost:PORT/api/health` ->
`{"status":"ok","integration":"crewai-crews","agent":"ok","timestamp":"..."}`
(HTTP 200).

### Checklist

- [x] Docker build succeeds locally
- [x] Unhardened build crashes on import with broken LLM endpoint
(negative control)
- [x] Hardened build starts cleanly with broken LLM endpoint and
responds 200 on `/api/health`
- [x] Upstream issue filed on crewAIInc/crewAI
jpr5 added a commit that referenced this pull request Apr 16, 2026
…3973)

## Summary

Follow-up hardening to #3971. aimock supports fixture schema validation
at startup via `--validate-on-load`, but the flag is **opt-in** and the
showcase Dockerfile was not passing it. That meant fixtures with
unrecognized response keys (e.g. `"text"` instead of `"content"`) loaded
silently and only surfaced as HTTP 500s at request time — which is
exactly what crashed crewai-crews and triggered #3971.

This PR wires up two independent safety nets so a broken fixture can't
ship again:

1. **Dockerfile (fail-fast at container boot)** —
`showcase/aimock/Dockerfile` now passes `--validate-on-load`. If any
fixture fails the aimock schema, the container exits non-zero instead of
starting and serving 500s. Railway will not promote a bad build.
2. **CI test (fail-fast in PR review)** — new vitest spec at
`showcase/scripts/__tests__/aimock-fixtures.test.ts` imports
`loadFixtureFile` + `validateFixtures` from `@copilotkit/aimock` and
asserts zero errors against both `feature-parity.json` and `smoke.json`.
Runs inside the existing ` Showcase: Validate` workflow
(`showcase/scripts` vitest suite) on every PR that touches
`showcase/**`.

## Verification

**Red-green on the vitest spec:**
- Rebased onto the tip of main *before* #3971 merged: the spec fails
with 5 errors — exactly the 5 broken `"text"` fixtures (`plan`, `steps`,
`mars`, `dashboard`, `report`) that #3971 repaired.
- Rebased forward onto main *after* #3971: spec passes with 0 errors,
all 549 showcase/scripts tests green.

**Red-green on the Dockerfile:**
- Current fixtures + `--validate-on-load`: container boots cleanly, logs
`Loaded 39 fixture(s) from /fixtures`.
- Injecting an intentionally broken fixture (`response: { "text": "..."
}`): container fails to start with `[aimock] Fixture 0: response is not
a recognized type (must have content, toolCalls, error, or embedding)` /
`Validation failed: 1 error(s), 0 warning(s)` and non-zero exit.

## Test plan

- [x] Local: full `showcase/scripts` vitest suite passes (549/549)
- [x] Local: `pnpm run test` (monorepo) passes
- [x] Docker: image builds and starts with `--validate-on-load` against
current fixtures
- [x] Docker red-green: broken fixture fails container start with
non-zero exit
- [ ] CI: ` Showcase: Validate` job runs the new test file on PR
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…ures (CopilotKit#3971)

## Summary

- Five fixtures in `showcase/aimock/feature-parity.json` used an
unrecognized `"text"` field instead of `"content"`. aimock's
`/v1/chat/completions` handler returns 500 `"Fixture response did not
match any known type"` when the response shape doesn't match its
discriminators.
- CrewAI's `ChatWithCrewFlow.__init__` calls
`generate_input_description_with_ai` at module import time. That prompt
contains `"Reporting Analyst"` / `"reports"` text (derived from the
`LatestAiDevelopment` crew yaml), which substring-matched the broken
`"report"` fixture and produced a 500. CrewAI treated that as
`InternalServerError`, crashing the crewai-crews container before
uvicorn could bind a port. Railway healthcheck failed → deployment
rolled back to the previous ACTIVE build.
- Fix: convert the five broken fixtures (`plan`, `steps`, `mars`,
`dashboard`, `report`) from `"text"` to `"content"`, and add a targeted
fixture that matches CrewAI's exact startup prompt prefix (`"Based on
the following context, write a concise"`) so it wins over the generic
fixtures.

## Root cause

aimock discriminators in `helpers.ts` only recognize `content`,
`toolCalls`, `error`, etc. — never `text`. Any fixture using `"text"`
silently fell through to the 500 branch. See
[server.ts:563-663](https://github.com/CopilotKit/aimock/blob/main/src/server.ts#L563)
and
[helpers.ts:51-80](https://github.com/CopilotKit/aimock/blob/main/src/helpers.ts#L51).

The regression window matches — fixtures landed 2026-04-14 12:52 PDT
(5ac07d4); Railway aimock picked them up at 2026-04-14T21:57 UTC.

## Verification

Red-green reproduced locally against `@copilotkit/[email protected]`:

```
PRE-FIX  status: 500
PRE-FIX  body:   {"error":{"message":"Fixture response did not match any known type","type":"server_error"}}

POST-FIX status: 200
POST-FIX body:   {"id":"chatcmpl-...","object":"chat.completion",...,"content":"A short input value used to parameterize the crew's tasks and agents."}
```

Also verified: the five previously-broken user messages (`report`,
`plan`, `dashboard`, `mars ... steps`, etc.) all return 200 with valid
content after the fix.

## Follow-up (not in this PR)

CrewAI's blocking LLM call at module import is fragile — any aimock
hiccup still crashes the container before it can bind a port. That is
upstream behavior (`crewai/cli/crew_chat.py:481
generate_input_description_with_ai`) and should be tracked as a separate
issue.

## Test plan

- [x] Local: red-green confirmed against `@copilotkit/[email protected]` —
500 pre-fix, 200 post-fix for CrewAI-style startup prompt
- [x] Local: the five previously-broken fixtures (`plan`, `steps`,
`mars`, `dashboard`, `report`) now return 200 + valid content
- [ ] Railway: aimock image rebuilds and picks up new fixtures;
crewai-crews next deploy reaches ACTIVE
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…opilotKit#3974)

## Summary

CrewAI's `ChatWithCrewFlow.__init__` (invoked from
`ag_ui_crewai.endpoint.add_crewai_crew_fastapi_endpoint` at module
import in `ag-ui-crewai <= 0.1.5`) makes synchronous blocking LLM calls
via `crewai.cli.crew_chat.generate_input_description_with_ai` and
`generate_crew_description_with_ai`. ANY LLM hiccup — aimock regression,
OpenAI outage, network blip, DNS failure — crashes the Python process
BEFORE uvicorn can bind its port, causing Railway/Kubernetes health
checks to fail and deploys to roll back.

This was the direct cause of the crewai-crews Railway crash fixed
server-side in CopilotKit#3971. That fix patched the aimock response schema, but
the underlying fragility in upstream CrewAI / ag-ui-crewai remained — a
future blip would crash us again.

This PR adds a defensive monkey-patch in `agent_server.py` that replaces
both generator functions with static-string returns BEFORE
`ag_ui_crewai` is imported. The AI-generated descriptions are only
surfaced in the CrewAI chat UI (which the CopilotKit runtime does not
use), so static defaults are functionally equivalent for our showcase.

Upstream issue filed: crewAIInc/crewAI#5510

The long-term fix is deferred construction in `ag-ui-crewai`, which has
landed on ag-ui `main` but is not yet released. Remove this shim once
`ag-ui-crewai > 0.1.5` ships.

## Why a monkey-patch and not lazy-init

`add_crewai_crew_fastapi_endpoint` is the entry point and internally
constructs `ChatWithCrewFlow(crew)` synchronously in `ag-ui-crewai <=
0.1.5`. Deferring that call would require either vendoring the endpoint
function or reimplementing it. The monkey-patch is two lines and removes
cleanly when the upstream fix ships.

## Test plan

Verified locally via Docker build + run with an intentionally broken LLM
endpoint (`OPENAI_BASE_URL=http://invalid-host/v1`):

**Unhardened (negative control):**

```
File "/app/agent_server.py", line 27, in <module>
    add_crewai_crew_fastapi_endpoint(app, LatestAiDevelopment(), "/")
  File ".../ag_ui_crewai/endpoint.py", line 250, in add_crewai_crew_fastapi_endpoint
    add_crewai_flow_fastapi_endpoint(app, ChatWithCrewFlow(crew=crew), path)
  File ".../ag_ui_crewai/crews.py", line 56, in __init__
    self.crew_chat_inputs = crew_chat_generate_crew_chat_inputs(...)
  File ".../crewai/cli/crew_chat.py", line 387, in generate_crew_chat_inputs
    description = generate_input_description_with_ai(input_name, crew, chat_llm)
  File ".../crewai/cli/crew_chat.py", line 481, in generate_input_description_with_ai
    response = chat_llm.call(...)
APIError
```

Container exits with code 1, never binds a port.

**Hardened (this PR):**

```
INFO:     Started server process [7]
INFO:     Waiting for application startup.
INFO:     Application startup complete.
INFO:     Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
```

`curl http://localhost:PORT/api/health` ->
`{"status":"ok","integration":"crewai-crews","agent":"ok","timestamp":"..."}`
(HTTP 200).

### Checklist

- [x] Docker build succeeds locally
- [x] Unhardened build crashes on import with broken LLM endpoint
(negative control)
- [x] Hardened build starts cleanly with broken LLM endpoint and
responds 200 on `/api/health`
- [x] Upstream issue filed on crewAIInc/crewAI
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
Follow-up to CopilotKit#3971. aimock supports fixture schema validation at startup via
--validate-on-load, but it's opt-in. The showcase Dockerfile did not pass
the flag, so fixtures with unrecognized response keys (e.g. "text" instead
of "content") loaded silently and only failed at request time with HTTP 500.
That's what crashed crewai-crews on startup.

Changes:
- showcase/aimock/Dockerfile: pass --validate-on-load so broken fixtures
  fail the container boot, not individual requests.
- showcase/scripts/__tests__/aimock-fixtures.test.ts: new vitest spec that
  loads feature-parity.json and smoke.json via @copilotkit/aimock's
  loadFixtureFile + validateFixtures and asserts zero errors. Runs as part
  of the existing showcase-validate CI workflow.
- showcase/scripts/package.json: add @copilotkit/aimock dependency for the
  validator import.

Verified red-green: with the pre-CopilotKit#3971 broken "text" fixtures, validateFixtures
flags 5 errors; post-CopilotKit#3971 it returns zero. Docker red-green: container with
an intentionally broken fixture fails to start with "Validation failed: 1
error(s)" and non-zero exit.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…opilotKit#3973)

## Summary

Follow-up hardening to CopilotKit#3971. aimock supports fixture schema validation
at startup via `--validate-on-load`, but the flag is **opt-in** and the
showcase Dockerfile was not passing it. That meant fixtures with
unrecognized response keys (e.g. `"text"` instead of `"content"`) loaded
silently and only surfaced as HTTP 500s at request time — which is
exactly what crashed crewai-crews and triggered CopilotKit#3971.

This PR wires up two independent safety nets so a broken fixture can't
ship again:

1. **Dockerfile (fail-fast at container boot)** —
`showcase/aimock/Dockerfile` now passes `--validate-on-load`. If any
fixture fails the aimock schema, the container exits non-zero instead of
starting and serving 500s. Railway will not promote a bad build.
2. **CI test (fail-fast in PR review)** — new vitest spec at
`showcase/scripts/__tests__/aimock-fixtures.test.ts` imports
`loadFixtureFile` + `validateFixtures` from `@copilotkit/aimock` and
asserts zero errors against both `feature-parity.json` and `smoke.json`.
Runs inside the existing ` Showcase: Validate` workflow
(`showcase/scripts` vitest suite) on every PR that touches
`showcase/**`.

## Verification

**Red-green on the vitest spec:**
- Rebased onto the tip of main *before* CopilotKit#3971 merged: the spec fails
with 5 errors — exactly the 5 broken `"text"` fixtures (`plan`, `steps`,
`mars`, `dashboard`, `report`) that CopilotKit#3971 repaired.
- Rebased forward onto main *after* CopilotKit#3971: spec passes with 0 errors,
all 549 showcase/scripts tests green.

**Red-green on the Dockerfile:**
- Current fixtures + `--validate-on-load`: container boots cleanly, logs
`Loaded 39 fixture(s) from /fixtures`.
- Injecting an intentionally broken fixture (`response: { "text": "..."
}`): container fails to start with `[aimock] Fixture 0: response is not
a recognized type (must have content, toolCalls, error, or embedding)` /
`Validation failed: 1 error(s), 0 warning(s)` and non-zero exit.

## Test plan

- [x] Local: full `showcase/scripts` vitest suite passes (549/549)
- [x] Local: `pnpm run test` (monorepo) passes
- [x] Docker: image builds and starts with `--validate-on-load` against
current fixtures
- [x] Docker red-green: broken fixture fails container start with
non-zero exit
- [ ] CI: ` Showcase: Validate` job runs the new test file on PR

This branch was successfully deployed

5 active deployments
Preview – travel — 08c60ce5 Deployed Apr 16, 2026 by vercel[bot]
Preview – research-canvas — 08c60ce5 Deployed Apr 16, 2026 by vercel[bot]
Preview – docs — 08c60ce5 Deployed Apr 16, 2026 by vercel[bot]
Preview – chat-with-your-data — 08c60ce5 Deployed Apr 16, 2026 by vercel[bot]
Preview – form-filling — 08c60ce5 Deployed Apr 16, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant