Skip to content

feat(dashboard): recover business context edits and preserve team priorities - #766

Merged
izadoesdev merged 2 commits into
stagingfrom
codex/business-context-recovery
Sep 8, 2026
Merged

feat(dashboard): recover business context edits and preserve team priorities#766
izadoesdev merged 2 commits into
stagingfrom
codex/business-context-recovery

Conversation

@izadoesdev

@izadoesdev izadoesdev commented Sep 8, 2026

Copy link
Copy Markdown
Member

Business context edits now survive navigation and reload. AI drafts can be permanently discarded or cancelled, and the last five saved versions can be reviewed as a diff and restored without silently overwriting a teammate's newer save.

Three optional team inputs—priority, success definition, and exclusions—survive regeneration and reach investigations as team assertions. Manual brief rewrites clear stale citations, while saved history preserves the original text and sources. Save and restore events record the correct organization, actor, and outcome in the audit log. Recovery clearing is guarded against late saves after navigation, failed browser storage cannot replace newer in-memory drafts, and explicit saved-version selection dismisses competing AI drafts. The context budget preserves a maximum-size brief plus all team inputs without increasing ordinary runs.

Validation: root lint and 33/33 workspace typecheck tasks; 23 isolated PostgreSQL tests; 8 RPC authorization/audit tests; 54 context-boundary tests plus the worker regressions; 10 browser regressions against a synthetic local database. No schema migration or customer data changes.

Scope: organization business context editing and its existing insight input contract. Parallel follow-ups add canonical context to chat and supplied-context attribution to investigation details. Generation scheduling reliability is separately reviewed in #765. AI-assisted implementation, reviewed and tested by Codex for the maintainer.

@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 9:31pm UTC
databuddy-status Ready Ready Preview Sep 8, 2026 9:31pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
documentation Skipped Skipped Sep 8, 2026 9:31pm UTC

@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 9:30pm

@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: e781509c-655a-4a0e-af53-f93a42638dff

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.

@vercel
vercel Bot temporarily deployed to Preview – documentation September 8, 2026 21:30 Inactive
@izadoesdev
izadoesdev marked this pull request as ready for review September 8, 2026 21:35
@izadoesdev
izadoesdev merged commit 656051c into staging Sep 8, 2026
19 checks passed
@izadoesdev
izadoesdev deleted the codex/business-context-recovery branch September 8, 2026 21:35
@greptile-apps

greptile-apps Bot commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR makes organization business-context editing recoverable and revision-aware while carrying structured team priorities into Insights.

  • Persists per-user, per-organization drafts across navigation and reload, with guarded clearing after asynchronous saves.
  • Adds generated-draft cancellation, saved-version history, conflict-aware restoration, and source/provenance handling.
  • Extends investigation context with separately attributed team priorities, success definitions, and exclusions.
  • Adds organization-scoped authorization and audit outcomes for business-context mutations.
  • Expands regression, service integration, RPC, and context-boundary coverage.

Confidence Score: 4/5

The behavioral changes appear sound, but the explicit repository requirements concerning nested ternaries and focusable non-interactive elements must be satisfied before merging.

No blocking correctness or security failure remains; the accepted findings are limited to two concrete repository-rule violations in the editor’s UI implementation.

Files Needing Attention: apps/dashboard/app/(main)/organizations/components/business-context-editor.tsx

Important Files Changed

Filename Overview
apps/dashboard/app/(main)/organizations/components/business-context-editor.tsx Adds structured team fields, generation cancellation, conflict/history review, restoration controls, and diff rendering; contains two explicit repository-style violations.
apps/dashboard/app/(main)/organizations/components/use-business-context-draft.ts Adds user/organization-scoped in-tab and session-storage draft recovery with a reference guard against late-save clearing.
apps/dashboard/app/(main)/organizations/components/business-context-settings.tsx Wires scoped recovery keys and save, cancel, restore, and generation mutations into the query cache.
packages/services/src/organization-business-context.ts Adds transactional history retention, conflict-aware restoration, durable generation cancellation, structured team context, and mixed provenance.
packages/rpc/src/routers/business-context.ts Adds authorized cancel and restore endpoints and explicitly audited business-context mutation flows.
apps/insights/src/business-context.ts Supplies structured team context separately from saved website or mixed background while preserving source attribution.
packages/ai/src/lib/business-context.ts Expands the exceptional context budget enough to retain a maximum brief, structured team fields, and a direct correction.
packages/shared/src/organization-business-context.ts Extends shared schemas with team fields, edit payloads, history, and mixed provenance.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  Editor[Business context editor] --> Recovery[Per-user and organization session draft]
  Editor --> Save[Revision-checked save]
  Editor --> Cancel[Cancel AI draft]
  Editor --> Restore[Restore retained version]
  Save --> Profile[Current organization profile]
  Restore --> Profile
  Profile --> History[Last five saved versions]
  Profile --> Context[Attributed investigation context]
  Context --> Team[Team priorities and definitions]
  Context --> Background[Team, website, or mixed brief]
  Team --> Insights[Insights selection and investigation]
  Background --> Insights
Loading

Reviews (1): Last reviewed commit: "fix(dashboard): protect newer context dr..." | Re-trigger Greptile

Comment on lines 493 to 497
{canEdit
? "Reading your website and preparing a draft. You can keep writing."
? generation?.status === "queued"
? "Waiting to start. You can keep writing."
: "Reading your website and preparing a draft. You can keep writing. Saving ends this generation."
: "An updated brief is being prepared."}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Nested ternaries obscure states

The new generation status uses nested ternaries, and the dialog title and description repeat this pattern. This violates the repository directive, “Don't use nested ternary expressions.” Extract named display values or use straightforward conditional logic. This repository requirement must be satisfied before merging.

Context Used: Ultracite Rules - AI-Ready Formatter and Linter (source)

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

{review === "generation"
<Dialog.Title
render={(props) => (
<h2 {...props} ref={reviewTitleRef} tabIndex={-1}>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Heading made programmatically focusable

The dialog renders a non-interactive h2 with tabIndex={-1} and targets it with initialFocus. This violates the repository directive, “Don't assign tabIndex to non-interactive HTML elements.” Use a focus target supported by the dialog primitive instead. This repository requirement must be satisfied before merging.

Context Used: Ultracite Rules - AI-Ready Formatter and Linter (source)

izadoesdev added a commit that referenced this pull request Sep 8, 2026
The three-case present-context follow-up stayed at 16/18 on the small manual rubric, still missed the targeted emitter attribution, and increased words by 7.3%. Remove the extra rule and its tests rather than retaining prompt growth without a demonstrated benefit.

Preserve the original attributed-assertions guidance and reference-budget fallback. The small fixture context again matches the original paired run byte for byte. This reverses the rule from 7aa476d after rebasing onto merged parent #766.
izadoesdev added a commit that referenced this pull request Sep 8, 2026
* feat(ai): deliver canonical organization context to chat agents

* feat(ai): deliver structured team context and mixed provenance

* fix(ai): attribute team-defined event and success meanings once

* fix(ai): preserve business assertions when references exceed budget

* revert(ai): drop ineffective event-attribution prompt rule

The three-case present-context follow-up stayed at 16/18 on the small manual rubric, still missed the targeted emitter attribution, and increased words by 7.3%. Remove the extra rule and its tests rather than retaining prompt growth without a demonstrated benefit.

Preserve the original attributed-assertions guidance and reference-budget fallback. The small fixture context again matches the original paired run byte for byte. This reverses the rule from 7aa476d after rebasing onto merged parent #766.
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