Skip to content

Add a Java runtime built on generated models - #444

Merged
Seth Juarez (sethjuarez) merged 5 commits into
mainfrom
sejuare-microsoft/java-runtime-implementation
Aug 19, 2026
Merged

Seth Juarez (sethjuarez) merged 5 commits into
mainfrom
sejuare-microsoft/java-runtime-implementation

Conversation

@sethjuarez

@sethjuarez Seth Juarez (sethjuarez) commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Add a Java runtime built on generated models

This is the Java runtime for Prompty, at parity with the other language runtimes. Like Rust, Python, C#, TypeScript, Go and Swift, the model layer is generated from the shared TypeSpec via @typra/emitter; the hand-written surface is the provider wire code plus the editable model seams.

What's here

  • Generated model layer (runtime/java/prompty/.../model) emitted by @typra/emitter@0.9.2 from schema/model/**, registered as a Java emit target in schema/tspconfig.yaml.
  • Editable seams filled — MessageMethods and ToolResultMethods mirror the Rust model_ext behavior (text joins TextPart.value with newlines; toTextContent returns a bare string when all parts are text, else the saved part list). These live in Typra's // <typra-editable-seam> regions and survive regeneration.
  • Providers — prompty-openai, prompty-anthropic, prompty-foundry build request wire payloads and interpret responses.
  • Conformance — the shared cross-runtime vectors.json (166 vectors) is graded by the Java suites (WireVectorsTest, ProcessVectorsTest, DiscoveryVectorsTest, load/parse/render, etc.), the same fixtures every other runtime is measured by.
  • CI — .github/workflows/prompty-java-check.yml runs ./gradlew build (all four modules, live provider tests excluded) on JDK 21 across ubuntu and windows.

Emitter bump

@typra/emitter ^0.9.0 → ^0.9.2. 0.9.2 fixes the Java test-emitter so string-literal enum assertions coerce through <EnumKind>.fromValue(...) (McpApprovalModeGeneratedTest). Regenerating at 0.9.2 changes only the Java output and the three .typra-generated metadata files — no other runtime's generated code moves, and vectors.json is unchanged. The schema generated-code reproducibility gate passes, confirming the committed tree matches a clean regeneration.

Tests

./gradlew build — 701 tests, 0 failures: prompty 442, openai 68, anthropic 67, foundry 124.

Follow-up: move provider wire coverage into shared vectors

Per maintainer direction, provider-specific wire behavior should be covered by the shared conformance vectors (to enforce cross-runtime parity) rather than by per-runtime hand-written tests. This runtime intentionally follows the existing repo pattern — hand-written provider wire tests (WireSchemaTest, WireMessageTest) alongside the shared vectors — exactly as Python, C#, TypeScript and Rust already do, so Java is consistent with its peers. Migrating that coverage into shared vectors is a repo-wide effort (each new vector must be registered in every runtime's harness) and is deliberately not bundled here.

While scoping that work, a genuine parity divergence surfaced that the migration should resolve:

  • Bound-parameter exclusion (hiding a host-bound tool parameter from the model's input_schema) is implemented in Java and TypeScript only. Rust, Python and C# wire all declared parameters. A shared vector for this edge would fail three runtimes until their wire mappers agree — this is exactly the kind of gap shared vectors are meant to catch, and it wants a deliberate decision (align the three, or the two) in its own PR.

Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com

Copilot AI lite review requested due to automatic review settings August 4, 2026 12:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 12:47

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 12:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

Copilot AI review requested due to automatic review settings August 4, 2026 12:58
@sethjuarez
Seth Juarez (sethjuarez) force-pushed the sejuare-microsoft/java-runtime-implementation branch from 785d645 to 4594f56 Compare August 4, 2026 12:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 13:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 14:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 15:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 16:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 17:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 18:06

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 18:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 19:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Copilot AI review requested due to automatic review settings August 4, 2026 20:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot wasn't able to review this pull request because it exceeds the maximum number of files (300). Try reducing the number of changed files and requesting a review from Copilot again.

Seth Juarez (sethjuarez) pushed a commit that referenced this pull request Aug 18, 2026
* fix(python): eliminate ReDoS in chat parser role-boundary regex

Unquoted, unterminated attributes let the value class in the
role-boundary regex overlap with the `,` separator and closing `]`,
giving the backtracking engine an exponential number of equivalent
splits to try on a failing match. Rewrite the attribute group as a
quoted/unquoted alternation with no shared characters between
branches, plus possessive quantifiers (Python 3.11+), matching the
fix already applied to the Java parser in #444.

Fixes #446

* fix(python): address ReDoS test review feedback

Test through the public parse() API instead of importing the
module-private _BOUNDARY_RE, and replace the fixed wall-clock
assertion with a doubling-input comparison so the test can't flake
on a slow CI runner while still catching a regression to exponential
behavior.

* docs(python): clarify the ReDoS test's absolute floor is a noise guard

The docstring said the assertion avoids an absolute wall-clock budget,
but it does include a 0.1s floor. Clarify that the floor only keeps
the relative comparison from collapsing to noise on a very fast run
and is not itself the enforced budget.

* docs(python): state the Python 3.11+ floor next to the possessive regex

The automated reviewer keeps flagging the possessive quantifiers as a
pre-3.11 risk because it only sees this diff, not pyproject.toml.
Say the constraint explicitly at the point of use so it's obvious
without cross-referencing another file.

* test(python): use best-of-20 timing in the ReDoS regression test

A single sample per size is susceptible to a scheduler blip or first-run
JIT/cache noise. Take the minimum of 20 samples instead so an occasional
slow tick can't cause a false failure, without weakening what the test
actually catches (exponential blowup still dwarfs this noise floor by
orders of magnitude).
@sethjuarez

Copy link
Copy Markdown
Member Author

Stale against current main — needs re-authoring, not a mechanical rebase. This PR predates two shifts it can't survive a merge across: the @typra/emitter 0.4.x -> 0.9.0 jump and the schema/model/ source reorg (contracts/ conformance/ operations/ wire/) with generated-model relocation across the runtimes. The concept here is still wanted and is not yet on main, so leaving this open as a tracker rather than closing. Re-author fresh on the 0.9.0 contracts/ layout. (Context: #481 assessed all 11 pre-0.9.0 in-flight PRs.)

….9.2

Add a Java emit target to tspconfig.yaml and bump the Typra emitter pin to
^0.9.2, which fixes the Java model test-emitter so string-literal enum
scalar-coercion assertions (e.g. McpApprovalMode) wrap the expected value in
<EnumKind>.fromValue(...) instead of a bare string.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Implements the Java runtime for Prompty with full parity to the other
runtimes. The model layer is generated from the shared TypeSpec via the
Typra emitter; the editable seams (MessageMethods, ToolResultMethods) are
filled to mirror the Rust model_ext behavior. Providers (openai, anthropic,
foundry) build request wire payloads and are validated against the shared
conformance vectors plus provider-specific wire tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Runs ./gradlew build (all four modules) on JDK 21 across ubuntu and
windows, mirroring the Rust runtime check.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@sethjuarez
Seth Juarez (sethjuarez) force-pushed the sejuare-microsoft/java-runtime-implementation branch from 31f4962 to d58e2ec Compare August 18, 2026 19:27
The Unix gradlew script was committed without the executable bit, so
./gradlew build failed with permission denied on ubuntu-latest.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…-port + open-union contracts

Brings the Java runtime up to parity with main after PRs #447 (engine
ports, open-union Connection, stream-failure) and #439 (Swift) landed.

- Resolve schema conflicts: union tspconfig.yaml (Java + Swift targets),
  pin @typra/emitter ^0.9.3, take main's package-lock + export-surfaces.
- Regenerate: adds Engine{Durability,Permission,PostCommit,Tool}Port,
  FailureChunk, StreamFailure(Outcome), UnknownConnection (+ generated
  round-trip tests); Connection becomes an open union, StreamChunk gains
  the failure case.
- Rewrite the hand-written unknown-connection-kind test to assert the new
  open-union round-trip (UnknownConnection preserves kind + extra keys)
  instead of expecting a throw.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@sethjuarez
Seth Juarez (sethjuarez) merged commit 0589d4d into main Aug 19, 2026
18 checks passed
@sethjuarez
Seth Juarez (sethjuarez) deleted the sejuare-microsoft/java-runtime-implementation branch August 19, 2026 03:21
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.

3 participants