Skip to content

core: reject arbitrary objects in nullable-number stats contract assertions #2969

Closed

Description

@schlessera

Context

Part of #2963. Source-verified finding from the 2026-10-25 multi-agent test-value audit at c670449d3bf1b0639e50ce554d728961f4313add. Broad inventory screening was followed by detailed inspection of this finding; this is not a claim of exhaustive manual review or measured CI savings.

Classification: Confirmed weak oracle; not a production defect and not a reason to remove integration coverage.

Evidence

keeps every pre-existing field and adds the health/size blocks uses ["number", "object"].includes(typeof value) for brokenLinkRate and embeddingCoverage (packages/core/tests/cli-contract.test.ts:712-740, especially 725-727). The comment promises number or null, but JavaScript reports object for {}, [] and null. Arbitrary object-valued ratios therefore satisfy this assertion. BrainStats.health actually specifies number | null (packages/core/src/lib/stats.ts:49-53) and the command emits that object at the external boundary (statsCommand, packages/core/src/cli/commands/stats.ts:472-484).

What can pass while broken / alternate proof

A command-only serialization regression that sets health.brokenLinkRate = {} before emission leaves this named contract test green on that field. The direct collector's health figures are the corpus goldens (packages/core/tests/stats.test.ts:114-124) and a corpus with no links has no broken-link rate (354-369) still prove the collector's number/null behavior, but do not protect a corruption introduced only at CLI emission.

reports the exact count the fixture staged and no table and an empty table both report 0 with unknown coverage (packages/core/tests/cli-vector-stats.test.ts:110-118, 130-143) already independently assert embedding coverage's actual 1/null variants at the CLI boundary. There was no comparable exact CLI brokenLinkRate assertion in the scoped search. This does not claim no other repository-level test could fail under a broad mutation.

Safe plan / acceptance

Replace the loose typeof-set check with an explicit number-or-null assertion, preferably fixture-specific non-null numeric expectations for the link-bearing corpus. Reuse the existing null fixtures for null-state evidence. Keep the full JSON envelope check; do not move machine-boundary proof entirely to TypeScript types or collector tests. Scan the same file's other object-shaped assertions (585, 721-722) and improve only where the contract requires a narrower structure; do not automatically call all object checks tautological.

Acceptance: {}, [], strings, booleans and a missing ratio fail the ratio oracle; valid fixture numbers and null remain valid where specified. No new CLI launch is necessary.

Focused verification/mutation proposal

Run the stats contract block and the existing vector/null controls. In an isolated checkout, corrupt only the JSON-boundary brokenLinkRate to an object; the existing assertion currently accepts that type, while the rewritten one must fail on the ratio's expected type/value. Restore and rerun. No mutation or focused baseline of this particular contract case was performed during the audit.

Scope

Narrow the existing CLI JSON ratio oracles to the actual number-or-null contract, reusing existing nonempty and null fixtures.

Out of scope

Changing product behavior, public contracts, required proof gates, offline guards, runtime pins or unrelated tests. Every distinct native, security, lifecycle and adapter obligation identified above remains. This issue does not authorize deleting the surviving owner named by another audit issue.

Acceptance criteria

  • Objects, arrays, strings, booleans and missing ratio fields fail the oracle; valid fixture numbers and documented null states pass.
  • A corruption introduced only at CLI emission fails the retained JSON-boundary assertion; no additional CLI invocation is required.
  • Record an assertion-to-owner mapping for every moved or removed case, including shared-helper obligations; do not count matching test names as proof of equivalence.
  • Run the proposed focused production mutation(s), observe failure on the intended assertion, restore, and record passing focused proof. A module-load error is not a behavioral receipt.
  • Any performance claim separates scenario/body cost, setup and total elapsed time and uses comparable observations; structural counts alone are not a speedup.

Verification

bun run test ./packages/core/tests/cli-contract.test.ts ./packages/core/tests/cli-vector-stats.test.ts ./packages/core/tests/stats.test.ts
bun run check:pr --base origin/main

Preserve the existing offline/keyless harness. Browser/native commands require the documented real runtime and OS-offline prerequisites; missing prerequisites are not passing or skipped proof. The mutation proposals and retained boundary checks are detailed above.

Contract impact

No integration-contract or product-behavior change is selected. This is test/proof maintenance; retain the current CLI/MCP/wire/schema/frontmatter envelopes. No release-content change is selected.

Activity

  1. added
    type: testCoverage, harness or proof work with no behaviour change.
    area: corepackages/core: the brain CLI, indexer, hybrid search, config, taxonomy, skills.
    on Oct 25, 2026
  2. added
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    on Oct 25, 2026
  3. schlessera commented on Oct 25, 2026

    @schlessera
    OwnerAuthor

    2026-10-26 triage at main c670449d3bf1b0639e50ce554d728961f4313add: verified the cited current test/production boundary and native #2963 parent. The scope names the retained proof, exclusions, checkable acceptance criteria, focused verification and mutation requirements; no unresolved design, decision, access or reproduction prerequisite prevents starting this test-maintenance task. Set priority p2 for wanted, unscheduled work and add agent-ready. Keep native/browser/SDK qualification required by the brief as implementation proof; this source/readiness review supplies no completed repair, post-change equivalence or measured CI saving.

  4. added this to the 0.44.0 milestone on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: corepackages/core: the brain CLI, indexer, hybrid search, config, taxonomy, skills.priority: p2Wanted, not scheduled. Pulled in when a milestone has room.type: testCoverage, harness or proof work with no behaviour change.

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions