← Back to Pull requests

feat(social): answer the client's comments on the review link (#1301) #1325

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 24, 2026 12:19 UTC
Author

What changed

The team can now answer a client's comment where the client reads it (#1301), and the plan review link follow-ups from #930 are folded in.

Reply (#1301)

  • New command social.review.reply (owners, admins and members; R1; audited with the answer, its post and link, and whether it cleared). One editable team reply per client answer: write, edit, or clear with an empty text / null. Plain text like the report note (NFC, LF, hidden characters stripped, trimmed), 1 to 2,000 characters like the client's own comment. A member limited to some channels (#1081) gets 403 CHANNEL_NOT_ALLOWED on a post with none of their channels; another org's answer is 404 REVIEW_FEEDBACK_NOT_FOUND.

  • social.review_link.list returns reply: { body, by, at } | null per answer; RPC social.reviewLinks.reply.

  • Public pages: both the single-post page and the plan page show the reply under the answer, signed "<name> trả lời" with the report branding's name or the org's. No member name, id or email leaves (tested on the JSON). Rendered as React text (escaped).

  • Panel: Trả lời khách under each answer in the review links card; a reply shows the member who wrote it last, with Sửa and Xóa trả lời. Viewers see replies without controls.

  • Replies are columns of the answer row, so the answer caps (100 per link, 20 per plan post) and the client's verdict (#770) are unchanged (tested).
  • #930

  • The plan page sends each post's body once: body on the post, and a channel's body is null when it shows the post's body (its own text otherwise). The page resolves it with planChannel.

  • crove_tenant loses INSERT on crove_social.review_link_post. social.review_link.create_plan fills its new link through the new definer crove_social.review_plan_posts_add(link, posts), which only fills a live plan link of the context's org that has no posts yet, for an owner or admin who made it, with 1 to 50 distinct live posts of the org (it computes the content keys itself).

  • The caps of 10 live links per post and 50 live plan links per org are counted under a transaction advisory lock (concurrency tested).
  • Migration 20261030010000_crove_social_review_replies.sql (renamed from the reserved 20261029250000 because #1292 landed 20261030001000; above #1297's 20261030002100):

  • reply_body, replied_by, replied_at on crove_social.review_feedback, with CHECKs on the length and all-or-none.

  • GRANT UPDATE (reply_body, replied_by, replied_at) to crove_tenant, plus a BEFORE UPDATE guard trigger review_feedback_reply_guard that refuses any change to the client's fields (whoever makes it, the database owner included) and a reply whose replied_by is not the context's user.

  • REVOKE INSERT ON crove_social.review_link_post FROM crove_tenant; new definer review_plan_posts_add (granted to crove_tenant only).

  • review_link_view and review_plan_page re-created from their newest definitions (20261029160000_crove_social_channel_signature.sql), bodies copied verbatim with only the reply (and, for the plan page, the body-once change) added; same signatures, SECURITY DEFINER on review_link_view, search_path = pg_catalog, pg_temp, REVOKE/GRANT restated.

  • packages/db types regenerated (review_link_post is now NotGranted for insert). No check-union change needed.
  • Protected path: this PR touches supabase/migrations/ and re-creates public SECURITY DEFINER functions, plus adds a tenant-callable definer. It needs the independent security review (the coordinator runs it).

    How it was tested

  • New apps/kernel/test/social-review-replies.db.test.ts (PostgreSQL 17): reply, edit, clear; viewer refused; the single-post and plan pages show the reply with no member name/id/email; answer rows, link answer counts and the client's verdict unchanged; audit rows; channel scope (#1081); crove_tenant cannot update client fields, insert or delete answers, write a reply in another member's name or break all-or-none; the guard refuses the database owner too; column privileges are exactly the three reply columns; no tenant INSERT on review_link_post; review_plan_posts_add refuses a frozen plan, a non-maker, a member, duplicates, empty lists, another org's or cancelled posts, and calls without a context; EXECUTE matrix; concurrent creates hold both caps.

  • Updated social-plan-review.db.test.ts (body once, review_link_post grants now SELECT only) and social-signature.db.test.ts (compares the #1190 definitions against the previous ones inside one transaction, since this PR re-creates them again; plan channel bodies resolved from the post).

  • New apps/app/test/social-review-replies.test.tsx: both public pages (org vs branding name, escaping, no reply, older server without the field, plan body once) and the panel (member names, a member who left, controls for members, none for viewers, vi and en).

  • Ran locally: the social DB tests touching review links (plan review, review link, signature, client approval, team report, report branding, banned words, chat alerts, link revoke, text variations), check-unions, the whole invariant suite (pass, apart from the known Windows-only route-coverage, and write-path which timed out under load and passes alone; rls-matrix, personal-data, kernel-invariants, conformance re-run green after the latest merge), modules/social and apps/app unit tests, pnpm typecheck, pnpm lint, pnpm docs:check, migration-order.mjs, and migration-lint.mjs --since.

  • Not run locally: e2e (the shared Docker disk is full); relying on CI.
  • Closes #1301
    Closes #930

    🤖 Generated with Claude Code

    ---

    <!-- dos-pr-summary -->

    📌 TL;DR


    This PR introduces a "Team Reply" feature (#1301) allowing agency members to respond to client feedback on social review links, with the reply displayed to clients under the organization's name rather than the individual member's. It also refactors the plan review data structure (#930) to store post bodies once per post rather than duplicating them across channels.

    🎯 Type of Change


  • 🚀 New feature

  • 🐛 Bugfix

  • 🧹 Refactor

  • ⚡ Performance

  • 📚 Documentation

  • ⚙️ CI / Configuration
  • 🔍 Changes Walkthrough


    | File | Summary of Changes |
    | :--- | :--- |
    | apps/app/src/components/social-review-links.tsx | Adds ClientAnswer component to handle reply UI (create, edit, delete) for team members. Updates ReviewLinks to accept canReply prop and pass member name resolution. |
    | apps/app/src/i18n/messages/en.ts | Adds English translations for reply actions, hints, and error messages. |
    | apps/app/src/i18n/messages/vi.ts | Adds Vietnamese translations for reply actions, hints, and error messages. |
    | apps/app/src/lib/kernel-errors.ts | Registers new REVIEW_FEEDBACK_NOT_FOUND error code. |
    | apps/app/src/routes/social-post.tsx | Passes canReply permission to the ReviewLinks component based on user write access. |
    | apps/app/src/routes/social-review.tsx | Updates client-facing review page to display team replies signed by the org name. Refactors PlanPost types to support single-body posts (#930) and adds TeamReply component. |
    | apps/app/test/social-review-replies.test.tsx | New frontend tests verifying reply visibility, org-name signing, XSS escaping, and permission controls. |
    | apps/kernel/src/review-link.ts | Updates ReviewAnswer and ReviewPlanPage types to include reply data and single-body post structure. |
    | apps/kernel/src/rpc.ts | Registers the new social.review.reply RPC handler. |
    | apps/kernel/test/social-plan-review.db.test.ts | Updates existing plan review tests to reflect the new single-body data structure. |
    | apps/kernel/test/social-review-replies.db.test.ts | New backend integration tests covering reply permissions, data integrity, RLS guards, audit logging, and plan body deduplication. |

    📊 Architectural Flow


    sequenceDiagram
        participant Member as Team Member
        participant App as Frontend App
        participant API as Kernel API
        participant DB as PostgreSQL
    
        Note over Member, DB: Team Member Replies to Client Feedback
    
        Member->>App: Click "Reply" / "Edit"
        App->>App: Validate permissions (canReply)
        App->>API: POST social.review.reply { feedbackId, body }
        API->>DB: UPDATE review_feedback SET reply_body, replied_by, replied_at
        Note right of DB: RLS Guard: Only own member ID allowed<br/>Max length 2000 chars
        DB-->>API: Success
        API-->>App: Return updated feedback
        App->>App: Invalidate query cache
    
        Note over Member, DB: Client Views Review Link
    
        participant Client as Client Browser
        Client->>API: GET review_link_view { token }
        API->>DB: SELECT feedback with reply data
        DB-->>API: Return feedback + reply
        API-->>Client: Render page
        Note right of Client: Reply displayed as:<br/>"Reply from [Org Name]"<br/>Member name hidden
    

    <!-- /dos-pr-summary -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: claude[bot] Review duration: 28m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1325"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%
    Repository