deepseek-ai/deepseek-harness · error

invariants: contains invalid regex

Error message

invariants: ${field} contains invalid regex ${JSON.stringify(value)}

What it means

Config validation in the invariants plugin: an entry in package_allowlist/package_blocklist is not a syntactically valid regular expression (the RegExp constructor threw). Fails at load so pattern compilation errors surface immediately.

Solutions

  1. Fix the regex so it compiles.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at packages/runtime-diagnostics/invariants/src/index.ts:88 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of deepseek-ai/deepseek-harness@b150a551b8 (2026-08-24). Data as JSON: /api/errors/16fbd9a9ba1b5071. Report an issue: GitHub.

Appendix: source

Thrown at packages/runtime-diagnostics/invariants/src/index.ts:88

    invariants: InvariantRegistry
  }
}

/** Compile and validate one package-filter list. */
function compilePatterns(field: 'package_allowlist' | 'package_blocklist', values: readonly string[]): RegExp[] {
  const seen = new Set<string>()
  return values.map((value) => {
    if (value.length === 0 || value.trim() !== value) {
      throw new Error(`invariants: ${field} entries must be non-blank and have no surrounding whitespace`)
    }
    if (seen.has(value)) {
      throw new Error(`invariants: ${field} contains duplicate regex ${JSON.stringify(value)}`)
    }
    seen.add(value)
    try {
      return new RegExp(value)
    } catch (cause) {
      throw new Error(`invariants: ${field} contains invalid regex ${JSON.stringify(value)}`, { cause })
    }
  })
}

/** Package-owned invariant registry with global and regex-based selection. */
export class InvariantRegistry extends Service {
  static Config: Schema<Config> = z.object({
    enabled: z.boolean().default(true),
    package_allowlist: z.array(z.string()).default([]),
    package_blocklist: z.array(z.string()).default([]),
  })

  private readonly enabled: boolean
  private readonly ownerCtx: Context
  private readonly packageAllowlist: readonly RegExp[]
  private readonly packageBlocklist: readonly RegExp[]
  private readonly registrations = new Set<string>()

View on GitHub (pinned to b150a551b8)