Skip to content

fix(plugin): synchronize the InvokeWithExecutor reverse-server handoff (data race) - #74

Merged
atrawog merged 5 commits into
mainfrom
feat/plugin-grpc-race
Jul 12, 2026
Merged

atrawog merged 5 commits into
mainfrom
feat/plugin-grpc-race

Conversation

@atrawog

@atrawog atrawog commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Fix a data race in the F10 reverse-channel InvokeWithExecutor

A pre-existing concurrency bug I surfaced running the full suite under -race (its own immediate cutover per R2). grpcProvider.InvokeWithExecutor stands up the host's ExecutorService on the go-plugin broker for the duration of a deploy/step/check Invoke, so an out-of-process plugin can dial back to run shell/SSH ops on the host's real venue.

The race

The reverse gRPC server was held in a plain var srv *grpc.Server: the AcceptAndServe callback (running on the broker-accept goroutine) WROTE it, while the deferred Stop() (running on the InvokeWithExecutor goroutine, after Invoke returns) READ it — an unsynchronized cross-goroutine handoff. -race flags it (WRITE plugin_grpc.go:170 vs READ :187), exercised by the substrate-lifecycle e2e reverse-channel round-trip.

Root-cause fix

srv becomes an atomic.Pointer[grpc.Server]: the callback Stores the server it built, the deferred Load reads it (or nil — if the plugin never dialed back, the callback never ran, so nothing to stop). A real happens-before edge — not a serialize-to-hide and not a -race suppression. Reverse-channel behaviour is otherwise unchanged (+16/−7 in one file).

Verification (against current main, incl. P8b #70 merged)

  • go test -run TestSubstrateLifecycle_PrepareVenueDescriptorRoundTrip -race -count=10 — 0 data-race reports (was a hard DATA RACE failing the test under -race).
  • Full go test ./charly/... green (no regression); build clean; golangci-lint 0 issues; gofmt clean.
  • Based on 3f6ef75, merged current main (1f57282, P8b) clean — no conflict (plugin_grpc.go disjoint from the build-drive move).

Flagged separately (NOT dragged into this cutover)

The full -race run surfaced TWO more, unrelated pre-existing races in TestRunWithPhaseResync_* (check_runner_cmd.go:403/408 vs check_phase_resync_test.go:118, check-runner subsystem) — routed to their owner. Also: -count>1 on provider-registering e2e tests hits a broad "provider already registered" test-isolation limitation (no unregister API) — a separate concern. Neither is this cutover's scope.

Assisted-by: Claude (analysed on a live system)

atrawog added 4 commits July 12, 2026 16:15
…f (data race)

grpcProvider.InvokeWithExecutor stands up the host ExecutorService on the go-plugin broker for
the duration of a deploy/step/check Invoke. The reverse gRPC server was held in a plain
`var srv *grpc.Server`: the AcceptAndServe callback (broker-accept goroutine) WROTE it while the
deferred Stop() (the InvokeWithExecutor goroutine, after Invoke returns) READ it — an
unsynchronized cross-goroutine handoff the -race detector flags (WRITE plugin_grpc.go:170 vs READ
:187), exercised by the substrate-lifecycle e2e reverse-channel round-trip. Root-cause fix: srv
becomes an atomic.Pointer[grpc.Server] — the callback Stores the server it built, the deferred
Load reads it (or nil if the plugin never dialed back). A real happens-before edge, NOT a
serialize-to-hide or a -race suppression; behaviour otherwise unchanged.

R2: opened as its own immediate cutover after the scaffold PR's full -race run surfaced the RCA.

Verified: go test -run TestSubstrateLifecycle_PrepareVenueDescriptorRoundTrip -race -count=10
(0 data-race reports, was a hard DATA RACE); full go test ./charly/... green; golangci-lint 0
issues; gofmt clean.

Assisted-by: Claude (analysed on a live system)
Claude-Session: https://claude.ai/code/session_01R8UGGr3ui1959oTb5JuSif
…sion

The #74 grpc-race CHANGELOG placeholder collided with the filename retention #73
finalized to at its merge (v2026.193.1414). Renamed to 2026.193.1422 (content
unchanged; the validator re-finalizes to the merge-time CalVer anyway). Keeps
#73's landed 2026.193.1414.md intact.

Assisted-by: Claude (documentation reviewed)
Claude-Session: https://claude.ai/code/session_01R8UGGr3ui1959oTb5JuSif
@atrawog

atrawog commented Jul 12, 2026

Copy link
Copy Markdown
Contributor Author

pr-validator — APPROVED ✅

Change class: charly/sdk Go (in-process concurrency fix — data race)
Head validated: d20b4fe · re-derived independently in a fresh worktree; no author claim trusted.

A genuine root-cause fix: InvokeWithExecutor held the F10 reverse gRPC server in a plain var srv *grpc.Server WRITTEN by the AcceptAndServe callback (broker-accept goroutine) and READ by the deferred Stop() (Invoke goroutine) — an unsynchronized cross-goroutine handoff. The fix makes srv an atomic.Pointer[grpc.Server] (callback Stores, deferred Loads) — a real happens-before edge, behaviour unchanged.

Checklist

  • [PASS] 0 security/anti-tampering — diff is CHANGELOG + plugin_grpc.go (+16/−7); only sync/atomic stdlib import; no network/secret/exec/supply-chain/guardrail change; no scope mismatch; no embedded validator-directed instructions.
  • [PASS] 1 description — summary + verification (gate named, output pasted) + tier + R2 routing; feat(spec): adopt sdk/spec InstallPlan IR enums (P4-unit-1 consumer) #31 -count>1 limitation explicitly disclosed.
  • [PASS] 2 change-class gate — the correct exercising gate is go test -race on the substrate-lifecycle e2e test (a check bed cannot detect an in-proc goroutine race — the detector isn't in the release binary). No dry-run fraud.
  • [PASS] 3 attribution tier — analysed on a live system (the changed path ran live under -race); not inflated to fully tested and validated (no disposable-bed deploy).
  • [PASS] 4 R0 skills — go / plugin / install-plan honored; reverse channel is a generic Mechanism seam.
  • [PASS] 5 R1 / zero-warning — real RCA to the root mechanism; CHANGELOG disclaims "serialize-to-hide" and "-race suppression"; vet 0, lint 0, gofmt clean.
  • [PASS] 6 R2 — the other flagged races (feat(buildkit): adopt sdk/buildkit ResolvedBox keystone (P3-unit-4 consumer) #30 check-runner, feat(spec): adopt sdk/spec InstallPlan IR enums (P4-unit-1 consumer) #31 registry-isolation) are genuinely separable (this fix's race gate passes without them — I proved it) and routed to their own cutovers. Not a "pre-existing" dodge.
  • [PASS] 7 R3 / [PASS] 8 R4 — single-site fix; atomic.Pointer is a real sync primitive, not a sleep/retry/serialize/suppression.
  • [PASS] 9 R5 — nothing deleted/renamed (srv stays srv); no dual-mode. [PASS] 12 SDD — no schema/*_gen.go/wire surface. [PASS] 15 boundary — no concrete-kind leak.
  • [PASS] 13 concurrency anti-cheat — I did not accept "passes on idle/serial": I reproduced the race on the pre-fix code and cleared it on the fixed code.
  • [PASS] 17 Go gates — go build clean, golangci-lint v2 = 0 issues, go vet clean, full go test ./charly/... green. [PASS] 18 CHANGELOG — present, proper RCA language, scoped to its own narrative (no feat(buildkit): adopt sdk/buildkit ResolvedBox keystone (P3-unit-4 consumer) #30/feat(spec): adopt sdk/spec InstallPlan IR enums (P4-unit-1 consumer) #31).

Independently-derived race proof (my runs)

POST-FIX  : 20/20 fresh processes  go test -run TestSubstrateLifecycle_...RoundTrip -race  → pass, 0 data-race reports
PRE-FIX   :  5/5 fresh processes (atomic reverted, same tree)                              → WARNING: DATA RACE
            WRITE plugin_grpc.go:177 (callback srv=grpc.NewServer) vs READ :194 (deferred if srv!=nil)
full suite: go test ./charly/... → green (48.5s) once box/* submodules present

Note: -race -count=10 in ONE process fails at substrate_lifecycle_e2e_test.go:56 "provider ... already registered" — the pre-flagged #31 test-isolation limit (process-global registry), not a data race. Correct stress vehicle is fresh processes, which I used.

Decision: the fix eliminates a real data race with the correct synchronization primitive, behaviour unchanged, all gates green, reproduced-then-cleared under -race. Finalizing merge-time CalVer, squash-merging, and tagging.

Assisted-by: Claude (analysed on a live system)

Merge-time version stamp for the InvokeWithExecutor reverse-server data-race fix.

Assisted-by: Claude (analysed on a live system)
@atrawog
atrawog merged commit ab6b001 into main Jul 12, 2026
@atrawog
atrawog deleted the feat/plugin-grpc-race branch July 12, 2026 14:46
atrawog added a commit that referenced this pull request Jul 12, 2026
…hoc cleanup + snapshot pluginSchemas

Addresses the PR #76 CHANGES-REQUESTED verdict (R3 + R1): the seam commit
b802371 claimed it 'replaces the ad-hoc delete(...) cleanups (ONE reset
pattern)' but its diff deleted nothing — apk_format_test.go's
TestRunPlan_StampsStepOrigin kept an ad-hoc registry-only
delete(providerRegistry.byKey/origins) cleanup, so two reset patterns coexisted
and the claim was false.

- Convert TestRunPlan_StampsStepOrigin to t.Cleanup(snapshotProviderState()) as
  its first line and DELETE the ad-hoc delete-block. The diff now SHOWS the
  deletion and 'ONE reset pattern' is TRUE. git grep 'delete(providerRegistry\.'
  returns nothing (R5).
- Extend snapshotProviderState() to also snapshot/restore the process-wide plugin
  schema set (pluginSchemas: sources/inputDefs/unified). This resolves the
  validator's non-blocking note by REMOVING the reliance, not merely confirming
  it: the append-only sources slice no longer grows under -count>N and the seam
  stops leaning on 'identical defs unify + no two tests share a def name'.

Verification: go test ./charly/... -count=2 green; go test -race -count=20 on all
47 registering e2e tests — 0 races, 0 duplicate-registration failures (rebased
onto main #74, so substrate-lifecycle passes full -race too); golangci-lint 0;
gofmt + fmt --diff clean.

Assisted-by: Claude (analysed on a live system)
Claude-Session: https://claude.ai/code/session_01LnxJjgvxzR2WePdDhAp7Wb
atrawog added a commit that referenced this pull request Jul 14, 2026
/#72/#74)

Evaluator-generated CalVer stamp for the gate-infrastructure batch cutover
(vm-destroy false-success #69, makepkg sibling-branch fetch #72, unstamped-binary
bed-runner guard #74). Renames the placeholder CHANGELOG to CHANGELOG/2026.195.0802.md and
stamps its H1 to match; folded into the squash-merge.

Assisted-by: Claude (fully tested and validated)
atrawog added a commit that referenced this pull request Jul 14, 2026
…ch fetch (#72), unstamped-binary bed-runner guard (#74)

Gate-infrastructure thematic batch — three independently-non-blocking bed/gate reliability fixes, one squash.

#69 — `charly vm destroy` backend-mismatch false-success + `bundle del` domain-teardown owner. `destroyVmDomain` probes libvirt authoritatively (regardless of the configured/default backend), tears the domain down from whichever backend holds it, VERIFIES it is gone, and hard-errors "no such VM" when nothing was torn; `vmPostTeardown` fires `vm destroy <entity> --domain <domain> --keep-deploy` as `bundle del`'s domain-teardown owner. + regression tests.

#72 — makepkg update-phase fetch scoping. The arch localpkg `build_template`'s `makepkg -sf` now sets `GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=fetch.recurseSubmodules GIT_CONFIG_VALUE_0=false`, so a worktree-shared superproject fetch no longer on-demand-recurses into a sibling branch's unpushed sdk gitlink ("not our ref"). Applied to BOTH `//go:embed` copies (R3); deb/rpm unaffected (no makepkg/git+file://).

#74 — bed-runner precondition. `CheckBinaryStamped` refuses `charly check run` on an unstamped ("unknown") binary, pointing at `task build:binary`; scoped to `run` via `commandPathKey` + os.Args; `charly version` also exits non-zero when unstamped. + unit tests.

Found + registered while landing: #76 (word-keyed plugin cache races across worktrees) → next bed-infra batch.

Validated by a fresh, independent pr-validator: golangci-lint 0 (charly / plugin-vm / plugin-deploy-vm), gofmt/vet/build/targeted-test clean; R10 beds corroborated (check-builder-vm 9/9 ok, check-local-vm 7/7 ok with the makepkg update phase ok:true under the live 4-sibling-gitlink state); placement CORRECT.

Assisted-by: Claude (fully tested and validated)
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