Skip to content

bug: Win11 generate can fail with raw 'Unexpected end of JSON input' #128

Closed

Description

@Sun-sunshine06

Summary

On Windows 11, generation can fail with a raw main-process IPC error:

Error invoking remote method 'codesign:v1:generate': CodesignError: Unexpected end of JSON input

The error is surfaced directly to the user instead of being translated into an actionable message or recovered gracefully.

Environment

  • OS: Windows 11
  • App: open-codesign desktop
  • Provider/model: unknown from screenshot
  • Flow: normal generate via codesign:v1:generate

Repro

  1. Open open-codesign on Windows 11.
  2. Start a normal generation.
  3. The run fails immediately or early in the request lifecycle.
  4. A modal appears with:
    Error invoking remote method 'codesign:v1:generate': CodesignError: Unexpected end of JSON input

Actual

  • Generation aborts.
  • The user sees a raw JSON parse error.
  • The UI does not indicate which local file/state is malformed or how to recover.

Expected

  • Generate should not expose a raw Unexpected end of JSON input error to end users.
  • If a local JSON-backed state file is truncated/corrupt, the app should:
    • detect it,
    • report which state source failed,
    • recover safely when possible, or
    • show an actionable error message (for example: re-login, reset preferences, or repair local state).

Suspected area

This looks like an uncaught JSON.parse failure somewhere on the main-process generate path.

Relevant entry points / likely parse sites:

  • apps/desktop/src/main/index.ts codesign:v1:generate
  • packages/providers/src/codex/token-store.ts reads persisted ChatGPT Codex auth via JSON.parse
  • apps/desktop/src/main/preferences-ipc.ts reads preferences.json
  • other local JSON-backed state read during generate/bootstrap

One likely failure mode is a partially written or truncated local JSON file on Windows, with the raw parse error bubbling through IPC.

Why this matters

This is a poor recovery path for a user-visible flow:

  • it blocks generation completely,
  • the message is too low-level,
  • and it gives the user no clue which state file is broken or what action to take.

Suggested fix direction

  • Wrap all JSON reads reachable from generate with source-specific error handling.
  • Replace raw parse failures with structured CodesignErrors.
  • Include the failing store/source in logs.
  • Show a user-facing recovery hint instead of the raw parse message.

Activity

  1. github-actions commented on Apr 22, 2026

    @github-actions
    Contributor

    Thanks for the detailed report — this is helpful.

    I checked the current code path and your diagnosis looks valid for the ChatGPT Codex route:

    • codesign:v1:generate calls runCodexGenerate(...) when provider is chatgpt-codex, and rethrows errors from that path as-is.
    • In that path, CodexTokenStore.read() parses codex-auth.json with JSON.parse, but on parse failure it throws a plain Error("Invalid Codex token store at ...") (not a structured CodesignError).
    • Renderer generation error handling currently surfaces err.message directly in UI/toast, so low-level parse failures can reach users.

    Relevant code:

    • apps/desktop/src/main/index.ts:505 — codesign:v1:generate handler
    • apps/desktop/src/main/codex-generate.ts:211 — Codex generate path reads token store
    • packages/providers/src/codex/token-store.ts:72 — JSON.parse of persisted auth
    • packages/providers/src/codex/token-store.ts:74 — parse failure throws plain Error
    • apps/desktop/src/renderer/src/store.ts:856 — generation error uses raw err.message
    • apps/desktop/src/main/preferences-ipc.ts:90 — preferences.json read failures are already wrapped (PREFERENCES_READ_FAILED)

    Also for context: the app is still in early v0.1.x polish (README currently says v0.1.3), so some recovery/diagnostics paths are still being hardened.

    Need more info:

    • When this happened, was the active provider chatgpt-codex?
    • Your app version (exact, e.g. v0.1.3)?
    • If possible, can you share whether %USERPROFILE%\\.config\\open-codesign\\codex-auth.json exists and looks truncated/partial?

    open-codesign Bot

  2. added
    bugSomething isn't working
    area:providerspackages/providers (pi-ai adapter, model calls)
    needs-reproNeeds reproduction steps from reporter
    on Apr 22, 2026
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

    area:providerspackages/providers (pi-ai adapter, model calls)bugSomething isn't workingneeds-reproNeeds reproduction steps from reporter

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions