Skip to content

"Tool task panicked" crashes: pdf-extract panics on malformed PDFs; swarm context history byte-slices multibyte text #573

Closed

Description

@vietgs03

Summary

Two separate Tool task panicked crashes observed in production session logs, both reproducible on latest master (28e476ac). Each kills the running tool task and surfaces a raw panic to the model instead of a recoverable error.

1. read tool: pdf-extract panics on malformed PDFs

crates/jcode-pdf/src/lib.rs calls pdf_extract::extract_text directly. The pdf-extract crate panics on exotic/malformed PDFs, e.g.:

Error: Tool task panicked: task 235 panicked with message "unexpected entry in unicode map"
Error: Tool task panicked: task 629 panicked with message "explicit panic"

Fix: wrap extraction in std::panic::catch_unwind and return a normal error ("PDF text extraction failed (parser panic: ...)") so a bad PDF cannot take down the tool task.

2. swarm context history: byte-slice truncation panics on multibyte text

crates/jcode-protocol/src/comm_format.rs format_comm_context_history truncates with &msg.content[..500] (byte index). With non-ASCII content (e.g. Vietnamese) index 500 can land inside a code point:

Error: Tool task panicked: task 10429 panicked with message
"end byte index 500 is not a char boundary; it is inside 'ủ' (bytes 499..502 of string)"

Fix: truncate on a char boundary via char_indices().nth(500).

Patch

Both fixes + regression tests are in vietgs03/jcode@168a692b on branch fix/oauth-ghost-builtin-tools (same branch as the fix referenced in #572).

  • cargo test -p jcode-protocol: 73 passed (includes 2 new truncation tests)
  • cargo build -p jcode-pdf: clean

Environment

  • jcode v0.56.0 (9aa8c5a), Linux x86_64
  • Panics recovered from session logs across 3 sessions

Activity

  1. added
    bug
    priority: high
    triage: reproducible
    autonomous: clear
    on Jul 24, 2026
  2. 1jehuang commented on Jul 24, 2026

    @1jehuang
    Owner

    Both crashes are fixed. jcode-pdf::extract_text now wraps pdf_extract in catch_unwind and returns "PDF text extraction failed (parser panic: ...)" instead of killing the tool task, and format_comm_context_history truncates on a char boundary rather than byte index 500. Regression tests added in both crates (cargo test -p jcode-protocol: 74 passed; -p jcode-pdf: 1 passed). Thanks for the clear panic traces.


    — Jcode agent (automated triage), on behalf of @1jehuang

  3. 1jehuang commented on Jul 24, 2026

    @1jehuang
    Owner

    Note: the fix is committed on branch triage/2026-07-24-batch (pushed). GitHub's pull-request creation API is currently returning 500s repo-wide, so the PR link will follow once that clears.


    — Jcode agent (automated triage), on behalf of @1jehuang

  4. 1jehuang commented on Jul 24, 2026

    @1jehuang
    Owner

    GitHub's PR API recovered: the fix is now in #580.


    — Jcode agent (automated triage), on behalf of @1jehuang

  5. added a commit that references this issue on Jul 24, 2026
    2d8736e
  6. added 2 commits that reference this issue on Aug 30, 2026
    75404da
    0467681
  7. added a commit that references this issue on Sep 18, 2026
    b2653fa
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

    autonomous: clearbugpriority: hightriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions