feat(#3673): add dispatch.maxConcurrency axis and dispatch-capacity query (#4162)

* test(#3673): add failing tests for dispatch.maxConcurrency axis and dispatch-capacity CLI route

Extends tests/host-integration.test.cjs with negotiateHostCapabilities
maxConcurrency negotiation coverage (test matrix rows 1-15, including a
fast-check property test) and a new #3673 dispatch-capacity CLI route
describe block spawning the real gsd-tools.cjs (rows 16-25). Extends
tests/host-integration-validator-parity.test.cjs with an all-19-descriptor
maxConcurrency presence/validity sweep (row 26) and adds a hostile-input
validator test to host-integration.test.cjs (row 27).

The dispatch.maxConcurrency field does not exist yet, so these tests fail.

* feat(#3673): add dispatch.maxConcurrency axis, negotiation, validator parity, and the dispatch-capacity query

Adds a numeric dispatch.maxConcurrency sub-field to the Host-Integration
Interface (ADR-1239 Phase 1), following the existing dispatch.isolation
sub-field pattern: DispatchCapability interface, SAFE_DEFAULTS/PROFILE_BASELINES
floors, and a negotiateHostCapabilities branch that passes through a positive
safe integer and fails closed to 1 otherwise (no engine-side reduction, per
the design doc's explicit rejection of a min(host,engine) rule).

capability-validator.cjs gains parity validation for the new field (optional,
positive safe integer or the "undocumented" sentinel — mirroring isolation's
"added after existing descriptors" treatment).

gsd-tools.cjs gains a new `query dispatch-capacity` route, a pure-read sibling
of `dispatch-isolation` with no side effects: live env
(GSD_DISPATCH_MAX_CONCURRENCY) > descriptor > fallback-to-1 precedence.

All 19 capabilities/*/capability.json descriptors now declare
dispatch.maxConcurrency: claude carries the one cited value (20, per
code.claude.com/docs/en/sub-agents); the other 18 carry "undocumented"
(not yet researched for this axis).

* docs(#3673): document dispatch.maxConcurrency and add its citation row to the capability matrix

Updates docs/reference/host-integration-interface.md's dispatch struct entry
(also backfilling the previously-undocumented isolation/backgroundDispatch
sub-fields found stale in the same table) and adds fail-closed/live-transport
precedence prose for the new maxConcurrency field.

Adds a dispatch.maxConcurrency row (with citation) to all 19 host sections in
docs/reference/host-integration-capability-matrix.md — required for
tests/host-integration-descriptors.test.cjs's kimi-code matrix-parity check,
which asserts every declared dispatch sub-axis is documented there.

Updates docs/how-to/add-or-update-a-host-integration.md's dispatch checklist
and example descriptor block to mention maxConcurrency (and, likewise
backfilling a stale gap, isolation/backgroundDispatch).

* fix(#3673): extract shared maxConcurrency validator, drop dead reserved-name check

Exports isPositiveSafeInteger from src/host-integration.cts as the single
source of truth for the dispatch.maxConcurrency positive-safe-integer
contract; negotiateHostCapabilities and gsd-tools.cjs's routeDispatchCapacity
now both call it instead of independently reimplementing the same predicate.

Also removes the __proto__/constructor/prototype reserved-name branch from
capability-validator.cjs's maxConcurrency check — copy-pasted from the
string-enum fields above it, but unreachable for a numeric field (the
generic positive-safe-integer branch already rejects any string) and absent
from maxDepth, the field the code's own comment claims to mirror.

---------

Co-authored-by: sim <sim@local>
This commit is contained in:
Tom Boucher
2026-09-01 21:39:12 -04:00
committed by GitHub
parent b848b23861
commit c0fd2e3f4c
28 changed files with 714 additions and 67 deletions

View File

@@ -1886,6 +1886,112 @@ function dispatchOverlayCapabilityCommand({ command, args, cwd, raw, error, load
}
}
/**
* #3673 (ADR-1239 Phase 1) — typed, PURE-READ query exposing the negotiated
* `dispatch.maxConcurrency` numeric sub-field. Sibling of `dispatch-isolation`
* above, but — per the #3673 design doc's explicit rejection of a write path
* for this query — writes NOTHING: no sentinel file, no side effect at all.
* A read-only capacity lookup for a later (Phase 4) scheduler to consult.
*
* Precedence:
* 1. GSD_DISPATCH_MAX_CONCURRENCY, if it parses as a positive safe
* integer → source: "live". A malformed value (non-numeric, zero,
* negative, fractional) is treated exactly as if the variable were
* unset — it falls through to tier 2, never errors.
* 2. registry.runtimes[id].runtime.hostIntegration.dispatch.maxConcurrency,
* if it is a positive safe integer → source: "descriptor". The
* "undocumented" sentinel and any other malformed shape fall through
* to tier 3.
* 3. 1 (the fail-closed floor) → source: "fallback".
*
* `isPositiveSafeInteger`, required below from `./lib/host-integration.cjs`,
* is the SAME exported predicate src/host-integration.cts's
* negotiateHostCapabilities applies to the descriptor value — applied
* identically to both the env value and the descriptor value here so the
* two tiers can never silently disagree on what counts as valid.
*
* `reason` names why the WINNING tier (or the fallback) was chosen: "ok" on
* the happy path (live or descriptor honored), else "missing" (descriptor
* omitted the field), "undocumented" (descriptor sentinel), "non_integer"
* (fractional or NaN), "unsafe_integer" (integer but outside
* Number.isSafeInteger's range), "non_positive" (zero or negative),
* "non_numeric" (string/object/array/null/boolean), or "unknown_runtime"
* (no registry entry for the resolved runtime id — resolution itself never
* throws; failure fails closed to the same fallback tier).
*
* Output:
* --raw → prints exactly one positive integer, nothing else
* --json → prints { runtime, capacity, declared, source, reason }
* default → same as --raw
*/
function routeDispatchCapacity({ args, cwd, raw }) {
const { UNDOCUMENTED, isPositiveSafeInteger } = require('./lib/host-integration.cjs');
let runtimeId = null;
let runtimeEntry = null;
try {
const { resolveRuntime } = require('./lib/runtime-slash.cjs');
runtimeId = resolveRuntime(cwd);
const registry = require('./lib/capability-registry.cjs');
runtimeEntry = registry.runtimes != null ? registry.runtimes[runtimeId] : null;
} catch {
runtimeEntry = null;
}
const declared = runtimeEntry?.runtime?.hostIntegration?.dispatch?.maxConcurrency ?? null;
let liveValue = null;
const rawEnv = process.env.GSD_DISPATCH_MAX_CONCURRENCY;
if (typeof rawEnv === 'string' && rawEnv.trim().length > 0) {
const parsed = Number(rawEnv.trim());
if (isPositiveSafeInteger(parsed)) {
liveValue = parsed;
}
}
let capacity;
let source;
let reason;
if (liveValue !== null) {
capacity = liveValue;
source = 'live';
reason = 'ok';
} else if (runtimeEntry == null) {
capacity = 1;
source = 'fallback';
reason = 'unknown_runtime';
} else if (declared === UNDOCUMENTED) {
capacity = 1;
source = 'fallback';
reason = 'undocumented';
} else if (isPositiveSafeInteger(declared)) {
capacity = declared;
source = 'descriptor';
reason = 'ok';
} else if (declared === null || declared === undefined) {
capacity = 1;
source = 'fallback';
reason = 'missing';
} else if (typeof declared !== 'number') {
capacity = 1;
source = 'fallback';
reason = 'non_numeric';
} else if (!Number.isSafeInteger(declared)) {
capacity = 1;
source = 'fallback';
reason = Number.isInteger(declared) ? 'unsafe_integer' : 'non_integer';
} else {
capacity = 1;
source = 'fallback';
reason = 'non_positive';
}
if (args.indexOf('--json') !== -1) {
output({ runtime: runtimeId, capacity, declared, source, reason }, raw);
} else {
process.stdout.write(String(capacity));
}
}
// #3714 follow-up — the dispatch seam gated only on PRESENCE of an explicit
// pin, never on its VALUE, so an Anthropic-flavored global default
// (~/.gsd/defaults.json model_overrides["gsd-executor"] = "sonnet"/"opus"/
@@ -4079,6 +4185,7 @@ const HOST_COMMAND_ROUTERS = {
'normalize-test-command': routeNormalizeTestCommand,
'dispatch-should-flatten': routeDispatchShouldFlatten,
'dispatch-isolation': routeDispatchIsolation,
'dispatch-capacity': routeDispatchCapacity,
'inspect-dispatch-isolation': routeInspectDispatchIsolation,
'record-dispatch-isolation': routeRecordDispatchIsolation,
'resolve-dispatch-type': routeResolveDispatchType,
@@ -4339,7 +4446,7 @@ const TOP_LEVEL_USAGE = 'Usage: gsd-tools <command> [args] [--raw] [--pick <fiel
'generate-dev-preferences, generate-slug, graphify, history-digest, init, intel, ' +
'capability, classify-confidence, git, learnings, list-seeds, list-todos, loop, milestone, package-legitimacy, phase, phase-plan-index, phases, planning, profile-questionnaire, ' +
'profile-sample, progress, project-instruction-file, prompt-budget, quick-tasks-append, requirements, research-plan, research-store, resolve-granularity, resolve-model, restore-custom-files, roadmap, runtime-identity, scaffold, smart-entry, state, ' +
'config-set-model-profile, dispatch-isolation, dispatch-should-flatten, inspect-dispatch-isolation, record-dispatch-isolation, estimate-calibrate, estimate-calibration, estimate-check, resolve-agent, resolve-dispatch-type, ' +
'config-set-model-profile, dispatch-capacity, dispatch-isolation, dispatch-should-flatten, inspect-dispatch-isolation, record-dispatch-isolation, estimate-calibrate, estimate-calibration, estimate-check, resolve-agent, resolve-dispatch-type, ' +
'resolve-execution, review-lane, skill-manifest, skills-root, state-snapshot, stats, summary-extract, teams-status, todo, uat, update-context, verification, websearch, windows, ' +
'task, template, user-story, validate, verify, verify-path-exists, verify-summary, eval, workstream, worktree\n\n' +
'Global flags:\n' +

View File

@@ -183,7 +183,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": "undocumented",
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -437,7 +438,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": "undocumented",
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -581,7 +583,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "harness-worktree"
"isolation": "harness-worktree",
"maxConcurrency": 20
},
"modelMode": "passive",
"hookBus": "host",
@@ -828,7 +831,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "read-only",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -1011,7 +1015,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -1162,7 +1167,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": true,
"isolation": "orchestrator-worktree"
"isolation": "orchestrator-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -1325,7 +1331,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -1424,7 +1431,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": true,
"isolation": "harness-worktree"
"isolation": "harness-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -1906,7 +1914,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "read-only",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -2074,7 +2083,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "undocumented",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -2173,7 +2183,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "undocumented",
"backgroundDispatch": true,
"isolation": "orchestrator-worktree"
"isolation": "orchestrator-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -2288,7 +2299,8 @@ const capabilities = {
"explore",
"plan"
],
"isolation": "orchestrator-worktree"
"isolation": "orchestrator-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -2933,7 +2945,8 @@ const capabilities = {
"background": false,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "orchestrator-worktree"
"isolation": "orchestrator-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -3123,7 +3136,8 @@ const capabilities = {
"background": false,
"backgroundDispatch": false,
"subagentToolkit": "undocumented",
"isolation": "none"
"isolation": "none",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -3307,7 +3321,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -3765,7 +3780,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "undocumented",
"backgroundDispatch": "undocumented",
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "engine",
@@ -3922,7 +3938,8 @@ const capabilities = {
"background": true,
"subagentToolkit": "undocumented",
"backgroundDispatch": "undocumented",
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "engine",
@@ -4007,7 +4024,8 @@ const capabilities = {
"background": "undocumented",
"subagentToolkit": "undocumented",
"backgroundDispatch": "undocumented",
"isolation": "none"
"isolation": "none",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -4121,7 +4139,8 @@ const capabilities = {
"background": false,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "none"
"isolation": "none",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -5455,7 +5474,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": "undocumented",
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -5626,7 +5646,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": "undocumented",
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -5724,7 +5745,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "harness-worktree"
"isolation": "harness-worktree",
"maxConcurrency": 20
},
"modelMode": "passive",
"hookBus": "host",
@@ -5883,7 +5905,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "read-only",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -6005,7 +6028,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -6106,7 +6130,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": true,
"isolation": "orchestrator-worktree"
"isolation": "orchestrator-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -6269,7 +6294,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -6368,7 +6394,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": true,
"isolation": "harness-worktree"
"isolation": "harness-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -6546,7 +6573,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "read-only",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -6662,7 +6690,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "undocumented",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -6761,7 +6790,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "undocumented",
"backgroundDispatch": true,
"isolation": "orchestrator-worktree"
"isolation": "orchestrator-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -6876,7 +6906,8 @@ const runtimes = {
"explore",
"plan"
],
"isolation": "orchestrator-worktree"
"isolation": "orchestrator-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -7052,7 +7083,8 @@ const runtimes = {
"background": false,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "orchestrator-worktree"
"isolation": "orchestrator-worktree",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -7188,7 +7220,8 @@ const runtimes = {
"background": false,
"backgroundDispatch": false,
"subagentToolkit": "undocumented",
"isolation": "none"
"isolation": "none",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "host",
@@ -7295,7 +7328,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -7436,7 +7470,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "undocumented",
"backgroundDispatch": "undocumented",
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "engine",
@@ -7498,7 +7533,8 @@ const runtimes = {
"background": true,
"subagentToolkit": "undocumented",
"backgroundDispatch": "undocumented",
"isolation": "undocumented"
"isolation": "undocumented",
"maxConcurrency": "undocumented"
},
"modelMode": "active",
"hookBus": "engine",
@@ -7583,7 +7619,8 @@ const runtimes = {
"background": "undocumented",
"subagentToolkit": "undocumented",
"backgroundDispatch": "undocumented",
"isolation": "none"
"isolation": "none",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",
@@ -7697,7 +7734,8 @@ const runtimes = {
"background": false,
"subagentToolkit": "full",
"backgroundDispatch": false,
"isolation": "none"
"isolation": "none",
"maxConcurrency": "undocumented"
},
"modelMode": "passive",
"hookBus": "host",

View File

@@ -1643,6 +1643,28 @@ function validateRuntimeBody(cap) {
' (or "undocumented") (got: ' + JSON.stringify(d.isolation) + ')',
);
}
// maxConcurrency — ADR-1239 Phase 1 (#3673). A numeric dispatch
// sub-field (not a closed-vocabulary enum member — same numeric
// dispatch sub-field treatment as maxDepth above; unlike maxDepth,
// 0 and negative values are invalid — 1 is the fail-closed floor, not
// a legitimate "no concurrency" declaration).
// OPTIONAL, like isolation: added after existing descriptors, so an
// omitted maxConcurrency is legitimate — negotiateHostCapabilities
// degrades it to 1 (the safe floor) and warns, exactly as for any
// other undeclared dispatch sub-field. Only a PRESENT value is
// checked against the positive-safe-integer contract.
if (d.maxConcurrency === undefined) {
// absent — nothing to validate; negotiateHostCapabilities fails it closed.
} else if (
d.maxConcurrency !== 'undocumented' &&
(!Number.isSafeInteger(d.maxConcurrency) || d.maxConcurrency < 1)
) {
errors.push(
'runtime.hostIntegration.dispatch.maxConcurrency must be a positive safe integer or "undocumented" ' +
'(got: ' + JSON.stringify(d.maxConcurrency) + ')',
);
}
}
}