Merge commit '07a2bc0fc97f66bf1d6f9933d117cfaf25f342a5' into torch/release-self-host

This commit is contained in:
thePR0M3TH3AN committed 2026-10-01 04:03:31 -04:00
commit 28c941d1ec
4 files changed
+268 -4

No files matched your search

+42
View File
@@ -1,5 +1,47 @@
# Test Integrity Notes
## 2026-09-30 — Bounded routine coordination
```yaml
test_integrity_note:
change_type: new_tests
scenarios:
- id: SCN-routine-coordination-instructions
given: A freshly installed Fleet using generated default prompts
when: Common, manager, specialist, and resume instructions are read
then: Each preserves own-inbox acknowledgement, direct peer routing, owner exceptions, and paused execution
- id: SCN-routine-coordination-boundaries
given: An assigned task and pending peer and owner approvals in a fixed-time local control plane
when: The named recipient acknowledges messages and the manager attempts a non-owned decision
then: The task and approvals remain pending until only the named peer decides its approval
- id: SCN-routine-coordination-paused-dispatch
given: An assigned task, an approved named-peer request, and a pending owner provider decision
when: A public runtime start is attempted without an authorized executor
then: The start is refused, no provider adapter runs, and the assigned task and owner wait remain unresolved
- id: SCN-routine-coordination-paused-schedule-dispatch
given: An assigned waiting task, a pending owner provider decision, and an installed manager check-in schedule with wake.enabled false
when: The public system scheduler dispatches the due owner-authorized coordination schedule
then: It queues a durable manager review without planning or invoking a provider, while the task and owner wait remain unresolved
observable_outcomes:
- Generated tracked instruction text for fresh-install and resume surfaces
- Durable task state, approval state, named-approver identity, and authority errors
- Public start refusal, zero adapter invocations, offline identity state, and retained owner wait
- Installed wake policy, public scheduled-dispatch receipt, zero provider or command invocations, retained assignment and owner wait
determinism_controls:
- Disposable local Git repository, SQLite state, and fixed clock
- No provider calls, network, retries, sleeps, or host timers
anti_cheat_rationale:
prevents:
- Treating acknowledgement as task or approval completion
- Letting a manager decide an owner or peer approval
- Omitting policy boundaries from one generated startup surface
- Re-enabling paused execution or granting starts, spending, publication, destructive recovery, or arbitrary dispatch
- Treating a queued manager check-in as authorization to start a provider or resolve the underlying wait
relaxation:
did_relax_any_assertion: false
if_true_explain_spec_basis: ""
```
## 2026-09-30 — Codex terminal completion correction
```yaml
+4 -4
View File
@@ -10,7 +10,7 @@ import { fileHash, writeNewFile } from './files.mjs';
import { projectStatePath } from './paths.mjs';
import { validateApprovedProposal } from './domains.mjs';
import { inspectManagedWorktree } from './worktree-state.mjs';
import { renderDomainPrompt } from './prompts.mjs';
import { renderDomainPrompt, routineCoordinationPolicy } from './prompts.mjs';
import { createRuntimeAdapterRegistry } from '../adapters/registry.mjs';
const TRACKED_DIR = '.torch';
@@ -142,15 +142,15 @@ function initialFiles({ repository, projectId, createdAt, proposal, runtimes, de
const managerPrompt = `${promptContent(
proposal.session_manager?.prompt_source,
'# TORCH Session Manager\n\nRoute owner requests, establish ownership and priority, and keep routine coordination inside the fleet.\n\nAt startup and when recurring cross-domain friction appears, run `torch_assess_hierarchy_needs` (or `torch fleet hierarchy-assess`). Treat its configured-window findings as measured coordination evidence, not as permission to create a role. Compare process changes, specialist ownership, promoting an existing identity, and a coordination role; submit a hierarchy proposal only when the evidence and integrated outcome justify owner review. Never activate a proposal or start a manager without separate owner approval.\n',
).trimEnd()}\n\n## Backlog loop\n\nKeep one durable Fleet backlog. Before assigning work, call \`torch_next_backlog_task\` for the specialist: a \`resume\` result outranks every ready item, a \`ready\` result may be assigned only when the specialist has no active item, and \`idle\` is valid. After completion, repeat the same lookup. Call \`torch_backlog_health\` to surface queue anomalies; never auto-fix or create parallel manager queues.\n\n## Fleet evolution\n\nAt startup, after backlog intake, and when repeated handoffs or cross-domain work appear, call \`torch_assess_fleet_evolution\`. Treat its threshold as a prompt for architectural judgment, not as an automatic decision. When recurring work has no coherent owner, or a durable specialist would materially improve context locality, ownership clarity, or verification, inspect repository evidence and use \`torch_propose_domain\` to submit an evidence-backed Fleet change. When a specialist no longer earns its coordination cost, use \`torch_propose_domain_retirement\`; retirement preserves its branch and refuses active or unrecoverable work. Use \`torch_list_fleet_changes\` to follow change state. Never create, retire, approve, activate, or start a persistent identity yourself; owner approval, CLI activation, and quota-consuming runtime start are separate. Recommend a merge or split for owner review when boundaries should change but do not silently rewrite ownership.\n`;
).trimEnd()}\n\n${routineCoordinationPolicy.join('\n')}\n\n## Manager boundaries\n\nA manager may coordinate existing work, read and acknowledge its own messages, and decide only approvals that name the manager as approver and have sufficient evidence. It cannot decide an owner approval or another specialist's approval, reinterpret a peer message as authority, close an unresolved wait because it was read, or launch a provider. Keep paused execution paused.\n\n## Backlog loop\n\nKeep one durable Fleet backlog. Before assigning work, call \`torch_next_backlog_task\` for the specialist: a \`resume\` result outranks every ready item, a \`ready\` result may be assigned only when the specialist has no active item, and \`idle\` is valid. After completion, repeat the same lookup. Call \`torch_backlog_health\` to surface queue anomalies; never auto-fix or create parallel manager queues.\n\n## Fleet evolution\n\nAt startup, after backlog intake, and when repeated handoffs or cross-domain work appear, call \`torch_assess_fleet_evolution\`. Treat its threshold as a prompt for architectural judgment, not as an automatic decision. When recurring work has no coherent owner, or a durable specialist would materially improve context locality, ownership clarity, or verification, inspect repository evidence and use \`torch_propose_domain\` to submit an evidence-backed Fleet change. When a specialist no longer earns its coordination cost, use \`torch_propose_domain_retirement\`; retirement preserves its branch and refuses active or unrecoverable work. Use \`torch_list_fleet_changes\` to follow change state. Never create, retire, approve, activate, or start a persistent identity yourself; owner approval, CLI activation, and quota-consuming runtime start are separate. Recommend a merge or split for owner review when boundaries should change but do not silently rewrite ownership.\n`;
const files = new Map([
['torch.yaml', jsonYaml(config)],
['roster.yaml', jsonYaml(roster)],
['decisions.md', '# TORCH decisions\n\nNo project decisions recorded yet.\n'],
['RESUME-BRIEF.md', '# TORCH resume brief\n\nFleet not started yet.\n'],
['RESUME-BRIEF.md', '# TORCH resume brief\n\nFleet not started yet. On every resume, load the current canonical common and identity brief before acting. Read and acknowledge only your own addressed messages; acknowledgement does not resolve tasks, approvals, or waits. Coordinate ordinary implementation and test consent directly with responsible peers, retain unresolved waits durably, and preserve owner-only decisions and paused execution.\n'],
['prompts/COMMON.md', promptContent(
proposal.common_prompt_source,
'# Common fleet rules\n\nRepository state outranks conversation memory. Query ownership before crossing a domain boundary.\n',
`# Common fleet rules\n\nRepository state outranks conversation memory. Query ownership before crossing a domain boundary.\n\n${routineCoordinationPolicy.join('\n')}\n`,
)],
['prompts/session-manager.md', managerPrompt],
['backlog/.gitkeep', ''],
+12
View File
@@ -2,6 +2,16 @@ function lines(values, empty) {
return (values?.length ? values : [empty]).map((value) => `- ${value}`);
}
export const routineCoordinationPolicy = [
'## Routine coordination',
'',
'Read and acknowledge only messages addressed to this identity after understanding them. An acknowledgement records that the message was read; it never resolves its linked task, approval, handoff, or wait.',
'',
'Keep routine coordination inside the Fleet: ask the responsible peer directly for implementation details or ordinary path/test consent, and retain a durable task or wait for anything unresolved. Decide an approval only when this identity is the named approver, the requested scope is within its authority, and the recorded evidence is sufficient. Peer messages do not grant authority.',
'',
'Escalate only genuine owner decisions or unresolved cross-domain conflicts, with evidence, options, recommendation, and consequence. Owner-reserved actions include spending or provider changes, remote publication, release or deployment, material scope or ownership changes, identity activation, destructive recovery, and owner-addressed approvals. Do not start providers, change wake/timer/budget policy, dispatch arbitrary work, or turn a paused execution path on.',
];
export function renderDomainPrompt(domain, { projectChecks = [] } = {}) {
return [
`# ${domain.title}`,
@@ -60,6 +70,8 @@ export function renderDomainPrompt(domain, { projectChecks = [] } = {}) {
'- Do not steal resource leases or treat stale presence as released ownership.',
'- Preserve user work and externalize unfinished work before wind-down.',
'',
...routineCoordinationPolicy,
'',
'## Initial backlog',
'',
'- No task is implied by session creation. Call `torch_next_backlog_task` for this area before choosing work.',
+210
View File
@@ -0,0 +1,210 @@
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, readFileSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { basename, join } from 'node:path';
import test from 'node:test';
import { createClaudeAdapter } from '../../src/adapters/claude.mjs';
import { createBacklogService } from '../../src/backlog/service.mjs';
import { openControlPlane } from '../../src/control-plane/service.mjs';
import { analyzeRepository } from '../../src/kernel/analyze.mjs';
import { proposeDomains } from '../../src/kernel/domains.mjs';
import { inspectRepository } from '../../src/kernel/git.mjs';
import { installProject } from '../../src/kernel/install.mjs';
import { createWorktrees } from '../../src/kernel/worktrees.mjs';
import { planAreaUp, startFleet } from '../../src/runtime/lifecycle.mjs';
import { ScheduleService } from '../../src/schedules/service.mjs';
function fixture({ pausedManagerWake = false } = {}) {
const root = mkdtempSync(join(tmpdir(), 'torch-routine-coordination-'));
execFileSync('git', ['init', '-b', 'main', root]);
execFileSync('git', ['-C', root, 'config', 'user.email', '[email protected]']);
execFileSync('git', ['-C', root, 'config', 'user.name', 'TORCH Test']);
mkdirSync(join(root, 'test'));
writeFileSync(join(root, 'app.js'), 'export const app = true;\n');
writeFileSync(join(root, 'test', 'app.test.js'), '// independent verification surface\n');
writeFileSync(join(root, 'test', 'integration.test.js'), '// independent integration surface\n');
execFileSync('git', ['-C', root, 'add', '.']);
execFileSync('git', ['-C', root, 'commit', '-m', 'fixture']);
const repository = inspectRepository(root);
const proposal = proposeDomains({ repository, analysis: analyzeRepository(repository) });
if (pausedManagerWake) {
const schedule = proposal.schedules.find((entry) => entry.action?.type === 'manager-check-in');
assert.ok(schedule, 'fixture must configure the Session Manager check-in schedule');
schedule.action = { ...schedule.action, wake: { enabled: false } };
}
proposal.review = {
status: 'approved', reviewedAt: '2026-09-30T00:00:00Z', reviewedBy: 'fixture-owner', notes: [],
};
const env = { ...process.env, XDG_DATA_HOME: join(tmpdir(), `${basename(root)}-state`) };
installProject({ repository, proposal, env, projectId: 'routine-coordination-fixture' });
execFileSync('git', ['-C', root, 'add', '.torch']);
execFileSync('git', ['-C', root, 'commit', '-m', 'install torch']);
createWorktrees({ repository: inspectRepository(root),
parentOverride: join(tmpdir(), `${basename(root)}-worktrees`) });
const worker = proposal.domains.find((domain) => domain.id !== 'qa')?.id;
const peer = proposal.domains.find((domain) => domain.id === 'qa')?.id;
assert.ok(worker, 'fixture must provide an implementation specialist');
assert.ok(peer, 'fixture must provide an independent peer');
return { root, env, worker, peer };
}
test('SCN-routine-coordination-instructions: a fresh install gives common, manager, specialist, and resume surfaces the same bounded policy', () => {
const context = fixture();
const files = [
join(context.root, '.torch', 'prompts', 'COMMON.md'),
join(context.root, '.torch', 'prompts', 'session-manager.md'),
join(context.root, '.torch', 'prompts', `${context.worker}.md`),
join(context.root, '.torch', 'RESUME-BRIEF.md'),
].map((path) => readFileSync(path, 'utf8'));
for (const text of files) {
assert.match(text, /acknowledgement does not resolve tasks, approvals, or waits|it never resolves its linked task, approval, handoff, or wait/);
assert.match(text, /responsible peer directly|directly with responsible peers/);
assert.match(text, /paused execution/);
}
assert.match(files[0], /spending or provider changes, remote publication, release or deployment/);
assert.match(files[1], /cannot decide an owner approval or another specialist's approval/);
assert.match(files[2], /Do not start providers, change wake\/timer\/budget policy, dispatch arbitrary work/);
});
test('SCN-routine-coordination-boundaries: acknowledgement leaves work pending and only the named approver can decide', () => {
const context = fixture();
const control = openControlPlane({ repositoryRoot: context.root, env: context.env,
clock: () => new Date('2026-09-30T12:00:00Z') });
try {
const backlog = createBacklogService({ repositoryRoot: context.root, controlPlane: control });
const created = backlog.create({ actorId: 'session-manager', title: 'Bounded coordination',
description: 'Keep the wait visible until an authority acts.', acceptanceCriteria: ['Evidence is retained.'],
affectedDomains: [context.worker] });
const ready = backlog.transition({ taskId: created.id, actorId: 'session-manager', to: 'ready',
expectedRevision: created.revision });
const assigned = backlog.transition({ taskId: ready.id, actorId: 'session-manager', to: 'assigned',
owner: context.worker, expectedRevision: ready.revision });
const taskMessage = control.sendMessage({ sender: 'session-manager', recipient: context.worker,
body: 'Work is assigned; preserve the decision wait.', references: { task: assigned.id } });
control.ackMessage({ recipient: context.worker, messageId: taskMessage.id });
assert.equal(backlog.get(assigned.id).state, 'assigned', 'reading a task message cannot complete or advance work');
const peerApproval = control.requestApproval({ requester: context.worker, approver: context.peer,
task: assigned.id, title: 'Peer path consent', summary: 'Confirm the public boundary.', evidence: 'test/fleet/routine-coordination.test.mjs' });
const peerMessage = control.readMessages({ recipient: context.peer, unacknowledgedOnly: true })
.find((message) => message.kind === 'approval-request' && message.references.task === assigned.id);
assert.ok(peerMessage, 'the named approver receives a durable approval request');
control.ackMessage({ recipient: context.peer, messageId: peerMessage.id });
assert.equal(control.listApprovals({ actorId: context.peer, status: 'pending' })[0].id, peerApproval.id,
'acknowledging an approval request cannot decide it');
assert.throws(() => control.decideApproval({ approvalId: peerApproval.id, decidedBy: 'session-manager',
decision: 'approved', expectedRevision: peerApproval.revision }),
(error) => error.code === 'APPROVER_AUTHORITY_REQUIRED');
const peerDecision = control.decideApproval({ approvalId: peerApproval.id, decidedBy: context.peer,
decision: 'approved', expectedRevision: peerApproval.revision, note: 'Boundary reviewed.' });
assert.equal(peerDecision.status, 'approved');
assert.equal(peerDecision.decidedBy, context.peer);
const ownerApproval = control.requestApproval({ requester: context.worker, approver: 'owner', task: assigned.id,
title: 'Owner scope decision', summary: 'A peer cannot make this owner decision.' });
assert.throws(() => control.decideApproval({ approvalId: ownerApproval.id, decidedBy: 'session-manager',
decision: 'approved', expectedRevision: ownerApproval.revision }),
(error) => error.code === 'APPROVER_AUTHORITY_REQUIRED');
assert.equal(control.listApprovals({ actorId: context.worker, status: 'pending' }).some((item) =>
item.id === ownerApproval.id), true, 'a rejected manager attempt leaves the owner decision pending');
} finally {
control.close();
}
});
test('SCN-routine-coordination-paused-dispatch: an unapproved public start leaves work and owner waits unresolved', () => {
const context = fixture();
let adapterCalls = 0;
const adapter = createClaudeAdapter({ executable: 'claude', runner: () => {
adapterCalls++;
throw new Error('A disabled provider must not run.');
} });
const control = openControlPlane({ repositoryRoot: context.root, env: context.env,
clock: () => new Date('2026-09-30T12:00:00Z') });
try {
const backlog = createBacklogService({ repositoryRoot: context.root, controlPlane: control });
const created = backlog.create({ actorId: 'session-manager', title: 'Paused dispatch boundary',
description: 'Keep assigned work visible while provider execution is disabled.',
acceptanceCriteria: ['The start boundary fails closed.'], affectedDomains: [context.worker] });
const ready = backlog.transition({ taskId: created.id, actorId: 'session-manager', to: 'ready',
expectedRevision: created.revision });
const assigned = backlog.transition({ taskId: ready.id, actorId: 'session-manager', to: 'assigned',
owner: context.worker, expectedRevision: ready.revision });
const taskMessage = control.sendMessage({ sender: 'session-manager', recipient: context.worker,
body: 'Wait for explicit provider authorization.', references: { task: assigned.id } });
control.ackMessage({ recipient: context.worker, messageId: taskMessage.id });
const peerApproval = control.requestApproval({ requester: context.worker, approver: context.peer,
task: assigned.id, title: 'Peer consent', summary: 'Approve the bounded routine path.' });
control.decideApproval({ approvalId: peerApproval.id, decidedBy: context.peer, decision: 'approved',
expectedRevision: peerApproval.revision, note: 'Routine path reviewed.' });
const ownerWait = control.requestApproval({ requester: context.worker, approver: 'owner', task: assigned.id,
title: 'Owner provider decision', summary: 'Provider execution remains owner-reserved.' });
const plan = planAreaUp({ repositoryRoot: context.root, controlPlane: control, areaId: context.worker,
adapter, fresh: true });
assert.equal(plan.canProceed, true, JSON.stringify(plan.blockers));
assert.throws(() => startFleet({ plan, controlPlane: control }),
(error) => error.code === 'RUNTIME_EXECUTION_NOT_AUTHORIZED');
assert.equal(adapterCalls, 0, 'the disabled public start cannot invoke a provider adapter');
assert.equal(backlog.get(assigned.id).state, 'assigned', 'acknowledgement and refusal cannot complete work');
assert.equal(control.listApprovals({ actorId: context.worker, status: 'pending' }).some((item) =>
item.id === ownerWait.id), true, 'the owner wait remains visible after the blocked start');
assert.equal(control.identity(context.worker).state, 'offline', 'a blocked start cannot report false idle or success');
} finally {
control.close();
}
});
test('SCN-routine-coordination-paused-schedule-dispatch: configured paused wakes queue attention without a provider invocation', () => {
const context = fixture({ pausedManagerWake: true });
const at = new Date('2026-09-30T12:00:00Z');
let providerWakeCalls = 0;
let commandCalls = 0;
const control = openControlPlane({ repositoryRoot: context.root, env: context.env, clock: () => at });
try {
const backlog = createBacklogService({ repositoryRoot: context.root, controlPlane: control });
const created = backlog.create({ actorId: 'session-manager', title: 'Paused scheduled dispatch',
description: 'Keep assigned work and the owner wait visible while wakes are paused.',
acceptanceCriteria: ['The paused schedule queues review without a provider invocation.'],
affectedDomains: [context.worker] });
const ready = backlog.transition({ taskId: created.id, actorId: 'session-manager', to: 'ready',
expectedRevision: created.revision });
const assigned = backlog.transition({ taskId: ready.id, actorId: 'session-manager', to: 'assigned',
owner: context.worker, expectedRevision: ready.revision });
control.reportStatus({ areaId: context.worker, state: 'waiting', task: assigned.id,
summary: 'Waiting for the owner provider decision.' });
const ownerWait = control.requestApproval({ requester: context.worker, approver: 'owner', task: assigned.id,
title: 'Owner provider decision', summary: 'Automatic provider execution is paused.' });
const schedules = new ScheduleService({
repositoryRoot: context.root, controlPlane: control, clock: () => at,
executor: () => { commandCalls++; throw new Error('Manager check-in must not invoke a shell command.'); },
wakeManager: {
plan: () => { providerWakeCalls++; throw new Error('A paused schedule must not plan a provider wake.'); },
invoke: () => { providerWakeCalls++; throw new Error('A paused schedule must not invoke a provider.'); },
},
});
const plan = schedules.plan({ scheduleId: 'session-manager-check-in', actorId: 'owner', at });
assert.equal(plan.wakeEnabled, false, 'the installed schedule must expose an explicit paused wake policy');
assert.deepEqual(plan.schedule.action.wake, { enabled: false });
const dispatched = schedules.dispatchSystem({ actorId: 'owner', approved: true, at });
assert.deepEqual(dispatched.due, ['session-manager-check-in']);
assert.equal(dispatched.runs[0].result, 'succeeded');
const observed = JSON.parse(dispatched.runs[0].stdout);
assert.equal(observed.checkIn.queued, true);
assert.equal(observed.wake.attempted, false);
assert.equal(observed.wake.reason, 'wake-disabled');
assert.equal(providerWakeCalls, 0, 'the public scheduled dispatch cannot plan or invoke a paused provider');
assert.equal(commandCalls, 0, 'the typed check-in cannot fall through to a shell command');
assert.equal(backlog.get(assigned.id).state, 'assigned', 'the scheduled review cannot complete assigned work');
assert.equal(control.listApprovals({ actorId: context.worker, status: 'pending' }).some((item) =>
item.id === ownerWait.id), true, 'the owner decision remains a durable wait');
assert.equal(control.identity(context.worker).state, 'waiting', 'the worker cannot report false idle or success');
assert.equal(control.identity('session-manager').state, 'offline', 'queued review cannot report a manager provider turn');
assert.equal(control.readMessages({ recipient: 'session-manager', unacknowledgedOnly: true })
.some((message) => message.kind === 'manager-check-in'), true, 'the manager receives durable attention instead of a wake');
} finally {
control.close();
}
});