-
Notifications
You must be signed in to change notification settings - Fork 1
feat(bg): B-0442.1 — missed-substrate detector skeleton (completes 3-skeleton mechanization suite) #3008
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
AceHack
merged 3 commits into
main
from
otto-b0442-1-missed-substrate-detector-skeleton-slice-1-impl-2026-05-13
May 13, 2026
Merged
feat(bg): B-0442.1 — missed-substrate detector skeleton (completes 3-skeleton mechanization suite) #3008
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { describe, expect, test } from "bun:test"; | ||
| import { DEFAULT_CONFIG, pollOnce, runDetector, type DetectorConfig } from "./missed-substrate-detector"; | ||
|
|
||
| describe("missed-substrate-detector slice 1", () => { | ||
| test("default config has sensible poll interval", () => { | ||
| expect(DEFAULT_CONFIG.pollIntervalMin).toBe(5); | ||
| expect(DEFAULT_CONFIG.once).toBe(false); | ||
| }); | ||
|
|
||
| test("pollOnce returns a result with no-op cascade scan", () => { | ||
| const result = pollOnce(DEFAULT_CONFIG); | ||
| expect(result.cascadesDetected).toBe(0); | ||
| expect(result.note).toContain("slice-1 skeleton"); | ||
| expect(result.pollAt).toMatch(/^\d{4}-\d{2}-\d{2}T/); | ||
| }); | ||
|
|
||
| test("runDetector with once: true exits after one iteration", async () => { | ||
| const config: DetectorConfig = { ...DEFAULT_CONFIG, once: true }; | ||
| const results = await runDetector(config); | ||
| expect(results).toHaveLength(1); | ||
| expect(results[0].cascadesDetected).toBe(0); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| // missed-substrate-detector.ts — B-0442 slice 1: skeleton + no-op poll loop | ||
| // | ||
| // Background service that detects branch-vs-merged-PR drift, e.g., commits | ||
| // landing on a feature branch AFTER its parent PR squash-merged. The | ||
| // canonical operational example: Otto-section-missed-PR-2980-by-3-min cascade | ||
| // (recovered via PR #2997). This service mechanizes detection so the cascade | ||
| // is caught BEFORE branch deletion erases substrate. | ||
|
AceHack marked this conversation as resolved.
Outdated
|
||
| // | ||
| // This slice ships ONLY the skeleton. Future slices add merged-PR state | ||
| // fetch, branch-vs-squash comparison, cascade-detection bus publish, and | ||
| // optional auto-recovery-PR opening. | ||
| // | ||
| // Run: bun tools/bg/missed-substrate-detector.ts [--once] [--poll-min N] | ||
| // Compose with: B-0442 + B-0400 (bus) + B-0440 / B-0441 (companion services). | ||
|
|
||
| export type DetectorConfig = { | ||
| /** How often to poll, in minutes */ | ||
| pollIntervalMin: number; | ||
| /** When true, run a single poll and exit */ | ||
| once: boolean; | ||
| }; | ||
|
|
||
| export const DEFAULT_CONFIG: DetectorConfig = { | ||
| pollIntervalMin: 5, | ||
| once: false, | ||
| }; | ||
|
|
||
| export type PollResult = { | ||
| pollAt: string; // ISO-8601 | ||
| cascadesDetected: number; | ||
| note: string; | ||
| }; | ||
|
|
||
| /** | ||
| * Single poll iteration. Slice 1 returns a no-op result. Future slices | ||
| * fetch recent merged PRs and compare branch HEAD against squash content. | ||
| */ | ||
| export function pollOnce(_config: DetectorConfig): PollResult { | ||
| return { | ||
| pollAt: new Date().toISOString(), | ||
| cascadesDetected: 0, | ||
| note: "slice-1 skeleton — no detection yet; future slices add merged-PR scan + branch-vs-squash compare + bus publish", | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Run the detector loop. When `once: true`, runs exactly one iteration and | ||
| * returns its result. Otherwise sleeps for pollIntervalMin between | ||
| * iterations and runs forever; results are NOT accumulated. | ||
| */ | ||
| export async function runDetector(config: DetectorConfig = DEFAULT_CONFIG): Promise<PollResult[]> { | ||
| if (config.once) { | ||
| const result = pollOnce(config); | ||
| console.log(JSON.stringify(result)); | ||
| return [result]; | ||
|
AceHack marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| while (true) { | ||
| const result = pollOnce(config); | ||
| console.log(JSON.stringify(result)); | ||
| await new Promise(resolve => setTimeout(resolve, config.pollIntervalMin * 60 * 1000)); | ||
| } | ||
| } | ||
|
|
||
| function parsePositiveMinutes(raw: string | undefined, name: string): number { | ||
| if (raw === undefined) throw new Error(`${name} requires a value`); | ||
| const n = Number(raw); | ||
| if (!Number.isFinite(n) || n <= 0) { | ||
| throw new Error(`${name} must be a positive finite number; got "${raw}"`); | ||
|
AceHack marked this conversation as resolved.
|
||
| } | ||
| return n; | ||
| } | ||
|
|
||
| function parseArgs(argv: string[]): DetectorConfig { | ||
| const config: DetectorConfig = { ...DEFAULT_CONFIG }; | ||
|
|
||
| for (let i = 0; i < argv.length; i++) { | ||
| const arg = argv[i]; | ||
| if (arg === "--once") config.once = true; | ||
| else if (arg === "--poll-min") { | ||
| config.pollIntervalMin = parsePositiveMinutes(argv[++i], "--poll-min"); | ||
| } | ||
| } | ||
|
|
||
| return config; | ||
|
AceHack marked this conversation as resolved.
Outdated
|
||
| } | ||
|
|
||
| if (import.meta.main) { | ||
| const config = parseArgs(process.argv.slice(2)); | ||
| await runDetector(config); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.