Repository navigation
feat!: add codec-owned redaction editing and clean projection - #1745
Closed
bbednarski9 wants to merge 50 commits into
Closed
bbednarski9 wants to merge 50 commits into
bbednarski9 wants to merge 50 commits into
Conversation
Expose consistent typed traversal and text extraction for normalized request items and response output. BREAKING CHANGE: normalized text helpers return Option<Cow<str>>, join all text/refusal parts, and retain textless selection boundaries. Signed-off-by: Bryan Bednarski <[email protected]>
Recognize Chat, Responses, and Anthropic message roles consistently when extension fields keep requests provider-native. Preserve payloads and textless selection boundaries, and exclude tool envelopes and metadata from text projection. Signed-off-by: Bryan Bednarski <[email protected]>
Normalize OpenAI Chat and Responses refusals as typed content, accumulate Chat refusal deltas, and preserve refusal fields through PII overlays. Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Preserve multipart text and refusals without falling back to raw provider payloads. Keep empty annotations authoritative and retain existing media, opaque content, tool-call, and usage projections. Signed-off-by: Bryan Bednarski <[email protected]>
Share text and refusal traversal for normalized instructions, history content, and response output. Keep trim and empty-content display rules, preserve JSON text literally, and exclude native reasoning, media, and tool payloads from default message text. Signed-off-by: Bryan Bednarski <[email protected]>
Traverse normalized output through the borrowed view while retaining the explicit text/refusal allowlist. Reuse joined strings when building fresh provider projections and keep native values, media, and tool payloads excluded. Signed-off-by: Bryan Bednarski <[email protected]>
Render OpenAI Chat content and refusal fields separately and preserve ordered text/refusal blocks in Responses. Retain empty values, fresh allowlisted payloads, and safe tool and usage projections; cover both response and event sanitizer paths. Signed-off-by: Bryan Bednarski <[email protected]>
Keep profile and prompt IR rendering policies distinct while sharing normalized part traversal. Preserve existing fingerprints, empty-part behavior, and structured payload rendering without allocating an intermediate string vector. Signed-off-by: Bryan Bednarski <[email protected]>
Retain media fingerprints and canonical structured values in prompt analysis, preserve block mapping and source-request reuse guards, and decline token-based hints when opaque costs are unknown. BREAKING CHANGE: BlockContentType adds StructuredInput and Opaque. ACG learning and bootstrap state uses the ::acg-ir=2 namespace and warms up independently of older records. Signed-off-by: Bryan Bednarski <[email protected]>
Expose message selection, typed parts, tool payload representations, normalized locations, and shared text extraction through read-only Python MessageView snapshots. Retain selected content independently of mutable annotations and materialize independent Python payload values on access. Document snapshot ownership and add regression coverage for extraction parity, source locations, iterator lifetime, and mutation isolation. Signed-off-by: Bryan Bednarski <[email protected]>
Add local dictionary-based message selection, typed content and tool payload views, normalized locations, and text extraction without requiring the main runtime extension or changing the worker protocol. Freeze only selected content and return independent Python payload values. Document the worker API and verify parity with Rust-backed views, mutation isolation, standalone imports, and source locations. Signed-off-by: Bryan Bednarski <[email protected]>
Expose codecs selection, discriminated content entries, tool payload views, normalized locations, and shared text extraction through a TypeScript facade over Rust-owned snapshots. Materialize independent JavaScript payload values only when accessed. Cover every built-in provider, ownership isolation, extraction boundaries, and declaration narrowing. Document the API and support qualified namespace members in generated Node reference pages. Signed-off-by: Bryan Bednarski <[email protected]>
Replace standalone Python selection and extraction policy with one authenticated, typed InspectLlmContent RPC. Centralize selection and owned projection in Rust, expose the operation in both worker SDKs, and keep returned snapshots locally readable without further host calls. Worker content helpers now take an explicit runtime and are async. Existing dictionary callbacks, codec RPCs, and worker v1 identities are preserved; older hosts report unsupported inspection without a local fallback. Cover typed payloads, source locations, auth/shutdown, cancellation, compatibility, and real installed-wheel worker round trips. Document the ownership and API migration. Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Cover removing leading normalized text and refusal parts, including removal of required text/refusal fields. The current backend must omit the response when a typed, position-preserving projection cannot be produced. Follow-up: bbednarski/codec-pii-part-provenance, stacked on this branch. Preserve source-part identities through sanitizer handoff, provider overlay, and normalized-target verification so a sanitized tail can remain in its original provider block after leading text/refusal removal. Keep this broader refactor separate; no follow-up PR yet. Review: NVIDIA#1730 (comment) Signed-off-by: Bryan Bednarski <[email protected]>
Python and Node recreated content iterators and skipped previously returned parts on every access. Retain shared Rust cursor state for linear traversal and cursor checkpoints for constant-time retained-entry lookups, without cloning payloads or indexing all text up front. Cover mixed multipart snapshots, independent iterators, borrowed strings, retained entries, and permanent exhaustion. Keep language-facing APIs and extraction policy unchanged. Signed-off-by: Bryan Bednarski <[email protected]>
Check collisions against names present before resolving each namespace target, preserving all overloads and merged declarations from that target. Add generated-page coverage for both declarations and their documentation. Signed-off-by: Bryan Bednarski <[email protected]>
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
|
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
…lays Signed-off-by: Bryan Bednarski <[email protected]>
Expose optional request and response redaction capabilities through the active codec. Keep source-aware editing separate from clean projection without original provider payloads, and keep PII detection and policy in the sanitizer. Move provider overlays and trajectory renderers into codecs. Carry normalized array slots through sanitization, map OpenAI Responses removals to original wire blocks, and reject unsupported or ambiguous edits. Preserve runtime pricing enrichment without treating estimated costs as provider fields. Document Rust opt-in and remaining custom binding work. Validate affected module suites, Python, Node, docs, and repository hooks. The full Rust run passed 6924 tests; its remaining worker example passed after restoring the missing temporary Buf tool. Existing Python/npm dependency audits remain unchanged. Signed-off-by: Bryan Bednarski <[email protected]>
bbednarski9
force-pushed
the
bbednarski/codec-pii-part-provenance
branch
from
November 22, 2026 01:52
d198a2b to
3805ff2
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #1745 +/- ##
==========================================
+ Coverage 94.10% 94.11% +0.01%
==========================================
Files 531 543 +12
Lines 168157 170545 +2388
Branches 153 236 +83
==========================================
+ Hits 158233 160494 +2261
- Misses 9923 10050 +127
Partials 1 1
... and 9 files with indirect coverage changes Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
Signed-off-by: Bryan Bednarski <[email protected]>
2 tasks done
bbednarski9
added a commit
that referenced
this pull request
Nov 23, 2026
…#1801) > [!IMPORTANT] > This is the second layer of the codec refactor, based on #1800. The Files changed tab shows the nine commits in this layer. Earlier review discussions are in #1745. #### Overview Make codecs responsible for applying sanitized edits and constructing clean trajectory payloads in their own provider format. The PII component keeps detection, field selection, and replacement/removal policy. Previously, normalized response sanitization and trajectory projection relied on provider-specific overlays and renderers inside `pii-redaction`. Custom/runtime codecs could not opt into those response and trajectory paths through their active codec handle. This change introduces explicit Rust capabilities and moves provider formatting, edit validation, and source mapping into `nemo-relay-codecs`. - [x] I confirm this contribution is my own work, or I have the right to submit it under this project's license. - [x] I searched existing issues and open pull requests, and this does not duplicate existing work. #### Details **Two operations, with different input boundaries** | Operation | Inputs | Responsibility | | --- | --- | --- | | `edit_request` / `edit_response` | Original provider payload plus `NormalizedEdits` | Apply supported changes at their original positions and verify the normalized result. | | `project_request` / `project_response` | Approved sanitized annotation only | Construct clean observability output without restoring fields from the original provider payload. | `LlmCodec::redaction()` and `LlmResponseCodec::redaction()` expose optional `LlmRequestRedaction` and `LlmResponseRedaction` capabilities. Each operation independently defaults to `Ok(None)`; codec identity alone does not establish support. Active runtime and opaque Rust codecs can opt in without joining a PII provider allowlist. ```mermaid flowchart TD Original["Original provider payload"] --> Decode["Active codec decodes"] Decode --> Baseline["Normalized baseline"] Baseline --> Policy["PII detection and policy"] Policy --> Sanitized["Sanitized normalized data"] Baseline --> Edits["NormalizedEdits: retain original array slots"] Sanitized --> Edits Original --> Edit["Codec source-aware editor"] Edits --> Edit Edit --> Edited["Verified sanitized provider payload"] Sanitized --> Project["Codec clean projector: no original payload"] Project --> Clean["Clean trajectory payload"] Edit -->|Unsupported or unsafe| Omit["Omit payload"] Project -->|Unsupported or unsafe| Omit ``` **Provider ownership and edit provenance** - Move provider overlays, clean renderers, and their provider-format tests from `pii-redaction` into `codecs`. All five existing built-in providers expose the capabilities. - Keep normalized array lengths and order through the sanitizer handoff. Removed entries remain null slots until the codec maps them to original source locations. These coordinates apply to one edit operation, not stable public edit handles. - Map mixed OpenAI Responses text/refusal parts to their original wire block paths. Removing leading parts and sanitizing a surviving tail preserves that tail's original block metadata and annotations. - Reject compacted handoffs, mismatched baselines, unsupported part-field edits, and ambiguous request-part deletions. Deleting a required text/refusal field still fails closed. - Require complete-output coverage when the policy selects normalized output or provider-specific output. Built-ins reject unmodeled extra choices/candidates in that case, including when the first result has no matching text. - Preserve the clean-projection boundary from #991: renderers receive approved sanitized annotations, never original wire payloads. - Adapt the runtime's pricing wrapper so capabilities remain available while estimated cost stays runtime enrichment rather than becoming an original provider field. Wire selectors and normalized selectors use the same original response. The PII policy reconciles their edits before the codec compacts arrays, so hashing applies once and raw annotation removals stay attached to the intended block. Provider overlays preserve untouched fields, including mixed tool calls and multiline text with citations. The trajectory preset carries a policy’s approved custom projection through event publication. A later sanitizer that changes the payload invalidates that approval. **Compatibility and remaining scope** - **Behavior change for custom codecs:** existing Rust implementations still compile because the new methods have defaults. However, custom codecs that previously relied only on request decode/encode for normalized PII sanitization must now explicitly opt into editing; otherwise that observability payload is omitted. Unsupported response/projection operations also omit the payload. - Custom Python request codecs can set `supports_request_redaction = True` to opt into verified edits through their source-preserving encoder. Google ADK uses this for request events. Response editing and clean projection through custom Python codecs, and custom codec opt-in in Node.js, C, and workers, remain follow-up work. - Generic raw-JSON sanitization remains independent of these capabilities. Normalized schemas/serialization and the borrowed content-read API are unchanged. - Caller-visible requests/responses are unchanged. This PR does not add PII detectors, live streaming editing, general mutable views, or comprehensive decoder-fidelity changes. Existing decoder text-block combining remains in place. **Validation at `ea504ac50`** - The codec and PII Rust suites passed all 797 tests, including original-slot removals, mixed tool calls, single hashing, and custom projections delivered to subscribers. - `just test-python-google-adk` passed all 588 tests, including the request redaction regression. - `just test-python` passed 85 native tests, 1,693 Python tests, and 24 example tests. One Python test was skipped. - All eight commits passed their staged hooks, including the dependency audits. The Python lockfile now selects the patched `wcmatch 11.2` release. - The local full Rust build stopped at the 4 GiB disk reserve. The full Rust test matrix passed on Linux (amd64 and arm64), macOS (arm64), and Windows (amd64 and arm64). All 71 executed jobs passed in [GitHub Actions](https://github.com/NVIDIA/NeMo-Relay/actions/runs/44985247884). #### Where should the reviewer start? 1. [Redaction contracts](https://github.com/NVIDIA/NeMo-Relay/blob/ea504ac506b3173b22df53e465740bdcdd36e777/crates/types/src/codec/redaction.rs) and [capability accessors](https://github.com/NVIDIA/NeMo-Relay/blob/ea504ac506b3173b22df53e465740bdcdd36e777/crates/types/src/codec/traits.rs): input boundaries, independent opt-in, and omission defaults. 2. [Provider-owned editor](https://github.com/NVIDIA/NeMo-Relay/blob/ea504ac506b3173b22df53e465740bdcdd36e777/crates/codecs/src/redaction/mod.rs) and [regressions](https://github.com/NVIDIA/NeMo-Relay/blob/ea504ac506b3173b22df53e465740bdcdd36e777/crates/codecs/tests/unit/redaction_tests.rs): source mapping, removal/metadata preservation, invalid handoffs, and built-in request/response coverage. 3. [PII delegation](https://github.com/NVIDIA/NeMo-Relay/blob/ea504ac506b3173b22df53e465740bdcdd36e777/crates/pii-redaction/src/builtin.rs) and [component tests](https://github.com/NVIDIA/NeMo-Relay/blob/ea504ac506b3173b22df53e465740bdcdd36e777/crates/pii-redaction/tests/unit/component_tests.rs): policy ownership and custom/runtime capability routing. 4. [Pricing adapter](https://github.com/NVIDIA/NeMo-Relay/blob/ea504ac506b3173b22df53e465740bdcdd36e777/crates/runtime/src/codec.rs), [clean projection](https://github.com/NVIDIA/NeMo-Relay/blob/ea504ac506b3173b22df53e465740bdcdd36e777/crates/codecs/src/redaction/projection.rs), and the [migration guide](https://github.com/NVIDIA/NeMo-Relay/blob/ea504ac506b3173b22df53e465740bdcdd36e777/docs/integrate-into-frameworks/provider-codecs.mdx#codec-owned-redaction-in-rust). #### Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to) - Relates to #1800 — prerequisite content APIs and existing projection fixes. - Relates to #991 — preserves the sanitized-only trajectory projection boundary. - Relates to: PII redaction from codec traits + APIs. No issue number was supplied; this PR does not automatically close an issue. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit - **New Features** - Built-in provider codecs can apply supported request and response redactions while retaining compatible provider data. - Supported codecs can generate sanitized request and response projections for managed trajectory data. Governed payloads are omitted when required redaction support or a safe projection is unavailable. - Python request codecs can opt in to verified redaction; ambiguous repeated Google ADK function calls are rejected. - Custom Rust codecs can provide redaction and projection support for their own formats. - OCI GenAI model selection now follows the configured serving type. - **Documentation** - Added guidance on codec redaction, projection behavior, and limitations for custom codecs. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Signed-off-by: Bryan Bednarski <[email protected]>
This branch was previously deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Manually stacked on #1730 — merge the parent PR first. This draft targets
mainbecause the parent branch exists only on the author's fork. GitHub's full diff therefore includes the parent work.Review this layer: follow-up-only comparison. The description and validation below cover this follow-up. Reconcile this branch with
mainafter #1730 lands, before merging this PR. This is a traditional manual stack, without GitHub stack submission.Overview
Make codecs responsible for applying sanitized edits and constructing clean trajectory payloads in their own provider format. The PII component keeps detection, field selection, and replacement/removal policy.
Previously, normalized response sanitization and trajectory projection relied on provider-specific overlays and renderers inside
pii-redaction. Custom/runtime codecs could not opt into those response and trajectory paths through their active codec handle. This change introduces explicit Rust capabilities and moves provider formatting, edit validation, and source mapping intonemo-relay-codecs.Details
Two operations, with different input boundaries
edit_request/edit_responseNormalizedEditsproject_request/project_responseLlmCodec::redaction()andLlmResponseCodec::redaction()expose optionalLlmRequestRedactionandLlmResponseRedactioncapabilities. Each operation independently defaults toOk(None); codec identity alone does not establish support. Active runtime and opaque Rust codecs can opt in without joining a PII provider allowlist.flowchart TD Original["Original provider payload"] --> Decode["Active codec decodes"] Decode --> Baseline["Normalized baseline"] Baseline --> Policy["PII detection and policy"] Policy --> Sanitized["Sanitized normalized data"] Baseline --> Edits["NormalizedEdits: retain original array slots"] Sanitized --> Edits Original --> Edit["Codec source-aware editor"] Edits --> Edit Edit --> Edited["Verified sanitized provider payload"] Sanitized --> Project["Codec clean projector: no original payload"] Project --> Clean["Clean trajectory payload"] Edit -->|Unsupported or unsafe| Omit["Omit payload"] Project -->|Unsupported or unsafe| OmitProvider ownership and edit provenance
pii-redactionintocodecs. All five existing built-in providers expose the capabilities.Wire selectors and normalized selectors use the same original response. The PII policy reconciles their edits before the codec compacts arrays, so hashing applies once and raw annotation removals stay attached to the intended block. Provider overlays preserve untouched fields, including mixed tool calls and multiline text with citations.
The trajectory preset carries a policy’s approved custom projection through event publication. A later sanitizer that changes the payload invalidates that approval.
Compatibility and remaining scope
supports_request_redaction = Trueto opt into verified edits through their source-preserving encoder. Google ADK uses this for request events. Response editing and clean projection through custom Python codecs, and custom codec opt-in in Node.js, C, and workers, remain follow-up work.Validation at
ea504ac50just test-python-google-adkpassed all 588 tests, including the request redaction regression.just test-pythonpassed 85 native tests, 1,693 Python tests, and 24 example tests. One Python test was skipped.wcmatch 11.2release.Where should the reviewer start?
Related Issues: (use one of the action keywords Closes / Fixes / Resolves / Relates to)