Skip to content

fix: reject mixed-generation ordinary dataset query results - #261

Merged
codeasier merged 4 commits into
mainfrom
fix/252-query-generation-guard
Oct 11, 2026
Merged

codeasier merged 4 commits into
mainfrom
fix/252-query-generation-guard

Conversation

@codeasier

@codeasier codeasier commented Oct 11, 2026 •

Copy link
Copy Markdown
Owner

Depends on #255; infrastructure ancestry is included. This PR intentionally leaves #252 open because its signal-cleanup requirements remain unresolved.

Summary

Refs #252. This change covers deterministic concurrent readers and interruption boundaries, and fixes the mixed-generation query-result bug uncovered by the mutation acceptance tests.

  • Exercise 2 and 4 independent readers in both threads and spawned processes on one dataset, through ATTACH and scratch routes. Barriers follow real SQLite operations; readers own distinct analyzers/connections, return identical complete results, preserve source hashes, and clean up their separate scratch directories on normal completion.
  • Exercise the real CLI after a completed scratch lifecycle insert with normal completion, SIGINT, SIGTERM, and SIGKILL. No test signal handler or reclamation implementation is introduced.
  • Before publishing any ordinary dataset query result, run the same generation/content guard already used by report composition, with the existing operation deadline and strong/immutable cache contracts.
  • Cover API and real JSON CLI, rows and count-only results, unchanged and in-place-mutated test-owned data, default and explicit immutable cache modes, final-guard timeout, and exact hash work.
  • Document the behavior and evidence limits in English and Chinese.

Bug reproduction and fix

Previously, an event query paused after first-shard hydration could return old allocated values for IDs 0–9 and values increased by 10,000 for IDs 10–79, without an integrity error. A count-only query could likewise combine counts from different generations. QueryService only applied its final guard to an internal _resolved report path.

The focused fix makes that existing guard unconditional for dataset queries. The deterministic mid-query mutations now raise DatabaseSchemaError; JSON CLI exits 1 with DATABASE_SCHEMA_INVALID, no stdout and no partial rows/counts. Unchanged queries retain their complete expected results.

This guard is change detection, not an atomic filesystem snapshot. The tests do not prove every change-and-restore race impossible. Existing strong/immutable assumptions remain in force.

Cost and signal limitations

Default verification adds one complete manifest/member hash pass to ordinary dataset queries. On the 8-member, 80-event compatibility-v1 fixture, the added pass is 9 hash calls / 132,113 bytes. Total cold/warm query counts are 27 / 18 calls and 396,339 / 264,226 bytes. Explicit POSIX immutable mode adds zero final hash scans; cold admission is 10 calls / 133,154 bytes, warm zero. No wall-time or RSS threshold is claimed.

Observed current signal behavior after a real insert:

  • Normal completion and SIGINT: product cleanup removes scratch; source hashes unchanged.
  • SIGTERM: exit -15; private pt-snap-lifecycle-* directory and derived.db remain.
  • SIGKILL: exit -9; the same residue boundary remains.
  • Neither abrupt termination publishes partial query output or changes source bytes.

The last two cases are passing characterization of an unresolved limitation, not acceptance of #252's requested no-residue kill behavior. Test teardown is never counted as product cleanup. A SIGTERM handling contract and any out-of-process/startup reclamation policy for SIGKILL require a separate decision and implementation.

Verification

  • Original 33 focused tests passed in 10.35 seconds on Linux / Python 3.12. The final infra + portability union passes 123 focused tests in 14.22 seconds, including all 37 new cases, provenance, CI tiers, acceptance-runner, governance, release, and wheel-audit contracts.
  • Original frozen runtime at 31acd7c, byte-identical to this final branch, passed the regular suite: 2640 passed, 14 skipped, 13 slow deselected in 333.00 seconds. The 14 skips are 12 existing browser cases (Chromium unavailable) and 2 intentionally unsupported slice-leak cases; none of the original 33 new cases skipped on this Linux run. The regular suite was not redundantly repeated for the additive reviewed-infra union and test/docs-only portability follow-up.
  • The 6 existing [test][P1] 规模、路由、预算、超时与并发的端到端覆盖 #252 timeout/error cases also passed against this branch's runtime source, pinned for both API and spawned CLI (4.01 seconds).
  • Ruff, Black, git diff --check: passed.
  • basedPyright: 0 errors (existing informational warnings remain).
  • New cases are small and unmarked. Actual signal cases require POSIX; hash accounting runs on every platform and adds a deterministic resolver-local non-POSIX simulation. No extra million-scale/nightly node is introduced.
  • Default strong warm reuse remains content-verified on every OS. Explicit immutable non-POSIX queries repeat cold admission and the full final hash guard: cold and warm each use two scans/member plus three manifest scans. No runtime cache behavior or guard is weakened.
  • Reviewed [test] 端到端测试缺口与 CI 分层 #248 CI infrastructure is inherited directly from remote-equivalent base 68d89670 (tree identical to local fe86fcff). Its compatibility/full/nightly separation is retained.
  • Existing timeout and six typed-failure contracts remain owned by the separate [test][P1] 规模、路由、预算、超时与并发的端到端覆盖 #252 route/failure change rather than duplicated here.

No live user snapshot, paid model, Mac execution, or external publication was used.

Commits

  1. ffd43e6 — concurrency and signal-boundary acceptance (byte-equivalent cherry-pick of ed06735).
  2. d63aa1a — ordinary-query generation guard and regressions (byte-equivalent cherry-pick of 31acd7c).
  3. 78e3e31 — platform-correct immutable hash accounting and deterministic non-POSIX regression; tests/docs only.

Publication base: 68d89670; final head: 78e3e317829a47b1b66c9d6b06ad84aed38827aa.
This PR leaves #252 open because the SIGTERM/SIGKILL cleanup policy remains unresolved.

Independent final review approved tree b65254fe5db5b3ff1fb44618f7959b06c7a4986b: 127 integration-focused tests passed; earlier runtime review passed 296 tests and 8 extra hidden-metadata/native/compatibility probes. All runtime source is byte-identical to the reviewed guard fix. Remote CI is pending.

Copy link
Copy Markdown
Owner Author

Latest-head CI verification (2026-10-11): commit 571fbb7e05349081b673db908bf0f216ab8d200c, Test run 38147252095 completed successfully. All seven applicable jobs passed (Python 3.10–3.13, lint/format/type checks, provenance, browser regression). Python 3.13: 2689 passed, 14 skipped, 1 deselected; coverage 93.17%. Wheel audit and clean-wheel Agent acceptance passed. The separate installed-wheel dataset/nightly job was intentionally skipped on the PR event; this is not remote nightly verification. Local scale evidence in the description/earlier comments remains separate. Draft status and issue status are unchanged.

Copy link
Copy Markdown
Owner Author

检视结论:approve

对照 #252 并发/信号 + 查询世代防护:对所有 dataset query 无条件 require_unchanged,修 mid-query 混代;默认 strong / immutable opt-in 合同保留。mutation / concurrency / signal 定向通过。SIGKILL 不保证清 scratch,测试已写明现状,可接受。

建议在 #258 之后、#263 之前合入(#263 依赖本 PR)。本评论不 approve/merge。

@codeasier codeasier left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

LGTM,已转为正式 PR。GitHub 不允许作者账号提交 APPROVE。建议在 #258 之后、#263 之前合。

Retain reviewed differential steps, all platform partitions and the unconditional generation guard. Query-service union matches independently reviewed combined runtime.

Copy link
Copy Markdown
Owner Author

已按授权顺序与 #258 后的 main 25ae3ad48788433678e310093e5acb5e711abd27 集成。最新 head d254454bff75cc3d1c8d05a35c76dde7c828e1be,树 806cd10a0ed349e216baf5d9bd2224f11e63d8fb。

仅共享 CI 基础出现上下文冲突;保留当前 main 的 differential step/evidence 和平台分片。查询服务自动合并同时保留 zero-rank completeness 与无条件世代防护,最终 query_service.py 字节与此前独立审阅的组合运行时完全一致。原 #261 的并发/变更/信号用例保留,双语说明合并。

实际当前集成树 129 项定向检查通过,覆盖 provenance、concurrency、mutation、signal、zero-rank、differential runner/CI、platform、governance。远端新树与该验证树相同;新 head 的完整托管 Test/Platform CI 待验证。SIGTERM/SIGKILL 残留仍是明确记录的限制,本次不新增清理行为、不关闭 #252。

@codeasier
codeasier merged commit e5ce037 into main Oct 11, 2026
26 checks passed
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