Skip to content

Discovery: session fragmentation + cost inefficiency #498

@arberx

Description

@arberx

Problem

Discovery probe sessions fragment into many tiny sessions instead of consolidating into one. On azcoatings, 10 sessions were created today each with only 1-2 probes. Each micro-session runs its own Gemini seed call (full executeTrackedQuery with Google Search grounding), resulting in massive waste.

Cost breakdown (azcoatings, 2026-05-15)

What happened: 10 sessions × (1 seed call + 1-2 probes) = 22 Gemini API calls

What should happen: 1 session × (1 seed call + 10 probes) = 11 Gemini API calls

Every redundant seed call is a full executeTrackedQuery with grounding — the most expensive operation in the pipeline.

Root causes

  1. No session consolidation — back-to-back discovery runs create new sessions instead of appending to an existing in-progress session
  2. Seed is per-session, not per-project — same ICP description gets re-seeded from scratch every session
  3. No cost awareness — no preview of API call impact before running discovery or promoting

Broader architecture concern

Even without fragmentation, discovery probes use executeTrackedQuery (full grounding) — the same expensive method as visibility sweeps. There is no cheaper "probe-only" mode.

Once promoted, discovered queries compound across ALL providers in every sweep. One discovered query becomes N provider calls per sweep, forever. A promotion of 30 queries × 4 providers = 120 extra API calls per sweep.

Proposed fixes

Immediate (session consolidation)

  • Reuse an existing in-progress session for the same project within a configurable time window (e.g., 1 hour)
  • Append probes to it instead of creating a new session + run

Near-term (seed reuse)

  • Cache the seed result per project for a TTL (e.g., 24h)
  • Skip re-seeding when a fresh-enough cached seed exists

Medium-term (cost controls)

  • Add --dry-run / --estimate to canonry discover run showing projected API call count
  • Add cost preview to canonry discover promote preview showing: "Adding N queries × M providers = X extra API calls per sweep"
  • Consider a "discovery-tracked" query tier that sweeps at lower frequency (e.g., every 3 sweeps)

Longer-term (cheaper probing)

  • Add a "probe-lite" mode that uses generateText (no grounding) for discovery probes — cheaper, and grounding metadata is nice-to-have for discovery, not essential
  • Allow discover promote to specify sweep frequency for promoted queries

Repro

canonry discover run azcoatings --icp "industrial coatings" --max-probes 5
canonry discover run azcoatings --icp "industrial coatings" --max-probes 5
# Creates 2 sessions instead of 1 with 10 probes

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions