Skip to content

feat(tx): read back and induce lenses for RPC-only apps - #2405

Open
abrichr wants to merge 5 commits into
mainfrom
claude/tx-rpc-read-template-2390
Open

abrichr wants to merge 5 commits into
mainfrom
claude/tx-rpc-read-template-2390

Conversation

@abrichr

@abrichr abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member

Stacked on #2404, which is stacked on #2393 (base claude/tx-induce-refuse-no-item-route). Retarget it to main after those merge. With #2393 and #2404 it completes #2390.

Problem

The real-app benchmark's held-out ERP sends every read and write as a JSON-RPC POST to one path. Three things failed on it:

  • A GET lens can't read a record back there, so all 24 wrapped updates stopped BLOCKED_PRECOMMIT before the agent acted.
  • Induction found nothing to learn from.
  • Such an app answers a failed call with a 2xx and an error member. On a live Tryton, writing a field that doesn't exist returns 200 {"error": [...]}.

Change

  • EndpointTemplate gets three data fields (no engine code names an app):
    • body_template: the JSON body, with {id}, {id:int} and {payload} placeholders;
    • record_path: a dotted path with list indexes, such as result.0;
    • error_path: when the value at this path is non-null, the call failed. LensHttpResponse.ok is then false, and call_error holds the value.
  • RPC induction from effects:
    • A read names record ids and a field list and returns exactly those records.
    • A write names one id and a dict of values, and a later read of the same model shows those values.
    • The model with the most confirmed writes is chosen.
    • The read-back template reads the union of the fields the trace read for that model. A field the server changed between reads without being asked is volatile.
    • An RPC trace with no confirmed write raises InductionRefused.

Known limits:

  • The frame covers only the fields the app itself read in the trace, not the whole table.
  • Related records (an address or contact row under a party) are separate models and need their own lens.
  • No create route is induced for RPC yet.

Tests

  • tests/test_tx_rpc_lens.py, in CI (local server speaking the envelope), 7 tests:
    • template rendering and record paths;
    • induction with a noise call;
    • volatility learned from evidence;
    • an engine write that changes only the intended field;
    • an error inside a 2xx is a failed write and never CONFIRMED;
    • read-only and unconfirmed-write traces are refused.
  • Live, lab only, on a local Tryton 7.0 with synthetic parties (needs OAFLOW_TX_LIVE_RPC_URL, _USER, _PASSWORD). Both tests pass:
    • The induced lens reads the party back, and write_date is learned as volatile.
    • The engine changes only code, confirmed by the test's own read. The result is UNCERTAIN with only unqualified_observation_only.
    • The app's 200 {"error": ...} answer is a failed write.
  • Suites on the lab's WSL: tx 242 passed; the verify facade 4 passed.

Not in this PR

Classifying the same endpoint's read calls on the wire, so the tap's budget isn't used up, is #2397's ReadRoute with a method body discriminator.

An app that sends every read and write as a JSON-RPC POST to one path had
no lens: a GET template can't read a record back, so every update stopped
before the agent acted, and induction found nothing to learn from.

EndpointTemplate gains three data fields:
- body_template: the JSON body, with {id}, {id:int} and {payload}
  placeholders, for reads and writes that carry their arguments in the
  body;
- record_path: a dotted path with list indexes (result.0) to the record;
- error_path: a member that, when non-null, makes a 2xx answer a failed
  call. Without it, a live RPC app's 200 answer to a write of a field that
  does not exist looked like success.

Induction takes RPC roles from effects, as for REST: a read names ids and
a field list and returns exactly those records; a write names one id and
values that a later read of the same model shows. The read-back template
reads the union of the fields the trace read for that model, so the frame
is what the app itself reads. A field the server changed between reads
without being asked is volatile. An RPC trace with no confirmed write is
refused.

Live on a local Tryton 7.0 (synthetic party records): the induced lens
reads the party back, the engine's write changes only the intended field
(UNCERTAIN with unqualified_observation_only, checked by the test's own
read), write_date is learned as volatile, and an RPC error inside a 200
is a failed write.

Signed-off-by: abrichr <richard.abrich@mldsai.com>
@abrichr

abrichr commented Nov 21, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Grok
Reviewed-Head: bc2a598

The new lens fields are sound and fail closed. body_template renders {id}, {id:int} (bools rejected) and {payload} without evaluating unexpected placeholders; a missing parameter becomes a failed request, not a partial body. record_path (for example result.0) takes precedence and yields no record on a miss. error_path makes a 2xx with a non-null error not ok, and get_one / write / post-commit already branch on .ok, so that failure is not treated as a successful HTTP write. Induction takes roles from effects: a read must return the named ids, a write must be followed by a later read of the same model that shows the written values, and a trace of only reads or a write with no confirming read raises InductionRefused. The read-back template unions the fields the trace itself read. Local tests cover rendering, induction, a confirmed update, a 2xx error, and the two refusal cases. CAPABILITIES.md / llms-full.txt describe the same behavior; the held Flow 3.4.0 changelog heading is untouched.

Residuals, not blocks: confirmation checks that a later read contains the values, not that they changed from a prior read, so a call whose dict already matched the record could be learned as the write method (execute still fails closed if that method does not actually write). IDs are induced only as integers. If at least half of the POSTs look like successful RPC calls, induction does not fall through to REST, and a mixed trace with no attributable RPC write is refused. Live tests are skipped unless OAFLOW_TX_LIVE_RPC_* is set.

Do not merge: stacked on #2404 / #2393, and the request was review only.

Pointer: openadapt-internal#211

# Conflicts:
#	CAPABILITIES.md
#	llms-full.txt
Base automatically changed from claude/tx-induce-refuse-no-item-route to main November 21, 2026 20:04
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude (independent reviewer)
Reviewed-Head: 991ea0b

No blockers.

@abrichr abrichr closed this Nov 22, 2026
@abrichr abrichr reopened this Nov 22, 2026
# Conflicts:
#	CAPABILITIES.md
#	llms-full.txt
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Claude (independent reviewer)
Reviewed-Head: d2cddb1

The only new commit since the approved head 991ea0b0b is d2cddb1d1, a merge of origin/main at a23cf5a65 (the current main tip). The merge is clean.

  • Packages unchanged in content. The net diff under packages/ against the merge base keeps the same +640/-4 lines across the same files. Only the blob index lines and hunk line offsets differ (for example induce.py @@ -775 became @@ -812, and lens.py +17 lines). That is because fix(tx): learn NULL versus empty string per field as a codec #2402 added code above these hunks in induce.py, lens.py and types.py. Every added and removed line is identical.
  • Net diff against main is only the PR. git diff a23cf5a65 d2cddb1d1 touches the same 6 files with the PR's own hunks only. fix(tx): learn NULL versus empty string per field as a codec #2402's null_empty changes in induce.py, lens.py, types.py and judge.py are kept, and no conflict markers remain.
  • CAPABILITIES.md tx-lens row. I compared the row sentence by sentence. Both of the PR's sentences are present: the single-RPC-endpoint lens with body_template, the result.0 record path and a 2xx with error counting as a failure, plus how induction learns it. None of main's sentences were lost, including fix(tx): learn NULL versus empty string per field as a codec #2402's redirect and null_empty sentences. The PR text sits before "Not checked:", and this is the only line that differs from main.
  • llms-full.txt. Running python scripts/build_llms_full.py in a detached worktree at this head leaves the tree clean, so the committed file matches the generator.

Merge-order note: #2397 also edits this row. Whichever of the two lands second will need the same kind of row merge.

@abrichr abrichr closed this Nov 22, 2026
@abrichr abrichr reopened this Nov 22, 2026
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: d2cddb1

Independent cross-vendor adversarial review of d2cddb1d19393c5787984ab8a0052a2659c7e3e3 (Claude-authored claude/tx-rpc-read-template-2390; I authored none of this PR).

Findings & fail-closed verification

  • 2xx-wrapped RPC error refusal (lens.py, types.py): EndpointTemplate adds data-only body_template, record_path, and error_path. When error_path resolves to a non-null value on a 2xx response, _request records call_error and LensHttpResponse.ok returns False, ensuring an RPC error inside HTTP 200 is treated as a failed call and never CONFIRMED.
  • Safe template rendering & path traversal (render_body_template, get_record_path): Rejects missing {payload}, rejects bool or non-integer values for {name:int}, rejects missing/None whole placeholders, and converts ValueError in _request into a failed LensHttpResponse(status_code=None, network_error=...). get_record_path checks Mapping membership and bounded non-negative list indices, failing closed with (False, None).
  • Effect-based RPC induction (induce.py): _rpc_call ignores error responses; _induce_rpc_lens requires read results to match requested integer IDs exactly, requires writes to be confirmed by a later read (seq > ex.seq) of the same (model, id), learns volatile_fields solely from unrequested changes between reads of the same record, and raises InductionRefused when an RPC-majority trace has no attributable write.

Generality gate

  1. No per-app code in engine: Verified; zero application or vendor names in tx/{types,lens,induce}.py.
  2. Fix the class, not the instance: Verified; handles RPC-only read-back, 2xx-wrapped errors, and effect-based induction across JSON-RPC endpoints via declarative EndpointTemplate data.
  3. Held-out evidence: Verified via 7 CI unit tests (test_tx_rpc_lens.py) plus live lab runs against held-out Tryton 7.0, with frame-scope and create-route limits honestly disclosed.

# Conflicts:
#	CAPABILITIES.md
#	llms-full.txt
@abrichr

abrichr commented Nov 22, 2026

Copy link
Copy Markdown
Member Author

Independent adversarial review: APPROVE

From: Gemini
Reviewed-Head: e668cf1

Verified clean merge with origin/main (24034b59d72ea4c05960b4e729d9aea72a771b06) over the previously approved head d2cddb1d19393c5787984ab8a0052a2659c7e3e3:

  • Only CAPABILITIES.md and llms-full.txt conflicted; resolved cleanly preserving both main (#2437 row) and #2405's RPC body_template note, and regenerated llms-full.txt via scripts/build_llms_full.py.
  • All PR code and test files (openadapt_flow/tx/induce.py, openadapt_flow/tx/lens.py, openadapt_flow/tx/types.py, tests/test_tx_rpc_lens.py) merged cleanly without conflict.
  • Targeted pytest (tests/test_tx_rpc_lens.py): 7 passed, 2 skipped (opt-in live tests).
  • Generality & durability: general RPC body_template read/write lens induction and 2xx-with-error refusal across apps, no per-app engine code.

This branch has not been deployed

No deployments
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.

1 participant