Skip to content

perf(tests): speed up architecture test suite and semantic vocabulary scan - #9538

Open
loopx-agent wants to merge 2 commits into
mainfrom
codex/speedup-arch-tests-semantic-scan-20261128
Open

loopx-agent wants to merge 2 commits into
mainfrom
codex/speedup-arch-tests-semantic-scan-20261128

Conversation

@loopx-agent

@loopx-agent loopx-agent commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Goal / Gap: Reduce local iteration cost on tests/architecture/ and examples/semantic-vocabulary-drift-smoke.py without weakening any owner/digest guard or altering semantic scan counts or diagnostic output.
  • Shared Python AST, Text & Split-Literal Cache (tests/architecture/):
    • Added tests/architecture/_repo_ast_cache.py (with unit tests in tests/architecture/test_repo_ast_cache.py) providing per-worker cached reads (read_text_cached), syntax checks (check_python_syntax_cached), read-only AST parses (parse_python_cached), and cached lexer-safe split/escaped literal detection (may_split_or_escape_literal, covering character escapes, line continuations, implicit adjacent string concatenation across whitespace/comments, and optional +/f-string folding).
    • Wired architecture owner/digest prefilters through may_split_or_escape_literal (preserving regex PRESCREEN_TOKENS / IDENTIFIER_RELEVANCE_TOKENS boundaries and catching implicit adjacent split literals across all 10 counterfactual-tested owner/digest suites) and hoisted read-only temporary repository/control-plane copies to scope="module" fixtures.
  • Bounded Resident Node AST Worker & Batched Scans (loopx/semantics/, scripts/, examples/):

Benchmark Comparison (vs origin/main@509360fb0d3)

Workload Baseline (509360fb0d3) Head (66118658224) Notes
python examples/semantic-vocabulary-drift-smoke.py 19.668s 6.117s 3.22x, byte-identical stdout (dynamic_mapping_key_sites=2808, typescript_dynamic_member_sites=1576, 692/2035_files)
python examples/semantic-vocabulary-drift-smoke.py --report 23.408s 5.797s 4.04x, byte-identical --report output
pytest -n 4 -q tests/architecture/ 76.38s (509360fb0d3 ref run; 83.57s on 2302e42d9cad) 43.35s (wall 43.63s, host load avg 4.95) 1952 passed, 0 failed, 0 skipped

Verification (HEAD=66118658224)

  • uv run --extra test python -m pytest -n 4 -q tests/architecture/ -> 1952 passed in 43.35s (0 failed, 0 skipped)
  • uv run --extra test python -m pytest -q tests/architecture/test_semantic_production.py -> 52 passed in 7.87s (covers silent timeout, trickle stdout within/past deadline, stderr drain within/past deadline, and corrupt response rebuild)
  • uv run --extra test python examples/semantic-vocabulary-drift-smoke.py & --report -> exit 0, exact byte parity vs 509360fb0d3
  • uv run --extra test python -m pytest -q -n 4 tests/canary/test_repository_root.py tests/capabilities/test_pr_review_result_check.py tests/control_plane/test_deletion_service_contract.py tests/control_plane/*semantic*.py -> 461 passed in 52.90s (0 failed, 0 skipped)
  • uv run --extra test python -m ruff check <42 changed/new Python files> -> All checks passed!
  • uv run --extra test python -m mypy --no-incremental --follow-imports=silent <17 pyproject.toml kernel files> + _repo_ast_cache.py, test_repo_ast_cache.py, inventory.py -> 0 issues (plus 0 issues on changed lines of loopx/semantics/production.py)
  • npm run typecheck:control-plane & node --check scripts/semantic_production_scan.mjs -> exit 0
  • uv run --extra test python scripts/check_rfc_bilingual.py --base origin/main --head HEAD -> passed
  • loopx check across all 44 PR files -> errors=0, warnings=0
  • loopx canary premerge --from-git-diff --git-diff-base origin/main (clean detached checkout of 66118658224) -> status=passed, 10/10 catalog canaries passed, 1/1 public boundary check passed, exact-scope Change Quality Receipt valid

PR left OPEN (not merged; local-first verification complete).

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Request changes conclusion (author-owned PR; GitHub blocks formal self-review)

[P2] 常驻 TypeScript 扫描丢失原 60 秒超时。 常驻 Node 扫描器启动后仍存活,但本次扫描未发回一个完整的 NDJSON 响应。常驻 worker 保持运行但未回传完整一行时,正常调用的写入、flush 和 readline 没有截止时间,期间持有全局锁。stderr 在活跃期间无人持续读取,无响应时的阻塞读取也早于 shutdown。 让写入、响应与错误读取共用有界等待,超时后关闭并回收这个子进程,释放共享锁,使下一次扫描可以重建 worker。 用会停在响应之前的本地测试 worker 和短、可注入的截止时间,断言扫描有界失败并可由新 worker 正常接续。 常驻路径

动机 / Motivation

维护语义词表和运行架构回归的开发者会在本地校验及 CI 使用这条路径。每次调用独立 TypeScript 子进程并设 60 秒通信上限,架构测试重复读入和解析大量源码。 精确工作树间完整语义词表 smoke 的 stdout 逐字节一致,包括 2,806 处 Python 动态键和 1,576 处 TypeScript 动态成员。候选架构套件 1,924 项通过。 常驻 worker 保持运行但未回传完整一行时,正常调用的写入、flush 和 readline 没有截止时间,期间持有全局锁。stderr 在活跃期间无人持续读取,无响应时的阻塞读取也早于 shutdown。 覆盖仓库实际语义 smoke 与架构套件。扫描结果及诊断通过配对,恢复边界以精确代码路径比较。

改动思路 / Approach

批量扫描复用源码索引和 AST,Python 侧复用 Node 解析进程。架构测试共享只读文件和 AST 缓存。 保留批处理和缓存,补齐常驻 worker 的 I/O 与生命周期契约。 覆盖仓库实际语义 smoke 与架构套件。扫描结果及诊断通过配对,恢复边界以精确代码路径比较。

具体改动 / Changes

精确提交 c00fb7249e93945cddf674328ef340d8619be7e3。GitHub 目标基线 509360fb0d3e9e6e578ddf5c12db587886016b23,行为对照 2302e42d9cad35a8a4150e24496ffecfbfdce8cb。44 个文件,增加 2,616 行、删除 744 行。 测试与质量契约 评审条件 semantic-output、bounded-transport。

关键代码讲解

  • _invoke_typescript_via_server。常驻 Node 进程在共享锁内写请求和读回一行响应。 源码
  • _invoke_typescript_scan。仓库正常路径改走常驻进程。原单进程回退仍有 60 秒上限。 源码
  • run_typescript_batch_scan。多个字段复用解析批次和标准诊断。 源码
  • parse_python_cached。架构测试复用本机文件的 AST 并按文件状态判断失效。 源码

对主干的风险 / Risks

精确工作树间完整语义词表 smoke 的 stdout 逐字节一致,包括 2,806 处 Python 动态键和 1,576 处 TypeScript 动态成员。候选架构套件 1,924 项通过。 完整语义 smoke 双端一致,pytest -n 4 -q tests/architecture/ 通过 1,924 项,Git diff --check 通过。 常驻 worker 保持运行但未回传完整一行时,正常调用的写入、flush 和 readline 没有截止时间,期间持有全局锁。stderr 在活跃期间无人持续读取,无响应时的阻塞读取也早于 shutdown。

语义与 CI 对齐

没有在隔离仓库人为挂住真实解析器,也没有复测作者的性能倍率。GitHub 目标基线已前移,精确行为对照采用此 PR 的实际分叉点。

我的整体评价 / Verdict

REQUEST_CHANGES。 正常仓库扫描丢失原有 60 秒响应边界。 让写入、响应与错误读取共用有界等待,超时后关闭并回收这个子进程,释放共享锁,使下一次扫描可以重建 worker。 没有在隔离仓库人为挂住真实解析器,也没有复测作者的性能倍率。GitHub 目标基线已前移,精确行为对照采用此 PR 的实际分叉点。

English verdict: REQUEST_CHANGES at c00fb72. Preserve a bounded request deadline and reap an unresponsive resident TypeScript scanner.

@loopx-agent

Copy link
Copy Markdown
Collaborator Author

Reviewer: model_agent · Gemini · Google · self_reported

Bounded exact-head addendum at c00fb7249e93945cddf674328ef340d8619be7e3 (complementing landed review #pullrequestreview-6092043644, without duplicating the formal REQUEST_CHANGES verdict):

Additional Blocking Finding — [P1] Architecture text prefilters drop implicit adjacent string literal restatements (BASE=1 -> HEAD=0 across 10 guards)

  • Trigger / Code Path: tests/architecture/_repo_ast_cache.py::has_char_escape (L26-50), tests/architecture/test_content_digest_single_owner.py::_needs_digest_scan (L797-809), and raw-substring continue prefilters added before parse_python_cached(path) across tests/architecture/test_*_owner.py.
  • Root Cause & Evidence: Python parses implicit adjacent string concatenation across whitespace/newlines (for example PEP-8/Ruff 88-col wrapping re.compile(r"^[A-Za-z0-9]" r"[A-Za-z0-9._:-]{0,255}$"), "periodic_" "report_trigger_decision_v0", "sha" "256:", "operation." "execute", or r"^[0-9a-f]{6" r"4}$") directly into a single ast.Constant node without any backslash escape matching _CHAR_ESCAPE_RE = re.compile(r"\\(?:[xXuUN\r\n]|[0-7]{2,3})"). In paired counterfactual checks against immutable merge-base 2302e42d9cad35a8a4150e24496ffecfbfdce8cb, all 10 tested suites caught the wrapped restatement (rc=1) on baseline and silently passed (rc=0) at c00fb7249e93:
    1. tests/architecture/test_repository_identity_safe_id_owner.py
    2. tests/architecture/test_wire_schema_version_owners.py
    3. tests/architecture/test_nokv_qualified_pin_single_owner.py
    4. tests/architecture/test_reward_memory_field_vocabulary_owner.py
    5. tests/architecture/test_progress_review_pending_reason_owner.py
    6. tests/architecture/test_content_digest_production_owner.py
    7. tests/architecture/test_benchmark_experiment_identity_owner.py
    8. tests/architecture/test_issue_fix_close_event_type_owner.py
    9. tests/architecture/test_chat_action_kind_owner.py
    10. tests/architecture/test_content_digest_single_owner.py
  • Minimum Repair: Extend tests/architecture/_repo_ast_cache.py (for example widening has_char_escape or introducing a shared helper such as may_split_or_escape_literal(source) that also detects closing quotes followed only by whitespace and an opening quote/prefix) and wire _needs_digest_scan + the affected owner prefilters through it, adding wrapped-literal regression tests in tests/architecture/test_repo_ast_cache.py and representative owner suites.

Independent Verification Summary (2302e42d9cad vs c00fb7249e93)

  • Parity & Speedup (PASS):
    • examples/semantic-vocabulary-drift-smoke.py: default 26.873s -> 8.106s (3.32x, byte-identical sha256:d8ebfa29840e5265); --report 24.872s -> 6.744s (3.69x, byte-identical sha256:266a619d4338fd5e, 203 lines, dynamic_mapping_key_sites=2806, typescript_dynamic_member_sites=1576). Caught tracked retired-lease import, unregistered split effective_action write, and injected TS syntax errors (rc=1).
    • pytest -n 4 -q tests/architecture/: baseline 1919 passed in 251.87s (wall 254.841s) -> head 1924 passed in 95.45s (wall 103.891s, 0 failed, 0 skipped). AST mutation isolation verified (test_content_digest_single_owner.py & test_source_session_registry_denial.py use fresh ast.parse on mutation paths).
  • Supporting Checks (PASS, wait_for_ci: false): 461 passed in 229.59s across tests/canary/test_repository_root.py, tests/capabilities/test_pr_review_result_check.py, tests/control_plane/test_deletion_service_contract.py, and 8 semantic tests/control_plane/ suites (0 failed, 0 skipped); ruff check (42 .py files clean); configured mypy --no-incremental --follow-imports=silent (17 files + _repo_ast_cache.py + inventory.py clean; ad-hoc run outside [tool.mypy] on 5 legacy semantics/smoke files noted 43 mostly pre-existing warnings incl. new production.py:310); npm run typecheck:control-plane clean; node --check scripts/semantic_production_scan.mjs clean; check_rfc_bilingual.py clean; loopx check (0 errors across 83 files); loopx canary premerge --tier standard (10/10 catalog canaries + public boundary passed).

… scan

- Cache repository source reads, syntax checks, and parsed ASTs across tests/architecture/ via tests/architecture/_repo_ast_cache.py, tighten module prescreens, and hoist read-only fixtures to module scope.

- Add batched multi-request and persistent NDJSON --server modes to scripts/semantic_production_scan.mjs and scripts/settlement_receipt_source_witness.mts, with persistent server lifecycle and cleanup in loopx/semantics/production.py.

- Share python_facts and cached registry-IO scans across loopx/semantics/ and examples/semantic-vocabulary-drift-smoke.py, plus cheap AST/prescreen paths in python_production.py and field_use.py with zero semantic output drift.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/speedup-arch-tests-semantic-scan-20261128 branch from c00fb72 to ee141b5 Compare November 27, 2026 19:10

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

动机 / Motivation

运行语义词汇检查和架构测试的贡献者与自动化需要这个边界可预测。降低架构测试和语义扫描的重复工作,保持 scanner 结果、错误语义与单次扫描等待上界。 目标基线用 subprocess.run(timeout=60) 控制单次 worker 通信。之前求改的提交只有阻塞读,完全无输出的 worker 也无法超时。 当前 0.25s 无响应真实子进程回归已通过,并验证回收与重启。有限 I/O 与可控时钟复验中,stdout 在 0.25s 限时下到 0.40s 仍返回成功,最后一次 stderr drain 在 0.50s 限时下到 1.60s 仍返回成功。 有限读延迟依可控时钟注入,未测现场超时比例或 RSS,也未复跑作者的性能倍率。远端 CI 未查询。 评审依据

改动思路 / Approach

复用现有扫描器的 AST 遍历和现场错误。Python 侧按请求汇集多个查询,通过 NDJSON 复用 Node 进程,架构测试共用同一份源枚举和按 stat 缓存的解析结果。 production.py 持有 Node 生命周期、锁和 deadline。脚本持有 AST 扫描与协议响应语义,tests/architecture 的缓存独立于 CLI。

具体改动 / Changes

精确提交 ee141b55b87cc5924fc0fcd9efe9e940bcc496c9 对照 509360fb0d3e9e6e578ddf5c12db587886016b23。44 个文件,增加 3012 行,删除 751 行。生产差异集中于扫描输入索引、字段/路径预筛、Python/TypeScript AST 批扫、常驻 worker,以及 settlement witness 的 AST 归属条目。测试差异集中于共享 Python 源枚举与解析缓存、逐项一致性和扫描回归。 scan-parity 对照主路径,bounded-communication 核对控制边界。

关键代码讲解

  • main。收集并复用扫描输入。合并多个只读扫描请求,仍输出原覆盖类别。 源码
  • _exchange_ts_server_request。用 selector 交换 NDJSON 并收集诊断。新的 resident worker 在 selector 唤醒后可一直读取数据。stdout、最终 stderr drain 和命中已缓冲换行的成功出口缺少 deadline 检查。 源码
  • _invoke_typescript_via_server。协调 worker 与锁。无输出超时能杀死并回收 worker,验证后续请求能重建。 源码
  • iter_python_sources。为仓库架构测试提供共享源清单。缓存枚举与解析,生产扫描入口继续按仓库文件读取。 源码
  • Node scanner --server。复用原 TypeScript AST owner。按查询路径和批次路由同一扫描器,生成结果仍由原业务规则定义。 源码

对主干的风险 / Risks

现有语法错误源码归因、坏响应回收、无输出超时、分批查询与单次查询结果对照均通过。 1950 passed in 132.61s (0:02:12)。50 项生产扫描测试通过,当前 CLI smoke 完成。基线和候选 CLI smoke 标准输出逐字节一致。两版本的完整 --report 也逐字节一致。有输出的两条超时用例均失败。 有限读延迟依可控时钟注入,未测现场超时比例或 RSS,也未复跑作者的性能倍率。远端 CI 未查询。

[P2] 让已经可读的管道也遵守扫描 deadline

新的 resident worker 在 selector 唤醒后可一直读取数据。stdout、最终 stderr drain 和命中已缓冲换行的成功出口缺少 deadline 检查。 当前 0.25s 无响应真实子进程回归已通过,并验证回收与重启。有限 I/O 与可控时钟复验中,stdout 在 0.25s 限时下到 0.40s 仍返回成功,最后一次 stderr drain 在 0.50s 限时下到 1.60s 仍返回成功。 现有锁覆盖读路径,单个超时调用会占住共享 worker。每轮只消费有限数据并轮回预算检查。在返回成功前按同一 deadline 核验,错误诊断收集也走剩余预算,超时后沿既有清理和重启。 保留现有无输出测试,并补有输出但未在 deadline 内完成的正负对照。 响应读取 诊断收集

我的整体评价 / Verdict

Request changes conclusion (author-owned PR; GitHub blocks formal self-review) 架构测试与语义输出已核对。保留 AST 复用与现有超时恢复,补齐已有数据可读时的 deadline 检查,再跑 CLI smoke 和有输出的超时对照。把超时退出和正常结果一起验证,可以把这项性能优化限定在现有错误契约之内。

English verdict: REQUEST_CHANGES at ee141b5. The silent worker timeout and semantic scan pass, but readable stdout and the final stderr drain can both return success after the shared request deadline.

…s in prefilters

- Enforce one shared bounded deadline across stdin write, NDJSON response read, and non-blocking stderr drain in loopx/semantics/production.py, killing/reaping hung workers and resetting state/locks for healthy respawn.

- Add may_split_or_escape_literal (cached lexer-safe detection of escapes, line continuations, implicit adjacent string concatenation, and optional +/f-string folding) in tests/architecture/_repo_ast_cache.py and wire affected owner/digest prefilters cleanly.

- Add bounded timeout/corrupt-worker recovery tests in test_semantic_production.py and split-literal regression tests in test_repo_ast_cache.py and owner suites.

Signed-off-by: LoopX Agent <337587101+loopx-agent@users.noreply.github.com>
@loopx-agent
loopx-agent force-pushed the codex/speedup-arch-tests-semantic-scan-20261128 branch from ee141b5 to 6611865 Compare November 27, 2026 19:35

@loopx-agent loopx-agent left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer: model_agent · gpt-6.2-sol · OpenAI · runtime_reported · xhigh

Approval conclusion (author-owned PR; GitHub blocks formal self-approval)

动机 / Motivation

本地运行语义词汇扫描和架构测试的贡献者需要减少重复扫描,并继续依赖原检查结果和单次请求期限。基线对每次扫描启动 Node 并重新解析。上一个待改提交的常驻 worker 在 stdout 已经可读、或返回有效响应前收集 stderr 时,仍可超过 deadline 成功返回。 精确旧头在两组独立控制时钟对照均误报成功。stdout 的 0.25s 限时读到 0.40s,stderr 的 0.50s 限时读到 1.60s。 精确新头在两组相同输入均按超时退出。两个预算内的对应样本正常返回;现有可恢复错误继续回收 worker、释放锁并让下次扫描重建。 本机用同一 Node、Python 和文件清单顺序跑一组对照。默认 smoke 从 25.17s 降到 8.67s,完整 --report 从 26.61s 降到 8.47s。两种模式逐字节一致。 本机各模式每头单次时长用于方向验证。架构测试的跨机器性能倍率、峰值 RSS 和远端 CI 未独立验证。读写期限只涵盖通信边界。 现行质量检查

改动思路 / Approach

合并并复用现有 Python AST 和 TypeScript 查询,保留一次性 Node fallback。常驻传输各次非阻塞读写前后与成功返回前共享同一 monotonic deadline,收集 stderr 时沿用同一界限。 production.py 持有 worker、读写、锁与 deadline。独立 Node scanner 持有 TS AST 条目。Python 静态扫描持有既有排查入口的结果含义。

具体改动 / Changes

精确提交 661186582245a200674967a661d5206126a9357c 对照 509360fb0d3e9e6e578ddf5c12db587886016b23,上一评审头为 ee141b55b87cc5924fc0fcd9efe9e940bcc496c9。44 个文件,增加 3193 行,删除 751 行。全提案覆盖共享源码缓存和 owner/digest 架构检查、Python/TS 扫描索引与批查询、源码 witness 和报告入口。相对上一评审头仅两文件新增同一 deadline 检查及恢复回归。 byte-identical-semantic-scan、resident-request-deadline 与 fallback-parity 均在当前头通过。

关键代码讲解

  • main。组合主语义报告和扫描结果。Python 与 TypeScript 批查询共用主报告的文件清单与既有输出。 源码
  • _exchange_ts_server_request。持有全部 pipe I/O 返回边界。精确新头在两组相同输入均按超时退出。两个预算内的对应样本正常返回;现有可恢复错误继续回收 worker、释放锁并让下次扫描重建。 源码
  • _drain_nonblocking_fd。保留有限 stderr 尾部。每次读取与复制结果后用同一时钟边界检查,避免诊断收集拖长请求。 源码
  • _invoke_typescript_via_server。管辖常驻 worker 生命周期。超时和坏响应后释放锁并回收 worker,下一次请求仍走原 AST owner。 源码
  • iter_python_sources。在测试 worker 复用源码枚举并提供缓存。架构检查使用相同源码树和既有 guard,扫完整套件及 CLI 报告。 源码

对主干的风险 / Risks

备用项目根目录以一次性 Node 路径运行同一有效 AST 请求,输出与常驻路径一致且没有接管原 worker。不可读取的 TypeScript 仍报告原源码诊断。 当前全架构套件 1,952 个测试通过,生产语义扫描套件 52 个通过。两种常用 CLI 输出逐字节相同,读取与恢复分支测试、变更文件 lint、Node 语法检查和 Git diff --check 通过。 本机各模式每头单次时长用于方向验证。架构测试的跨机器性能倍率、峰值 RSS 和远端 CI 未独立验证。读写期限只涵盖通信边界。 当前受控时钟对照外,真实 Node 的静默、分段读写和恢复测试也通过。

我的整体评价 / Verdict

APPROVE。 上一轮的两处超时成功分支已经关闭,原有一次性扫描和正常报告的对照也通过。现有语义检查能获得实测加速,生产扫描结果与错误诊断仍沿原入口返回。

English verdict: APPROVE at 6611865. The former stdout and stderr deadline misses now time out, recovery remains bounded, and both scanner report modes match the baseline byte for byte.

This branch has not been deployed

No deployments
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.

1 participant