Repository navigation
Description
What's the problem
Found during a mock-only audit of dashboard/tests (2026-10-03), while measuring per-test coverage.
Gap
dashboard/tests/service/test_storage_telemetry.py:366, in TestTelemetryTableHealth::test_a_failed_recovery_reads_unhealthy:
monkeypatch.setattr("mining_dashboard.service.storage_service.sqlite3.connect", boom)storage_service.sqlite3 is the global sqlite3 module. So for the duration of the test, this replaces sqlite3.connect for the whole process, not just for storage_service. monkeypatch restores it afterwards, so a plain run is unaffected. But anything else that opens SQLite during the test fails. coverage.py does exactly that when it records per-test contexts, which blocks per-test coverage analysis of the dashboard suite.
Scheduling
Filed to maintenance & gates at the operator's direction, to revisit after the 2.0.0 release. Blocked on #2774.
what it impacts
Impact is not separately established in the existing report; confirm the affected users or behavior.
How I found it
Evidence
Runs were made on 26f07d6. dashboard/ is identical at develop 9c74fc4. Commands are run from dashboard/ with uv run --locked --extra test.
| Check | Result |
|---|---|
python -c "import sqlite3; from mining_dashboard.service import storage_service as m; print(m.sqlite3 is sqlite3)" |
True |
python -m pytest --cov=mining_dashboard --cov-context=test --cov-report= tests/service/test_storage_telemetry.py tests/service/test_storage_worker.py |
exit 3: 33 passed, 85 errors, sqlite3.OperationalError: unable to open database file raised from coverage's data file |
the same, with --deselect tests/service/test_storage_telemetry.py::TestTelemetryTableHealth::test_a_failed_recovery_reads_unhealthy |
exit 0: 74 passed |
| the same two files, plain run without coverage | 75 passed |
full dashboard suite with --cov-context=test |
1,668 passed, 1 skipped and 2,650 errors as-is; 2,991 passed and 1 skipped with that one test deselected |
A candidate fix, checked locally, patches only the module's reference:
monkeypatch.setattr(storage_service, "sqlite3", SimpleNamespace(**{**vars(sqlite3), "connect": boom}))With that change, the two-file per-test coverage run exits 0 with 75 passed, and the test still passes. Its is_db_unrecoverable() is True assertion holds only if the reconnect raised.
The same dotted-path form lands on other stdlib globals in 16 places: random.random 9, socket.socket 3, and one each of time.time, time.strftime, requests.get and asyncio.sleep. None of them showed an effect in the full per-test coverage run, so they are out of scope here.
how important is it
Importance has not been assessed explicitly; triage must state the priority and its reason.
acceptance criteria
Acceptance
Done means the script at the end of this section prints ACCEPTED and exits 0 on the PR head. Every check is a mechanical pass or fail, so no judgment call is needed. Paste the script's full output into the PR body.
# save the script below as /tmp/accept_3058.py (outside the repo), then:
cd dashboard
uv run --locked --extra test python /tmp/accept_3058.py
It takes about 5 minutes. It runs the dashboard suite twice. It changes mining_dashboard/service/storage_service.py once, for C7, and restores the file afterwards.
| Check | Passes when |
|---|---|
| C1 | Only dashboard/tests/service/test_storage_telemetry.py differs from develop. CHANGELOG.md is also allowed. |
| C2 | The file contains no patch target naming the sqlite3 module's connect: no string ending in sqlite3.connect" and no sqlite3, "connect" argument pair. |
| C3 | The file passes. |
| C4 | A probe plugin confirms that sqlite3.connect is still the original function at the end of every test body in the file, while that test's monkeypatches are still in place. |
| C5 | Per-test coverage (--cov-context=test) over the telemetry and storage-worker test files exits 0. |
| C6 | Per-test coverage over the full dashboard suite exits 0. |
| C7 | With _recover_corrupt_db's reconnect changed to __import__("sqlite3").connect(...), which bypasses storage_service's own sqlite3 name, test_a_failed_recovery_reads_unhealthy fails. This proves the test's verdict still depends on the patched reconnect. |
| C8 | make test-dashboard exits 0. |
Rules:
- Do not change the script's test IDs, anchors or expected outcomes. If a check prints
error(anchor found 0x ...), production code has moved since this issue was filed. Stop and comment here with the output instead of editing the anchor. - A reviewer re-runs the same script on the head they review. A changed head needs a fresh run.
- The repo's normal gates still apply on top of this:
make test,make test-patch-coverage, and the adversarial review.
Baseline, run 2026-10-03 on 26f07d6 (dashboard/ identical to develop at 9c74fc4): unmodified develop prints NOT ACCEPTED: 2/8 checks pass. Only C3 and C8 pass, and C4 names test_a_failed_recovery_reads_unhealthy. A throwaway prototype, not committed, printed ACCEPTED: 8/8 checks pass. It used the scoped patch from the Evidence section plus from types import SimpleNamespace and from mining_dashboard.service import storage_service.
Hint, not binding: the prototype above is the whole change. Keep the imports in the order the repo's ruff config expects (make lint-py).
accept_3058.py
"""Acceptance check for p2pool-starter-stack/pithead#3058.
Save this file OUTSIDE the repo (for example /tmp/accept_3058.py) so it is never committed.
Run from dashboard/ on the PR head:
uv run --locked --extra test python /tmp/accept_3058.py
Prints PASS/FAIL per check and exits 0 only when every check passes. Production code is
mutated in place for one check and restored in a finally block.
"""
import os
import re
import subprocess
import sys
import tempfile
from pathlib import Path
FILE = "tests/service/test_storage_telemetry.py"
TEST = FILE + "::TestTelemetryTableHealth::test_a_failed_recovery_reads_unhealthy"
ALLOWED = {"dashboard/" + FILE, "CHANGELOG.md"}
STORAGE = Path("mining_dashboard/service/storage_service.py")
RECONNECT = "self._conn = sqlite3.connect(self.db_path, timeout=30.0, check_same_thread=False)"
PLUGIN = '''
import os, sqlite3, pytest
_ORIGINAL = sqlite3.connect
@pytest.hookimpl(hookwrapper=True)
def pytest_runtest_call(item):
yield
if sqlite3.connect is not _ORIGINAL: # still inside the test: its monkeypatch is not undone yet
with open(os.environ["ACCEPT_3058_MARK"], "a") as f:
f.write(item.nodeid + "\\n")
'''
ENV = {**os.environ, "PYTHONDONTWRITEBYTECODE": "1"}
results = []
def report(name, ok, detail=""):
results.append(ok)
print(f"{'PASS' if ok else 'FAIL'} {name}" + (f" [{detail}]" if detail else ""), flush=True)
def run_pytest(*args, env=ENV):
cmd = [sys.executable, "-m", "pytest", "-q", "-p", "no:cacheprovider",
"-o", "addopts=--import-mode=importlib", *args]
code = subprocess.run(cmd, capture_output=True, text=True, env=env).returncode
return {0: "pass", 1: "fail"}.get(code, f"error(pytest exit {code})")
subprocess.run(["git", "fetch", "-q", "origin", "develop"], check=False)
base = subprocess.run(["git", "merge-base", "origin/develop", "HEAD"],
capture_output=True, text=True).stdout.strip()
changed = set(subprocess.run(["git", "diff", "--name-only", base], capture_output=True,
text=True, cwd="..").stdout.split())
report("C1 the telemetry test file is changed, and nothing outside it (CHANGELOG.md allowed)",
"dashboard/" + FILE in changed and changed <= ALLOWED, f"changed: {sorted(changed)}")
text = Path(FILE).read_text()
hits = re.findall(r"""sqlite3\.connect["']|sqlite3,\s*["']connect["']""", text)
report("C2 the file has no patch target naming the sqlite3 module's connect", not hits, f"found {hits}" if hits else "")
report("C3 the test and its file pass unmutated", run_pytest(FILE) == "pass")
with tempfile.TemporaryDirectory() as tmp:
Path(tmp, "accept_3058_plugin.py").write_text(PLUGIN)
mark = Path(tmp, "mark")
env = {**ENV, "PYTHONPATH": tmp + os.pathsep + ENV.get("PYTHONPATH", ""),
"ACCEPT_3058_MARK": str(mark)}
outcome = run_pytest("-p", "accept_3058_plugin", FILE, env=env)
replaced = mark.read_text().split() if mark.exists() else []
report("C4 no test in the telemetry file replaces sqlite3.connect process-wide",
outcome == "pass" and not replaced, f"pytest {outcome}; replaced in {replaced}")
cov_env = {**ENV, "COVERAGE_FILE": str(Path(tmp, "cov"))}
two = run_pytest("--cov=mining_dashboard", "--cov-context=test", "--cov-report=", FILE,
"tests/service/test_storage_worker.py", env=cov_env)
report("C5 per-test coverage over the telemetry and worker storage files runs clean",
two == "pass", f"got {two}")
full = run_pytest("--cov=mining_dashboard", "--cov-context=test", "--cov-report=", env=cov_env)
report("C6 per-test coverage over the full dashboard suite runs clean", full == "pass",
f"got {full}")
src = STORAGE.read_text()
start = src.find("def _recover_corrupt_db")
at = src.find(RECONNECT, start)
if start < 0 or at < 0:
got = "error(reconnect anchor not found in _recover_corrupt_db)"
else:
try:
STORAGE.write_text(src[:at] + RECONNECT.replace("sqlite3.connect", '__import__("sqlite3").connect')
+ src[at + len(RECONNECT):])
got = run_pytest(TEST)
finally:
STORAGE.write_text(src)
report("C7 reconnect bypasses storage_service's sqlite3 name: the test must fail", got == "fail",
f"got {got}")
report("C8 make test-dashboard exits 0",
subprocess.run(["make", "-C", "..", "test-dashboard"], capture_output=True, env=ENV).returncode == 0)
print(f"\n{'ACCEPTED' if all(results) else 'NOT ACCEPTED'}: {sum(results)}/{len(results)} checks pass")
sys.exit(0 if all(results) else 1)possible solutions
No distinct solution options are recorded; investigate the existing report before choosing an approach.
Activity
VijitSingh97 commentedon Oct 3, 2026
Blocked on #2774. The operator deferred this until after the 2.0.0 release; work it once #2774 closes.
pithead-developer commentedon Oct 19, 2026
Questions before work continues (answer here, then remove the
questionlabel):May the unchanged C1–C8 acceptance script run locally as an exception to the touched-module-only Mac rule (default: retain the queued hosted workflow because it respects that restriction)?
pithead-architect commentedon Oct 19, 2026
Ruling: Take the default: retain the hosted workflow; no exception to the touched-module-only local testing rule. Acceptance run 39264870242 remains queued. Return
waiting, preserving PR #3518 and the unchanged C1–C8 script. When it finishes, record the complete acceptance output against the actual PR head in the PR body, investigate any failed check without changing its expected outcome, and renew independent verification. Completion still requires the normal GitHub gates, current-head agent review PASS, then the owner's formal approval.pithead-developer commentedon Oct 19, 2026
Questions before work continues (answer here, then remove the
questionlabel):Once the remaining shell gates pass, may the runner re-review unchanged head c4498aa using successful hosted acceptance run 39284275388 (default: yes, because another push cancels current CI and invalidates the proven SHA)?
pithead-architect commentedon Oct 19, 2026
Ruling: Yes—authorize one re-review of unchanged head c4498aa after all normal gates, including the aggregate shell check, pass and current lane policy permits. Hosted acceptance run 39284275388 succeeded against that head with C1–C8 passing; preserve its complete output in PR #3518. Return
waitingon GitHub Actions while checks remain pending; do not push solely to trigger review. Use the documented operator re-review mechanism. The reviewer must still rerun the unchanged acceptance script as the issue requires and resolve the returned findings. Merge requires current-head agent PASS followed by VijitSingh97’s formal approval. Any changed head needs fresh acceptance evidence.12 remaining items
pithead-architect commentedon Nov 6, 2026
Ruling: (1) No new PR. #3518 is this issue's PR, and the runner closed it as a lean-roadmap park whose closing comment says to reopen it. Opening a replacement for a base correction needs the owner's approval under
prompts/base.md:88, so keep #3518. In order: reopen #3518; mergeorigin/develop-v2.1.0intoagent/3058-dashboard-tests-test-a-failed-recovery-r(a merge, never a rebase); retarget it withgh pr edit 3518 --base develop-v2.1.0; leave it a draft. The branch is 2 commits ahead ofdevelop-v2.1.0and touches onlydashboard/tests/service/test_storage_telemetry.py, and the process-wide patch is still at line 366 ondevelop-v2.1.0, so the merge is small and the fix still applies. If the shim refuses the reopen or the retarget, returnquestionwith the refusal output and open nothing new. (2) Scope the PR to #3058 only. #3069 and #3070 are both closed, so the grouping finding no longer applies. Don't call this an owner-approved exclusion: it is one issue, one PR. The change is test-only and touches no box path, so tiers 1–3 are the gate and no tier-4 job is needed. Say both things in one line in the PR body, under Decisions taken. (3) Don't push a temporary workflow branch, and don't push toagent/3058-acceptance-proofagain. The proof on the new head has two parts. First, the PR's normal Actions checks on that head. Second, the issue's own reproduction, run by you and quoted: the--cov=mining_dashboard --cov-context=testcommand on the two storage test files exits 3 with theunable to open database fileerrors when the fix is reverted, and exits 0 with it applied. That is the red-then-green the test-honesty rule asks for. The reviewer reruns those same local commands on their own, so no hosted rerun needs to be arranged. Update the PR body in place: the new head SHA, the new base, the old c4498aa proof replaced rather than appended to, and the three sections only. Then post "Ready for review" and let the normal review → owner-approval path run. Take your defaults on anything else and list them under Decisions taken.test(dashboard): drop narrating comment from the SQLite recovery test (…
pithead-developer commentedon Nov 6, 2026
Blocked on #3923. The returned finding does not trace to this PR. All five failing checks are
CI / Build image(dashboard, monero, p2pool, tor, xmrig-proxy), and each fails at the Trivy gate on apt CVE-2026-109518 (HIGH, fixed upstream) in the ubuntu 24.04 base; the p2pool log readsTotal: 2 (HIGH: 2, CRITICAL: 0). The PR changes onlydashboard/tests/service/test_storage_telemetry.py, so it cannot change an image scan, and the same gate fails on every branch. The root-cause fix is PR #3926 for issue #3923. #3926 is open and mergeable with all its checks green (44 SUCCESS, 2 SKIPPED, including the image builds), but it is not merged. The blocker is that #3926 has to merge intodevelop-v2.1.0, which the owner or runner must do. Once #3923 closes, I mergedevelop-v2.1.0into this branch, push and reread the checks. Finished so far: the fix, the red (exit 3) then green (exit 0) reproduction, the other 44 checks green, and a clean verifier pass. Head 66a8fd8 is unchanged, and I posted the same explanation on the PR.The runner resumes this issue when that one closes.
pithead-developer commentedon Nov 8, 2026
Blocked on #3940. The prior session's handoff was wrong: #3926's Trivy fix landed only on develop-v2.0.3, so the five required
CI / Build imagechecks are still red at head 3dc9861 (run 42433803291), failing on base-image packages (apt CVE-2026-109518 on p2pool/monero/xmrig-proxy/dashboard, zlib CVE-2026-76844/CVE-2026-85091 on dashboard, musl CVE-2026-107891 on tor) that this test-only diff cannot affect. #3940 tracks bringing that fix onto develop-v2.1.0 and its acceptance criteria require the change on the base branch itself, so it must not ride on this PR; when #3940 closes, this session resumes, merges origin/develop-v2.1.0 and the five checks rerun. The #3058 work itself is finished and verified on this head (red exit 3 / green exit 0 reproduction, acceptance C2–C8, lint gates, 43/50 checks green); I corrected the body's false "fixed by #3926" claim and posted the block explanation with the run id on PR #3518 (#3518 (comment)).The runner resumes this issue when that one closes.
dashboard: fix #3058 — isolate the SQLite recovery test patch (#3518)
pithead-developer commentedon Nov 9, 2026
Merged in #3518.