Files
aitbc/ai-memory/bug-patterns.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

117 lines
3.3 KiB
Markdown

# Bug Patterns — AITBC Repository
This document records known bug patterns and their fixes to prevent reoccurrence.
---
## Pattern: Service Import Name Shadowing in CLI
**Symptom**
```
KeyError: slice(None, 1, None)
```
or similar when invoking a CLI command that calls a service function.
**Root Cause**
CLI command modules import a service function (e.g., `generate_sar`) and then define a Click command function with the same name. The command function overwrites the imported service reference, causing the command body to call itself or the Click object instead of the service.
**Typical Code**
```python
from regulatory_reporting import generate_sar # <-- import
@click.command()
def generate_sar(...): # <-- name collision! Overwrites the import
...
result = generate_sar(...) # BAD: now refers to this function, not the service
```
**Fix**
Rename the imported function using an alias (e.g., `_svc` suffix) and update all internal calls.
```python
from regulatory_reporting import generate_sar as generate_sar_svc
@click.command()
def generate_sar(...):
...
result = generate_sar_svc(...) # GOOD: calls the actual service
```
**Files Affected**
- `cli/aitbc_cli/commands/regulatory.py` (primary example)
**Prevention**
- Use consistent import aliasing when names might clash.
- Consider naming CLI commands with a verb prefix (e.g., `cmd_generate_sar`) to avoid collision.
- Static analysis could flag functions that shadow imported names.
---
## Pattern: Missing Service Dependencies in CLI Venv
**Symptom**
```
ModuleNotFoundError: No module named 'numpy'
```
or similar when running CLI commands that import service modules.
**Root Cause**
CLI virtualenv lacks packages required by coordinator-api service modules (e.g., numpy, pandas, aiohttp, fastapi, uvicorn). The service modules are imported by CLI commands but their dependencies are not listed in the CLI's `pyproject.toml`.
**Fix**
Add the missing dependencies to the CLI package dependencies and reinstall.
```toml
dependencies = [
# existing...
"numpy>=1.26.0",
"pandas>=2.0.0",
"aiohttp>=3.9.0",
"fastapi>=0.111.0",
"uvicorn[standard]>=0.30.0"
]
```
Then:
```bash
pip install -e ./cli
```
**Files Affected**
- `pyproject.toml` (root)
- CLI virtualenv (`cli_venv/`)
**Prevention**
- Keep service module dependencies in a shared location or explicitly list them in CLI deps.
- Run import tests in CI to catch missing deps early.
---
## Pattern: Brother Chain Not Producing Blocks
**Symptom**
Chain height stays at 0, transactions (e.g., mintFaucet) not confirmed.
**Root Cause**
PoA proposer not defined as authority in the consensus configuration, or no node is acting as the authorized proposer.
**Fix**
Ensure the genesis configuration includes the proposer as an authority and that the node's `.env` matches:
- `PROPOSER_ID` and `PROPOSER_KEY` set
- `CHAIN_ID` matches the genesis file
- Node started with proper PYTHONPATH
If still not producing, check logs for authority registration and consider creating a manual block or restarting with a proper genesis that includes the proposer.
**Related Files**
- `apps/blockchain-node/src/aitbc_chain/consensus/poa.py`
- `.env` for brother node
- Genesis YAML file
**Prevention**
- Provide a helper script to initialize a PoA chain with a single proposer for devnets.
- Document the proposer setup clearly.
---
*End of bug patterns.*