Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pkgs/mcpx/internal/cli/adapter_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions pkgs/mcpx/internal/cli/adapter_import_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 4 additions & 6 deletions pkgs/mcpx/internal/daemon/scriptview.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion pkgs/mcpx/internal/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions pkgs/mcpx/internal/defaults/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 23 additions & 1 deletion pkgs/mcpx/internal/defaults/guard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}

Expand Down
4 changes: 3 additions & 1 deletion pkgs/mcpx/internal/mcpauth/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down