Files
aitbc/ai-memory/failure-archive/regulatory-shadowing-trap.md
aitbc 1fd659604a
Some checks failed
AITBC CI/CD Pipeline / lint-and-test (3.11) (pull_request) Has been cancelled
AITBC CI/CD Pipeline / lint-and-test (3.12) (pull_request) Has been cancelled
AITBC CI/CD Pipeline / lint-and-test (3.13) (pull_request) Has been cancelled
Security Scanning / Bandit Security Scan (apps/coordinator-api/src) (pull_request) Has been cancelled
Security Scanning / Bandit Security Scan (cli/aitbc_cli) (pull_request) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-core/src) (pull_request) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-crypto/src) (pull_request) Has been cancelled
Security Scanning / Bandit Security Scan (packages/py/aitbc-sdk/src) (pull_request) Has been cancelled
Security Scanning / Bandit Security Scan (tests) (pull_request) Has been cancelled
Security Scanning / CodeQL Security Analysis (javascript) (pull_request) Has been cancelled
Security Scanning / CodeQL Security Analysis (python) (pull_request) Has been cancelled
Security Scanning / Dependency Security Scan (pull_request) Has been cancelled
Security Scanning / Container Security Scan (pull_request) Has been cancelled
Security Scanning / OSSF Scorecard (pull_request) Has been cancelled
AITBC CI/CD Pipeline / test-cli (pull_request) Has been cancelled
AITBC CI/CD Pipeline / test-services (pull_request) Has been cancelled
AITBC CI/CD Pipeline / test-production-services (pull_request) Has been cancelled
AITBC CI/CD Pipeline / security-scan (pull_request) Has been cancelled
AITBC CI/CD Pipeline / build (pull_request) Has been cancelled
AITBC CI/CD Pipeline / deploy-staging (pull_request) Has been cancelled
AITBC CI/CD Pipeline / deploy-production (pull_request) Has been cancelled
AITBC CI/CD Pipeline / performance-test (pull_request) Has been cancelled
AITBC CI/CD Pipeline / docs (pull_request) Has been cancelled
AITBC CI/CD Pipeline / release (pull_request) Has been cancelled
AITBC CI/CD Pipeline / notify (pull_request) Has been cancelled
Security Scanning / Security Summary Report (pull_request) Has been cancelled
docs: add ai-memory layer (bug patterns, architecture, debugging playbook, agent notes, initial failure archive)
2026-03-15 13:29:44 +00:00

2.2 KiB
Raw Blame History

Failure Archive Entry

Issue

Related to PR #10 (aitbc1/fix-imports-docs) initial attempt before fixing.

Attempt

Branch: aitbc1/fix-imports-docs (first version) Author: aitbc1

Approach

Fixed CLI import errors by adding numpy, pandas, aiohttp, fastapi, uvicorn to pyproject.toml and modifying main.py to conditionally import enterprise integration.

Did not rename the shadowed functions in regulatory.py.

Failure Mode

Running aitbc regulatory test resulted in:

KeyError: slice(None, 1, None)

The Click command function generate_sar was shadowing the imported generate_sar from regulatory_reporting. When the command body called generate_sar(...), it actually invoked the command function recursively or accessed the Click command object's subscript, causing a crash.

Root Cause

Name collision between imported service function and CLI command function.

Detection

Reproduced by running the regulatory test command after the branch was merged into a local main. Failure trace showed the command function being called with wrong arguments.

Resolution

Renamed imported functions in regulatory.py with _svc suffix:

  • generate_sargenerate_sar_svc
  • generate_compliance_summarygenerate_compliance_summary_svc
  • list_reportslist_reports_svc

Updated all internal calls accordingly.

Useful Artifacts

  • The pattern of shadowing is now documented in ai-memory/bug-patterns.md.
  • The fix (aliasing service imports) should be applied to any command module where names overlap.

Prevention

  • When writing CLI command groups, avoid naming command functions identically to any imported callables from service modules.
  • Consider static analysis rule: flag functions that define a name already imported at module scope.
  • Alternatively, always import service functions with a distinct suffix (e.g., _svc) as a coding standard.

Recommendation

Future implementations of CLI commands should adopt the naming convention: service imports end with _svc. Example:

from regulatory_reporting import generate_sar as generate_sar_svc
...
def generate_sar(...):
    return generate_sar_svc(...)

Archived on 2026-03-15.