Skip to content

CheckResponseSchema rejects numeric memory/runtime fields from LeetCode API #55

Description

@vikasraok

Summary

submit_solution intermittently fails with a schema validation error even when the underlying LeetCode submission was actually accepted:

Check response did not match expected schema: [
  {
    "code": "invalid_type",
    "expected": "string",
    "received": "number",
    "path": ["memory"],
    "message": "Expected string, received number"
  }
]

Root cause

In src/leetcode/schemas.ts (compiled to build/leetcode/schemas.js), CheckResponseSchema declares:

runtime: z.string().optional(),
memory: z.string().optional(),

LeetCode's /submissions/detail/<id>/check/ endpoint doesn't consistently return these as formatted strings (e.g. "58.1 MB") — it sometimes returns raw numeric values instead. When that happens, .parse() throws a ZodError, and the tool surfaces this as a failure even though the submission itself succeeded (verifiable via get_recent_submissions, which shows "statusDisplay":"Accepted" for the same submission).

Suggested fix

Widen both fields to accept either type:

runtime: z.union([z.string(), z.number()]).optional(),
memory: z.union([z.string(), z.number()]).optional(),

I applied this locally (patched the cached npx build) and confirmed submissions no longer throw, while get_recent_submissions correctly showed the prior submission as Accepted despite the earlier tool-level error.

Repro

  1. Call submit_solution for any problem with a working solution.
  2. Occasionally (API-dependent), the response's memory field comes back as a number rather than a string.
  3. Tool call errors out with the schema mismatch above instead of returning the accepted result.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions