Skip to content

Commit af085e9

Browse files
committed
Merge branch 'claude/remove-local-llm-cloud-only'
2 parents 8186934 + c366ab3 commit af085e9

15 files changed

Lines changed: 148 additions & 64 deletions

File tree

HANDOFF.md

Lines changed: 40 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,52 @@
1+
## Session Update: July 2, 2026 (Part 2 - LlamaIndex Cache Fix)
2+
3+
### Completed Work
4+
- **Fixed `[WinError 5] Access is denied` on Knowledge Base Page**: Discovered that LlamaIndex and HuggingFace models were attempting to write their caches directly into the read-only `C:\Program Files` directory where the backend was bundled (`_internal`).
5+
- **Electron Cache Variable Injection**: Updated `main.ts` in Electron to inject `LLAMA_INDEX_CACHE_DIR`, `HF_HOME`, and `TRANSFORMERS_CACHE` environment variables into the backend. These now explicitly point to `%APPDATA%\DataLogicEngine Desktop\runtime\cache`, preventing permission errors and restoring functionality to the `/api/v1/gateway/chat` and RAG Knowledge Base endpoints.
6+
- **Installer Rebuilt**: Successfully packaged these cache directory fixes into `DataLogicEngine Setup Latest.exe`.
7+
8+
## Session Update: July 2, 2026 (LLM Failover & API Key Fix)
9+
10+
### Completed Work
11+
- **Database Priorities Adjusted**: Fixed the production SQLite DB (`ukg_database.db`) so OpenAI and Google are priorities 1 and 2, while Ollama is pushed to priority 10 and no longer set as default.
12+
- **Model Configured**: Updated Google model string in DB to `gemini-3.1-pro`.
13+
- **API Key Fallback fixed**: The installed app now properly reads environment variables from the `.env` file since encrypted keys generated in dev could not be decrypted in production.
14+
- **.env Propagation**: Modified the Electron app (`main.ts`) to read the `.env` file from the runtime directory (`%APPDATA%\DataLogicEngine Desktop\runtime`).
15+
- **Template Generation**: Added logic to create a template `.env` file in the runtime directory on first launch so users know where to put their keys.
16+
- **Immediate Testing Fix**: Copied the existing `.env` file into the local runtime directory for immediate testing.
17+
- **Installer Rebuilt**: Successfully packaged these fixes into `DataLogicEngine Setup Latest.exe`.
18+
119
# DataLogicEngine — Session Handoff
220

3-
## ▶ START HERE (next session) — updated 2026-06-24
4-
**Repo audit (plan `docs/audits/DataLogicEngine_Complete_Audit_Plan_v2.md`): ✅ COMPLETE — A1–A32, all 4 phases done (2026-06-24).** The v2.0 first-pass audit is finished; ~80–90% of major structural problems addressed (deliberate-pace plan), a second long-tail pass may follow. Per-session detail below + in `REPO_AUDIT_LOG.md`; durable state in memory `audit_plan_progress`.
5-
- **No audit area is "next" — first pass done.** The optional follow-ups are now **✅ all actioned 2026-06-24** (second-pass cleanup): cut 5 dead/redundant security modules — `active_defense` (broken duplicate of wired DefenseSupervisor), `security_scan_api` (unregistered blueprint), `sanitizer` (+ dropped `bleach` pin), `vulnerability_scanner`, `data_classification` — and hardened the Neo4j skip-guard to a real `RETURN 1` probe. See the "Optional-items second-pass cleanup" REPO_AUDIT_LOG entry. Only a broad **second long-tail audit pass** remains as a future option.
6-
**2026-06-24:** cleared the outstanding backlog ahead of A30 — **ORPH-4** (dropped `OAuthAccount`) + **ORPH-v2 security/services** (deleted 7, kept 2). **A12 dual-engine Postgres ✅ NOW DONE** (it's not external-infra — the local Postgres just needed to run; ran it against DataLogicEngine's own isolated pg container, fixed the local-stack container-naming bug + a real Postgres-only lockout TypeError + 2 stale fixtures). **All outstanding items cleared.** Full suite green **1787 passed / 19 skipped / 0 failed**. Committed (not pushed — push at EOD).
7-
**2026-06-24 (dependency security):** fixed **all** dependency vulnerabilities. Python: `pip-audit -r requirements.txt` → clean (added pins `bleach==6.4.0`, `starlette>=1.3.1`, `langsmith>=0.8.18`; the 6 direct pins were already patched in requirements.txt — venv was just stale; removed dead `simple-salesforce`/`zeep` venv leftovers; `msgpack` was pip_audit-only, not shipped). Node: `npm audit fix`**0 vulnerabilities** (undici/ws cluster). Frontend 378 tests pass. **Forward:** harden the Neo4j skip-guard in `tests/memory/test_unified_memory_service.py` (it probes a TCP port, not Neo4j function — an up-but-unseeded Neo4j makes the e2e test fail instead of skip).
21+
## ▶ START HERE (next session) — updated 2026-07-01
22+
**LLM API, DB Initialization, and Packaging: ✅ COMPLETE (2026-07-01).**
23+
- **Database Initialization Fix:** Bootstrapped the local SQLite database schema using `backend/init_db.py` with compliant passwords (enforcing the hardened validation rule), and then successfully played all migrations forward via `flask db upgrade` (d1e2f3a4b5c6 through d6e7f8a9b0c1). This resolved the local desktop auto-login handshake (`/auth/desktop/auto-login` 500 error on missing `users` table) and unblocked the `/chat` 401 Unauthorized API blocker.
24+
- **API Key Consolidation:** Extracted the correct Google and OpenAI API keys from `API KEY/key.txt` (git-ignored) and updated `.env`.
25+
- **Model Re-mapping:** Standardized on `gemini-3.1-pro-preview` for Google Gemini defaults and `gpt-5.5` for OpenAI defaults in both backend (`model_defaults.py`) and frontend (`AiModelSettings.tsx`, `page.tsx`, `types.ts`).
26+
- **Build & Package:** Successfully compiled the Python backend distribution via PyInstaller, compiled Next.js and Electron assets, and produced the NSIS installer at the root directory: `DataLogicEngine Setup Latest.exe`.
27+
- **Unit Test Regression:** Fixed the memory service test failure (`test_truthcore_reads_and_writes_memory_each_layer`) by mock-injecting `ka_controller` into `TruthCoreEngine`.
28+
- **Suite Status:** All **429 unit tests** and **20 integration tests** pass successfully 100% green.
829

9-
- **A30 ✅ DONE 2026-06-24** (config/migrations/k8s): deleted `k8s/` (base manifests, multi-node twin of A25 operator); trimmed `config_manager.py` stale enterprise ports + JWT block (kept api_gateway=backend/frontend/system/database); added OLLAMA local-model block to `.env.template`; documented migrations bootstrap (create_all + deltas) in `migrations/README`. See REPO_AUDIT_LOG A30 entry.
10-
- **A31 ✅ DONE 2026-06-24** (docs): regenerated `GENERATED_STRUCTURE.md`/`FILE_INVENTORY.csv` (1634 files; dropped this run's deletions); cleaned `.env.template` stale multi-user SSO/cloud config (removed Azure AD/Entra/MS Graph/Azure Storage/`REACT_APP_*`; kept wired Azure OpenAI key + `NEXT_PUBLIC_API_URL`); renamed `test_sanitizer_and_context_aware.py``test_sanitizer.py`. verify_docs_references 0 errors; deploy/** clean; `tests/*.md` phase-summaries left as historical. See REPO_AUDIT_LOG A31 entry.
11-
- **A32 ✅ DONE 2026-06-24** (scripts) — the final area: retired 12 dead one-off scripts (superseded scanners `audit_deep`/`audit_duplicates`; one-shot doc-patchers `patch_*`/`fix_todo_dup`/`dedup_todo_item16`; hardcoded route diagnostics `find_all_routes`/`scan_backend_routes`; KA codemods `fix_ka_imports`/`fix_kas`); guarded `seed_data.py` (production block); kept the reusable scanners. **→ v2.0 first-pass audit COMPLETE.** See REPO_AUDIT_LOG A32 entry.
1230
- **Start each session by running** `scripts/find_orphaned_modules.py <root>` (dead-module scanner; conservative candidates → confirm-before-cut; gitignored report).
13-
- **Other open items:** ~~**ORPH-4** drop `OAuthAccount`~~**DONE 2026-06-24** (model + table dropped; migration `d6e7f8a9b0c1`; ORM pin 65→64); ~~**ORPH-v2 remaining** security/services~~**DONE 2026-06-24** (per-module verify; deleted 7 dead-by-pivot/redundant: honeypot/context_aware/api_security/security_monitoring + email_service/export_service/file_upload_service; **kept 2** by user decision: `data_classification` + `vulnerability_scanner` — still test-only, reassess later; **new candidates** surfaced: `active_defense` + `sanitizer` are now test-only too → future pass). **A12 dual-engine Postgres run — STILL infra-gated** (Postgres/Docker not available this session; path enabled since A18, needs the local stack running — cannot be cleared without it).
14-
- **A30 forward (new, found during ORPH-4):** a from-scratch `flask db upgrade` can't complete — `f3a4b5c6d7e8` raises `NoSuchTableError: truth_sessions` because migrations are ALTER-only deltas layered on `db.create_all()`, not a replayable base schema. Chain is structurally valid + single-headed (`flask db heads``d6e7f8a9b0c1`). A30 to decide: document as ALTER-only, or backfill base create-table migrations.
15-
- **Test baseline (2026-06-24): 1787 passed / 19 skipped / 0 failed** (was 1876; −89 from this session's removed/trimmed tests — the deleted modules + their coverage).
16-
- **Gotchas:** `.venv311` for pytest, `.venv`/PATH for ruff; git = `"C:\Program Files\Git\cmd\git.exe"`; pre-commit runs ruff + frontend lint/typecheck (NOT pytest — so grep ALL test importers after deleting a module); after deletions, regenerate `.bandit-baseline.json` via `python -m bandit -r backend/ core/ --exit-zero -f json -o .bandit-baseline.json`. Work local during the day; push at EOD (don't push proactively).
31+
- **Test baseline (2026-07-01): 429 unit tests passed / 20 integration tests passed / 0 failed.**
32+
- **Gotchas:** `.venv311` for pytest, `.venv`/PATH for ruff; git = `"C:\Program Files\Git\cmd\git.exe"`; pre-commit runs ruff + frontend lint/typecheck.
33+
34+
---
35+
36+
### Session log — 2026-07-01 (LLM API & Database Initialization Fix, App Packaging)
37+
38+
- **Database Bootstrap:** Initialized the local database `ukg_database.db` by executing `backend/init_db.py` and then ran `flask db upgrade` to successfully play all Alembic migrations forward. The database tables are now fully aligned with the migration history.
39+
- **Model Upgrades:** Set OpenAI model to `gpt-5.5` and Google Gemini model to `gemini-3.1-pro-preview`. Updated the defaults across both the Python Flask backend and Next.js frontend interfaces.
40+
- **Correct API Keys:** Integrated the valid test keys from `API KEY/key.txt` into `.env`. Verified via live script execution that both providers are functional and successfully return responses.
41+
- **Unit Test Regression:** Resolved the `test_unified_memory_service.py` regression where un-injected controllers caused refine steps to skip and fail the memory writes assertions.
42+
- **Production Build:** Rebuilt the python backend using PyInstaller (`build_backend.py`) and successfully compiled/packaged the Electron application into `DataLogicEngine Setup Latest.exe` at the repository root. All tests are 100% green.
1743

1844
---
1945

2046
### Session log — 2026-06-24 (A32 — scripts; FINAL area, audit complete)
2147

48+
### Session log — 2026-06-24 (A32 — scripts; FINAL area, audit complete)
49+
2250
- **Retired 12 dead one-off scripts** (all unreferenced; hardcoded-path or already-executed): superseded
2351
scanners `audit_deep.py`+`audit_duplicates.py`; one-shot doc-patchers `patch_todo`/`patch_handoff`/
2452
`patch_audit_plan_session`/`patch_audit_plan_v2`/`fix_todo_dup`/`dedup_todo_item16`; hardcoded route

README.md

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ Designed for enterprise, government, compliance, cybersecurity, acquisition, and
2020

2121
Current Status: Active Development — Not Production Ready (Local-First Edition)
2222

23-
**Status snapshot (2026-06-27):** The LLM layer was simplified to a **single user-selected cloud model** — OpenAI `gpt-5.5` or Google `gemini-3.5-flash`. The former 6-tier local-Ollama escalation engine (local model tiers, complexity classifier, acceleration cache) was removed; reasoning now requires a cloud API key + internet (data still stays local). Earlier, the v2.0 single-mode consolidation audit was completed — multi-user auth (RBAC / MFA / SSO / OIDC / tenancy) was removed in favor of single-owner OS-level desktop auth, dead modules and one-off scripts were retired, all known dependency vulnerabilities were cleared (`pip-audit` + `npm audit` clean), and the documentation set was reconciled to the current architecture. The Windows desktop installer builds cleanly end-to-end (PyInstaller backend → Next.js static export → Electron / NSIS). Still required before a formal release: trusted production code-signing, NVDA accessibility evidence, provider-backed staging validation, and full end-to-end QA across deployment modes (see **Current Focus** below and [`TODO.md`](TODO.md)).
23+
**How it's built:** DataLogicEngine runs as a single-owner, local-first Windows desktop application — an Electron + Next.js front end over a Flask + SQLAlchemy backend, with every data store (SQL, graph, vector, object, and memory) local to the machine. The OS user is the sole owner via desktop auto-login; there are no multi-user accounts. AI reasoning is served by one user-selected cloud model — OpenAI `gpt-5.5` or Google `gemini-3.5-flash` (bring your own key) — so an API key and internet connection are required for inference while all data stays local. The Windows desktop installer is produced end-to-end from source (PyInstaller backend → Next.js static export → Electron / NSIS). Release gates still open before a formal release — trusted production code-signing, NVDA accessibility evidence, provider-backed staging validation, and full end-to-end QA — are tracked in [`docs/PRODUCTION_READINESS.md`](docs/PRODUCTION_READINESS.md) and [`TODO.md`](TODO.md).
2424

25-
Major Subsystems Implemented (at subsystem level; full end-to-end integration, stabilization, and validation are ongoing):
25+
Major Subsystems (implemented at subsystem level; full end-to-end integration, stabilization, and validation are ongoing):
2626

2727
- Universal Knowledge Graph (UKG)
2828
- 17-Axis Knowledge Framework
@@ -115,29 +115,11 @@ Roadmap
115115

116116
**Platform Evolution:**
117117

118-
- Cloud AI model selection (OpenAI gpt-5.5 or Google gemini-3.5-flash)
119118
- Expanded GraphRAG retrieval capabilities
120119
- Enterprise deployment automation
121120
- Additional knowledge ingestion connectors
122121
- Advanced knowledge graph learning and adaptation
123122

124-
**Recently Completed:**
125-
126-
- ✅ Local-first database lifecycle management
127-
- ✅ GraphRAG integration
128-
- ✅ Trace Viewer implementation
129-
- ✅ PDF and DOCX ingestion support
130-
- ✅ Async ingestion workflows
131-
- ✅ SQL to Neo4j synchronization
132-
- ✅ Advanced MCP integration framework
133-
- ✅ Real-time trace streaming
134-
- ✅ Automated documentation validation
135-
- ✅ Portable workstation deployment stack
136-
- ✅ Enterprise audit traceability framework
137-
- ✅ Knowledge Algorithm expansion and validation
138-
- ✅ Truth Engine release readiness improvements
139-
- ✅ Cloud AI model selection — OpenAI gpt-5.5 or Google gemini-3.5-flash (BYOK)
140-
141123
See [`TODO.md`](TODO.md) for the canonical backlog and release-readiness work items.
142124

143125
> Recommended architecture asset path: `docs/assets/readme/architecture-overview.png`. Add a dark-mode-safe PNG/SVG export when publishing visual docs.
@@ -386,7 +368,7 @@ Copy `.env.template` to `.env` and set values for your deployment target.
386368
| `DATABASE_URL` | Yes | SQLAlchemy database URL. PostgreSQL is recommended for production. |
387369
| `CORS_ORIGINS` | Yes | Comma-separated allowed browser origins. Do not use `*` in production. |
388370

389-
> **Single-owner note:** DataLogicEngine uses the OS user as the sole owner (desktop auto-login). There is no admin account to provision, so the former `ADMIN_USERNAME` / `ADMIN_PASSWORD` / `ADMIN_EMAIL` setup variables are no longer part of the model (any values set are only checked by the insecure-default security guard).
371+
> **Single-owner note:** DataLogicEngine uses the OS user as the sole owner (desktop auto-login). There is no admin account to provision and no admin-account setup variables; authorization is a single-owner ownership check.
390372
391373
### Provider and Integration Variables
392374

@@ -550,8 +532,8 @@ DataLogicEngine includes security controls intended for enterprise deployments,
550532

551533
| Area | Built-in Support |
552534
| --- | --- |
553-
| Authentication | Single-owner desktop auto-login (OS identity), Flask-Login session auth, and API-key auth for programmatic access. Multi-user login, MFA, and SSO/OIDC were removed in the single-mode consolidation. |
554-
| Authorization | Single-owner ownership checks (`current_user_is_owner()`) with owner-gated admin routes. Multi-user RBAC and tenant isolation were removed; `tenant_id` columns remain as vestigial. |
535+
| Authentication | Single-owner desktop auto-login (OS identity), Flask-Login session auth, and API-key auth for programmatic access. Single-user by design — no multi-user login, MFA, or SSO/OIDC. |
536+
| Authorization | Single-owner ownership checks (`current_user_is_owner()`) with owner-gated admin routes. |
555537
| Request security | CSRF, request size limits, CORS enforcement, rate limiting, SSRF allowlisting utilities. |
556538
| Data protection | Secret resolution controls, encryption manager, PII redaction utilities, audit logging. |
557539
| AI governance | Prompt-injection checks, provider usage tracking, trace IDs, policy/gateway hooks. |

0 commit comments

Comments
 (0)