Skip to content

fix(gateway): eliminate silent error swallowing in CHIT API - #650

Merged
POWERFULMOVES merged 5 commits into
PMOVES.AI-Edition-Hardenedfrom
fix/gateway-silent-errors
Feb 17, 2026
Merged

POWERFULMOVES merged 5 commits into
PMOVES.AI-Edition-Hardenedfrom
fix/gateway-silent-errors

Conversation

@POWERFULMOVES

Copy link
Copy Markdown
Owner

Summary

Four atomic commits eliminating bare except: pass blocks and silent data loss in the CHIT gateway API:

  1. fix(chit): preserve anchor_enc on decryption failure — bare except: pass caught everything (including SystemExit), then unconditionally popped anchor_enc, permanently losing encrypted data. Now catches only JSONDecodeError/UnicodeDecodeError, logs error, preserves anchor_enc for retry.

  2. fix(chit): log event emission failuresemit_event() failures swallowed silently, causing downstream consumers (Discord publisher, monitoring) to stop receiving geometry events. Now logs ImportError at DEBUG, other errors via logger.exception.

  3. fix(chit): return shape_id from /geometry/event — endpoint discarded ingest_cgp() return value. Callers now receive {ok, shape_id, event} for tracking.

  4. fix(chit): log transformer summarization failures_learned_enhance() silently fell back to keyword summarizer when configured T5 model failed. Now logs the failure before fallback.

Fixes silent failure audit issues #3 (HIGH), #4 (HIGH), #6 (MEDIUM), #7 (MEDIUM).

Test plan

  • Send CGP with corrupted anchor_enc — verify error logged, anchor_enc preserved
  • Disable events module, ingest CGP — verify DEBUG log, no crash
  • POST /geometry/event — verify response includes shape_id
  • Set CHIT_T5_MODEL to invalid path — verify exception logged, keyword fallback works

🤖 Generated with Claude Code

hunnibear and others added 4 commits February 17, 2026 17:08
…rors

The bare `except: pass` in decrypt_anchor() caught all exceptions
(including SystemExit) and then unconditionally popped anchor_enc,
permanently losing the encrypted anchor with no trace.

Now catches only json.JSONDecodeError and UnicodeDecodeError, logs the
error with constellation ID, and returns early to preserve anchor_enc
for retry/debugging.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ingest_cgp() swallowed all exceptions from emit_event() including
ImportError, ConnectionRefused, and serialization errors. Downstream
consumers (Discord publisher, monitoring) would silently stop receiving
geometry events with no indication in logs.

Now: ImportError logs at DEBUG (expected when events module absent),
all other exceptions log full traceback via logger.exception.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The endpoint discarded ingest_cgp()'s return value, giving callers only
{"ok": true} with no reference to track the ingested shape. Now returns
shape_id and event type so callers (mcp_server, external agents) can
perform subsequent operations (jumps, decode) without recomputing.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
_learned_enhance() silently fell back to keyword-frequency summarizer
when CHIT_T5_MODEL was configured but failed (CUDA OOM, corrupt model,
network error). Operators received degraded results with no indication.

Now: ImportError logs WARNING (expected when transformers not installed),
other exceptions log full traceback before falling back.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/gateway-silent-errors

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

Incorporate both aead.decrypt InvalidTag guard (base branch)
and improved JSON decode error logging (PR #650).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@POWERFULMOVES
POWERFULMOVES merged commit 6b9dc73 into PMOVES.AI-Edition-Hardened Feb 17, 2026
6 of 7 checks passed
@POWERFULMOVES
POWERFULMOVES deleted the fix/gateway-silent-errors branch March 7, 2026 21:46
POWERFULMOVES pushed a commit that referenced this pull request Mar 26, 2026
#650)

* feat: Provider-agnostic error handling for Issue #362

Implements generic error handling that works for OpenAI, Google AI,
Anthropic, and other LLM providers to prevent silent failures.

Essential files only:
1. Provider error adapters (new) - handles any LLM provider
2. Backend API key validation - detects invalid keys before operations
3. Frontend error handler - provider-aware error messages
4. Updated hooks - uses generic error handling

Core functionality:
✅ Validates API keys before expensive operations (crawl, upload, refresh)
✅ Shows clear provider-specific error messages
✅ Works with OpenAI: 'Please verify your OpenAI API key in Settings'
✅ Works with Google: 'Please verify your Google API key in Settings'
✅ Prevents 90-minute debugging sessions from Issue #362

No unnecessary changes - only essential error handling logic.

Fixes #362

* fix: Enhance API key validation with detailed logging and error handling

- Add comprehensive logging to trace validation flow
- Ensure validation actually blocks operations on authentication failures
- Improve error detection to catch wrapped OpenAI errors
- Fail fast on any validation errors to prevent wasted operations

This should ensure invalid API keys are caught before crawl starts,
not during embedding processing after documents are crawled.

* fix: Simplify API key validation to always fail on exceptions

- Remove complex provider adapter imports that cause module issues
- Simplified validation that fails fast on any embedding creation error
- Enhanced logging to trace exactly what's happening
- Always block operations when API key validation fails

This ensures invalid API keys are caught immediately before
crawl operations start, preventing silent failures.

* fix: Add API key validation to refresh and upload endpoints

The validation was only added to new crawl endpoint but missing from:
- Knowledge item refresh endpoint (/knowledge-items/{source_id}/refresh)
- Document upload endpoint (/documents/upload)

Now all three endpoints that create embeddings will validate API keys
before starting operations, preventing silent failures on refresh/upload.

* security: Implement core security fixes from CodeRabbit review

Enhanced sanitization and provider detection based on CodeRabbit feedback:

✅ Comprehensive regex patterns for all provider API keys
  - OpenAI: sk-[a-zA-Z0-9]{48} with case-insensitive matching
  - Google AI: AIza[a-zA-Z0-9_-]{35} with flexible matching
  - Anthropic: sk-ant-[a-zA-Z0-9_-]{10,} with variable length

✅ Enhanced provider detection with multiple patterns
  - Case-insensitive keyword matching (openai, google, anthropic)
  - Regex-based API key detection for reliable identification
  - Additional keywords (gpt, claude, vertex, googleapis)

✅ Improved sanitization patterns
  - Provider-specific URL sanitization (openai.com, googleapis.com, anthropic.com)
  - Organization and project ID redaction
  - OAuth token and bearer token sanitization
  - Sensitive keyword detection and generic fallback

✅ Sanitized error logging
  - All error messages sanitized before logging
  - Prevents sensitive data exposure in backend logs
  - Maintains debugging capability with redacted information

Core security improvements while maintaining simplicity for beta deployment.

* fix: Replace ad-hoc error sanitization with centralized ProviderErrorFactory

- Remove local _sanitize_provider_error implementation with inline regex patterns
- Add ProviderErrorFactory import from embeddings.provider_error_adapters
- Update _validate_provider_api_key calls to pass correct active embedding provider
- Replace sanitization call with ProviderErrorFactory.sanitize_provider_error()
- Eliminate duplicate logic and fixed-length key assumptions
- Ensure provider-specific, configurable sanitization patterns are used consistently

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* chore: Remove accidentally committed PRP file

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: address code review feedback

- Add barrel export for providerErrorHandler in utils/index.ts
- Change TypeScript typing from 'any' to 'unknown' for strict type safety

---------

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Rasmus Widing <rasmus.widing@gmail.com>
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.

2 participants