Skip to content

Commit 7536bcb

Browse files
committed
feat: enhance Docker debugging setup with readiness checks and improved cleanup in entrypoint script
1 parent d20f56c commit 7536bcb

5 files changed

Lines changed: 111 additions & 10 deletions

File tree

CORTEX-DESIGN-PLAN-TODO.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,28 @@ Legend: `Implemented`, `Partial`, `Missing`
9494
| Storage contracts and persistence schema | Implemented | `core/types.ts`, `storage/OPFSVectorStore.ts`, `storage/IndexedDbMetadataStore.ts`, `tests/Persistence.test.ts` | Current tests are Node-lane with mocked browser APIs. |
9595
| Model-derived numeric governance | Implemented | `core/ModelProfile.ts`, `core/ModelDefaults.ts`, `core/ModelProfileResolver.ts`, `Policy.ts`, `scripts/guard-model-derived.mjs` | Guard command enforced by `npm run guard:model-derived`. |
9696
| Adaptive provider resolver infrastructure | Partial | `embeddings/ProviderResolver.ts`, `embeddings/EmbeddingRunner.ts` | Real providers not yet wired; dummy provider baseline exists. |
97-
| Browser/Electron runtime-realism lanes | Partial | `playwright.config.mjs`, `runtime/harness/index.html`, `tests/runtime/browser-harness.spec.mjs`, `tests/runtime/electron-harness.spec.mjs`, `.vscode/launch.json`, `.vscode/tasks.json`, `docker/electron-debug/Dockerfile`, `docker-compose.electron-debug.yml` | Browser lane passes; Electron host-shell runs can `SIGSEGV` in constrained contexts. Dockerized attach flow is now available, but CI/runtime-context policy is still pending. |
97+
| Browser/Electron runtime-realism lanes | Partial | `playwright.config.mjs`, `runtime/harness/index.html`, `tests/runtime/browser-harness.spec.mjs`, `tests/runtime/electron-harness.spec.mjs`, `.vscode/launch.json`, `.vscode/tasks.json`, `docker/electron-debug/Dockerfile`, `docker-compose.electron-debug.yml` | Browser lane passes; Electron host-shell runs can `SIGSEGV` in constrained contexts. Dockerized attach flow is validated for sandbox-isolated debugging, while CI/runtime-context policy is still pending. |
9898
| Hippocampus ingest orchestrator | Missing | (planned module) | No text chunking -> embed -> persist orchestration path yet. |
9999
| Cortex retrieval and coherence path | Missing | (planned module) | Ranking stack and open-path solver not yet implemented. |
100100
| Daydreamer consolidation loop | Missing | (planned module) | Idle scheduling and recalc loop not yet implemented. |
101101
| Crypto signing and verification helpers | Missing | (planned module `core/crypto`) | Entity fields exist in `core/types.ts`, helper module pending. |
102102

103+
### 0.6 Night Handoff (2026-03-12)
104+
105+
Where we are now:
106+
1. Browser runtime lane is passing.
107+
2. Dockerized Electron attach lane is validated for sandbox-isolated debugging.
108+
3. Host-shell Electron remains context-sensitive and can still fail with `SIGSEGV` in constrained shells.
109+
4. Docker lane currently runs software rendering and is not the final GPU-realism gate.
110+
111+
Tomorrow's code-first sequence:
112+
1. Implement `embeddings/TransformersEmbeddingBackend.ts` for `webnn/webgpu/wasm`.
113+
2. Implement `embeddings/OrtWebglEmbeddingBackend.ts` for explicit `webgl` fallback.
114+
3. Expand resolver wiring in `embeddings/ProviderResolver.ts` so real providers participate in capability + benchmark selection.
115+
4. Add strict Red -> Green tests for new provider registration and selection behavior under capability constraints.
116+
5. Implement first `hippocampus` ingest orchestration entry point using resolved `ModelProfile` values.
117+
6. Implement first `cortex` retrieval orchestration entry point with deterministic baseline ordering.
118+
103119
## 1. Design
104120

105121
### 1.1 Product contract

PROJECT-EXECUTION-PLAN.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,41 @@ Completed in this pass:
9090
- short `docker compose ... up` smoke with forced recreate + teardown
9191
- ready markers observed (`harness ready`, main inspector `9230`, renderer debugger `9222`)
9292
- no `SIGSEGV` observed inside container during smoke window
93+
23. Host-side VS Code attach behavior is now validated for the Docker lane:
94+
- user desktop debug run showed both endpoints active
95+
- `Debugger attached.` observed for attach sessions during `Electron: Docker Main + Renderer`
96+
24. Hardened Docker startup sequencing to avoid attach races:
97+
- `docker/electron-debug/entrypoint.sh` now waits for live debugger endpoints before emitting ready markers
98+
- `docker/electron-debug/Dockerfile` now includes `curl` for readiness probes
9399

94100
Open items carried to next pass:
95101
1. Wire resolved `ModelProfile` into first concrete ingest/query orchestrator path.
96102
2. Add real embedding providers (ONNX/Transformers/WebNN/WebGPU/WebGL/WASM) as candidates for the resolver.
97-
3. Validate full VS Code host attach cycle against the Docker lane (`Electron: Docker Main + Renderer`) and codify it as the runtime-electron context contract when host-shell runs are unstable.
103+
3. Codify Docker lane as the default sandbox-isolated Electron debugging contract and document when host-shell Electron is still required.
98104
4. Define CI prerequisites for the chosen runtime-electron context (binary + graphics/runtime assumptions) and enforce one canonical gate.
99105
5. Implement first Hippocampus/Cortex vertical slice on top of runtime harness lanes.
100106

107+
### Night Handoff Note (2026-03-12)
108+
109+
Where we are now:
110+
1. Docker Electron debug lane is stable for sandbox-isolated debugging and VS Code attach.
111+
2. Host-shell Electron remains environment-sensitive and can still fail with `SIGSEGV` in constrained contexts.
112+
3. Browser runtime lane is validated and should remain part of the merge confidence path.
113+
4. Docker lane runs software rendering, so it is a debugger-stability lane rather than final GPU-realism proof.
114+
115+
Tomorrow's first coding steps:
116+
1. Add failing tests for real-provider registration + capability-driven selection in embeddings runtime.
117+
2. Implement `embeddings/TransformersEmbeddingBackend.ts` and wire it into resolver candidates.
118+
3. Implement `embeddings/OrtWebglEmbeddingBackend.ts` and wire explicit `webgl` fallback path.
119+
4. Implement first `Hippocampus` ingest entry point with profile-derived defaults.
120+
5. Implement first `Cortex` retrieval entry point with deterministic baseline ordering.
121+
122+
Tomorrow startup commands:
123+
1. `npm run test:unit`
124+
2. `npm run test:browser`
125+
3. `npm run docker:electron:up`
126+
4. VS Code debug: `Electron: Docker Main + Renderer`
127+
101128
### Documentation Synchronization Protocol (Required)
102129

103130
At the end of every implementation pass, update docs in this order:
@@ -265,10 +292,10 @@ Planned commands to add in later passes:
265292

266293
1. Blocker A - File path: `scripts/electron-harness-main.mjs`, `.vscode/launch.json`, `scripts/run-electron-runtime-smoke.mjs`
267294
2. Blocker A - Failure symptom: Electron exits with `SIGSEGV` (`139`) in this tool-executed terminal context for both desktop-style and headless/software-style launches, despite Electron being installed and harness server reachability.
268-
3. Blocker A - Next action: run the containerized attach flow (`npm run docker:electron:up` + `Electron: Docker Main + Renderer`) and treat host-shell crashes as environment-limited unless reproducible in the Docker lane.
269-
4. Blocker B - File path: `.vscode/launch.json`, `.vscode/tasks.json`, `docker-compose.electron-debug.yml`
270-
5. Blocker B - Failure symptom: Docker lane now builds and starts cleanly, but host-side VS Code attach/breakpoint workflow against that lane has not yet been validated in-session.
271-
6. Blocker B - Next action: run `Electron: Docker Main + Renderer` from VS Code, verify main + renderer breakpoint binding, then lock CI/runtime-electron contract to that validated context.
295+
3. Blocker A - Next action: use the Docker attach flow (`Electron: Docker Main + Renderer`) as the default debugging lane and treat host-shell crashes as environment-limited unless reproducible in Docker.
296+
4. Blocker B - File path: `docker/electron-debug/Dockerfile`, `docker/electron-debug/entrypoint.sh`, runtime lane policy docs
297+
5. Blocker B - Failure symptom: Docker lane runs under software rendering (`webgpu`/`webgl` unavailable or blocklisted), so it is strong for debugger stability but not a full GPU-realism proxy.
298+
6. Blocker B - Next action: keep Docker as debug isolation lane and define a separate GPU-capable runtime-electron gate context for realism-sensitive verification.
272299

273300
## Known Hardcoded Hotspots To Clean First
274301

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Current implementation snapshot:
1818
2. Model-profile-driven numeric ownership is implemented and guarded by `npm run guard:model-derived`.
1919
3. Adaptive embedding resolver infrastructure exists, but real providers are still being wired.
2020
4. Runtime harness and browser lane are implemented (`npm run dev:harness`, `npm run test:browser`).
21-
5. Electron lane is wired but runtime-context-sensitive on host shells; a containerized debug lane is now available to isolate from editor/runtime sandbox effects (`npm run docker:electron:up`, then attach with `Electron: Docker Main + Renderer`).
21+
5. Electron lane is runtime-context-sensitive on host shells; the containerized debug lane is now validated as the preferred sandbox-isolated debugging path (`Electron: Docker Main + Renderer`).
2222
6. Hippocampus/Cortex/Daydreamer orchestration layers remain the primary vertical-slice gap.
2323

2424
Current delivery priorities (P0):
@@ -50,6 +50,20 @@ Docker debug quick start:
5050
1. In VS Code Run and Debug, launch `Electron: Docker Main + Renderer` (this auto-runs `docker:electron:up`).
5151
2. If you need manual control, start the lane with `npm run docker:electron:up` and stop it with `npm run docker:electron:down`.
5252

53+
Expected container log noise (non-fatal):
54+
1. `dbus/bus.cc` connection warnings are expected in slim container environments without a system DBus daemon.
55+
2. `WebGL2 blocklisted` is expected with software rendering in Xvfb; this does not imply Electron main-process crash.
56+
57+
Night handoff note (2026-03-12):
58+
1. Runtime debugging status: `Electron: Docker Main + Renderer` is the validated sandbox-isolated debug path.
59+
2. Host-shell context status: local host-shell Electron runs can still fail with `SIGSEGV`; treat Docker attach as source of truth for debugger stability.
60+
3. Runtime realism status: Docker lane is software-rendered and is not the final GPU-realism gate.
61+
4. Tomorrow kickoff step 1: add real provider adapters in embeddings runtime (`Transformers` path for `webnn/webgpu/wasm`, explicit ORT path for `webgl`).
62+
5. Tomorrow kickoff step 2: add failing-first tests for provider registration and selection behavior, then implement to green.
63+
6. Tomorrow kickoff step 3: build first `Hippocampus` ingest slice with resolved model profile values.
64+
7. Tomorrow kickoff step 4: build first `Cortex` retrieval slice with deterministic baseline ordering.
65+
8. First commands for tomorrow: `npm run test:unit`, `npm run test:browser`, then `npm run docker:electron:up` with VS Code debug `Electron: Docker Main + Renderer`.
66+
5367
Docs note:
5468
1. Numeric examples in design docs are illustrative unless explicitly sourced from model metadata.
5569
2. Legacy sketch docs were retired; canonical architecture lives in `CORTEX-DESIGN-PLAN-TODO.md` and execution sequencing lives in `PROJECT-EXECUTION-PLAN.md`.

docker/electron-debug/Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ ENV DEBIAN_FRONTEND=noninteractive
44

55
RUN apt-get update && apt-get install -y --no-install-recommends \
66
ca-certificates \
7+
curl \
78
fonts-liberation \
89
libasound2 \
910
libatk-bridge2.0-0 \

docker/electron-debug/entrypoint.sh

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ MAIN_INSPECT_PORT="${CORTEX_DOCKER_MAIN_INSPECT_PORT:-9230}"
99
RENDERER_DEBUG_PORT="${CORTEX_DOCKER_RENDERER_DEBUG_PORT:-9222}"
1010

1111
cleanup() {
12+
if [[ -n "${ELECTRON_PID:-}" ]] && kill -0 "${ELECTRON_PID}" 2>/dev/null; then
13+
kill "${ELECTRON_PID}" >/dev/null 2>&1 || true
14+
wait "${ELECTRON_PID}" 2>/dev/null || true
15+
fi
16+
1217
if [[ -n "${HARNESS_PID:-}" ]] && kill -0 "${HARNESS_PID}" 2>/dev/null; then
1318
kill "${HARNESS_PID}" >/dev/null 2>&1 || true
1419
wait "${HARNESS_PID}" 2>/dev/null || true
@@ -37,8 +42,29 @@ if [[ "${ready}" -ne 1 ]]; then
3742
fi
3843

3944
echo "[docker-electron] harness ready at ${HARNESS_URL}"
40-
echo "[docker-electron] main inspector: 0.0.0.0:${MAIN_INSPECT_PORT}"
41-
echo "[docker-electron] renderer debugger: 0.0.0.0:${RENDERER_DEBUG_PORT}"
45+
46+
wait_for_main_debugger() {
47+
for _attempt in $(seq 1 200); do
48+
if curl -fsS "http://127.0.0.1:${MAIN_INSPECT_PORT}/json/version" >/dev/null 2>&1; then
49+
return 0
50+
fi
51+
sleep 0.1
52+
done
53+
return 1
54+
}
55+
56+
wait_for_renderer_debugger() {
57+
for _attempt in $(seq 1 200); do
58+
if curl -fsS "http://127.0.0.1:${RENDERER_DEBUG_PORT}/json/version" >/dev/null 2>&1; then
59+
return 0
60+
fi
61+
if curl -fsS "http://127.0.0.1:${RENDERER_DEBUG_PORT}/json/list" >/dev/null 2>&1; then
62+
return 0
63+
fi
64+
sleep 0.1
65+
done
66+
return 1
67+
}
4268

4369
env \
4470
HARNESS_URL="${HARNESS_URL}" \
@@ -54,4 +80,21 @@ env \
5480
--inspect="0.0.0.0:${MAIN_INSPECT_PORT}" \
5581
--remote-debugging-address=0.0.0.0 \
5682
--remote-debugging-port="${RENDERER_DEBUG_PORT}" \
57-
"${ROOT_DIR}/scripts/electron-harness-main.mjs"
83+
"${ROOT_DIR}/scripts/electron-harness-main.mjs" &
84+
85+
ELECTRON_PID=$!
86+
87+
if ! wait_for_main_debugger; then
88+
echo "[docker-electron] main inspector failed to become ready on 0.0.0.0:${MAIN_INSPECT_PORT}"
89+
exit 1
90+
fi
91+
92+
if ! wait_for_renderer_debugger; then
93+
echo "[docker-electron] renderer debugger failed to become ready on 0.0.0.0:${RENDERER_DEBUG_PORT}"
94+
exit 1
95+
fi
96+
97+
echo "[docker-electron] main inspector: 0.0.0.0:${MAIN_INSPECT_PORT}"
98+
echo "[docker-electron] renderer debugger: 0.0.0.0:${RENDERER_DEBUG_PORT}"
99+
100+
wait "${ELECTRON_PID}"

0 commit comments

Comments
 (0)