Skip to content

fix(insights): bound business context generation and stop stale work - #765

Merged
izadoesdev merged 1 commit into
stagingfrom
codex/business-context-generation-reliability
Sep 8, 2026
Merged

fix(insights): bound business context generation and stop stale work#765
izadoesdev merged 1 commit into
stagingfrom
codex/business-context-generation-reliability

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Sep 8, 2026

Copy link
Copy Markdown
Member

Description

Saving or cancelling during selection now stops further page reads and synthesis while billing the consumed call. Both model phases share one AI logger so the generation summary includes their combined usage.

Queue age counts toward the existing 180-second request deadline. Work is capped at 115 seconds with a five-second reserve for returned-call billing and persistence; model timeouts use the remaining budget.

Slice

Validation

  • Worker tests: 43 passed, including cancellation, deadline edges, billing, and native logger totals.
  • Insights package: 573 passed, 6 live tests skipped.
  • Repository lint and insights typecheck passed.
  • Workspace typecheck: 33/33 tasks passed (32 cached), independently run by the parent in this worktree.
  • Frozen-lockfile install; lockfile unchanged. Final diff reviewed.

AI-assisted, maintainer-directed implementation.


Summary by cubic

Fixes business context generation to respect the 180‑second request deadline and stop work when the generation is saved, cancelled, or superseded, while still billing consumed model calls.

Behavior changes

  • Queue age now counts toward the deadline; work is capped at 115 seconds with a 5‑second reserve for billing and persistence.
  • Cancellation is checked after each phase (credits, homepage, discovery, selected‑page) and stops further reads or model calls.
  • Both model phases share one AI logger, so usage is combined in the generation summary.
  • Model timeouts use the remaining request budget instead of a fixed 45 seconds.

Written for commit 76dfb18. Summary will update on new commits.

Review in cubic

@vercel

vercel Bot commented Sep 8, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated
databuddy-status Ready Ready Preview Sep 8, 2026 9:02pm UTC
2 Skipped Deployments
Project Deployment Actions Updated
dashboard Skipped Skipped Sep 8, 2026 9:02pm UTC
documentation Skipped Skipped Sep 8, 2026 9:02pm UTC

@coderabbitai

coderabbitai Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 558dc30b-2539-4c0d-9d57-557123b1b5b6

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@izadoesdev
izadoesdev marked this pull request as ready for review September 8, 2026 21:11
@izadoesdev
izadoesdev merged commit 4573c49 into staging Sep 8, 2026
18 checks passed
@izadoesdev
izadoesdev deleted the codex/business-context-generation-reliability branch September 8, 2026 21:11
@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR bounds organization business-context generation by both queue age and worker runtime, adds lifecycle checkpoints to stop stale work, reserves time for billing and persistence, and aggregates both model phases through one AI logger.

  • Applies the existing 180-second request deadline while limiting active worker time to 115 seconds.
  • Revalidates generation state between credits, page reads, selection, and synthesis.
  • Uses remaining-budget model timeouts and a separate settlement deadline for billing and terminal persistence.
  • Expands worker coverage for cancellation, supersession, deadline edges, billing, and combined usage telemetry.

Confidence Score: 5/5

The PR appears safe to merge; guarded persistence and lifecycle checkpoints prevent stale generation work from overwriting newer state.

No actionable failures remain after verifying that terminal writes recheck generation identity and status atomically, while model work, billing, and persistence observe their intended deadline boundaries.

Important Files Changed

Filename Overview
apps/insights/src/organization-business-context.ts Adds queue-aware deadline accounting, stale-generation checkpoints, bounded settlement, and shared model logging without an identified correctness regression.
apps/insights/src/organization-business-context.test.ts Adds focused coverage for lifecycle races, timeout boundaries, billing completion, and combined model usage.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Queued generation] --> B[Load and validate current state]
    B --> C{Deadline and generation current?}
    C -- No --> X[Stop or persist friendly failure]
    C -- Yes --> D[Load website and verify credits]
    D --> E[Read homepage and discover paths]
    E --> F[Selection model call]
    F --> G[Bill consumed selection call]
    G --> H{Generation still current?}
    H -- No --> Y[Stop stale work]
    H -- Yes --> I[Read selected pages]
    I --> J{Generation still current?}
    J -- No --> Y
    J -- Yes --> K[Synthesis model call]
    K --> L[Bill consumed synthesis call]
    L --> M[Guarded ready-state persistence]
    C -. work deadline .-> N[Five-second settlement reserve]
    N --> G
    N --> L
    N --> M
Loading

Reviews (1): Last reviewed commit: "fix(insights): bound business context ge..." | Re-trigger Greptile

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