Skip to content

Cache generated JSON schemas by Class and Type - #1

Open
skrcode wants to merge 2 commits into
jnduan:fix/jsonschema-thread-safetyfrom
skrcode:jaipilot/pr-1-7tDTG1hkrVzf
Open

Cache generated JSON schemas by Class and Type#1
skrcode wants to merge 2 commits into
jnduan:fix/jsonschema-thread-safetyfrom
skrcode:jaipilot/pr-1-7tDTG1hkrVzf

Conversation

@skrcode

@skrcode skrcode commented Aug 23, 2026

Copy link
Copy Markdown

This is a one-commit JAIPilot Cloud follow-up on the exact current head of agentscope-ai/agentscope-java#2796. It targets the original contributor branch so there is no duplicate upstream feature PR.

Change

Cache each generated JsonNode by Class or Type. Cache misses still use the existing SCHEMA_LOCK, while every caller still receives a newly converted, independently mutable Map.

Proof

  • Exact parent: 15859a9, the current fix(core): make JsonSchemaUtils schema generation thread-safe agentscope-ai/agentscope-java#2796 head.
  • Four characterization tests preserve schema equality, independent returned-map mutation, and null-argument behavior.
  • Downstream ToolSchemaGenerator and ReActAgent structured-output tests passed.
  • Identical 16-thread, 80,000-call workload over two repeated classes, five observations per side: median 20,323 ms to 899 ms; p95 26,779 ms to 3,836 ms in the managed sandbox.
  • Final repository-native gate: mvn -pl agentscope-core -am verify passed.

Boundary and disclosure

The benefit depends on repeated schema types. The caches retain one entry per encountered Class or Type, so the project should confirm that lifecycle assumption for dynamic class-loading environments. Absolute production latency is not claimed.

JAIPilot Cloud generated and validated the patch in skrcode/agentscope-java#2. I reviewed the exact ancestry, complete two-file diff, test evidence, measurement boundary, and limitation before offering it here.

jnduan and others added 2 commits August 22, 2026 18:02
The shared static victools SchemaGenerator is not thread-safe: its
JacksonModule keeps an unsynchronized introspection cache, so concurrent
structured calls can fail with ConcurrentModificationException. Guard
both schemaGenerator.generateSchema(...) call sites with a dedicated lock.
@jnduan
jnduan force-pushed the fix/jsonschema-thread-safety branch 2 times, most recently from 16a0623 to 7cc7317 Compare August 27, 2026 16:26
@jnduan
jnduan force-pushed the fix/jsonschema-thread-safety branch 5 times, most recently from 186f878 to 35080eb Compare September 3, 2026 01:32
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.

2 participants