Loop Detector

_archivesourcetypescript
Path: _archive/loom-stale-pre-sprint-snapshot/src/execution/loop-detector.tsRelative: loom-stale-pre-sprint-snapshot/src/execution/loop-detector.tsSubproject: _archiveCategory: archived
Lines: 23Bytes: 687Imports: 0Exports: 1

Content Preview

  1. /**
  2. * H3.2 — Action-hash loop detector (P5).
  3. * sha256(tool + canonicalJSON(args)) over a sliding window of W steps;
  4. * the L-th identical hash inside the window halts the stage. No 40-step doom loops.
  5. */
  6. export class LoopDetector {
  7. private readonly window: string[] = [];
  8. constructor(
  9. private readonly w: number = 10,
  10. private readonly l: number = 3
  11. ) {}
  12. /** Record a hash; returns true when the loop threshold is hit (HALT_LOOP). */
  13. record(hash: string): boolean {
  14. this.win