Skip to content

Commit 4b79888

Browse files
authored
refactor: read gitcrawl and context stores via node:sqlite (#1126)
The last five sqlite3 CLI subprocess invocations (related-context lookup and the two gitcrawl importers) now use read-only node:sqlite, removing the PATH/executable, child-process, timeout, buffer-limit, and CLI-JSON-parsing failure modes -- and the workflow step that installed the sqlite3 binary. Behavior is pinned, not silently improved: JSON-path integers keep the legacy number coercion the CLI applied (9007199254740993 reads as 9007199254740992, documented), scalar reads stay exact text, WAL-backed portable and legacy stores are covered by new real-fixture tests, and missing/corrupt/empty-store errors map to the same caller-visible outcomes as subprocess failures did. Maintainer acceptance recorded for removing the former subprocess timeout/buffer boundary: those guards defended against subprocess pathologies (hangs, unbounded stdout) that synchronous in-process reads cannot exhibit. Proof: before/after equivalence on real fixture stores through the old CLI path and the new in-process path with byte-identical parsed results, plus the full suite green in a Docker-backed Crabbox container that deliberately has no sqlite3 binary -- the migration's own point -- with committed receipt.
1 parent 27d0dca commit 4b79888

13 files changed

Lines changed: 1227 additions & 47 deletions

‎.github/workflows/repair-cluster-intake.yml‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,13 +193,6 @@ jobs:
193193
path: gitcrawl-store
194194
fetch-depth: 1
195195

196-
- name: Ensure SQLite CLI
197-
run: |
198-
if ! command -v sqlite3 >/dev/null 2>&1; then
199-
sudo apt-get update
200-
sudo apt-get install -y sqlite3
201-
fi
202-
203196
- name: Prepare intake
204197
id: prepare
205198
env:
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Node SQLite migration proof
2+
3+
## Claim
4+
5+
The five gitcrawl SQLite query subprocesses now use Node 24's synchronous
6+
`node:sqlite` API in read-only mode without changing their parsed row, scalar,
7+
empty-result, or caller-level error contracts. The cluster-intake workflow no
8+
longer installs the obsolete `sqlite3` executable.
9+
10+
## Host equivalence
11+
12+
`run-proof.mjs` creates a real portable gitcrawl database with committed rows
13+
still resident in its WAL sidecar. It extracts the three old source files from
14+
`origin/main`, verifies their five old `sqlite3` invocations, and executes the
15+
same scalar and JSON queries through the host `sqlite3` CLI and the new
16+
`node:sqlite` helper. Their parsed JSON bytes and scalar text must be identical.
17+
18+
Run after `pnpm run build:all`:
19+
20+
```sh
21+
node docs/proof/node-sqlite-migration/run-proof.mjs
22+
```
23+
24+
The machine-readable result is `equivalence.json`.
25+
26+
## Contract decisions
27+
28+
JSON query rows intentionally remain ordinary JavaScript objects containing
29+
numbers. Statements read SQLite integers as BigInts and explicitly normalize
30+
them with `Number()`, matching the old `sqlite3 -json` plus `JSON.parse` path,
31+
including its precision loss above `Number.MAX_SAFE_INTEGER`. Scalar queries
32+
retain exact decimal text; their existing callers continue to apply `Number()`.
33+
34+
Every query opens `DatabaseSync(dbPath, { readOnly: true })`, so committed WAL
35+
rows remain visible while a missing database is no longer created as a side
36+
effect. Related-context still catches query failures: a missing configured path
37+
returns `[]`/`false` before a query, and a corrupt store returns `[]`/`null`.
38+
Both importer entry points still fail nonzero for missing or corrupt stores.
39+
40+
## Container and gates
41+
42+
The seven local gates passed on Node 24.19.0 and pnpm 11.10.0:
43+
44+
1. Host old/new equivalence proof: three scalar and three JSON query cases,
45+
including missing/corrupt error evidence.
46+
2. Focused real-database fixtures: 6 passed, 0 failed.
47+
3. `pnpm run build:all`: all three TypeScript projects passed.
48+
4. `pnpm run test:no-build`: 3,333 tests; 3,324 passed, 9 skipped, 0 failed.
49+
5. `pnpm run lint`: all four lint lanes passed.
50+
6. `pnpm run format:check`: 663 files passed.
51+
7. `pnpm run check:static`: active-surface, dashboard boundary, docs, limits,
52+
and format checks passed.
53+
54+
The committed `container-proof.sh` requires a fresh PR checkout whose image has
55+
no `sqlite3` binary. It installs the repository's pinned pnpm through Corepack,
56+
downloads jq 1.8.1, verifies the selected jq binary against the official
57+
published checksum, runs the focused real-database fixtures through only the
58+
new path, and then runs the full `pnpm check` gate.
59+
60+
Container provenance and secret-scanned stdout are committed alongside this
61+
proof after the required `--fresh-pr` run. Crabbox resolved `provider=aws` and
62+
ran pushed head `31386dccd6ee9f77fe480ab6c705253647f4aaf2` in lease
63+
`cbx_3ddd8eadc1bb` (`amber-barnacle-28b5`), run `run_61e78be4ed53`. The
64+
`node:24-bookworm` command exited 0 after 187,543 ms: all 6 focused fixtures
65+
passed, then full `pnpm check` passed 3,333 tests with 3,325 passed, 8 skipped,
66+
and 0 failed at 81.60% line, 74.06% branch, and 87.40% function coverage.
67+
`sqlite3` was absent before and after the rsync-only system dependency setup.
68+
69+
The full 571,547-byte stdout capture has SHA-256
70+
`28669d632e2d5387d901c76504611ab37a19bd23de0c29453767e2bf5efe5c76`.
71+
TruffleHog 3.96.0 scanned that exact file with zero verified or unverified
72+
secrets; `container-stdout.log` retains the proof-bearing stdout lines. Full
73+
machine-readable details, including the three discarded harness attempts, are
74+
in `container-provenance.json` and `container-secret-scan.json`.
75+
76+
The run's project-local Crabbox 0.38.3-5 wrapper timed out while releasing the
77+
otherwise successful lease. Crabbox 0.41.1 then explicitly released
78+
`cbx_3ddd8eadc1bb`; a provider-specific lease listing returned empty.
79+
80+
## Limits and Bay impact
81+
82+
Fixtures are disposable local files; no proof command contacts Gitcrawl,
83+
GitHub APIs, Worker storage, or another production service. The host needs
84+
`sqlite3` only for old-path equivalence. The container intentionally cannot run
85+
the old path because the binary is absent.
86+
87+
OpenClaw Bay is unaffected. This changes local read-only store access and one
88+
workflow bootstrap step, not lifecycle publication, queue control, status
89+
telemetry, dashboard data, or Bay's observer-only boundary.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
echo "CONTAINER_PHASE=environment"
5+
node --version
6+
corepack pnpm --version
7+
if command -v sqlite3 >/dev/null 2>&1; then
8+
echo "unexpected sqlite3 binary: $(command -v sqlite3)" >&2
9+
exit 1
10+
fi
11+
echo "SQLITE3_BINARY=absent"
12+
13+
jq_version="1.8.2"
14+
case "$(uname -m)" in
15+
x86_64) jq_asset="jq-linux-amd64" ;;
16+
aarch64|arm64) jq_asset="jq-linux-arm64" ;;
17+
*) echo "unsupported jq architecture: $(uname -m)" >&2; exit 1 ;;
18+
esac
19+
jq_dir="$(mktemp -d)"
20+
trap 'rm -rf "$jq_dir"' EXIT
21+
curl --fail --show-error --silent --location \
22+
"https://github.com/jqlang/jq/releases/download/jq-${jq_version}/${jq_asset}" \
23+
--output "${jq_dir}/${jq_asset}"
24+
curl --fail --show-error --silent --location \
25+
"https://github.com/jqlang/jq/releases/download/jq-${jq_version}/sha256sum.txt" \
26+
--output "${jq_dir}/sha256sum.txt"
27+
(cd "$jq_dir" && grep " ${jq_asset}$" sha256sum.txt | sha256sum --check -)
28+
install -m 0755 "${jq_dir}/${jq_asset}" /usr/local/bin/jq
29+
jq --version
30+
31+
echo "CONTAINER_PHASE=system-dependencies"
32+
apt-get update
33+
apt-get install --yes --no-install-recommends rsync
34+
if command -v sqlite3 >/dev/null 2>&1; then
35+
echo "sqlite3 appeared after system dependency setup: $(command -v sqlite3)" >&2
36+
exit 1
37+
fi
38+
echo "SQLITE3_BINARY_AFTER_SETUP=absent"
39+
40+
echo "CONTAINER_PHASE=install"
41+
corepack enable
42+
pnpm install --frozen-lockfile
43+
44+
echo "CONTAINER_PHASE=focused-new-path"
45+
pnpm run build:all
46+
node --test test/repair/gitcrawl-sqlite.test.ts
47+
48+
echo "CONTAINER_PHASE=full-suite"
49+
pnpm run check
50+
51+
echo "CONTAINER_PROOF_RC=0"
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"schema": "clawsweeper-real-boundary-proof-provenance/v1",
3+
"claim": "The pushed node:sqlite migration passes its real gitcrawl fixtures and the full repository check in a fresh PR checkout mounted into a container with no sqlite3 executable.",
4+
"pull_request": "https://github.com/openclaw/clawsweeper/pull/1126",
5+
"reviewed_head": "31386dccd6ee9f77fe480ab6c705253647f4aaf2",
6+
"crabbox": {
7+
"run_cli_version": "0.38.3-5-g2a79805d",
8+
"cleanup_cli_version": "0.41.1",
9+
"provider": "aws",
10+
"lease_id": "cbx_3ddd8eadc1bb",
11+
"slug": "amber-barnacle-28b5",
12+
"run_id": "run_61e78be4ed53",
13+
"machine_type": "c7a.8xlarge",
14+
"checkout": "--fresh-pr openclaw/clawsweeper#1126 --no-hydrate",
15+
"container_image": "node:24-bookworm",
16+
"sync_ms": 28841,
17+
"command_ms": 187543,
18+
"total_ms": 218120,
19+
"exit_code": 0,
20+
"run_status": "succeeded",
21+
"lease_stopped": true,
22+
"lease_stop_status": "Initial release calls timed out through the older project-local wrapper; Crabbox 0.41.1 explicitly released the same provider-bound lease and a provider-specific list returned empty."
23+
},
24+
"runtime": {
25+
"node": "v24.18.1",
26+
"pnpm": "11.10.0",
27+
"jq": "jq-1.8.2",
28+
"jq_asset": "jq-linux-amd64",
29+
"jq_sha256": "b1c22172dd303f3be49e935aa56aa48a8b7a46e0bc838b4997d3bb451495870f",
30+
"jq_checksum_source": "https://github.com/jqlang/jq/releases/download/jq-1.8.2/sha256sum.txt",
31+
"jq_checksum_verified": true,
32+
"rsync": "3.2.7-1+deb12u6",
33+
"sqlite3_before_setup": "absent",
34+
"sqlite3_after_setup": "absent"
35+
},
36+
"result": {
37+
"proof_rc": 0,
38+
"focused_new_path": {
39+
"tests": 6,
40+
"passed": 6,
41+
"failed": 0
42+
},
43+
"full_check": {
44+
"tests": 3333,
45+
"passed": 3325,
46+
"skipped": 8,
47+
"failed": 0,
48+
"line_coverage_percent": 81.6,
49+
"branch_coverage_percent": 74.06,
50+
"function_coverage_percent": 87.4
51+
},
52+
"stdout": {
53+
"full_capture_bytes": 571547,
54+
"full_capture_sha256": "28669d632e2d5387d901c76504611ab37a19bd23de0c29453767e2bf5efe5c76",
55+
"committed_excerpt": "container-stdout.log",
56+
"secret_scan": "container-secret-scan.json"
57+
}
58+
},
59+
"discarded_attempts": [
60+
{
61+
"run_id": "run_a89db9823eff",
62+
"lease_id": "cbx_ee91b67ca4e2",
63+
"exit_code": 1,
64+
"reason": "Checksum-verified jq was not added to PATH; six workflow fixtures took their jq-unavailable branches.",
65+
"lease_stopped": true
66+
},
67+
{
68+
"run_id": "run_b79ada848eae",
69+
"lease_id": "cbx_f537a4c19fb2",
70+
"exit_code": 1,
71+
"reason": "Debian login shells reset the temporary jq PATH; the harness moved jq to /usr/local/bin.",
72+
"lease_stopped": true
73+
},
74+
{
75+
"run_id": "run_86c974950519",
76+
"lease_id": "cbx_ed3ea0261b4d",
77+
"exit_code": 1,
78+
"reason": "The full suite reached a maintainer-report fixture requiring rsync, which the base image did not contain.",
79+
"lease_stopped": true
80+
}
81+
],
82+
"limits": [
83+
"The container intentionally cannot run the old sqlite3 subprocess path because sqlite3 is absent before and after dependency setup.",
84+
"Old-versus-new byte equivalence runs on the host and is recorded separately in equivalence.json.",
85+
"Fixtures are disposable local files and do not contact Gitcrawl, GitHub APIs, Worker storage, or production services."
86+
]
87+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"schema": "clawsweeper-proof-secret-scan/v1",
3+
"scanner": "trufflehog 3.96.0",
4+
"command": "trufflehog filesystem <stdout> --only-verified --json",
5+
"source": {
6+
"kind": "full captured stdout",
7+
"bytes": 571547,
8+
"sha256": "28669d632e2d5387d901c76504611ab37a19bd23de0c29453767e2bf5efe5c76"
9+
},
10+
"committed_excerpt": {
11+
"path": "docs/proof/node-sqlite-migration/container-stdout.log",
12+
"bytes": 1784,
13+
"sha256": "de269b8d102f0286ebb2816fc0373c447f2f9b23435d24a955c93a4e3a56e5ce",
14+
"scan_status": "clean",
15+
"verified_secrets": 0,
16+
"unverified_secrets": 0
17+
},
18+
"result": {
19+
"exit_code": 0,
20+
"verified_secrets": 0,
21+
"unverified_secrets": 0,
22+
"json_output_bytes": 0
23+
}
24+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
CONTAINER_PHASE=environment
2+
v24.18.1
3+
11.10.0
4+
SQLITE3_BINARY=absent
5+
jq-linux-amd64: OK
6+
jq-1.8.2
7+
CONTAINER_PHASE=system-dependencies
8+
Setting up rsync (3.2.7-1+deb12u6) ...
9+
SQLITE3_BINARY_AFTER_SETUP=absent
10+
CONTAINER_PHASE=install
11+
Lockfile is up to date, resolution step is skipped
12+
Lockfile passes supply-chain policies (79 entries in 818ms)
13+
Done in 1.3s using pnpm v11.10.0
14+
CONTAINER_PHASE=focused-new-path
15+
✔ read-only SQLite queries preserve sqlite3 JSON integer behavior (22.710191ms)
16+
✔ related-context reads portable gitcrawl rows committed in a WAL sidecar (64.054329ms)
17+
✔ related-context and cluster importer query the legacy gitcrawl schema (108.933367ms)
18+
✔ related-context preserves empty, missing, and corrupt database fallbacks (62.820168ms)
19+
✔ gitcrawl importer CLIs query real WAL-backed fixtures without sqlite3 (151.968339ms)
20+
✔ gitcrawl importer CLIs preserve empty-result and database failure outcomes (330.957805ms)
21+
ℹ tests 6
22+
ℹ suites 0
23+
ℹ pass 6
24+
ℹ fail 0
25+
ℹ cancelled 0
26+
ℹ skipped 0
27+
ℹ todo 0
28+
ℹ duration_ms 1039.788403
29+
CONTAINER_PHASE=full-suite
30+
. check:dashboard-queue-boundary: dashboard queue boundary check passed
31+
. check:docs: Documentation checks passed.
32+
. format:check: All matched files use the correct format.
33+
. lint:src: Found 0 warnings and 0 errors.
34+
ℹ tests 12
35+
ℹ suites 0
36+
ℹ pass 12
37+
ℹ fail 0
38+
ℹ cancelled 0
39+
ℹ skipped 0
40+
ℹ todo 0
41+
ℹ duration_ms 261.598252
42+
ℹ all files | 100.00 | 88.61 | 100.00 |
43+
ℹ tests 3333
44+
ℹ suites 0
45+
ℹ pass 3325
46+
ℹ fail 0
47+
ℹ cancelled 0
48+
ℹ skipped 8
49+
ℹ todo 0
50+
ℹ duration_ms 122619.919772
51+
ℹ sqlite-readonly.js | 100.00 | 85.71 | 100.00 |
52+
ℹ all files | 81.60 | 74.06 | 87.40 |
53+
CONTAINER_PROOF_RC=0

0 commit comments

Comments
 (0)