Skip to content

feat(report) + refactor(detector): Slices 2-4 of engineering doctrine cycle (RCA + single-pass + 0.574x baseline) - #236

Merged
FabioLeitao merged 5 commits into
mainfrom
cursor/sre-agent-protocol-4c97
Apr 27, 2026
Merged

FabioLeitao merged 5 commits into
mainfrom
cursor/sre-agent-protocol-4c97

Conversation

@cursor

@cursor cursor Bot commented Apr 27, 2026

Copy link
Copy Markdown
Contributor

Description

Closes the original engineering-doctrine execution plan after PRs #230 / #231 (Slice 1: doctrine manifestos + 200k benchmark evidence baseline). Three coherent commits, one per slice, each with its own pin test:

Slice 2 — feat(report): RCA block in data-boar-report failure path

  • cli/reporter.py: every failure now emits a Sysinternals-style RCA block on stderr so an operator can see which step of the regen pipeline broke without paging the maintainer for a traceback.
  • Steps named explicitly: load_config, open_sqlite, fetch_findings, build_manifest, render_markdown, write_output. Each step maps to a narrowed hypothesis + the smallest deterministic command an operator can paste to reproduce the failure on the same SQLite.
  • Stdout stays reserved for stakeholder Markdown so piped captures are never poisoned. New --debug-traceback flag appends the full traceback on top of the RCA for lab use.
  • Doctrine references inline: docs/ops/inspirations/INTERNAL_DIAGNOSTIC_AESTHETICS.md §2.2-3 and DEFENSIVE_SCANNING_MANIFESTO.md §1 (read-only against customer SQLite — no DDL, no temp objects, no live connector).
  • New tests/test_cli_reporter_rca.py pins the contract (5 tests).

Slice 3 — refactor(detector): single-pass Pro fallback + skip redundant chunk copy

  • pro/worker_logic.py::basic_python_scan: was two passes over payloads (OpenCore prefilter then Luhn loop with a set membership probe); now a single list comprehension with hoisted bound-method references and a short-circuit or chain over the same three predicates (CPF regex, email regex, Luhn-valid card).
  • pro/engine.py::process_chunk_worker: O(1) probe (isinstance(chunk, list) and isinstance(chunk[0], str)) reuses the input on the documented hot path so the [str(item) for item in chunk] allocation is skipped when the orchestrator already produced a list[str]. Cold path (tuples, generators, mixed types) still gets the defensive coercion.
  • Safety rail honored per Slack mission brief: no sample caps, statement timeouts, isolation, or precision logic were modified. Same regexes, same Luhn validator, same acceptance contract.
  • New tests/test_basic_python_scan_single_pass_parity.py pins acceptance set: OpenCore-accepted CPF/email rows must remain a strict subset of the new output, Luhn-valid cards must still be admitted while invalid cards must not, rows hitting multiple predicates appear at most once per input, and a 5_000-row clean corpus must yield zero survivors.

Slice 4 — docs(plans): close the loop, record 0.574x as technical debt baseline

  • docs/plans/PLAN_ENGINEERING_DOCTRINE_CONSOLIDATION.md: status line + sequential to-do table now show Slices 1–3 ✅ with file pointers; Slice 4 marks itself in flight.
  • docs/plans/BENCHMARK_EVOLUTION.md: new §8 explains the recorded speedup_vs_opencore = 0.574 from tests/benchmarks/official_benchmark_200k.json in plain English (Pro is ~1.74x slower than OpenCore in this profile because the lab host runs the Python fallback — no Rust extension yet). Names the precision invariant pro_hits == opencore_hits and the existing test that fails first if it is ever broken.
  • docs/plans/PLANS_TODO.md integration thread rewritten so testers see Slices 1–3 done and Slice 4 governance refresh as the only remaining piece.

The 200k JSON evidence artifact is intentionally left untouched: the agent VM wall-time is not comparable to lab hardware, and inventing a "Pro faster" number here would violate INTERNAL_DIAGNOSTIC_AESTHETICS.md §4 (no invented numbers). The next scripts/benchmark-ab.ps1 run on the lab will measure the algorithmic delta against the recorded baseline.

Type of change

  • New feature (Slice 2 RCA block — additive operator surface)
  • Refactor / maintenance (Slice 3 single-pass + chunk-copy skip)
  • Documentation (Slice 4 governance + benchmark §8)

Checklist

  • Tests pass locally (uv run pytest) — 913 passed, 5 skipped (pre-existing PowerShell parse failures on Linux runner without pwsh are environment-only, unrelated to this PR).
  • Lint / format passes (pre-commit ruff + ruff format clean on every commit).
  • Docs updated (BENCHMARK_EVOLUTION.md §8, PLAN_ENGINEERING_DOCTRINE_CONSOLIDATION.md, PLANS_TODO.md integration thread).
  • Security-sensitive changes: none. The regen path is read-only against the local SQLite; the precision contract for the Pro fallback (CPF/email/Luhn) is unchanged.

Related

Operational notes

  • Mission brief from Slack honored: no sample caps, no timeout, no precision logic touched. Performance gains come from algorithmic efficiency (one fused pass instead of two) and memory hygiene (skip redundant per-chunk string copy on the hot path).
  • 0.574x is now explicitly recorded as the current technical debt baseline, not as a target to silently flip.
Open in Web View Automation 

cursoragent and others added 3 commits April 27, 2026 16:14
Surface a Sysinternals-style RCA block on stderr when 'data-boar-report'
fails so an operator can tell which step of the regen pipeline broke
without paging the maintainer for a traceback.

Pipeline steps named explicitly: load_config, open_sqlite,
fetch_findings, build_manifest, render_markdown, write_output. Each step
maps to a narrowed hypothesis (config schema, sqlite path, sandbox guard,
write permission) plus the smallest deterministic command an operator
can paste to reproduce the failure on the same SQLite. Stdout stays
reserved for stakeholder Markdown so piped captures are never poisoned;
optional --debug-traceback appends the full traceback for lab use.

No customer database is touched - the regen path is read-only against
the local SQLite, per docs/ops/inspirations/DEFENSIVE_SCANNING_MANIFESTO.md
section 1. Diagnostic shape follows
docs/ops/inspirations/INTERNAL_DIAGNOSTIC_AESTHETICS.md sections 2.2-3
(short, factual, no invented numbers, one concept per line).

tests/test_cli_reporter_rca.py pins the contract: missing config returns
exit code 3 with the labelled RCA on stderr only, debug flag appends the
traceback, and harmless inputs still return zero so the RCA path stays
reserved for real failures.

Co-authored-by: Fabio Tavares Leitão <[email protected]>
…opy (Slice 3)

Address the algorithmic side of the recorded 0.574x latency baseline in
the Pro Python fallback path (tests/benchmarks/official_benchmark_200k.json):
the previous shape walked each chunk twice and held three intermediate
collections in memory at the same time. The fused single-pass shape
preserves the exact acceptance contract (CPF regex, email regex, Luhn
card validator) so the precision invariant promised in the doctrine
manifestos is unchanged.

pro/worker_logic.py::basic_python_scan
  - was: OpenCorePreFilter().filter_candidates(payloads) -> list,
         list(candidates) copy, set(candidates) hash set, then a second
         loop over the full payload list with membership probing for the
         Luhn check.
  - now: a single list comprehension over payloads with hoisted
         bound-method references, evaluating CPF or email or Luhn-valid
         card via short-circuit 'or'. No regex was widened or narrowed.
         Empty / falsy rows are skipped explicitly to save three regex
         calls per empty cell (sparse customer columns are common).

pro/engine.py::process_chunk_worker
  - was: always materialized data_batch = [str(item) for item in chunk],
         even when the orchestrator already produced list[str] (the hot
         path documented in ProOrchestrator._row_to_payload).
  - now: O(1) probe (isinstance(chunk, list) and isinstance(chunk[0], str))
         reuses the input directly on the hot path; tuples, generators,
         and mixed-type inputs still get the defensive str-coercion copy
         so the downstream contract is unchanged.

tests/test_basic_python_scan_single_pass_parity.py pins the parity:
OpenCore-accepted CPF/email rows must remain a strict subset of the new
output, Luhn-valid cards must still be admitted while invalid cards must
not, rows hitting multiple predicates must appear at most once per input
(no de-duplication regression), and a 5_000-row clean corpus must yield
zero survivors.

Safety rail explicitly respected per Slack mission brief: no sample
caps, statement timeouts, isolation, or precision logic were changed.
The 200k JSON evidence artifact is left untouched so the operator's
next lab run can measure the algorithmic delta against the recorded
baseline. Doctrine references inline:
docs/ops/inspirations/DEFENSIVE_SCANNING_MANIFESTO.md sections 1-2,
docs/ops/inspirations/THE_ART_OF_THE_FALLBACK.md section 2,
docs/ops/inspirations/INTERNAL_DIAGNOSTIC_AESTHETICS.md section 3.

Co-authored-by: Fabio Tavares Leitão <[email protected]>
…ne (Slice 4)

Update governance docs after the Slice 2 (RCA) and Slice 3 (single-pass
fallback) commits land:

docs/plans/PLAN_ENGINEERING_DOCTRINE_CONSOLIDATION.md
  - Status line: Slices 1-3 complete on main; Slice 4 in flight.
  - Sequential to-do table: rows 9-11 marked done with file pointers
    (cli/reporter.py + tests/test_cli_reporter_rca.py for the RCA block,
    pro/worker_logic.py + pro/engine.py + the parity test for the
    single-pass refactor); row 12 in progress in this commit window.

docs/plans/BENCHMARK_EVOLUTION.md
  - New section 8 'Pro path - current technical debt baseline'
    explains the recorded speedup_vs_opencore = 0.574 from
    tests/benchmarks/official_benchmark_200k.json in plain English:
    Pro is ~1.74x slower than OpenCore in this profile because the
    lab host runs the Python fallback (no Rust extension yet). Names
    the precision invariant pro_hits == opencore_hits (Luhn + CPF +
    email parity) and the test that fails first if it is ever lost
    (test_benchmark_findings_parity).
  - Header Status block: lists which slices are doc-only vs code,
    points to the two parity test files.
  - Revision log: 2026-04-27 row that summarizes the cycle.

docs/plans/PLANS_TODO.md
  - Integration thread bullet rewritten so testers and contributors
    see Slices 1-3 as done and Slice 4 governance refresh as the only
    remaining piece, with file paths to both pin tests.

No code changes. The 200k JSON evidence artifact is intentionally left
untouched so the operator's next lab run can record the algorithmic
delta against the recorded baseline (publication truthfulness rule:
do not invent benchmark numbers from the agent VM, where wall-time is
not comparable to lab hardware).

Co-authored-by: Fabio Tavares Leitão <[email protected]>
Comment thread cli/reporter.py
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(md, encoding="utf-8")
return 0
except BaseException as exc: # noqa: BLE001 — RCA must observe every failure mode
FabioLeitao and others added 2 commits April 27, 2026 15:36
Fixes Lint (pre-commit) ruff-format check after conflict resolution on PR #236.

Co-authored-by: Fabio Tavares Leitão <[email protected]>
@FabioLeitao
FabioLeitao marked this pull request as ready for review April 27, 2026 18:46
@FabioLeitao
FabioLeitao merged commit 93e2814 into main Apr 27, 2026
1 check passed
@FabioLeitao
FabioLeitao deleted the cursor/sre-agent-protocol-4c97 branch April 27, 2026 18:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants