Skip to content

fix: retain service owners during construction - #29676

Merged
XuPeng-SH merged 21 commits into
mainfrom
codex/quality-29249-owners-20261007
Oct 9, 2026
Merged

XuPeng-SH merged 21 commits into
mainfrom
codex/quality-29249-owners-20261007

Conversation

@XuPeng-SH

@XuPeng-SH XuPeng-SH commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

  • API-change
  • BUG
  • Improvement
  • Documentation
  • Feature
  • Test and CI
  • Code Refactoring

Which issue(s) this PR fixes:

Refs #29249
Fixes #29639
Fixes #29640

What this PR does / why we need it:

Failed construction and teardown before Start could lose an acquired service owner or release dependencies while work was still active. This change publishes owners before fallible initialization, retains them through error, panic and Goexit, and retires them through the existing Close paths.

  • Publish and retain CN, TN, LOG, shard and lock allocator owners, including embedded and standalone callers. Gate public CN/TN wrapper operations through the existing construction mutex; publication alone does not make a backend ready.
  • Reuse idempotent, nil-safe aggregate Close for partial initialization. Move TN I/O startup after prerequisites, and close LOG RPC ingress before its data-sync consumer.
  • Seal async RPC admission, cancel admitted requests, close ingress, then join accepted jobs, including inline fallback. Reuse native codec cancellation only with matching Done/owner provenance; mixed contexts retain removable linkage. Future owns sender timestamps, and one typed helper serves sync/async execution.
  • Distinguish completed remote-withdrawal diagnostics from incomplete local cleanup. Complete owners can retire while preserving their diagnostic; incomplete owners retain dependencies and admission. Retire standalone file services after their borrowers.
  • Integrate the latest main engine ownership change into CN's aggregate construction rollback and dependency-ordered Close. Remove the superseded engine-only rollback. Ordinary construction failures retain both primary and cleanup errors; incomplete owners remain available, and repeated Close does not replay cleanup.
  • Give each shard test-fixture owner its own defer and retire its borrowed waiter afterward. A cleanup diagnostic or fatal reporting cannot skip another acquired owner. Capture published partial owners immediately so constructor rollback diagnostics remain observable.

The focused fixture regression reuses two real child services and checks listeners, cleanup counts, dependency order and original diagnostics across healthy, Close-error, fatal-report, constructor-panic and constructor-Goexit cases. A small reporting callback keeps expected failure diagnostics inside the test without a subprocess or production hook.

Design and review

The versioned v3 design and distinct design approval cover the production ownership and request-lifecycle design. The original implementation predated its public design; that historical gap remains disclosed.

The cleanup fix and rebase integration received separate actual gpt-6.1-sol / xhigh design gates through Codex CLI session 01a11dbc-8cc7-73e1-be03-c4808e2df2d3. Final overall review of 560c8aa148cea14ea237425075018147e5c45458: APPROVE, no unresolved material findings, actual gpt-6.1-sol / xhigh, same recorded session. Review artifact SHA256 4cbfaf7765d18cf75ff3a640ebd3a5a06c98c225fe3e236f015c59ccfbe0cf0c; complete delivery diff SHA256 e00b60e813f9dabf87448b383294a647f87f40309c4f13f8a9dffdadf3309e83. Model selection and reasoning effort are verified from runtime turn metadata.

All four earlier substantive inline findings remain resolved. The subsequent fatal fixture-cleanup finding is addressed by independent owner defers and nonfatal default reporting.

Validation

Final revision 560c8aa148cea14ea237425075018147e5c45458, rebased onto main 56871479fb9ce39f4ef4487d4e1e51d02ba7ba8e; Darwin arm64, Go 1.27.1, GOMAXPROCS=4, verified matching CPU native artifacts:

  • Complete CN and shardservice packages pass normally and with race, -count=1: 305 and 84 named tests/subcases per mode, no skips.
  • Standalone wrapper owning package short normal/race: 63 named passes and 14 existing heavy skips per mode. The skips are not counted as passes; previously verified unrestricted standalone fixture limitations remain disclosed.
  • Real embedded-cluster SQL, dynamic CN expansion and close, plus constructor/retained-owner controls: 8 named passes per mode. Engine scheduler/constructor/GC ownership boundaries: 11 named passes per mode.
  • Exact new/changed fixture, CN constructor, producer-drain and shutdown-order tests each pass 100 bounded race repetitions. No whole-package repeated stress.
  • Negative overlays delayed fixture ownership capture and removed CN cleanup-error joining. Both fail at the intended actual diagnostic/error-chain assertions and exit normally; no overlay is delivered. The original fatal aggregate cleanup also has real-listener normal/race reproduction and nonfatal controls.
  • Formatting/diff checks and incremental go vet, configured molint and golangci-lint 2.14.0 cover all nine delivery packages plus queryservice and tests/upgrade consumers. All exit 0; golangci reports 0 issues. Molint retains exactly the two previously verified baseline diagnostics in lockservice test_helper.go and txn_test.go, with no new diagnostic.

Earlier complete-PR runtime, race, consumer and CI evidence is reused only for unchanged ownership/RPC/native/dependency inputs. The rebase changed CN and engine interactions, so those boundaries have fresh runtime proof above. The interrupted pre-rebase race command is excluded. New-head CI is pending after publication.

Performance and complexity

This follow-up adds no production hot-path state or worker; error joining occurs only during failed construction. The shard fixture uses existing owners and lexical defers, with no cleanup registry. Its five-case regression body took about 0.01 seconds in normal/race measurement.

Historical Go 1.27.0 paired samples against the original PR base showed codec/async allocations decreasing 15 to 13, with approximately 131 ns (10.7%) extra primitive cost; real RPC samples did not show a consistent slowdown. RPC source, native inputs and relevant dependencies remain unchanged by this follow-up. These are historical scoped measurements, not a new SQL/TPCC throughput result.

Existing owner collections, lifecycle/status authorities and Close paths remain authoritative. Superseded rollback, unused owner/config fields, duplicate request bookkeeping and escaping execution wrappers are removed.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@mergify mergify Bot added kind/bug Something isn't working kind/enhancement kind/test-ci kind/refactor Code refactor labels Oct 7, 2026
@matrix-meow matrix-meow added the size/XL Denotes a PR that changes [1000, 1999] lines label Oct 7, 2026

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

REQUEST_CHANGES at 4085d574825e9f3e23c60ebf359cf330d5406f21, against declared base/merge-base f20f5ca147c44b012343d0f48dfcd84b6a5986a1. Main-session independent deep review, no subagents. This is a self-authored PR, so the decision is submitted as COMMENT, not a formal GitHub REQUEST_CHANGES event.

One newly verified P2 remains in CN test-service construction/publication (inline below). An external probe pauses the real newCNService -> cnservice.NewService at the metadata file-service prerequisite after the same collection publication used by initCNServices, then invokes the actual public indexed lifecycle operations. CloseCNServiceIndexed completes and permanently marks the wrapper closed before construction finishes; StartCNServiceIndexed panics on the nil backend. Both fail deterministically under -race, with ordinary assertion failures and independently released/joined constructor cleanup. A lock-only control prevents premature Close (normal and race); restoring the old publication location prevents the Start panic. Controls isolate the cause; they are not a delivered fix. This new evidence supersedes the prior overall approval.

Root cause: retaining a partial cleanup owner was conflated with publishing an operationally initialized service. The existing constructor tests exercise unwind and post-construction cleanup, but omit concurrent consumers during publication. The design explicitly forbids exposing the partial service concurrently; the CN wrapper does not implement that boundary. The analogous TN constructor already holds its wrapper mutex. Complete the CN handoff, including the later cancel installation and public getters/lifecycle operations, through the existing ownership/serialization mechanism rather than adding a second state machine.

The three previous implementation/test findings remain resolved: shutdown cancellation before join, actual-parent completion-vs-diagnostic handling, and bounded shard-test cleanup. The public design artifact/approval gap is also closed. No new blocker was found in the RPC optimization or the other ownership closures.

Coverage: every changed hunk across all 40 files / nine closures read, owners/callers and terminal paths traced. Full diff SHA256 8454c7ddb7d24289cbddc73cdfab3a4112694bc1058c0fb2b99a21a954325701; all 40 source/doc hashes match delivered evidence. Valid evidence reused includes exact-current morpc normal/race (510 named test/subcases each), focused close/provenance race repetitions, four bounded mutation controls, and configured incremental SCA, plus semantically unchanged constructor/parent/real embed SQL/restart evidence. The previously disclosed unrestricted tests/service baseline failure and short-mode skips are not claimed green.

Costs reviewed separately: implementation +583/-235 (net +348), _test.go +1425/-71 (net +1354), docs +103. Existing fixtures and most added oracles are distinct, but the newly found publication gap means volume did not establish lifecycle completeness.

Performance evidence remains scoped: final versus 7296339, actual codec/async dispatch 17 -> 13 allocations and about1244 -> 944B/op; real RPC100-caller median sync/async/mixed changes -2.0%/-1.6%/+1.0%, with overlapping samples/outliers. This supports lower allocation, not zero-overhead or a SQL/TPCC throughput guarantee. No tracked code changed during this review. Current head is unchanged; UT/SCA/coverage/BVT CI is still pending, not passed. No merge.

Comment thread pkg/tests/service/cnservice.go Resolved

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Semantic decision: APPROVE for 9355809

The publication-window P2 in discussion_r4216990632 is fixed and verified. This supersedes the previous semantic REQUEST_CHANGES review at 4085d57. Final independent model review used actual gpt-6.1-sol / xhigh (session 01a11ad3-fba3-7db2-89c9-cd4e18d21902), reconciled all 40 files/nine closures, and found no unresolved material blocker at content fingerprint 6d2621f1041ef3a33337267efd360112bb955ac116eb8cd77c0c3fa82f7e6455.

The fix reuses existing mutex/status/Close ownership, removes late cancellation wiring, guards operational access through construction and failed cleanup, and synchronizes the existing collection/parent boundaries. It adds no RPC hot-path work or new state machine.

Fresh local normal/race owning-package tests pass 63 named cases each with 14 disclosed existing heavy skips. Each exact new concurrency test passed 100 race repetitions (800 named case passes in total, no skips); four independent omission controls failed the intended bounded oracles. Formatting/vet/molint/incremental lint pass. Other 34 files and RPC benchmark inputs are byte-identical to prior valid evidence.

Limit: legacy standalone SQL/expansion integration is not claimed successful; exact prior-head Runtime failure and an external registration-overlay TN-report failure before CN construction remain disclosed. Healthy public wrapper witnesses and unchanged real kernel/embed evidence cover this focused correction. Neither zero overhead nor SQL throughput gains are claimed. New-head CI remains a separate pending merge condition.

This is a COMMENT with an explicit semantic approval because the authenticated account is the PR author; it is not a formal external GitHub APPROVE.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

APPROVE / no new material blocker at 93558093badac0cb9578fafad871d332c4779bbe, subject to required CI. Independent deep review in the main session, no subagents and no source changes.

All four substantive findings are fixed and all four review threads are now resolved: async cancellation before ingress close/join; parent consumption of CN local completion with diagnostics preserved; bounded shard-test failure/independent cleanup; and early-publication readiness/cancellation handoff. Existing holders/collections, aggregate Close and lifecycle mutexes remain the owners. No new request registry, retry state machine or parallel execution path is introduced. The new join covers ants jobs that raw RPC Close cannot join; native parenting and removable linkage are mutually selected, with Done + owner provenance preventing detached/foreign contexts from bypassing cancellation. The shared typed execution body and sole Future timestamp remove redundant closure/assertion/storage while preserving cleanup, metrics and liveness semantics.

New independent QA uses the real TN constructor after a backend is acquired/published, then triggers HA-factory error, panic and Goexit. Actual public indexed operations reject restart/unavailable getters, repeated Close succeeds, blockio is not acquired, and borrowed FS Close count stays zero with write/read still working. Ordinary/race pass; exact selected race100 passes all three cases each repetition. Reconciled unchanged final evidence includes package normal/race, publication/unwind race100, four bounded omission controls, full morpc + shard/query consumer evidence and configured SCA. No compile-only or skipped test is counted as a runtime pass.

I also compared the declared PR base f20f5ca1 with this head, rather than only optimization-before 7296339. Identical precompiled fixtures, GOMAXPROCS4, four alternating pairs per case; mixed4 had a fixed six-pair extension and all ten pairs are retained. Real RPC sync/async/mixed allocations fall 28/29/28 -> 26/27/27. At100callers median ns changes are -7.0%/-3.4%/-4.9%; at4callers -0.3%/+2.0%/+0.4%. Initial mixed4 +7.5% does not persist in the full ten-pair set. The codec+async primitive still costs 131ns (+10.7%) versus pre-fix base, with allocations15 ->13. CPU/mutex profiles were examined; parent cancellation registration/removal and admission/join are real safety work. These results establish lower allocation and no consistent real-RPC regression in these samples, not zero overhead or a SQL/TPCC throughput guarantee.

Full delta is implementation+661/-255 (net+406, includes test support), tests+1643/-71 (net+1572), docs+105. Test additions cover distinct ownership, failure, provenance and readiness contracts with shared small fixtures; their size was separately reviewed, not exempted. No newly confirmed unused abstraction, duplicate state/storage/execution or obsolete wiring needs another cleanup patch.

Limits: whole standalone short normal/race has63named passes and14existing heavy skips each. The unrestricted real standalone TestClusterStart is not green: its Config.Validate runtime failure reproduces before this fix; a runtime-registration-only probe then stalls at TN reporting before CN construction. That probe is not counted as a pass or attributed as a new regression. Unchanged production embed/kernel consumer proofs are narrower controls. Required CI is still running, with no failure observed at this review snapshot; await its terminal results before merge.

The posting account is the PR author, so this records semantic APPROVE via COMMENT; it is not GitHub's formal external APPROVED state.

@XuPeng-SH XuPeng-SH left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Semantic decision: APPROVE for code/design at a75f980, subject to required CI. Submitted as COMMENT because GitHub does not permit the author to formally self-approve. Main-session deep review and independent QA; no subagents or source edits.

Reviewed the complete 41-file scope against declared base/merge-base f20f5ca. No new confirmed blocking finding. The previous four substantive comments are fixed by actual behavior and all four threads are resolved: cancel before async join, parent consumption of local completion despite diagnostics, bounded failed-stop test with independent cleanup, and construction publication/operational handoff. Constructor rollback uses aggregate Close and existing caller holders; async cancellation uses existing context ancestry/removable linkage plus one admission/join boundary; dispatch and sender timestamp have one owner. No duplicate request registry or execution body was introduced.

New independent QA: inject a diagnostic error after the real underlying RPC Close. Real-wire async, mixed async, inline ants-rejection fallback, mixed inline and sync all preserve the error and wait for handler completion, including concurrent/repeated Close. Normal/race pass all five scenarios; adaptive race count100 passes 500 scenario results plus100 parent results, zero skips. An external mutation that returns on RPC Close error before async join fails normally at “Close returned before handler finished” in0.325s; independent cleanup completes. No overlay is delivered. Prior complete owner/consumer/SCA evidence is reused only after exact-content reconciliation; the latest LOG fallback correction independently passed focused normal/race, race100, static checks and a delayed-fallback negative control.

Costs assessed separately: implementation +661/-255 (net406), tests +1653/-71 (net1582), docs +105/-0. Test additions cover different acquisition, completion, cancellation, provenance and publication contracts using existing fixtures; test volume is not treated as proof of sufficiency.

Limits: performance is not zero cost. Original-base paired evidence shows codec/async primitive +131ns (+10.7%), with fewer allocations; complete real-RPC samples show no consistent regression, not a SQL/TPCC guarantee. The unrestricted standalone journey remains unproven: baseline runtime/config failure and a pre-CN TN-report stall are disclosed; short-mode heavy skips are not passes. The unchanged fallback1s wall-clock assertion retains scheduler sensitivity. Required remote CI must pass before merge. Further QA challenges requested by the user continue separately; their outcomes are not pre-claimed here.

Additional black-box QA after review publication: two real method servers share one client. Eight admitted requests on the first owner all observe shutdown cancellation; a held exit barrier proves Close cannot return early. The second owner successfully answers over the same client both during first-owner drain and after first-owner retirement. Ordinary/race1 and adaptive race100 pass (100 named repeats, zero skips), with no delivered source changes. This closes a real-wire multi-request/owner-isolation gap beyond the earlier single-request and context-level isolation controls. It does not claim whole standalone/workload coverage.

Further independent QA: actual malformed peers target a live all-async method server while eight requests remain admitted on another connection. A headerless complete frame and a deadline-header/trace-truncated complete frame are each rejected by closing only the offending connection (EOF observed, not timeout). Healthy requests to the same server still return correct responses after each rejection; existing borrowers remain uncanceled until intentional owner shutdown, and the other server/shared client stays usable. Ordinary/race1 and adaptive race100 pass with zero skips. White-box tracing confirms failed decode cancels the per-frame timeout child, not the owner root; pre-handoff cancellation ownership and native provenance remain unchanged. External overlays only; delivered source is clean. No new defect is established. Full standalone and production-workload evidence limits remain unchanged.

@XuPeng-SH XuPeng-SH left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Deep review verdict: APPROVE recommendation (self-authored PR; COMMENT) on 560c8aa148cea14ea237425075018147e5c45458. Performed directly without subagents.

Ownership and design: wrappers publish and retain acquired owners during construction; the existing service mutex serializes construction/start/close. Admitted RPC work is canceled and joined before dependent resources retire, and completion certification remains distinct from diagnostic close errors. The rebased CN constructor now uses established Service.Close -> Engine.Close for unwind, removing the overlapping engine-only cleanup defer. Unknown producer-drain failures retain the engine and dependencies.

Latest rebased41-file scope reconciled:38PR files are byte-identical to the previously reviewed revision; all differences in cnservice/server.go, server_test.go and shardservice/service_test.go were read, and new-base disttae scheduler/push-client/statistics lifecycle dependencies were traced. Current production +657/-261, tests +1977/-138, docs +105.

Fresh native build and exact-head race -count2 validation pass: actual NewService error/cancel/panic/Goexit and cleanup-error paths, incomplete-producer preservation, increment -> engine -> transaction-client close order and repeated Close; actual two-owner shard listener/borrowed-waiter cleanup including fatal reporting and constructor panic/Goexit; actual Engine.New acquired-pool retirement and scheduler ownership controls. cnservice3.510s, shardservice2.804s, disttae2.066s. Qualified prior wire-RPC cancellation/close, owner-isolation and malformed-frame evidence was reused with matching-source reconciliation.

No verified blocking finding remains; historical actionable comments are closed and the prior merge conflict is gone. Existing performance evidence shows fewer request allocations while the codec capability check has a small measured primitive cost; no universal zero-overhead claim or fresh fleet/BVT throughput result is made. Latest-head CI was still running at the refresh.

GitHub prevents authors from formally approving their own PR. This submitted COMMENT records the completed review and APPROVE recommendation; it is not an independent GitHub APPROVE event.

This branch was previously deployed

1 inactive deployment
ci — 90999523 Deployed Oct 9, 2026 by XuPeng-SH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working kind/enhancement kind/refactor Code refactor kind/test-ci size/XL Denotes a PR that changes [1000, 1999] lines

Projects

None yet

3 participants