Skip to content

Detector: fire REPEAT_SEARCH at its declared minimum - #52

Open
Orpheus-agent wants to merge 1 commit into
mainfrom
orpheus/daily-improve-20261007-61
Open

Orpheus-agent wants to merge 1 commit into
mainfrom
orpheus/daily-improve-20261007-61

Conversation

@Orpheus-agent

Copy link
Copy Markdown
Collaborator

What

detectRepeatSearch fired one search past its declared minimum:

if (arr.length > rule.minRepeats) {   // minRepeats defaults to 2

With minRepeats: 2, a query had to be searched three times before REPEAT_SEARCH was produced. Every other count rule in src/lib/struggle/detect.ts fires at its declared minimum — minPastes: 2 fires on the 2nd paste, minToggles: 3 on the 3rd toggle, minDismisses: 2 / minRetries: 2 on the 2nd, and so on. This was the only rule using > rather than >=/< … continue.

Why it matters

The smallest possible repeat — a user running the same query twice — is exactly the case the REPEAT_SEARCH intervention copy is written for ("Same query? Try a different phrasing or a filter."). Because the rule never fired on it, that user produced no detection at all: nothing on the friction dashboard and no dispatched intervention.

Change

Fire at >= minRepeats:

if (arr.length < rule.minRepeats) continue

A regression test (tests/struggle.test.ts, detectStruggles - repeat search) pins the behaviour: it fails on the current code (expected +0 to be 1) and passes with the fix. It also asserts the rule does not fire for two different queries, and still emits a single detection per (session, element, type).

public/demo/demo.js is rebuilt from the same source because the guided demo bundles the production detector client-side; CI's stale-bundle check enforces that the checked-in bundle matches a fresh build.

Verification

  • pnpm typecheck — clean
  • pnpm lint — clean
  • pnpm test — 277 passed (274 baseline + 3 new); the new "fires on the second identical search" test was confirmed to fail against the pre-fix code
  • pnpm sdk:build / sdk:build:min / demo:build — SDK bundles unchanged; demo.js rebuilt and deterministic across two builds
  • pnpm sdk:verify, pnpm demo:verify (real Chromium, desktop + mobile) — pass
  • pnpm build — production build succeeds

Opened for review by Orpheus-agent; not auto-merged.

detectRepeatSearch used `arr.length > rule.minRepeats`, so with the default
`minRepeats: 2` a query had to be searched three times before REPEAT_SEARCH
fired. Every other count rule in the detector fires at its declared minimum
(`minPastes`, `minToggles`, `minDismisses`, `minRetries`…), and the
REPEAT_SEARCH copy ("Same query? Try a different phrasing or a filter") is
written for the smallest possible repeat. A user who searched the same thing
twice therefore produced no detection at all - nothing on the friction
dashboard, no intervention. Fire at `>= minRepeats` and pin it with a
regression test.

The guided demo bundles the production detector client-side, so
public/demo/demo.js is rebuilt from the same source to keep the checked-in
bundle in sync (CI's stale-bundle check enforces this).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant