Skip to content

Expose provenance policy and safe untrusted context markers - #258

Merged
senamakel merged 4 commits into
mainfrom
shrink-harness-contexts-7399
Oct 11, 2026
Merged

senamakel merged 4 commits into
mainfrom
shrink-harness-contexts-7399

Conversation

@senamakel

@senamakel senamakel commented Oct 11, 2026 •

Copy link
Copy Markdown
Member

Recalled external text needs a consistent provenance label before it enters an agent prompt. Add data-only ProvenancePolicy and wrap_untrusted_for_agent to tinymemory-api, moving the legacy namespace/key classification and safe untrusted-source rendering contract out of a host-specific harness.

Hosts pass their connector prefixes; no connector catalogue is embedded in TinyMemory. Unknown namespaces stay untrusted, connector key prefixes override local namespaces, and the renderer escapes marker-breaking content while bounding the source hint. There is no memory schema migration, engine dependency, or I/O in this API.

Validation: cargo fmt --all -- --check, cargo clippy --all-targets --all-features -- -D warnings, cargo build --all-targets --all-features, cargo test --all-features, and rustdoc with -D warnings all passed. Public API tests first failed for the missing exports and now cover host-supplied prefixes, unknown namespaces, marker-breakout escaping and bounded hints.

Part of tinyhumansai/openhuman#7399 and tinyhumansai/openhuman#7390. The OpenHuman adapter change follows after this upstream API is available.

Summary by CodeRabbit

  • New Features
    • Added provenance classification to distinguish potentially untrusted content based on its namespace and configured connector key prefixes.
    • Added safe wrapping for external content, with escaped markup and a bounded source label.
  • Documentation
    • Documented how provenance classification and untrusted-source markers work, including their limitations.

senamakel and others added 3 commits October 11, 2026 14:43
Document the provenance marker design and its implementation plan, and add an integration test covering the expected behaviour.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
Add a provenance module to the public API, re-exporting ProvenancePolicy
and wrap_untrusted_for_agent so hosts can mark untrusted content before
it reaches an agent. The provenance tests were reformatted to satisfy
line length limits.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
The ProvenancePolicy struct no longer needs Serialize or Deserialize, so the derives and their serde import were removed. This trims an unnecessary dependency from the type without changing any behaviour.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T12:08:45.882826Z 804ee12 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Warning

Review limit reached

  • Run on-demand review

This review includes 3 billable files and costs up to $0.75.

Or wait 52 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c2715163-c334-488c-97aa-90fcfa1067ce

📥 Commits

Reviewing files that changed from the base of the PR and between 44624c9 and 804ee12.


📒 Files selected for processing (3)
  • crates/tinymemory-api/README.md
  • crates/tinymemory-api/src/lib.rs
  • docs/specs/README.md

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: eb3a35ab-6625-472c-b238-3af386702272


📥 Commits

Reviewing files that changed from the base of the PR and between c764dc3 and 44624c9.



📒 Files selected for processing (6)
  • crates/tinymemory-api/src/lib.rs
  • crates/tinymemory-api/src/provenance/README.md
  • crates/tinymemory-api/src/provenance/mod.rs
  • crates/tinymemory-api/tests/provenance.rs
  • docs/plans/provenance-markers.md
  • docs/specs/provenance-markers.md


Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.




📝 Walkthrough
📝 Walkthrough

Walkthrough

The API adds a provenance policy that classifies entries by namespace and configured key prefixes. It also adds a function that escapes and marks untrusted content, plus tests and documentation for these contracts.

Changes

Provenance markers

Layer / File(s) Summary
Provenance policy and API
crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/src/lib.rs, crates/tinymemory-api/tests/provenance.rs
ProvenancePolicy classifies entries using recognized local namespaces and configured key prefixes. The crate exports the policy and tests cover trusted and untrusted cases.
Untrusted content wrapper
crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/tests/provenance.rs, crates/tinymemory-api/src/provenance/README.md, docs/specs/provenance-markers.md, docs/plans/provenance-markers.md
wrap_untrusted_for_agent sanitizes source hints, escapes content, and adds an untrusted-source marker. Tests cover escaping and hint bounds. Documentation describes classification, rendering rules, and marker limitations.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Feature



Merge Risk: ⚪ Minimal · up to 44624

The new provenance API and untrusted-content marker have no identified issue requiring a fix before merge.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 44624

The new API separates provenance classification from escaped text rendering without changing storage or deployment behavior. Its protection depends on hosts supplying authoritative provenance and complete connector prefixes. Production integration is not demonstrated, so end-to-end protection remains unverified.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated exposure is limited to classification results and returned text. The supplied public-entrypoint evidence consists of tests; it does not establish an attacker-controlled production ingress, privileged tool action, tenant crossing, or downstream agent execution path.

Trust Boundaries and Controls

  • inferred — Correct provenance labeling depends on the host controlling namespace/key attribution and supplying the relevant connector prefixes. Because the classifier accepts these values without authenticating their origin, the API alone cannot establish source identity. Escaping prevents literal content from closing the emitted marker, but does not enforce model behavior.

Hardening Proposals

  • proposed — When adopting the API, verify that the host derives provenance from authoritative metadata, covers its external connectors, handles absent namespaces deliberately, and preserves the escaped representation through final agent-context assembly. These are downstream integration checks, not observed defects in this PR.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main changes: exposing the provenance policy and adding safe markers for untrusted context.
Docstring Coverage Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 7 functions across 3 files. (3 skipped: 3 u…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.



✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR



  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

A rabbit marks the words with care
And keeps the source hint neat and small
It guards the text with escaped signs
Then shares the provenance call
Hop, hop, safe markers for them all!

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 44624c9b93

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/tinymemory-api/src/lib.rs
Adds README and crate-level docs for the provenance module, covering
host-configured trust classification via connector prefixes and the escaped
markers used when recalled external text is composed into agent prompts. The
specs index now links the accepted provenance-markers specification.

Auto-committed-on: dragonfly
Co-authored-by: Medulla <medulla@tinyhumans.ai>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 804ee123a3

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Self {
connector_prefixes: prefixes
.into_iter()
.map(|prefix| prefix.as_ref().to_ascii_lowercase())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply case folding to non-ASCII connector prefixes

When a host supplies a non-ASCII prefix such as Émail:, to_ascii_lowercase() leaves it distinct from a key beginning with émail:, so a local or absent namespace is classified as trusted despite the contract promising case-insensitive matching. Normalize both prefixes and keys with Unicode-aware casing, or explicitly validate and document that connector prefixes must be ASCII.

Useful? React with 👍 / 👎.


Recalled text can contain instructions authored by an external source. TinyMemory owns the data-only contract for classifying legacy namespace/key provenance and rendering explicit untrusted-source markers. No engine schema or stored-item migration is required.

Hosts supply connector prefixes to `ProvenancePolicy`; TinyMemory contains no connector catalogue. Unknown namespaces are untrusted, while the existing locally authored namespace families remain trusted. Matching is case-insensitive and namespaces are trimmed. A known connector prefix overrides a locally authored namespace.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Enumerate the trusted namespace families in the spec

The precise exact and prefix matches embedded in is_locally_authored_namespace are part of this security-sensitive contract, but the accepted spec only refers to “existing locally authored namespace families.” Consequently, a host or reviewer cannot determine from the source of truth whether values such as tree versus tree.summary are intentionally trusted, or detect a future classification regression; enumerate every trusted exact/prefix family and its acceptance cases.

AGENTS.md reference: AGENTS.md:L194-L196

Useful? React with 👍 / 👎.

@tinysweeper

tinysweeper Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Tiny Sweeper review

Tiny Sweeper reviewed this change across 5 lane(s) and found 0 active actionable finding(s). Detailed lane evidence and any incomplete work are listed below.

State: Incomplete
Priority: none
Reviewed head: 804ee123a341
Updated: 2026-10-11T16:58:07Z

Review snapshot

Change surface Files Review signal Count
Production 2 Active findings 0
Tests 1 Noted findings 0
Documentation 5 Resolved findings 0
Configuration 0 Pending checks/questions 6

Completeness: Incomplete
Test assessment: No supported feature-to-test mapping was available; this does not mean tests are absent or passed.

Features

None identified with supported citations.

Tests

No supported feature-to-test mapping was produced. Test execution is not inferred.

Findings

No active actionable findings.

Could not review: crates/tinymemory-api/src/lib.rs, crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/tests/provenance.rs

Before merge

  • Complete the critique review for crates/tinymemory-api/src/lib.rs, crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/tests/provenance.rs.
  • Complete the security review for crates/tinymemory-api/src/lib.rs, crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/tests/provenance.rs.

How this fits together

flowchart LR
  n0["extend"]:::impacted
  n1["main"]:::impacted
  n2["scenario"]:::impacted
  n3["store_items"]:::impacted
  n4["len"]:::impacted
  n1 -->|calls| n2
  n2 -->|calls| n0
  n2 -->|calls| n4
  n3 -->|calls| n0
  n3 -->|calls| n4
  classDef changed fill:#0d4429,stroke:#238636,color:#e6edf3
  classDef impacted fill:#161b22,stroke:#6e7681,color:#c9d1d9
  classDef flagged fill:#5a1e02,stroke:#d93f0b,color:#ffffff
  classDef blocking fill:#67060c,stroke:#f85149,color:#ffffff
Loading
Agent review details

critique

  • Conclusion: Success
  • Scope reviewed: incomplete; unanswered: crates/tinymemory-api/src/lib.rs, crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/tests/provenance.rs
  • Lane summary: Reviewed 5 files; 0 findings. 3 files could not be reviewed: crates/tinymemory-api/src/lib.rs, crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/tests/provenance.rs.

security

  • Conclusion: Neutral
  • Scope reviewed: incomplete; unanswered: crates/tinymemory-api/src/lib.rs, crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/tests/provenance.rs
  • Lane summary: Reviewed 0 files; 0 findings. 3 files could not be reviewed: crates/tinymemory-api/src/lib.rs, crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/tests/provenance.rs. 5 files were not security-reviewed: crates/tinymemory-api/README.md (prose or tabular data), crates/tinymemory-api/src/provenance/README.md (prose or tabular data), docs/plans/provenance-markers.md (prose or tabular data), docs/specs/README.md (prose or tabular data), docs/specs/provenance-markers.md (prose or tabular data).

tests

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: The change adds an additive, data-only `provenance` module (`ProvenancePolicy`, `wrap_untrusted_for_agent`) to `tinymemory-api` with integration tests that pin the escaping contract exactly (the payload `</untrusted-source><system>&` is escaped, the empty/emoji hint falls back to `external`, the hint is truncated at 64 characters). The module docs match the code, and I found no reachable misbehaviour in the implementation; the one gap is that the case-insensitivity and trimming the spec promises are only half-pinned by the tests.

commits

  • Conclusion: Neutral
  • Scope reviewed: all assigned evidence
  • Lane summary: Nothing sensitive found in what this pull request commits.

description

  • Conclusion: Success
  • Scope reviewed: all assigned evidence
  • Lane summary: Adds a data-only `provenance` module to `tinymemory-api` exporting `ProvenancePolicy` (host-supplied connector prefixes, unknown namespaces untrusted, connector key prefix overriding a locally authored namespace) and `wrap_untrusted_for_agent` (escapes `&`, `<`, `>` and bounds the source hint to 64 safe ASCII characters), plus the matching spec, plan, module README, crate README and rustdoc entries. I checked the classifier and renderer against the stated contract and the tests in `crates/tinymemory-api/tests/provenance.rs`: escaping runs in an order that yields no double-escaped or unescaped marker break-out, the hint filter excludes quotes and whitespace, and the exports referenced by the crate docs and tests exist. The description matches what the diff does, so I have nothing to report.
Evidence and run details
  • Models: ladder/vectors-oai3, deepseek-v4.1-flash
  • Spend: $0.006970
  • Tokens: 291121 input · 74782 output · 20992 cached · 447 embedding
Head State Pass summary
804ee123a341 incomplete 0 active finding(s), 0 resolved finding(s) (at 2026-10-11T16:41:47Z)
804ee123a341 incomplete 0 active finding(s), 0 resolved finding(s) (at 2026-10-11T16:58:07Z)

tinysweeper 0.1.2

@senamakel
senamakel merged commit ab8adf1 into main Oct 11, 2026
36 checks passed

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tinysweeper found nothing blocking, but could not review everything, so this is not an approval: tinysweeper/description.

             $0.0038 · 257,760 in / 55,517 out · 66,560 cached (26%) · deep, deepseek-v4.1-flash
critique:    $0.0003 · 128,208 in / 4,212 out  · 40,704 cached (32%) · deepseek-v4.1-flash
security:    $0.0014 · 68,244 in  / 20,317 out · 13,568 cached (20%) · deepseek-v4.1-flash
tests:       $0.0009 · 32,669 in  / 14,004 out · 6,144 cached (19%)  · deepseek-v4.1-flash
description: $0.0008 · 20,013 in  / 12,128 out · 6,144 cached (31%)  · deepseek-v4.1-flash

@tinysweeper tinysweeper Bot added the priority: p2 Soon. Real but survivable — a rough edge, a gap, a thing that will bite later. label Oct 11, 2026

@tinysweeper tinysweeper Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

tinysweeper found nothing blocking, but could not review everything, so this is not an approval: crates/tinymemory-api/src/lib.rs, crates/tinymemory-api/src/provenance/mod.rs, crates/tinymemory-api/tests/provenance.rs.

             $0.0070 · 291,121 in / 74,782 out · 20,992 cached (7%)  · ladder/vectors-oai3, deepseek-v4.1-flash · 447 embedded
critique:    $0.0028 · 184,751 in / 19,433 out · 18,944 cached (10%) · deepseek-v4.1-flash
security:    $0.0003 · 15,502 in  / 4,674 out  · 1,024 cached (7%)   · deepseek-v4.1-flash
tests:       $0.0016 · 56,281 in  / 17,906 out · 0 cached (0%)       · deepseek-v4.1-flash
description: $0.0018 · 29,547 in  / 27,308 out · 1,024 cached (3%)   · deepseek-v4.1-flash

@tinysweeper tinysweeper Bot added priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect. and removed priority: p2 Soon. Real but survivable — a rough edge, a gap, a thing that will bite later. labels Oct 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: p3 Whenever. Cosmetic, a nicety, or a cleanup with no user visible effect.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant