Skip to content
Closed
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.CLIImportTimeout)
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.CLIImportTimeout)
defer cancel()
cmd := exec.CommandContext(ctx, binary, args...)
cmd.Env = os.Environ()
Expand Down
2 changes: 1 addition & 1 deletion pkgs/mcpx/internal/daemon/scriptview.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// 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
var scriptWaitDelay = defaults.ScriptWaitDelay

// ScriptAnnotations is the behaviour hints a script-backed view declares
// (#1933 slice 2). A script has no upstream annotations, so the declaration
Expand Down
65 changes: 59 additions & 6 deletions pkgs/mcpx/internal/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ type Defaults struct {
Trace bool `json:"trace"`
} `json:"logging"`
Daemon struct {
ReapInterval string `json:"reapInterval"`
SaveInterval string `json:"saveInterval"`
TSNetUpTimeout string `json:"tsnetUpTimeout"`
ReapInterval string `json:"reapInterval"`
SaveInterval string `json:"saveInterval"`
TSNetUpTimeout string `json:"tsnetUpTimeout"`
ScriptWaitDelay string `json:"scriptWaitDelay"`
} `json:"daemon"`
Secrets struct {
RequestRetention string `json:"requestRetention"`
Expand Down Expand Up @@ -141,8 +142,9 @@ type Defaults struct {
// CLI governs how the command line renders what it did not write a
// formatter for: the commands generated from the /v1 operation table.
CLI struct {
CellWidth int `json:"cellWidth"`
UsageColumn int `json:"usageColumn"`
CellWidth int `json:"cellWidth"`
UsageColumn int `json:"usageColumn"`
ImportTimeout string `json:"importTimeout"`
} `json:"cli"`
Catalog struct {
Budget int `json:"budget"`
Expand Down Expand Up @@ -396,6 +398,28 @@ type Defaults struct {
Proxy struct {
Timeout string `json:"timeout"`
} `json:"proxy"`
// McpAuth is the GitHub identity failover machinery's timing
// (internal/mcpauth). The JWT values are bounded by GitHub's own
// rules -- an App JWT may live at most ten minutes -- so they are
// data here rather than settings: a configuration key that pushed
// the lifetime past the cap would only mint tokens GitHub refuses.
McpAuth struct {
Cooldown string `json:"cooldown"`
RefreshSkew string `json:"refreshSkew"`
JWTBackdate string `json:"jwtBackdate"`
JWTLifetime string `json:"jwtLifetime"`
} `json:"mcpauth"`
// TestSupport is the test harness's own timing (internal/
// testsupport): how long the leftover-process sweep waits out an
// orderly shutdown, and how long the era test server waits for a
// reply before calling it dropped. They are here so the constants
// guard has exactly one answer for them, not because a user of
// the shipped binary can reach them.
TestSupport struct {
LeftoverGracePeriod string `json:"leftoverGracePeriod"`
LeftoverPollInterval string `json:"leftoverPollInterval"`
EraReplyWait string `json:"eraReplyWait"`
} `json:"testsupport"`
}

// Embeddings defaults.
Expand All @@ -405,6 +429,29 @@ var (
ProxyUpstreamTimeout = mustDur(builtin.Proxy.Timeout, "proxy.timeout")
)

// McpAuth (GitHub identity failover) defaults.
var (
// McpAuthCooldown is the failover cooldown when the config sets
// no CooldownSeconds: how long a soft-blocked identity is skipped.
McpAuthCooldown = mustDur(builtin.McpAuth.Cooldown, "mcpauth.cooldown")
// McpAuthRefreshSkew is how far ahead of expiry a minted App
// token stops being reused, so a token never dies mid-request.
McpAuthRefreshSkew = mustDur(builtin.McpAuth.RefreshSkew, "mcpauth.refreshSkew")
// McpAuthJWTBackdate is how far the App JWT's iat is backdated
// for clock skew between this host and GitHub.
McpAuthJWTBackdate = mustDur(builtin.McpAuth.JWTBackdate, "mcpauth.jwtBackdate")
// McpAuthJWTLifetime is the App JWT's lifetime; GitHub caps it
// at ten minutes, and this sits under the cap.
McpAuthJWTLifetime = mustDur(builtin.McpAuth.JWTLifetime, "mcpauth.jwtLifetime")
)

// TestSupport (test harness) defaults.
var (
TestSupportLeftoverGracePeriod = mustDur(builtin.TestSupport.LeftoverGracePeriod, "testsupport.leftoverGracePeriod")
TestSupportLeftoverPollInterval = mustDur(builtin.TestSupport.LeftoverPollInterval, "testsupport.leftoverPollInterval")
TestSupportEraReplyWait = mustDur(builtin.TestSupport.EraReplyWait, "testsupport.eraReplyWait")
)

// Upstream connection defaults.
var (
// UpstreamProtocol is the era preference for a server that names none.
Expand Down Expand Up @@ -573,7 +620,10 @@ var (
SaveInterval = mustDur(builtin.Daemon.SaveInterval, "daemon.saveInterval")
// TSNetUpTimeout bounds how long a tsnet node may take to authenticate
// and reach Running before its listener is believed.
TSNetUpTimeout = mustDur(builtin.Daemon.TSNetUpTimeout, "daemon.tsnetUpTimeout")
TSNetUpTimeout = mustDur(builtin.Daemon.TSNetUpTimeout, "daemon.tsnetUpTimeout")
// ScriptWaitDelay bounds how long a script view's call waits on
// its output pipes after the program exits.
ScriptWaitDelay = mustDur(builtin.Daemon.ScriptWaitDelay, "daemon.scriptWaitDelay")
SecretRequestRetention = mustDur(builtin.Secrets.RequestRetention, "secrets.requestRetention")

ShutdownGrace = mustDur(builtin.Plumbing.ShutdownGrace, "plumbing.shutdownGrace")
Expand Down Expand Up @@ -721,6 +771,9 @@ var (
// description in full turns a table into a wall.
OpCellWidth = builtin.CLI.CellWidth
UsageColumn = builtin.CLI.UsageColumn
// CLIImportTimeout bounds one import probe of a binary (its
// --help, its man page): a probe that hangs would hang the import.
CLIImportTimeout = mustDur(builtin.CLI.ImportTimeout, "cli.importTimeout")

Permissions = builtin.Script.Permissions
// RuntimeOrder is the order auto tries runtimes in.
Expand Down
17 changes: 15 additions & 2 deletions pkgs/mcpx/internal/defaults/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@
"daemon": {
"reapInterval": "30s",
"saveInterval": "5m",
"tsnetUpTimeout": "30s"
"tsnetUpTimeout": "30s",
"scriptWaitDelay": "2s"
},
"secrets": {
"requestRetention": "10m"
},
"cli": {
"cellWidth": 60,
"usageColumn": 30
"usageColumn": 30,
"importTimeout": "10s"
},
"catalog": {
"budget": 2000
Expand Down Expand Up @@ -310,5 +312,16 @@
},
"hooks": {
"timeout": "2s"
},
"mcpauth": {
"cooldown": "60s",
"refreshSkew": "5m",
"jwtBackdate": "60s",
"jwtLifetime": "9m"
},
"testsupport": {
"leftoverGracePeriod": "10s",
"leftoverPollInterval": "100ms",
"eraReplyWait": "2s"
}
}
1 change: 1 addition & 0 deletions pkgs/mcpx/internal/defaults/guard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var allowed = map[string]string{
"1<<20": "the definition of a mebibyte, in the size parser",
"1<<30": "the definition of a gibibyte, in the size parser",
"1<<40": "the definition of a tebibyte, in the size parser",
"1<<63": "the int64 sign mask: seed.Shuffle clears the sign bit of a uint64 hash to derive a non-negative int64 (MaxInt63 by arithmetic), in internal/testsupport/seed",

// A unit boundary in a duration renderer: it decides whether to print
// hours or days, which is arithmetic rather than policy.
Expand Down
12 changes: 7 additions & 5 deletions 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 @@ -81,13 +83,13 @@ type Failover struct {
StatePath string `json:"statePath,omitempty"`

// CooldownSeconds is how long a soft-blocked identity is skipped.
// A response's Retry-After wins when it is longer. Zero means 60.
// A response's Retry-After wins when it is longer. Zero means defaults.McpAuthCooldown.
CooldownSeconds int `json:"cooldownSeconds,omitempty"`
}

func (f *Failover) cooldown() time.Duration {
if f == nil || f.CooldownSeconds <= 0 {
return 60 * time.Second
return defaults.McpAuthCooldown
}
return time.Duration(f.CooldownSeconds) * time.Second
}
Expand Down Expand Up @@ -270,7 +272,7 @@ func (r *Rotator) Token(ctx context.Context, id Identity, secrets SecretFunc, mi
return secrets(id.Secret)
case "app":
r.mu.Lock()
if mt, ok := r.minted[id.Name]; ok && r.now().Before(mt.expires.Add(-5*time.Minute)) {
if mt, ok := r.minted[id.Name]; ok && r.now().Before(mt.expires.Add(-defaults.McpAuthRefreshSkew)) {
r.mu.Unlock()
return mt.token, nil
}
Expand Down Expand Up @@ -496,8 +498,8 @@ func signAppJWT(keyPEM []byte, appID int64, now time.Time) (string, error) {
header := enc([]byte(`{"alg":"RS256","typ":"JWT"}`))
claims, _ := json.Marshal(map[string]any{
"iss": appID,
"iat": now.Add(-60 * time.Second).Unix(),
"exp": now.Add(9 * time.Minute).Unix(),
"iat": now.Add(-defaults.McpAuthJWTBackdate).Unix(),
"exp": now.Add(defaults.McpAuthJWTLifetime).Unix(),
})
signing := header + "." + enc(claims)
sum := sha256.Sum256([]byte(signing))
Expand Down
4 changes: 3 additions & 1 deletion pkgs/mcpx/internal/testsupport/eramcp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ import (
"sync"
"sync/atomic"
"time"

"github.com/developing-today/code/pkgs/mcpx/internal/defaults"
)

type frame struct {
Expand Down Expand Up @@ -223,7 +225,7 @@ func handle(f frame) {
select {
case <-answered:
ok(f.ID, textResult("answered"))
case <-time.After(2 * time.Second):
case <-time.After(defaults.TestSupportEraReplyWait):
ok(f.ID, textResult("dropped"))
}
return
Expand Down
6 changes: 4 additions & 2 deletions pkgs/mcpx/internal/testsupport/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"
"sync"
"time"

"github.com/developing-today/code/pkgs/mcpx/internal/defaults"
)

// The build temp dirs this test binary created by its fixture builders
Expand Down Expand Up @@ -110,9 +112,9 @@ func processesExecutingFrom(dirs []string) []LeftoverProcess {
// allows the same 10 seconds for the asynchronous exit). Polling inside
// that budget is not leniency — a survivor past it is not draining, it
// is leaked.
var leftoverGracePeriod = 10 * time.Second
var leftoverGracePeriod = defaults.TestSupportLeftoverGracePeriod

const leftoverPollInterval = 100 * time.Millisecond
var leftoverPollInterval = defaults.TestSupportLeftoverPollInterval

// SweepBuildTempDirs is the suite-wide sweep of #1971 remainder item 2:
// it removes this test binary's build temp dirs and reports any process
Expand Down