Skip to content

fix(review): stop logging raw unparseable AI output - #5147

Closed
JSONbored wants to merge 1 commit into
mainfrom
codex/propose-patch-for-ai-output-leak
Closed

fix(review): stop logging raw unparseable AI output#5147
JSONbored wants to merge 1 commit into
mainfrom
codex/propose-patch-for-ai-output-leak

Conversation

@JSONbored

Copy link
Copy Markdown
Owner

Motivation

  • Prevent leaking raw AI provider output into observability systems (Sentry) by removing the bounded responseSnippet field from structured logs and diagnostics.

Description

  • Stop collecting and emitting responseSnippet from unparseable model responses by removing the snippet field and its size cap usage from runWorkersOpinion in src/services/ai-review.ts.
  • Preserve safe metadata: keep responseChars and hasJsonObject in per-attempt warn logs and the final error exhaustion log while omitting any raw provider text.
  • Adjust the lastUnparseable shape to no longer carry responseSnippet and remove the UNPARSEABLE_RESPONSE_SNIPPET_MAX_CHARS usage from logging paths.
  • Update regression/unit tests in test/unit/ai-review.test.ts to assert that diagnostics and structured log payloads do not contain responseSnippet and continue to validate responseChars/hasJsonObject metadata.

Testing

  • Ran npx vitest run test/unit/ai-review.test.ts -t "unparseable" which passed the targeted tests.
  • Ran npx vitest run test/unit/ai-review.test.ts and the ai-review unit suite passed (all tests in that file succeeded).
  • Ran npm run typecheck which completed successfully.
  • Attempted a full npm run test:coverage but the local full-suite coverage run surfaced unrelated existing failures in test/unit/queue-5.test.ts so the unsharded coverage run could not be completed end-to-end locally; the change’s targeted tests were exercised and pass.
  • Attempted npm audit --audit-level=moderate but the audit endpoint returned 403 Forbidden (external limitation).

Codex Task

@superagent-security

Copy link
Copy Markdown
Contributor

Superagent didn't find any vulnerabilities or security issues in this PR.

@codecov

codecov Bot commented Jul 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.21%. Comparing base (01b37d0) to head (796c7c8).
⚠️ Report is 31 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5147      +/-   ##
==========================================
- Coverage   94.21%   94.21%   -0.01%     
==========================================
  Files         470      470              
  Lines       39743    39741       -2     
  Branches    14506    14506              
==========================================
- Hits        37442    37440       -2     
  Misses       1645     1645              
  Partials      656      656              
Flag Coverage Δ
shard-1 46.40% <100.00%> (-0.03%) ⬇️
shard-2 33.64% <0.00%> (-0.22%) ⬇️
shard-3 31.35% <0.00%> (-0.80%) ⬇️
shard-4 32.80% <100.00%> (+0.98%) ⬆️
shard-5 33.43% <100.00%> (-0.10%) ⬇️
shard-6 45.09% <0.00%> (+0.19%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
src/services/ai-review.ts 96.73% <100.00%> (-0.02%) ⬇️
🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@loopover-orb loopover-orb Bot added the gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. label Jul 12, 2026
@loopover-orb

loopover-orb Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Warning

🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨🟨

⏸️ Gittensory review result - manual review recommended

Review updated: 2026-07-12 09:00:01 UTC

2 files · 1 AI reviewer · 2 blockers · readiness 93/100 · CI green · unstable

⏸️ Suggested Action - Manual Review

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.

Review summary
This diff removes the raw AI-provider `responseSnippet` field from both structured logs and the returned diagnostics in `runWorkersOpinion`, replacing it with only `responseChars`/`hasJsonObject` metadata, and updates the corresponding tests to assert the snippet is absent everywhere (diagnostics, warn log, and exhausted error log). The change is narrowly scoped, internally consistent — the `UNPARSEABLE_RESPONSE_SNIPPET_MAX_CHARS` constant and all its usages are removed together, so nothing is left dangling — and the tests now positively assert `responseSnippet` is not present and that raw response text does not leak into the log string, which is a meaningful strengthening over the old snippet-content assertions.

Blockers

  • PR description: you need to close or clearly link an eligible open issue for this repository; add an explicit `Closes #NNNN` / `Fixes #NNNN` reference or explain the maintainer-authorized issue this work belongs to.
Nits — 5 non-blocking
  • The PR description doesn't reference a specific tracked issue number for this observability/security fix — worth confirming there's a linked issue per repo convention.
  • test/unit/ai-review.test.ts renamed both test titles; consider keeping the `#observability-unparseable` tag consistent with any related follow-up tests elsewhere in the suite for grep-ability.
  • Consider a quick repo-wide grep for `responseSnippet` to confirm no other call site (e.g. a reviewer-fallback path or Sentry context builder) still expects this field, since the diagnostic shape change could ripple into consumers not shown in this diff.
  • test/unit/ai-review.test.ts:3090 and test/unit/ai-review.test.ts:3110 restore console spies only at the end of the test body; wrap them in `try/finally` or use the suite's shared restore pattern so a failed assertion does not leak the spy into later tests.
  • test/unit/ai-review.test.ts:3097 keep the new `not.toHaveProperty("responseSnippet")` assertion, but also consider asserting `JSON.stringify(payload)` does not contain the raw response in the exhaustion-log test, matching the warn-log regression coverage.

Concerns raised — review before merging

  • No linked issue detected — If this PR is intended to solve an issue, link it explicitly in the PR body.
  • Maintainer requires a linked issue — Link the relevant issue (for example Closes #123) before opening the PR.
Signal Result Evidence
Code review ❌ 2 blockers 1 reviewer
Linked issue ⚠️ Missing No linked issue or no-issue rationale found.
Related work ✅ No active overlap found No same-issue or scoped active PR overlap found.
Change scope ✅ 20/20 Low review scope from cached public metadata (no linked issue context).
Validation posture ✅ 25/25 PR body includes validation/test evidence.
Contributor workload ✅ 10/10 Author activity: 45 registered-repo PR(s), 37 merged, 409 issue(s).
Contributor context ✅ Confirmed Gittensor contributor JSONbored; Gittensor profile; 45 PR(s), 409 issue(s).
Gate result ❌ Blocking Repo-configured hard blocker found.
Improvement ✅ Minor risk: clean · value: minor — Code changes are accompanied by test evidence.
Review context
  • Author: JSONbored
  • Role context: owner (maintainer lane)
  • Public audience mode: oss maintainer
  • Lane context: Repository is configured for direct PR review.
  • Public profile languages: not available
  • Official Gittensor activity: 45 PR(s), 409 issue(s).
  • PR-specific overlap: none found.
Contributor next steps
  • Treat this as maintainer-lane context rather than normal contributor-lane activity.
  • Explain no-issue PR.
  • Link the issue being solved, or explicitly explain why this is a no-issue PR.
Signal definitions
  • Related work = same linked issue, overlapping active PRs, or title/path similarity.
  • Change scope = cached public metadata such as size labels, draft state, and review-burden hints.
  • Validation posture = whether the PR provides enough public validation/test evidence for maintainer review.
  • Contributor workload = public contributor activity and cleanup pressure, not a repo-wide quality failure.
  • Contributor context = public GitHub/Gittensor identity context; non-Gittensor status is not a blocker.
[BETA] Chat with Gittensory

Ask Gittensory a question about this PR directly in a comment — grounded only in the same cached, public-safe facts shown above, never a new claim.

  • @gittensory ask &lt;question&gt; answers contribution-quality Q&A with source citations and freshness.
  • @gittensory chat &lt;question&gt; answers in natural prose from cached decision-pack facts via local inference (maintainer/collaborator; read-only).
  • A plain-language @gittensory mention with a real question is routed to the closest matching read-only command automatically -- no exact syntax required.

Full command reference: https://gittensory.aethereal.dev/docs/gittensory-commands

🟩 Safe / merged · 🟦 Advisory · 🟨 Held for review · 🟥 Blocked / closed


💰 Earn for open-source contributions like this. Gittensor lets GitHub contributors earn for the work they already do — register to start earning →.

Checked by Gittensory, a quiet PR intelligence layer for OSS maintainers.

  • Re-run Gittensory review

@loopover-orb loopover-orb Bot added the manual-review Gittensor contributor context label Jul 12, 2026
@JSONbored

Copy link
Copy Markdown
Owner Author

Closing: this reverses #5071/#5073 (merged earlier this session), which added the response-snippet log specifically to diagnose a live, still-firing Sentry issue (ai_review_provider_unparseable_exhausted, unactionable since 2026-07-01 without it). The stated motivation — preventing raw provider output from reaching Sentry — was already the design: the snippet is capped at 400 chars, deliberately excluded from the public/Sentry-facing reviewDiagnostics array, and reaches only the internal structured-log forwarder (the same self-host-operator-owned Sentry instance, not a third-party sink — same reasoning as closing #5111). Keeping the diagnostic snippet.

@JSONbored JSONbored closed this Jul 12, 2026
@JSONbored
JSONbored deleted the codex/propose-patch-for-ai-output-leak branch July 19, 2026 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gittensor:bug Gittensor-scored bug fix — scores a 0.05x multiplier. manual-review Gittensor contributor context

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant