Skip to content

feat(insights): retain supplied business context on investigations - #767

Merged
izadoesdev merged 3 commits into
stagingfrom
codex/business-context-attribution
Sep 8, 2026
Merged

feat(insights): retain supplied business context on investigations#767
izadoesdev merged 3 commits into
stagingfrom
codex/business-context-attribution

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Sep 8, 2026

Copy link
Copy Markdown
Member

Description

Investigation observations currently lose the business background supplied to the model. Persist that bounded snapshot in the existing outcome JSON and expose it in a collapsed Business context disclosure on each investigation update, including canonical profile revision/time, supplied text, source names, and recorded URLs.

Generation retains the context from its frozen candidate; resume appends a fresh snapshot without rewriting prior observations. When sources exist, the disclosure says “Background available for this update” and explains once that the snapshot does not identify which facts influenced individual claims. Empty or unavailable snapshots omit the availability introduction and retain their status message and capture time. Application code assigns the snapshot; model-authored output and subsequent observation-history prompts exclude it.

The additions are optional for older investigations. There is no database migration, new API, or additional model turn.

Slice and integration

  • Issue: Maintainer-directed business-context QA follow-up.
  • Scope: Investigation generation/resume, shared outcome/source schemas, and investigation detail disclosure.
  • Depends on feat(dashboard): recover business context edits and preserve team priorities #766 and feat(ai): deliver canonical organization context to chat agents #768, both merged; also rebased after the domain compatibility follow-up fix(ai): preserve supported chat domain selectors #769 and auth-session fix landed. Rebased onto staging at cf6f7e2201eebe00593c92db3342b2b3c6efe045; the diff contains only this attribution slice and its copy follow-up.
  • The shared schema extraction preserves team | website | mixed origin. Both canonical background and structured team-context chunks retain profileVersion.
  • The merged adaptive budget is unchanged: normally 16k characters, expanding for the saved profile plus a 4k correction allowance, capped at 24k. The combined maximum-size test retains the complete brief, all three team fields, the correction, and revision metadata on all five profile chunks.
  • Canonical services/schema, worker, organization settings, and chat delivery remain as merged on staging.

Final validation

  • Focused schemas, attribution, generation/resume, AI-context, and disclosure tests: 299 passed, 1 gated integration test skipped.
  • Native isolated PostgreSQL snapshot persistence/resume and scope tests: 8 passed.
  • Merged chat compatibility: 46 AI/domain tests and 6 API tests passed using their configured Bun isolation/Vitest runners.
  • Root lint passed; full type checks passed 33/33 tasks (rerun after the final fix(ai): preserve supported chat domain selectors #769 rebase).
  • Pre-push root test suite passed 27/27 tasks (normal environment-gated skips retained).
  • UI validation covers rendered disclosure markup, escaping, source links, and legacy/unavailable states. No authenticated browser session or live model call was run for this attribution slice.

Review notes

  • Rebased after all dependencies and fix(ai): preserve supported chat domain selectors #769 landed; range-diff confirms all three approved attribution commits are unchanged.
  • Additive payload compatibility, mixed origin, team fields, adaptive budget, and profile revisions verified.
  • Relevant tests, root lint, and root type checks passed.
  • No parent settings or chat-delivery edits included in this slice.

AI assistance: Codex implemented, reviewed, and tested this maintainer-directed slice and prepared this PR. Automated validation is described above; human verification is not implied.

@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
dashboard Ready Ready Preview Sep 8, 2026 10:12pm UTC
databuddy-status Ready Ready Preview Sep 8, 2026 10:12pm UTC
documentation Ready Ready Preview Sep 8, 2026 10:12pm 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: d809ee36-42da-4eab-8779-76e591d255ab

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.

@unkey-deploy

unkey-deploy Bot commented Sep 8, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Unkey Deploy

Name Status Preview Inspect Updated (UTC)
links (preview) Ready Visit Preview Inspect Sep 8, 2026 10:11pm

@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds an optional, bounded business-context snapshot to investigation outcomes and displays that snapshot on each dashboard timeline update.

  • Generation and resume attach application-supplied context while discarding model-authored or previous snapshots.
  • Historical snapshots are excluded from subsequent model prompts.
  • Shared schemas retain source origin, references, and canonical profile revision metadata.
  • The dashboard adds a collapsed disclosure for supplied text, timestamps, revisions, and validated source links.
  • The unavailable-state copy should be made internally consistent, and the changed tests must be brought into compliance with the repository’s TypeScript rules.

Confidence Score: 4/5

The persistence and prompt-isolation behavior appears sound, but the explicit repository-rule violations must be corrected before merging; the contradictory unavailable-state copy should also be fixed.

No blocking behavioral failure was found in snapshot generation, persistence, resume, or model-history isolation. The remaining concerns are misleading unavailable-state UI copy and two categories of explicit test-code rule violations.

Files Needing Attention: apps/dashboard/app/(main)/insights/_components/context-used.tsx, apps/insights/src/business-context.integration.test.ts, apps/insights/src/generation-sources.test.ts, apps/insights/src/business-context-generation.test.ts

Important Files Changed

Filename Overview
packages/shared/src/insights.ts Centralizes the bounded business-context schemas, adds optional profile revision metadata, and extends durable outcomes while excluding snapshots from model-authored output.
apps/insights/src/business-context.ts Adds canonical profile revision metadata and a helper that replaces untrusted or previous snapshots with a parsed application-supplied snapshot.
apps/insights/src/generation.ts Attaches each frozen candidate’s business context to the generated durable outcome.
apps/insights/src/resume.ts Attaches the fresh context supplied during a reply turn before the guarded observation commit.
apps/insights/src/agent.ts Removes durable context snapshots from prior investigation history before constructing subsequent model prompts.
apps/dashboard/app/(main)/insights/_components/context-used.tsx Adds the context disclosure and safe HTTP(S) source rendering, but presents contradictory availability copy for unavailable snapshots.
apps/insights/src/business-context.integration.test.ts Covers snapshot persistence and resume revision behavior but introduces repository-prohibited delete operators.
apps/insights/src/generation-sources.test.ts Verifies that application-supplied context replaces model-authored provenance, but introduces a prohibited postfix non-null assertion.

Sequence Diagram

sequenceDiagram
    participant Profile as Business profile
    participant Worker as Insights worker
    participant Agent as Investigation agent
    participant Store as Observation storage
    participant UI as Investigation timeline
    Worker->>Profile: Load bounded context and revision
    Worker->>Agent: Supply context with evidence
    Agent-->>Worker: Return structured outcome
    Worker->>Worker: Remove authored/previous snapshot
    Worker->>Store: Persist outcome with supplied snapshot
    Store-->>UI: Return timeline observation
    UI->>UI: Render collapsed Business context
    Note over Worker,Agent: Prior snapshots are removed from later history prompts
Loading

Reviews (1): Last reviewed commit: "fix(dashboard): clarify business context..." | Re-trigger Greptile

Comment thread apps/dashboard/app/(main)/insights/_components/context-used.tsx Outdated
Comment thread apps/insights/src/business-context.integration.test.ts Outdated
Comment thread apps/insights/src/generation-sources.test.ts Outdated
@izadoesdev
izadoesdev force-pushed the codex/business-context-attribution branch from 4d59b5b to ba2ca52 Compare September 8, 2026 22:11
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