diff --git a/pkgs/mcpx/internal/cli/adapter_import.go b/pkgs/mcpx/internal/cli/adapter_import.go index baeb59eea6..f1406c3f3b 100644 --- a/pkgs/mcpx/internal/cli/adapter_import.go +++ b/pkgs/mcpx/internal/cli/adapter_import.go @@ -15,6 +15,7 @@ import ( "unicode" "github.com/developing-today/code/pkgs/mcpx/internal/adapter" + "github.com/developing-today/code/pkgs/mcpx/internal/defaults" ) // Declaration generation for `mcpx adapter import` (#1962 steps 2-5). @@ -682,7 +683,7 @@ func parseCompletion(text, shell, name string) *importShape { // runCapture runs a program for its text output with a bound: import // probes binaries, and a probe that hangs would hang the import. func runCapture(binary string, args ...string) (string, error) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), defaults.PreflightProbeTimeout) defer cancel() cmd := exec.CommandContext(ctx, binary, args...) var out strings.Builder diff --git a/pkgs/mcpx/internal/cli/adapter_import_parse.go b/pkgs/mcpx/internal/cli/adapter_import_parse.go index 3835d64ad4..cfb0af0d1f 100644 --- a/pkgs/mcpx/internal/cli/adapter_import_parse.go +++ b/pkgs/mcpx/internal/cli/adapter_import_parse.go @@ -7,7 +7,8 @@ import ( "regexp" "sort" "strings" - "time" + + "github.com/developing-today/code/pkgs/mcpx/internal/defaults" ) // The source parsers for adapter import (#1962). Each is a pure function @@ -441,7 +442,7 @@ func manShape(binary string) (*importShape, error) { // runCaptureEnv is runCapture with extra environment. func runCaptureEnv(env map[string]string, binary string, args ...string) (string, error) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + ctx, cancel := context.WithTimeout(context.Background(), defaults.PreflightProbeTimeout) defer cancel() cmd := exec.CommandContext(ctx, binary, args...) cmd.Env = os.Environ() diff --git a/pkgs/mcpx/internal/daemon/scriptview.go b/pkgs/mcpx/internal/daemon/scriptview.go index 45f32e83b7..66ca638d1e 100644 --- a/pkgs/mcpx/internal/daemon/scriptview.go +++ b/pkgs/mcpx/internal/daemon/scriptview.go @@ -23,11 +23,6 @@ import ( "github.com/developing-today/code/pkgs/mcpx/internal/schemaval" ) -// scriptWaitDelay bounds how long a script view's call waits on its output -// pipes after the program exits, so a grandchild that inherited them cannot -// hold the call open. -const scriptWaitDelay = 2 * time.Second - // ScriptAnnotations is the behaviour hints a script-backed view declares // (#1933 slice 2). A script has no upstream annotations, so the declaration // is the only classification input the confirmation and write policy have: @@ -200,7 +195,10 @@ func callScriptView(ctx context.Context, pl *pool.Pool, tool string, tv *config. stdout := &cappedBuffer{max: defaults.ExecStdoutLimit} stderr := &cappedBuffer{max: defaults.ExecStderrLimit} cmd.Stdout, cmd.Stderr = stdout, stderr - cmd.WaitDelay = scriptWaitDelay + // WaitDelay is defaults.ScriptWait: how long the call waits on the + // output pipes after the program exits, so a grandchild that + // inherited them cannot hold the call open. + cmd.WaitDelay = defaults.ScriptWait // Dispatch is noted only after the program has actually started: // a command that cannot start (a missing executable, a permission // failure) never ran, so its outcome is known -- it performed no diff --git a/pkgs/mcpx/internal/defaults/defaults.go b/pkgs/mcpx/internal/defaults/defaults.go index a08eab8991..3a4e4bb22d 100644 --- a/pkgs/mcpx/internal/defaults/defaults.go +++ b/pkgs/mcpx/internal/defaults/defaults.go @@ -82,6 +82,8 @@ type Defaults struct { StatsTop int `json:"statsTop"` RegistryLimit int `json:"registryLimit"` HandoffRetryInterval string `json:"handoffRetryInterval"` + ScriptWait string `json:"scriptWait"` + FailoverCooldown string `json:"failoverCooldown"` } `json:"plumbing"` // Resolve governs GET /v1/resolve, which answers "which daemon serves // this directory" for a caller that has no mcpx binary. @@ -91,7 +93,8 @@ type Defaults struct { // Preflight governs the resolver's own outbound lookups while it // walks an import graph. Preflight struct { - NPMTimeout string `json:"npmTimeout"` + NPMTimeout string `json:"npmTimeout"` + ProbeTimeout string `json:"probeTimeout"` } `json:"preflight"` // Elicit governs questions a server asks back. Elicit struct { @@ -607,6 +610,14 @@ var ( // HandoffRetryInterval is how often a takeover re-checks pools that were // busy with in-flight calls. HandoffRetryInterval = mustDur(builtin.Plumbing.HandoffRetryInterval, "plumbing.handoffRetryInterval") + // ScriptWait bounds how long a script view's call waits on its output + // pipes after the program exits, so a grandchild that inherited them + // cannot hold the call open (exec.Cmd.WaitDelay). + ScriptWait = mustDur(builtin.Plumbing.ScriptWait, "plumbing.scriptWait") + // FailoverCooldown is the fallback skip for a soft-blocked auth + // identity whose config names no cooldownSeconds: the Failover + // config's own "zero means 60" rule, homed here like every default. + FailoverCooldown = mustDur(builtin.Plumbing.FailoverCooldown, "plumbing.failoverCooldown") // ResolveDialTimeout bounds the liveness check /v1/resolve makes against // the socket it is about to name. It is a local connect on a unix @@ -619,6 +630,11 @@ var ( // internal bound, so it lives in defaults.json only and is // deliberately absent from the settings registry. PreflightNPMTimeout = mustDur(builtin.Preflight.NPMTimeout, "preflight.npmTimeout") + // PreflightProbeTimeout bounds one import probe (a completion dump, + // `man`, --help): import probes binaries, and a probe that hangs + // would hang the import. Like PreflightNPMTimeout it is an internal + // bound, in defaults.json only and absent from the settings registry. + PreflightProbeTimeout = mustDur(builtin.Preflight.ProbeTimeout, "preflight.probeTimeout") ElicitTTL = mustDur(builtin.Elicit.TTL, "elicit.ttl") // ElicitMaxAge is the absolute ceiling on a question's life under the diff --git a/pkgs/mcpx/internal/defaults/defaults.json b/pkgs/mcpx/internal/defaults/defaults.json index 2a17df41da..3f3f63f345 100644 --- a/pkgs/mcpx/internal/defaults/defaults.json +++ b/pkgs/mcpx/internal/defaults/defaults.json @@ -102,13 +102,16 @@ "taskResultWait": "2m", "statsTop": 20, "registryLimit": 20, - "handoffRetryInterval": "10ms" + "handoffRetryInterval": "10ms", + "scriptWait": "2s", + "failoverCooldown": "60s" }, "resolve": { "dialTimeout": "200ms" }, "preflight": { - "npmTimeout": "5s" + "npmTimeout": "5s", + "probeTimeout": "10s" }, "elicit": { "ttl": "120s", diff --git a/pkgs/mcpx/internal/defaults/guard_test.go b/pkgs/mcpx/internal/defaults/guard_test.go index 8595a1746c..2e8f0fb22a 100644 --- a/pkgs/mcpx/internal/defaults/guard_test.go +++ b/pkgs/mcpx/internal/defaults/guard_test.go @@ -77,7 +77,29 @@ var allowed = map[string]string{ // A unit boundary in a duration renderer: it decides whether to print // hours or days, which is arithmetic rather than policy. - "24*time.Hour": "a unit boundary in the duration formatter", + "24*time.Hour": "a unit boundary in the duration formatter", + + // Token-lifetime arithmetic in mcpauth's App minter and rotator. + // GitHub's platform rules fix these numbers — an App JWT may live + // at most 10 minutes and an installation token one hour — so they + // are protocol constants imposed from outside, not preferences a + // user could set differently. + "60*time.Second": "the App JWT iat backdate in mcpauth: the documented clock-skew allowance, so a minting host a few seconds fast is not refused", + "9*time.Minute": "the App JWT lifetime in mcpauth: GitHub caps App JWTs at 10 minutes and 9 leaves headroom under that cap", + "5*time.Minute": "the installation-token refresh margin in mcpauth: a cached token is re-minted this long before its one-hour expiry", + + // Test-harness timing in internal/testsupport. These bound how the + // suite waits on its own fakes and stray processes; nothing a user + // runs has these values in it. + "2*time.Second": "the reply window eramcp (testsupport's fake MCP server) gives a client before answering 'dropped': a simulated peer's timing, not a product default", + "10*time.Second": "the leftover grace in testsupport's sweep: how long a process seen running from a build dir gets to exit on its own before the sweep calls it leaked; it mirrors the harness's daemon drain budget", + "100*time.Millisecond": "the leftover poll interval in testsupport's sweep: how often the sweep re-checks a draining process inside its grace period", + + // A definition, like the kibibyte shifts above: the seed's shuffle + // formula masks a hash to MaxInt63, and (1<<63 - 1) is that value + // by definition; the formula is pinned to two other implementations + // by the seed package's tests. + "1<<63": "the MaxInt63 mask in testsupport/seed's shuffle derivation", "2*time.Millisecond": "the poll interval in artifacts' schema-migration race guard (ensureLastTouched): a bounded loop waiting out a concurrent opener's ALTER; race arbitration, not a policy value", } diff --git a/pkgs/mcpx/internal/mcpauth/failover.go b/pkgs/mcpx/internal/mcpauth/failover.go index ec03bf79d3..527ddecc90 100644 --- a/pkgs/mcpx/internal/mcpauth/failover.go +++ b/pkgs/mcpx/internal/mcpauth/failover.go @@ -44,6 +44,8 @@ import ( "strings" "sync" "time" + + "github.com/developing-today/code/pkgs/mcpx/internal/defaults" ) // Identity is one entry in a failover list. @@ -87,7 +89,7 @@ type Failover struct { func (f *Failover) cooldown() time.Duration { if f == nil || f.CooldownSeconds <= 0 { - return 60 * time.Second + return defaults.FailoverCooldown } return time.Duration(f.CooldownSeconds) * time.Second }