Skip to content

fix(pii): mask texts over spaCy's length limit and drop encoded files from logs - #9979

Merged
waleedlatif1 merged 4 commits into
stagingfrom
fix/pii-redaction-binary-and-long-text
Nov 13, 2026
Merged

waleedlatif1 merged 4 commits into
stagingfrom
fix/pii-redaction-binary-and-long-text

Conversation

@waleedlatif1

@waleedlatif1 waleedlatif1 commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Presidio masks texts longer than spaCy's max_length (1,000,000) instead of failing with E088 → 500. Pattern, checksum, and custom recognizers run once over the whole text (they have no length limit, so no match can straddle a cut). Only spaCy NER runs in 100k-character windows that overlap by 1,000 characters, with spans shifted to whole-text offsets and merged. Texts under the limit and regex-only requests take exactly the same path as before
  • Encoded file bodies (base64 data: URLs, and bare base64 ≥1 KiB, optionally wrapped) are replaced with [BINARY_CONTENT_REDACTED] in the execution log only. That is an explicit replaceEncodedBinary option set by the log entry points (redactPIIFromExecution, redactLargeValueRefs). Text masking can't see PII inside a file, and replacing can only over-redact. Live data (workflow input, block outputs, memory) keeps every string on the masking path, so nothing skips redaction because of its shape
  • A route 500 now gets 3 attempts instead of 8 (general hardening). 502/503/504/408/429 keep the full backoff, since 500 also covers deterministic per-input failures
  • Data retention docs: what happens to encoded file content, and that Run from block / re-run with a previous input read the redacted log

Type of Change

  • Bug fix

Testing

  • apps/sim/scripts/test-pii-redaction-e2e.ts against a running app plus a real Presidio container (docker/pii.Dockerfile), report written to PII_E2E_REPORT_PATH
    • staging: 0/3. Presidio 500s on the over-length text, the log path retries ~66s then writes [REDACTION_FAILED], and live block output aborts the run after ~62s
    • this branch: 3/3
      • a 1.5M-char text is masked in ~10s: a name straddling an NER window edge, a whitespace-spanning custom pattern, and a name at the end
      • log with a 5M-char base64 PDF and a 3M-char text: the PDF becomes the marker without being sent, the name is masked, 0 failed requests, ~20s
      • live block output with the same content: masked in full, no abort, ~25s for 8M chars of NER
  • Window-merge harness drives the real _analyze_long with a marker at 14 window-edge offsets: 14/14 found exactly once
  • Unit tests (written first, each guard mutated and seen red):
    • log-only replacement, including wrapped base64, trailing newline, and a data URL with long metadata
    • live data stays on the masking path, including a base64-shaped identifier containing an SSN
    • not-a-file controls
    • large-value wiring for both the log and live entry points
    • the 500 attempt cap
  • bun run --cwd apps/sim test on the PII files: 66 passed. Biome, check:explicit-any, check:comment-hygiene, check:utils, check:test-patterns, check:file-names pass locally; full lint/type-check/check:audits run in CI

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing (new tests pass the test-audit authoring gate)
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 13, 2026 5:33am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain from this review.

Summary

Handles text beyond spaCy's length limit and removes encoded file bodies from execution logs.

  • PII masking handles text longer than spaCy’s limit.
  • Saved logs replace recognized encoded file bodies with a marker.
  • PII masking stops retrying HTTP 500 responses after three attempts.

Reviews (4) · Last reviewed commit: "fix(pii): keep every NER window's spans ..." · Reviewed by Greptile

Comment thread apps/sim/lib/guardrails/pii-batching.ts Resolved

@cubic-dev-ai cubic-dev-ai Bot 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.

All reported issues were addressed across 10 files

Turn on auto-fix | Re-trigger cubic

Comment thread apps/sim/lib/guardrails/pii-batching.ts Resolved
@waleedlatif1
waleedlatif1 force-pushed the fix/pii-redaction-binary-and-long-text branch from b8b946e to 5ff04d2 Compare November 13, 2026 05:17
@waleedlatif1 waleedlatif1 changed the title fix(pii): keep encoded files away from Presidio and split texts too long for one NER pass fix(pii): mask texts over spaCy's length limit and drop encoded files from logs Nov 13, 2026
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

1 issue found across 9 files

Confidence score: 4/5

  • The oversized-text and binary-log checks in apps/sim/scripts/test-pii-redaction-e2e.ts won't run automatically because the script isn't registered in the package or CI workflows. Add an entry that provides the required service and environment.
Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="apps/sim/scripts/test-pii-redaction-e2e.ts">

<violation number="1" location="apps/sim/scripts/test-pii-redaction-e2e.ts:1">
P2: This E2E script is not registered in `apps/sim/package.json` and no workflow invokes it, so the oversized-text and binary-log checks never run automatically. Add a package or CI entry with the required service and environment setup.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/pii/server.py Resolved
…acement to the log

- Presidio runs pattern and custom recognizers over the whole text and spaCy NER in overlapping windows when a text exceeds spaCy's max_length, so no match can straddle a cut; the app no longer splits texts
- Encoded file bodies are replaced only in the execution log (explicit replaceEncodedBinary option set by the log entry points); live data keeps every string on the masking path
- Data URL headers are parsed through the first comma, and log-mode detection no longer requires mixed character classes
- e2e: setup failures are recorded in the report
…ata: case-insensitively

- Long-text NER windows also run the pattern entities when a score_threshold is set, so context-boosted matches clear it as they do on short texts
- The data: URI scheme is matched case-insensitively
- e2e asserts each name is masked as one <PERSON> span and is registered as test:pii-redaction:e2e
@waleedlatif1
waleedlatif1 force-pushed the fix/pii-redaction-binary-and-long-text branch from 5ff04d2 to aefa16a Compare November 13, 2026 05:26
@waleedlatif1
waleedlatif1 requested a review from a team as a code owner November 13, 2026 05:26
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 10 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

Comment thread apps/pii/server.py Resolved
…ur found them

NER reads context, so a window can find a name the previous one missed or cut short; spans are now only deduplicated by exact position, and overlapping spans are left to the anonymizer to merge
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cubic-dev-ai review this PR

@cubic-dev-ai

cubic-dev-ai Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai review this PR

@waleedlatif1 I have started the AI code review. It will take a few minutes to complete.

@cubic-dev-ai cubic-dev-ai Bot 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.

No issues found across 10 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit 9c3aab4 into staging Nov 13, 2026
82 checks passed

This branch was previously deployed

1 inactive deployment
Preview — 3ada4621 Deployed Nov 13, 2026 by vercel[bot]
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