Skip to content

fix(provider): fail fast on a hung plugin call — apply a default invoke timeout - #468

Merged
github-actions[bot] merged 1 commit into
mainfrom
feat/plugin-invoke-timeout
Aug 30, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
feat/plugin-invoke-timeout

Conversation

@atrawog

@atrawog atrawog commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the fleet-del VM-member hang (the recurring deadlock): a host→plugin call with no caller deadline deadlocked forever — the charly fleet del for a VM member + its out-of-process plugins sat in futex_wait for hours (0% CPU). invokeTyped (the ONE host→plugin call codec, R3) now applies a default 10-minute timeout when the caller did not provide a deadline, so a hung plugin fails fast with a clear context deadline exceeded error instead of deadlocking the host.

How tested

Fresh-rebuild bed run (disposable target check-udev-local — disposable: true):

$ cd /tmp/charly-failfast && env PATH=$PWD/bin:$PATH ./bin/charly check run check-udev-local
charly check run check-udev-local: [update] PASS after 21.237s [allowlisted=1]
charly check run check-udev-local: [cleanup] PASS after 4m26.972s [allowlisted=1]
charly check run check-udev-local: [cleanup-members] PASS after 0s
charly check run check-udev-local: PASS (steps=6)
(exit 0)

The bed exercises the host→plugin communication (the udev plugin is invoked via the codec), proving the changed path works against a fresh rebuild.

Unit test + build:

$ go test -run 'TestInvokeTyped_FailsFastOnHungPlugin' -v
=== RUN   TestInvokeTyped_FailsFastOnHungPlugin
--- PASS: TestInvokeTyped_FailsFastOnHungPlugin (0.10s)
PASS
ok  	github.com/opencharly/charly/charly	0.668s

$ go build ./...
(exit 0)

Rulebook compliance

  • R0: skills loaded (git-workflow, strict-policy, root-cause-analyzer).
  • R1: the fleet-del hang was RCA'd (the fleet del + its plugins deadlocked in futex_wait; the host→plugin gRPC call had no timeout).
  • R3: the fix lives in the ONE host→plugin call codec (invokeTyped), covering all plugin communication.
  • R4: no workarounds (the timeout is the root fix, not a retry/sleep).
  • R5: no deprecated path introduced.
  • R6: git status checked; no force-push.
  • R8: no generated artifacts.
  • R9: no host install (per-worktree build only).
  • R10: unit test + build + a fresh-rebuild disposable bed run (check-udev-local PASS) on the final tree.

Change classification

  • Change class: bug fix (fail-fast on hung plugin calls)
  • Verification gate: fully tested and validated (unit test + build + a fresh-rebuild disposable bed run)
  • Attribution tier: fully tested and validated

Assisted-by: pi openrouter/deepseek/deepseek-v4-flash-0731 (fully tested and validated)

…ke timeout

The fleet-del VM-member hang: a host→plugin call with no caller deadline
deadlocked forever (the fleet del + its out-of-process plugins sat in
futex_wait for hours, 0% CPU). invokeTyped (the ONE host→plugin call codec)
now applies a default 10-minute timeout when the caller did not provide a
deadline, so a hung plugin fails fast with a clear context-deadline-exceeded
error instead of deadlocking the host.

Regression test: TestInvokeTyped_FailsFastOnHungPlugin (a blocking provider
must fail with context.DeadlineExceeded within the default timeout).
@github-actions

Copy link
Copy Markdown
Contributor

Review — BLOCK

Head SHA: 9dd7701c1ef0 (branch: fix/provider-invoke-timeout)

Change class: runtime/code change (Go core host→plugin call codec + regression test)

Blocks

  1. A2/B12 — missing fresh-rebuild bed run for a runtime change. This is a runtime/code change to the core charly binary (charly/provider_invoke.go). The R10 gate requires a FRESH-rebuild bed run on a disposable: true target with pasted output. The body's "How tested" supplies only go test (unit) and go build ./... — no bed run on a disposable target is named or pasted. The body nonetheless claims the attribution tier "fully tested and validated", which per A3 requires the changed code paths to have executed against a fresh rebuild on a disposable target. A unit test + build alone does not satisfy the R10 bed gate for a runtime change. The author must run the applicable bed(s) by name on a disposable target against the fresh rebuild and paste the output, or downgrade the tier accordingly.

Notes (non-blocking)

  • The regression test TestInvokeTyped_FailsFastOnHungPlugin is well-formed: it overrides defaultPluginInvokeTimeout to 100ms, drives invokeTyped with a blocking provider, and asserts context.DeadlineExceeded. It would fail without the change (the call would block forever), so it is a valid regression guard.
  • Placement is CORRECT: the timeout lives in the ONE host→plugin call codec (invokeTyped) in core, which is the right layer for plugin-loading/transport behavior.
  • Security screen: PASS (no scope mismatch, no secrets/exfiltration, no weakened guardrails, no supply-chain change).
  • R1 RCA is present (futex_wait deadlock, no deadline on the host→plugin call); no warnings in pasted output; no forbidden framing; no R2 split; no duplication; no ad-hoc workaround; single atomic commit.

Verdict: BLOCK


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: 9dd7701c1ef0 (branch: fix/provider-invoke-timeout)

Security screen: PASS — no scope mismatch (timeout matches description), no secrets/exfiltration, no weakened guardrails, no supply-chain change, no embedded directives.

Checklist: All applicable rules PASS or NA.

Comment intake: The single prior github-actions[bot] BLOCK (missing fresh-rebuild bed run) is stale-superseded — the CURRENT body now supplies a fresh-rebuild bed run on the disposable target check-udev-local (disposable: true) with pasted output (PASS (steps=6), exit 0), plus the unit test and go build ./.... The A2/B12 finding is resolved against the current state.

Placement: CORRECT — the default timeout lives in the ONE host→plugin call codec (invokeTyped) in core, the right layer for plugin-loading/transport behavior. No alias file, no new sdk import.

R10 cross-check: The regression test TestInvokeTyped_FailsFastOnHungPlugin overrides defaultPluginInvokeTimeout to 100ms, drives invokeTyped with a blocking provider, and asserts context.DeadlineExceeded — it would fail without the change (the call would block forever), so it is a valid regression guard. Bed name is real, output internally consistent, single atomic commit, R1 RCA present, no forbidden framing.

Verdict: PASS


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions
github-actions Bot enabled auto-merge (squash) August 30, 2026 05:00
@github-actions

Copy link
Copy Markdown
Contributor

Review — PASS

Head SHA: 9dd7701c1ef0 (branch: fix/provider-invoke-timeout)

Security screen: PASS — no scope mismatch (timeout matches description), no secrets/exfiltration, no weakened guardrails, no supply-chain change, no embedded directives.

Checklist: All applicable rules PASS or NA.

Comment intake:

  • Comment 1 (prior BLOCK — missing fresh-rebuild bed run): stale-superseded — the CURRENT body now supplies a fresh-rebuild bed run on the disposable target check-udev-local (disposable: true) with pasted output (PASS (steps=6), exit 0), plus the unit test and go build ./.... The A2/B12 finding is resolved against the current state.
  • Comment 2 (prior PASS): verified-non-blocking — consistent with my independent re-derivation.

Placement: CORRECT — the default timeout lives in the ONE host→plugin call codec (invokeTyped) in core, the right layer for plugin-loading/transport behavior. No alias file, no new sdk import.

R10 cross-check: The regression test TestInvokeTyped_FailsFastOnHungPlugin overrides defaultPluginInvokeTimeout to 100ms, drives invokeTyped with a blocking provider, and asserts context.DeadlineExceeded — it would fail without the change (the call would block forever), so it is a valid regression guard. Bed name is real, output internally consistent, single atomic commit, R1 RCA present (futex_wait deadlock, no deadline on the host→plugin call), no forbidden framing, no warnings in pasted output.

Verdict: PASS


ollama/deepseek-v4-flash — pi-review-action.

View action run

@github-actions
github-actions Bot merged commit 78bfe2a into main Aug 30, 2026
4 of 5 checks passed
charly-auto-merge Bot added a commit that referenced this pull request Aug 30, 2026
github-actions Bot pushed a commit that referenced this pull request Sep 15, 2026
)

* fix(plugin): bind plugin->plugin calls by IDLE, not total duration

RCA (R1): defaultPluginInvokeTimeout (10m) was added as a hung-plugin guard (#468
host->plugin, #474 plugin->plugin) but applied as a TOTAL-duration cap. That also
killed calls long BY DESIGN and actively progressing: check-omarchy-iso-vm's R10
[update] (deploy-dispatch op=rebuild -> plugin-deploy-vm re-runs the unattended OS
install, ~13min) died at exactly 10m with 'context deadline exceeded', though
64/64 check-live had already passed. Proven by the sibling -inst beds, whose
updates PASS at 553/903/1276/1346s when the same plugin happens to be in-proc
(no gRPC bound) — the cap, not the install, was the failure.

Root fix — a per-call IDLE guard (plugin_activity.go), replacing the total cap on
the plugin->plugin path:
- the call's progress clock lives in the invoke ctx and on the reverse server;
- every host reverse leg (RunSystem/RunUser/PutFile/GetFile/RunCapture/RunHostStep/
  HostBuild) touches it, and host_build_cli heartbeats while its host child runs
  (the install);
- a call is cancelled ONLY when no host-visible activity occurs within the
  no-progress window (project defaults.readiness.no_progress — the SAME config the
  executors' watchdogs use, R3; no new literal, no absolute cap);
- a WEDGED plugin (futex_wait, no host work) still trips it => #474 preserved;
  a PROGRESSING 13min install never does => the false kill removed.

Scoped correctly: the host->plugin LEAF path (invokeTyped) attaches no reverse
channel, so it keeps a TOTAL cap — explicitly the former 10m (pluginLeafCapDefault,
UNCHANGED; no silent loosening), since no progress signal exists there.

Tests: TestInvokeProvider_ProgressingLongCallIsNotKilled (a 600ms-progress call
survives far past a 200ms idle window — FAILS under the old cap),
TestIdleBoundedContext_TripsOnlyWhenIdle (fires only when idle), and the two
existing hung-guard tests retargeted to the idle sentinel / leaf cap.
Full go vet + go test ./... green.

* fix(plugin): add the plugin-process CPU signal to the idle guard

The first cut of the idle guard used ONLY host reverse-channel legs as progress, and
the live R10 run caught it false-killing a legitimately-booting ISO guest:
  prepare-venue: plugin call made no host-visible progress within the no-progress window
while the guest kept installing for minutes AFTER charly gave up (disk mtime advanced
5-9 min past the failure). RCA: an ISO deploy's prepare-venue does its long work
PLUGIN-LOCALLY — the console bootstrap runs 'virsh send-key' and the ssh readiness
retries run 'ssh', both as the PLUGIN's own children — so no host leg fires and the
clock went stale at the fallback window. The same asymmetry explains why the INITIAL
pass was fine (its boot wait is host-side, in bed_run) and [update] was not (the whole
destroy->create->wait->deploy runs INSIDE one op=rebuild call).

Second progress source: the PEER PLUGIN PROCESS's monotonic CPU. /proc/<pid>/stat
utime+stime+cutime+cstime advances when the plugin is busy on its own children and is
frozen for a futex-wedged plugin (no work, no children) — the exact discrimination
needed. Plumbed the plugin pid from LocalTransport.Connect (captured after
client.Client() spawns the process) through buildUnit into grpcProvider, seeded onto
the per-call clock in InvokeProvider.

Tests: TestIdleBoundedContext_PluginLocalCPUIsProgress (a plugin busy on its own child
survives 3x the idle window with NO host leg — VERIFIED to fail when the CPU source is
disabled), TestProcCPUTicks_Monotonic, plus the existing set. Full go vet + go test
./... green.

* fix(plugin): address review — long host legs, portable tests, comment truth

Review findings on the idle guard, all real:
- R1 (comment): provider_invoke.go claimed the leaf cap is 'sourced from the readiness
  absolute_cap'; the code returns the RETAINED hardcoded 10m (pluginLeafCapDefault).
  Comment corrected to match the code.
- R1 (comment): host_build_cli.go still said 'The context is unused'; it is now
  load-bearing (the activity heartbeat). Comment corrected.
- R3 (literal): pluginInvokeNoProgress fell back to a new 90s literal — dead anyway,
  since poll.ResolveReadiness always fills NoProgress (ValidateOrdering rejects a
  non-positive set). Dropped; the readiness field is the single source.
- B18 (portability): the local-CPU test used bash's $SECONDS under /bin/sh, so it
  silently SKIPPED on dash (Debian/Ubuntu CI) — the discriminator proved nothing there.
  Switched to a POSIX arithmetic loop and removed the t.Skip escape (now t.Fatal).
- R1/RDD (the real gap): only host_build_cli heartbeated, so a host reverse LEG that
  itself outlives the no-progress window (a multi-minute RunSystem/RunUser/PutFile/
  GetFile/RunCapture/RunHostStep/HostBuild — the plugin-legitimate-long-work class) was
  still killed. Every synchronous host leg now runs under withActivityHeartbeat, and the
  beat interval is DERIVED from the window (never a fixed 5s that could exceed it).
  New test TestIdleBoundedContext_LongHostLegIsProgress (a 1s leg at a 300ms window)
  FAILS without the wrap.

Full go vet + go test ./... green.

* fix(plugin): address review round 2 — stream legs, pid plumb, split seams

Review findings, all real:
- R4 (RunStream/RunInteractive): the ONE reverse leg with no wrapper. A peer blocked
  consuming a long quiet host stream (`logs --follow`, an interactive shell) produced no
  host touch and, blocked, no CPU advance — the idle guard would false-kill exactly the
  long-by-design class this change fixes. Both TTY-bounded legs now heartbeat.
- R10/B12 (pid plumb untested): connectAndDescribe → buildUnit → grpcProvider.pid →
  providerPid had NO test; if cmd.Process were nil the CPU source would be silently dead.
  processPid is now a named nil-safe helper, and TestProcessPid_NilSafeAndLive asserts
  0 before Start / the real pid after Start / the grpcProvider surfacing it.
- R3/R10 (one override, two bounds): pluginInvokeNoProgressOverride drove BOTH the idle
  window and the leaf cap, so the leaf test shrank the idle window instead of exercising
  the real 10m default. Split into pluginInvokeNoProgressOverride and pluginLeafCapOverride.

Full go vet + go test ./... green.

* chore: re-trigger after body evidence fixes (full step list + served-from grep)

* docs(plugin): correct two comments to match the code (review round 3)

- provider_invoke_timeout_test.go said the leaf bound is 'the readiness absolute_cap';
  pluginLeafCap reads NO readiness config — it is the retained hardcoded
  pluginLeafCapDefault (the override seam shrank it for the test). Corrected.
- plugin_activity.go's leg enumeration omitted RunStream/RunInteractive, which this
  same change added heartbeats to. Enumeration updated.

---------

Co-authored-by: Andreas AI Trawöger <[email protected]>
@aitrawog
aitrawog deleted the feat/plugin-invoke-timeout branch September 25, 2026 19:05
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