Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
eabfe66
docs(codec): freeze internal value contract prototype
bbopen Sep 20, 2026
103ccd6
docs(codec): narrow prototype to float16 scientific values
bbopen Sep 20, 2026
dfef732
feat(codegen): validate and preserve callable contracts
bbopen Sep 20, 2026
56cfa61
docs(codec): compose unions and fixed tuples in value contract
bbopen Sep 20, 2026
f300b71
feat(codegen): route callable contracts through generation
bbopen Sep 20, 2026
40370ee
fix callable compiler integration regressions
bbopen Sep 20, 2026
c5c02e8
refresh menagerie callable contract snapshots
bbopen Sep 20, 2026
8b2bd08
harden overload correlation and IR traversal
bbopen Sep 20, 2026
825a46f
honor Python 3.10 overload fallback in tests
bbopen Sep 20, 2026
b5a96b6
normalize cross-version overload snapshot and verify Torch dtype
bbopen Sep 20, 2026
8ec57da
feat(codec): define bytes and per-call provenance contracts
bbopen Sep 20, 2026
88ad9de
feat(codec): define bytes and per-call provenance contracts
bbopen Sep 20, 2026
a2e2773
feat(codec): carry scalar ndarray proof per RPC call
bbopen Sep 20, 2026
9d9ae8e
consume bytes and scalar provenance in callable validators
bbopen Sep 20, 2026
7e14414
test(architecture): add independent numeric oracle and fixed cases
bbopen Sep 20, 2026
16e2c48
test(architecture): bound exhaustive oracle assertion cost
bbopen Sep 20, 2026
05a891e
test: expect broad hidden overload implementation
bbopen Sep 20, 2026
855115e
style(test): use braces in architecture oracle
bbopen Sep 20, 2026
7e2301c
fix(rpc): keep one-argument validator call shape
bbopen Sep 20, 2026
bc3641b
Merge commit '755616fc2dfac972f3f58fcc997afc53e8b705cf' into codex/ty…
bbopen Sep 20, 2026
a642527
test(rpc): assert additive validator provenance
bbopen Sep 20, 2026
27cf162
Merge commit 'a642527' into codex/tywrap-callable-compiler-20260919
bbopen Sep 20, 2026
552b530
test: prove scalar float16 through generated HTTP wrapper
bbopen Sep 20, 2026
1fa6a87
test(architecture): add overloaded nested-record fixtures
bbopen Sep 20, 2026
fe21240
Merge branch 'codex/tywrap-callable-compiler-20260919' into codex/tyw…
bbopen Sep 20, 2026
e14d2f3
fix(codec): bind Torch float16 to nested ndarray dtype
bbopen Sep 20, 2026
e9fa9b2
test: align nested scalar proof with array index normalization
bbopen Sep 20, 2026
0c3a1ce
Merge value interface Torch float16 guard
bbopen Sep 20, 2026
f20b4a7
test: exercise generated Torch float16 wrapper through HTTP codec
bbopen Sep 20, 2026
0ac3823
test: exercise generated callable contracts in isolated consumer
bbopen Sep 20, 2026
f33cc5b
Merge approved Torch dtype contract for conformance proof
bbopen Sep 20, 2026
b831054
test: reject architecture contract mutations structurally
bbopen Sep 20, 2026
64087dc
test: keep overload helper out of extracted module callables
bbopen Sep 20, 2026
0852f78
Merge compiler candidate generated Torch and index proofs
bbopen Sep 20, 2026
5c1728f
fix(compiler): derive callable types from IR and detect bound overloa…
bbopen Sep 20, 2026
fda3d6d
fix(ir): avoid array index as inherited type parameters
bbopen Sep 20, 2026
5d0b3ad
fix(scientific): resolve NumPy float16 dtype from expanded annotation
bbopen Sep 20, 2026
ba6da84
Merge compiler NumPy float16 and IR authority fixes for conformance p…
bbopen Sep 20, 2026
96041aa
test: preserve strict NumPy warning control and required dataclass fi…
bbopen Sep 20, 2026
461ff6a
fix(scientific): require NumPy and Torch dtype identity
bbopen Sep 20, 2026
ecba0e0
test: typecheck generated float16 scalar and array results
bbopen Sep 20, 2026
87ce83e
Merge qualified scientific dtype guard and compiler corrections
bbopen Sep 20, 2026
6f82ccb
fix(ir): clear only matching scientific annotation warnings
bbopen Sep 20, 2026
1736b68
Merge exact scientific warning filter for conformance proof
bbopen Sep 20, 2026
0006a3f
feat(generator): expose isolated runtime binding template
bbopen Sep 20, 2026
6a72dce
fix(generator): isolate binding provider namespace
bbopen Sep 20, 2026
fb93225
style: format callable compiler source and tests
bbopen Sep 20, 2026
fcfb829
docs: exclude internal contract notes from llms bundle
bbopen Sep 20, 2026
1d76041
test(node): assert generated coroutine return contract
bbopen Sep 20, 2026
3fefce2
test(pyodide): assert generated coroutine return contract
bbopen Sep 20, 2026
7670512
Merge branch 'codex/tywrap-coroutines-20260920' into codex/tywrap-cor…
bbopen Sep 20, 2026
1515267
test(pyodide): exercise default coroutine capability
bbopen Sep 20, 2026
37ee8db
Integrate coroutine capability and safe object fallback
bbopen Sep 20, 2026
db77710
merge: combine callable compiler with coroutine runtime fixtures
bbopen Sep 20, 2026
67f030e
Update object return snapshots to unknown
bbopen Sep 20, 2026
57cdbc7
Fail closed on unresolved returns and recognize torch HalfTensor
bbopen Sep 20, 2026
4f7c8e5
Keep validation checks when widening unresolved results
bbopen Sep 20, 2026
a289bdc
Resolve selected local records and simple aliases
bbopen Sep 20, 2026
ebfa17e
Reconcile generic safety tests and generated snapshots
bbopen Sep 20, 2026
ec2dbb6
Compose local value contracts and guard foreign validation
bbopen Sep 20, 2026
42feeca
Bound compile-local alias expansion depth
bbopen Sep 20, 2026
3763324
merge: take accepted callable compiler baseline
bbopen Sep 20, 2026
54cef7c
merge: take accepted conformance evidence
bbopen Sep 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/guide/runtimes/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ setRuntimeBridge(
payloads. You must provide a compatible server endpoint. Each call is an
independent POST request because the protocol is stateless.

Generated async callables have typed results when their return annotations have
supported value conversions. The in-repo Node and Pyodide bridges await Python
coroutines. For `HttpBridge`, your server must await coroutines before it sends
the result. `HttpBridge` cannot verify a remote server's coroutine support.

tywrap does not include an HTTP server. See the [API reference](/reference/api/)
for the expected request and response format.

Expand Down
114 changes: 114 additions & 0 deletions docs/maintainers/callable-contracts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
# Callable compilation contracts

`tywrap_ir` emits IR 0.4. `validateIrContract()` checks required fields in
unknown JSON. Each diagnostic has a JSON path. Validation stops after 100,000
array entries.

`compileContract()` is an internal pure step. It accepts validated IR,
exported-name selection, value conversions, capabilities, and a generator. It
maps callable types from the validated IR. The selection input cannot change
those types. It returns the resolved module, callable records, diagnostics, and
TypeScript and declaration content.

The compiler does not read files. It does not start Python. It does not read a
cache. It does not write files. It does not access a runtime registry.

`generate()` owns Python discovery, cache reads, output comparison, and writes.
It validates IR and maps annotations, then calls `compileContract()` before
emission. Offline contract files omit extractor metadata for stable bytes. The
reader restores an empty metadata object.

## Resolved callable data

The compiler records each parameter and result, including overloads. Each record
has a Python type, direction, source path, and conversion result. One resolved
module model serves declarations, call wrappers, and return validators.

Each value conversion uses revision 2 of
[value-contracts.v2.json](value-contracts.v2.json). Do not infer a wire rule
from the TypeScript type.

| Case | Result |
| --------------------- | ------------------------------------------------------------------------------------- |
| `int` | JSON number, JavaScript number, safe-integer constraint |
| `bytes` | Existing base64 envelope, decoded as `Uint8Array` |
| nested `dict[str, T]` | JSON record with the child conversion at every value path |
| `str \| int` | Selected union alternative with one child contract per option |
| `tuple[int, str]` | Exact JSON array with a contract for each index |
| float16 ndarray | Existing Arrow or JSON-fallback envelope, decoded as a numeric scalar or nested array |
| float16 Torch tensor | Outer `torch.float16` envelope with a nested `float16` ndarray |

The compiler requires an explicit float16 dtype. An untyped ndarray or Torch
tensor stays unresolved.

For an evaluated PyTorch annotation, use `torch.HalfTensor`. The compiler
accepts this exact class and leaves other Torch tensor classes unresolved.

NumPy can spell `NDArray[np.float16]` as
`numpy.ndarray[tuple[Any, ...], numpy.dtype[numpy.float16]]`. The compiler reads
the dtype argument, not the shape wildcard. Only a supported scientific result
clears its matching external-annotation IR warning. Other external annotations
remain warnings.

The codec records scalar ndarray dtype and rank for one call. A generated return
validator accepts a scalar only with matching proof. Nested proof follows its
parent and array index or record key. Array index `0` and `"0"` refer to the
same child. Equal numbers from separate calls do not share proof. Array and
tensor objects keep their identity-based marker proof.

The compiler keeps Arrow int64 behavior outside this prototype. Existing Arrow
int64 values can decode as `bigint`.

Selected local non-generic `TypedDict` classes use revision-2 record contracts
when every field has a supported conversion. Nested records and selected simple
aliases compose through the same resolver. Foreign and recursive names remain
unresolved.

## Diagnostics and fallback

Known unsupported cases create error diagnostics. The compiler changes the
affected generated type to `unknown`. `generate()` returns each diagnostic as a
warning, so `--fail-on-warn` rejects strict builds.

- The default compiler capability covers coroutine execution in the in-repo Node
and Pyodide bridges. A caller can mark this capability unavailable when it
uses an older or custom bridge. The compiler then emits `unknown` and an error
diagnostic for async results.
- Dataclasses require an adapter owned by #339. The default capability stays
unavailable. An explicit output record conversion can use the adapter
capability when enabled.
- Non-string record keys require an explicit conversion.

Unresolved annotations create warning diagnostics. Their result type is
`unknown`, including an output that contains `object` or a type variable. Python
`object` can hold a primitive value. A type variable has no validated conversion
to the decoded result. Neither annotation justifies a precise TypeScript return.

The compiler keeps an existing best-effort return check when it widens a
declaration. For example, an unresolved `list[object]` still rejects a non-array
result, and a `DataFrame` annotation still requires a decoded marker.

`Literal` returns keep their exact-value validator, but stay `unknown` until a
literal value contract exists. Unresolved literal overloads cannot select a
precise return at runtime.

IR overload signatures stay separate from the implementation signature. The
extractor collects type variables from overload annotations. Generated
declarations retain each input-to-result relation. The hidden TypeScript
implementation accepts `unknown` values so it can cover every declared overload.

At runtime, the wrapper selects the first supported overload that matches bound
arguments. This follows TypeScript declaration order. The compiler warns when
overload inputs may overlap, including an omitted optional argument. Python 3.10
cannot expose registered overloads through `typing.get_overloads`; it keeps the
implementation signature and emits an IR warning.

## Deferred work

Revision 2 does not describe references or recursive aliases. The compiler
reports these cases as unresolved. A later value-contract revision can give them
a supported conversion.

The client-binding work may consume the resolved callable model later. It must
remain opt-in. It must not add files to default generation or mutate the global
runtime registry.
14 changes: 14 additions & 0 deletions docs/maintainers/value-contract-fixtures.v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@
{ "decimal": "9223372036854775807", "outcome": "reject" },
{ "decimal": "265252859812191058636308480000000", "outcome": "reject" }
],
"bytesCases": [
{
"logicalHex": "00ff80",
"requestEnvelope": { "__tywrap_bytes__": true, "b64": "AP+A" },
"responseEnvelope": { "__type__": "bytes", "encoding": "base64", "data": "AP+A" },
"decodedAs": "Uint8Array[0,255,128]"
},
{
"logicalHex": "",
"requestEnvelope": { "__tywrap_bytes__": true, "b64": "" },
"responseEnvelope": { "__type__": "bytes", "encoding": "base64", "data": "" },
"decodedAs": "Uint8Array[]"
}
],
"binary16Cases": [
{ "wordHex": "0000", "outcome": "0" },
{ "wordHex": "8000", "outcome": "-0" },
Expand Down
Loading
Loading