Files
proffesor-for-testing__agen…/docs/implementation/specs/SPEC-033-B-speculative-execution.md
Profa 2253d05618 feat: flatten project structure — archive v2, promote v3 to root
Remove the nested v3/ subdirectory by moving all active source code,
tests, configs, and assets directly to the project root. Archive v2/
(dead code, 847MB) to v2-archive.tar.gz.

Key changes:
- Move v3/src/ → src/, v3/tests/ → tests/, v3/packages/ → packages/
- Move v3/tsconfig.json, v3/vitest.config.ts to root
- Merge v3/package.json into root package.json (ESM, scripts, deps, exports)
- Merge v3/scripts/ into scripts/, v3/implementation/ into docs/implementation/
- Update all CI workflows to remove "cd v3 &&" and v3/ path prefixes
- Fix all init installer path resolution (3-level-up → 2-level-up)
- Fix hooks to use "node ./dist/cli/bundle.js" instead of bare "aqe"
- Update settings.json ADR/DDD directories to docs/implementation/
- Fix helper scripts (statusline, adr-compliance, ddd-tracker, guidance-hooks)
- Update 58 agent definitions: aqe/v3/ → aqe/ memory namespaces
- Update 15 guidance shards: v3/src/ → src/ path references
- Fix sync interfaces: remove v3/ and v2/ path references
- Fix test path calculations (process.cwd() + '..' no longer needed)
- Fix flaky perf test threshold (500ms → 1000ms for CI environments)
- Fix complexity-analyzer test to match ADR-051 keyword-based eligibility

Build passes, 17,901 tests pass, CLI and MCP bundles verified.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 11:35:41 +00:00

4.4 KiB

SPEC-033-B: Speculative Execution

Field Value
Specification ID SPEC-033-B
Parent ADR ADR-033
Version 1.0
Status Draft
Last Updated 2026-01-20
Author Architecture Team

Overview

This specification defines the speculative test execution system that predicts outcomes for skipped test layers after an early exit decision. It enables the system to maintain quality confidence while reducing compute time.


Speculative Result Types

export interface SpeculativeResult {
  /** Predicted outcome */
  predicted: 'pass' | 'fail' | 'flaky';

  /** Confidence in prediction (0-1) */
  confidence: number;

  /** Whether prediction was verified */
  verified: boolean;

  /** Actual outcome (if verified) */
  actual?: 'pass' | 'fail' | 'flaky';

  /** Whether speculation was correct */
  correct?: boolean;
}

SpeculativeExecutor Class

export class SpeculativeExecutor {
  constructor(private config: EarlyExitConfig) {}

  /** Generate speculative predictions for skipped layers */
  async speculate(
    exitDecision: EarlyExitDecision,
    skippedLayers: TestLayer[]
  ): Promise<SpeculativeResult[]> {
    const results: SpeculativeResult[] = [];

    for (const layer of skippedLayers) {
      // Predict based on historical patterns and current quality signal
      const prediction = await this.predictLayerOutcome(layer, exitDecision);
      results.push(prediction);
    }

    return results;
  }

  /** Verify speculative predictions with actual execution */
  async verify(
    speculations: SpeculativeResult[],
    skippedLayers: TestLayer[]
  ): Promise<SpeculativeResult[]> {
    const verified: SpeculativeResult[] = [];

    for (let i = 0; i < speculations.length && i < this.config.verificationLayers; i++) {
      const layer = skippedLayers[i];
      const speculation = speculations[i];

      // Run actual tests
      const actual = await this.runLayer(layer);

      verified.push({
        ...speculation,
        verified: true,
        actual: actual.outcome,
        correct: speculation.predicted === actual.outcome,
      });
    }

    // Include unverified speculations
    for (let i = this.config.verificationLayers; i < speculations.length; i++) {
      verified.push(speculations[i]);
    }

    return verified;
  }

  private async predictLayerOutcome(
    layer: TestLayer,
    decision: EarlyExitDecision
  ): Promise<SpeculativeResult> {
    // Simple heuristic: high confidence predicts pass
    const passThreshold = 0.85;

    if (decision.confidence >= passThreshold) {
      return {
        predicted: 'pass',
        confidence: decision.confidence,
        verified: false,
      };
    } else if (decision.confidence >= 0.7) {
      return {
        predicted: 'flaky',
        confidence: decision.confidence,
        verified: false,
      };
    } else {
      return {
        predicted: 'fail',
        confidence: 1 - decision.confidence,
        verified: false,
      };
    }
  }

  private async runLayer(layer: TestLayer): Promise<{ outcome: 'pass' | 'fail' | 'flaky' }> {
    // Execute actual tests
    const executor = new TestExecutor(layer);
    const result = await executor.run();

    if (result.passRate >= 0.99) {
      return { outcome: 'pass' };
    } else if (result.flakyRatio > 0.1) {
      return { outcome: 'flaky' };
    } else {
      return { outcome: 'fail' };
    }
  }
}

Validation Rules

Rule ID Description Severity
SPEC-033-B-001 verificationLayers must be >= 0 Error
SPEC-033-B-002 Prediction confidence must be 0-1 Error
SPEC-033-B-003 Verification count <= speculation count Warning

Spec ID Title Relationship
SPEC-033-A Early Exit Algorithm Provides exit decisions
SPEC-033-C Controller Integration Orchestrates speculation

Changelog

Version Date Author Changes
1.0 2026-01-20 Architecture Team Initial specification

References