Skip to content

Prospects: durable runs — frozen input, stop, per-run results, rerun, clarifying questions - #662

Open
rafchen wants to merge 3 commits into
mainfrom
growth/prospects-run-lifecycle
Open

rafchen wants to merge 3 commits into
mainfrom
growth/prospects-run-lifecycle

Conversation

@rafchen

@rafchen rafchen commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

This makes Prospects runs durable, faster to repeat, and reliable to stop.

  1. Each run freezes its input.
    • distribution_runs.input holds the segment as it was, plus any answers given before the run.
    • Every step reads that copy through programForRun, including exclusions. Editing a segment mid-run changes nothing, and a run can be repeated exactly.
  2. Stop works.
    • A new stopped status.
    • Inngest cancelOn on the job.
    • Inline runs watch their own row, so a stop works whichever server receives it.
    • Every step checks for a stop, so a lost cancel stops spending.
    • Finished statuses, and their error message, are never overwritten.
    • A stopped run keeps a summary of what it did.
  3. Per-run results.
    • distribution_run_results points at the segment's company rows, which stay as the shared pipeline (stage, notes, people).
    • Each run keeps its own scored list, and the run sheet shows it.
  4. Run again.
    • Reruns from the frozen input and reuses the plan, with no planning call.
    • Research done for this segment and input in the last 7 days is reused: no site reads, model calls, publishing or credits. The fit check and score still run again.
    • Reuse is keyed to partner_relationships.researched_at / researched_for, so it never renews itself or crosses segments.
    • freshResearch / replan are available.
  5. Optional clarifying questions.
    • One fast model call before a live run, asking only when an ambiguity would change which companies are found.
    • At most 2 questions, with the suggested answers already picked, and Skip.
    • Capped at 8s, cached per segment version, and never blocks a run.
  6. Durability and timeouts.
    • Each company's research: 3 minutes, and it fails on its own. One bad site no longer fails the run, and earlier research is kept.
    • Inngest: timeouts {start: 15m, finish: 90m} and retries: 2.
    • Stale runs: a heartbeat per company, and failStaleRuns ends runs that are stuck queued or have gone silent, with the reason.
    • The picture step is bounded.
  7. Fixes from the review of Growth Prospects: faster search, Clay-style cards, Find companies like this, Scenarios link, MCP (includes #587) #632:
    • The find_similar_companies fallback took the wrong batch.
    • pageImages gave up after an unusable tag.
    • Picture URLs could point at local or IP hosts (publicHttpsUrl).
    • "Companies like this" match points were given without a model check.
    • Research could wipe an icon.

Efficiency

  • A rerun skips planning and, for recent research, the research agent: the biggest cost per company.
  • Finished runs stop polling and skip the progress query.
  • Stale-run cleanup runs at most once a minute.
  • Clarifying questions are asked once per segment version.
  • Indexes back every new query and cascade.

Testing

  • run-lifecycle.e2e (8 tests, real Postgres, sample providers):
    • a run works from its frozen input after the segment is edited;
    • each run keeps its own results;
    • a rerun plans and researches nothing, and reuse doesn't restart its clock;
    • fresh research runs again;
    • stops: between steps, a lost cancel, mid-research, and before pickup;
    • a stopped run never shows a failure;
    • failed research keeps the earlier dossier;
    • the run row is bumped while a company is researched;
    • stuck queued runs and silent runs are ended, while working runs are not.
    • It caught two SQL bugs (Dates passed raw), now fixed.
  • clarify-before-run (4 tests): the real provider and dialog. No questions starts at once; answers are passed; Skip; a failed ask never blocks.
  • Pipelines: 372 pass, including new unit tests for the snapshot, question cleaning, the reuse rules and the research key.
  • Web: the Prospects, distribution, MCP and i18n suites pass (46 suites, 470 tests).
  • Full web tsc, pipelines and tools tsc, and eslint on the changed files: clean.
  • Reviews: three independent subagent reviews (code smells, latency and efficiency, reliability), then a verification pass on the fixes. Every finding is resolved, except the limitation below.

Notes for reviewers

  • Migration prospects_run_lifecycle, additive only:
    • distribution_runs.input;
    • partner_relationships.researched_at and researched_for;
    • the distribution_run_results table with 4 indexes.
    • New columns are declared last in schema.ts.
  • Known limitation: the clarify call's 8s cap stops the user waiting, but the model call can't be cancelled (invokeStructured takes no signal). The cache keeps that to at most once per segment version.
  • Caches are per instance: the clarify cache and the stale-check throttle live in each server instance, so they are best-effort across several. Both are safe to repeat.
  • One behaviour change: a company whose research throws now leaves that company unresearched instead of failing the run. run.test.ts is updated to match.

🤖 Generated with Claude Code

rafchen and others added 3 commits November 29, 2026 22:11
…rerun, clarifying questions

Work in progress; review fixes and the end-to-end test results follow.
- Runs freeze the segment (distribution_runs.input) and work from it.
- Stop: a "stopped" status nothing overwrites, Inngest cancelOn, inline
  runs watch their row; timeouts per company's research and per run.
- Per-run results (distribution_run_results), listed in the run sheet.
- Rerun from a run's input, reusing its plan and research under 7 days.
- Optional clarifying questions before a live run.
- Fixes from review: similar.ts fallback, pageImages fallthrough and
  local-host refusal, match points only on a yes, icons kept, picture
  step bounded, stale runs ended.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
From three independent reviews (smells, latency, reliability):
- Research reuse is keyed to the segment's own research time and input
  (relationships.researched_at / researched_for), set only when research
  actually ran: reuse no longer renews itself, and an edited segment or
  different answers research again.
- Research that fails or times out keeps the previous dossier; every page
  it reads is cut off at the deadline too.
- Each company bumps the run row (touchRun), so a long run is never ended
  as stale; finished statuses (not only stopped) are never overwritten.
- Every step checks for a stop (a lost cancel no longer keeps spending);
  a stop mid-research skips that company and keeps the run's summary.
- Exclusions come from the frozen input; reruns pick a mode the
  environment can serve, and a pre-snapshot run plans again.
- Finished runs skip the progress query and stop polling; stale-run
  cleanup at most once a minute; clarifying questions cached per segment
  version; indexes for run-result cascades; Inngest finish 90m.
- Shared run-start rules (rerunOf, runModeFor, insufficientCreditsResponse),
  RunProgram type, one clarification limit, publicHttpsUrl (refuses
  trailing-dot local names), doc and import tidy-ups.
- Two SQL bugs the end-to-end test caught: Dates passed raw into the
  status guard and the stale check.

Tests: run-lifecycle.e2e (frozen input, per-run results, rerun without
planning or research, fresh research, stop between steps and mid-research,
stale queued and silent runs) and clarify-before-run (UI flow).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- failRun can no longer write an error onto a finished (stopped) run:
  errorMessage joins the finished-status guard.
- A run finished before it starts, or stopped while it searches, exits
  prepare early: no resolve, research, pictures or empty summary; the
  Inngest picture step skips a stopped run (a cancel that never arrived).
- Any research that does not finish (thrown, timed out, out of turns)
  keeps the earlier dossier, and an earlier dossier is not republished.
- Research reuse is also keyed to HS codes; answers are normalised.
- Bounded stale-check memory; per-instance caches documented.
- Tests: stopped before pickup, no error on a stopped run, earlier
  research kept on failure without restarting the reuse clock, and the
  run row bumped while a company is researched.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Nov 30, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
pdr-ai-v2 Ignored Ignored Nov 30, 2026 3:49am UTC

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