feat(#1708): typed documentation-sourced #853 dispatch-flatten (ADR-1239 Phase B) (#1719)

* feat(#1708): typed documentation-sourced #853 dispatch-flatten

Graduate the #853 orchestrator-backgrounding decision from a scattered RUNTIME==='codex' prose check to a typed, documentation-sourced engine decision. Adds a backgroundDispatch dispatch sub-axis (sourced per host: codex+cursor documented true, 9 documented false, 5 undocumented), shouldFlattenDispatch(dispatch) (inline UNLESS background && backgroundDispatch, fail-closed), and a gsd_run query dispatch-should-flatten the plan/execute workflows call. Cursor is newly background-eligible per its docs (inline->background) — a documentation-justified behavior change. No RUNTIME-name residue for this decision.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* docs(#1708): backgroundDispatch citations in matrix + CONTEXT note

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* fix(#1708): address review findings on typed dispatch-flatten

Code/adversarial review: convert the manager.md/autonomous.md Compound Action preamble from hardcoded 'On Codex' to FLATTEN-based branching (the handlers already use the query; the preamble contradicted them and was wrong for cursor); make shouldFlattenDispatch null-safe + type-honest (accepts raw 'undocumented' registry values); make backgroundDispatch a required descriptor field (matching its siblings, all 16 carry it); strengthen the config.runtime behavioral test; update the bug-853 prose-pin test + comment. Security review clean; Codex confirmed no fail-open.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test(#1708): backfill backgroundDispatch in role:runtime test fixtures

Making backgroundDispatch a required descriptor field broke role:runtime fixtures in capability-manifest-version/capability-registry/host-integration-descriptors tests that build a dispatch object without it (caught by full gsd-test, not scoped npm test). Backfill backgroundDispatch:false into the well-formed fixtures; the deliberately-malformed 'required-field' test fixture is left malformed by design.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test(#1708): update fix-1521 dispatch-gating assertion to the FLATTEN gate

fix-1521 pinned the codex-specific run_in_background prose that #1708 graduated to the typed dispatch-should-flatten/FLATTEN gate. Update its assertions to verify FLATTEN=false gating (not a runtime name) + that the old RUNTIME===codex gate is gone. Caught by full gsd-test.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* docs(#1708): add changeset for typed dispatch-flatten

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* chore(#1708): remove stray temp PR-body file

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test(#1708): add issue ref to bug-853 allow-test-rule annotations

ADR-456 requires every allow-test-rule exemption to carry a see #NNN reference; the source-text-is-the-product annotations added when migrating the prose assertions lacked it (lint-tests CI gate). Add (see #1708).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Tom Boucher
2026-06-25 15:37:33 -04:00
committed by GitHub
parent 481d121dd4
commit cf2e66b39e
33 changed files with 744 additions and 149 deletions

View File

@@ -844,6 +844,155 @@ describe('Fix: degradationFor unknown point → {level:"absent", unknown:true}',
});
});
// ---------------------------------------------------------------------------
// Phase B: shouldFlattenDispatch — ADR-1239 Phase B / #1708
// ---------------------------------------------------------------------------
describe('Phase B: shouldFlattenDispatch — contract pin', () => {
const { shouldFlattenDispatch } = hi;
test('shouldFlattenDispatch is exported as a function', () => {
assert.strictEqual(typeof shouldFlattenDispatch, 'function',
'shouldFlattenDispatch must be exported from host-integration module');
});
test('{background:true, backgroundDispatch:true} → false (background OK)', () => {
assert.strictEqual(shouldFlattenDispatch({ background: true, backgroundDispatch: true }), false,
'canBackground=true when both background===true AND backgroundDispatch===true → flatten=false');
});
test('{background:true, backgroundDispatch:false} → true (must flatten)', () => {
assert.strictEqual(shouldFlattenDispatch({ background: true, backgroundDispatch: false }), true,
'backgroundDispatch===false → canBackground=false → flatten=true');
});
test('{background:true, backgroundDispatch:"undocumented"} → true (undocumented is not === true)', () => {
assert.strictEqual(shouldFlattenDispatch({ background: true, backgroundDispatch: 'undocumented' }), true,
'"undocumented" is not === true → canBackground=false → flatten=true');
});
test('{background:false, backgroundDispatch:true} → true (background is false)', () => {
assert.strictEqual(shouldFlattenDispatch({ background: false, backgroundDispatch: true }), true,
'background===false → canBackground=false → flatten=true');
});
test('{} (empty) → true (missing fields → fail-closed)', () => {
assert.strictEqual(shouldFlattenDispatch({}), true,
'empty dispatch → canBackground=false → flatten=true');
});
test('missing fields individually', () => {
assert.strictEqual(shouldFlattenDispatch({ background: true }), true,
'backgroundDispatch missing → not === true → flatten=true');
assert.strictEqual(shouldFlattenDispatch({ backgroundDispatch: true }), true,
'background missing → not === true → flatten=true');
});
// M1: null-safety — null/undefined/non-object dispatch must fail-closed (not throw)
test('null dispatch → true (fail-closed, no throw)', () => {
assert.strictEqual(shouldFlattenDispatch(null), true,
'null dispatch must fail-closed to true');
});
test('undefined dispatch → true (fail-closed, no throw)', () => {
assert.strictEqual(shouldFlattenDispatch(undefined), true,
'undefined dispatch must fail-closed to true');
});
test('string dispatch → true (fail-closed, no throw)', () => {
assert.strictEqual(shouldFlattenDispatch('x'), true,
'non-object dispatch (string) must fail-closed to true');
});
// #853 codex-like profile: full dispatch including backgroundDispatch:true → background OK
test('#853 codex-like: {namedDispatch:true,nested:true,maxDepth:1,background:true,subagentToolkit:"full",backgroundDispatch:true} → false (background OK)', () => {
assert.strictEqual(
shouldFlattenDispatch({ namedDispatch: true, nested: true, maxDepth: 1, background: true, subagentToolkit: 'full', backgroundDispatch: true }),
false,
'codex-like dispatch with backgroundDispatch:true must be background-OK (flatten=false)',
);
});
// #853 claude-like profile: backgroundDispatch:false → must flatten
test('#853 claude-like: {...,background:true,backgroundDispatch:false} → true (inline)', () => {
assert.strictEqual(
shouldFlattenDispatch({ namedDispatch: true, nested: true, maxDepth: -1, background: true, subagentToolkit: 'full', backgroundDispatch: false }),
true,
'claude-like dispatch with backgroundDispatch:false must flatten inline',
);
});
});
// ---------------------------------------------------------------------------
// Phase B: negotiateHostCapabilities — backgroundDispatch field
// ---------------------------------------------------------------------------
describe('Phase B: negotiateHostCapabilities — backgroundDispatch', () => {
test('host dispatch.backgroundDispatch:true against DEFAULT_ENGINE → effective.dispatch.backgroundDispatch===true', () => {
const result = negotiateHostCapabilities({
...PROFILE_BASELINES['programmatic-cli'],
dispatch: { namedDispatch: true, nested: true, maxDepth: -1, background: true, subagentToolkit: 'full', backgroundDispatch: true },
});
assert.strictEqual(result.effective.dispatch.backgroundDispatch, true,
'backgroundDispatch:true on host AND engine must yield effective backgroundDispatch===true');
});
test('host dispatch.backgroundDispatch:"undocumented" → effective.dispatch.backgroundDispatch===false + warning', () => {
const result = negotiateHostCapabilities({
...PROFILE_BASELINES['programmatic-cli'],
dispatch: { namedDispatch: true, nested: true, maxDepth: -1, background: true, subagentToolkit: 'full', backgroundDispatch: 'undocumented' },
});
assert.strictEqual(result.effective.dispatch.backgroundDispatch, false,
'"undocumented" must fail-closed to false');
const warnText = result.warnings.join(' ');
assert.ok(warnText.includes('backgroundDispatch') && warnText.includes('undocumented'),
`Expected warning about backgroundDispatch being undocumented; got: ${warnText}`);
});
test('host dispatch.backgroundDispatch:false → effective.dispatch.backgroundDispatch===false', () => {
const result = negotiateHostCapabilities({
...PROFILE_BASELINES['programmatic-cli'],
dispatch: { namedDispatch: true, nested: true, maxDepth: -1, background: true, subagentToolkit: 'full', backgroundDispatch: false },
});
assert.strictEqual(result.effective.dispatch.backgroundDispatch, false);
});
test('host dispatch without backgroundDispatch key → effective.dispatch.backgroundDispatch===false (fail-closed)', () => {
const result = negotiateHostCapabilities({
...PROFILE_BASELINES['programmatic-cli'],
dispatch: { namedDispatch: true, nested: true, maxDepth: -1, background: true, subagentToolkit: 'full' },
});
assert.strictEqual(result.effective.dispatch.backgroundDispatch, false,
'Missing backgroundDispatch key must fail-closed to false');
});
test('negotiateHostCapabilities({}) → effective.dispatch.backgroundDispatch===false', () => {
const result = negotiateHostCapabilities({});
assert.strictEqual(result.effective.dispatch.backgroundDispatch, false,
'Empty host must produce backgroundDispatch===false (SAFE_DEFAULTS)');
});
test('SAFE_DEFAULTS.dispatch.backgroundDispatch is false', () => {
// Verified via negotiation with empty host
const result = negotiateHostCapabilities({});
assert.strictEqual(result.effective.dispatch.backgroundDispatch, false);
});
test('DEFAULT_ENGINE.axes.dispatch.backgroundDispatch is true', () => {
assert.strictEqual(DEFAULT_ENGINE.axes.dispatch.backgroundDispatch, true,
'DEFAULT_ENGINE (full engine) must declare backgroundDispatch:true');
});
test('existing dispatch tests still pass — effective.dispatch.namedDispatch present alongside backgroundDispatch', () => {
const result = negotiateHostCapabilities(PROFILE_BASELINES['programmatic-cli']);
const d = result.effective.dispatch;
assert.ok('namedDispatch' in d, 'namedDispatch must still be present');
assert.ok('backgroundDispatch' in d, 'backgroundDispatch must be present');
assert.ok('nested' in d && 'maxDepth' in d && 'background' in d && 'subagentToolkit' in d,
'all original dispatch fields must still be present');
});
});
// ---------------------------------------------------------------------------
// Fix 2: negotiateHostCapabilities — host omitting 'dispatch' → subagentToolkit 'read-only'
// ---------------------------------------------------------------------------