← Back to Pull requests

feat(social): add a channel to many posts at once, and send many drafts for review (#1178) #1184

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Oct 23, 2026 11:05 UTC
Author

What changed

Add a channel to many posts (social.post.bulk_add_channel, R1, members and above)

  • One channel, up to 100 posts per command, in the bulk-edit.ts pattern of social.post.bulk_replace (#1144). The posts are locked in id order, each with its variants. Each post then goes through social.post.add_channels as a nested command (ctx.tryRun with a LEFT_OUT map), which writes its own audit row.

  • social.post.add_channels now appends a post version (withVersion), so each post gets a version for the new channel. Single adds get one too.

  • The new channel is a draft with the post's base content and planned time.

  • The channel is checked once for the whole command: a channel outside the caller's scope (#1081) is 403 CHANNEL_NOT_ALLOWED, and a channel that is not live in the org is CHANNEL_NOT_FOUND.

  • The plan checks everything a nested add could refuse, so one post never fails the batch. The reasons for leaving a post out are:

  • - not_found
    - not_allowed: on none of the caller's channels. This check runs first, so a limited member learns nothing about the post.
    - published: no channel is still open
    - already_on: the channel is live on the post (a cancelled one can be added again)
    - too_many_channels: the post already has 20
    - in_flight: a channel is going out or needs attention
  • The answer has added: [{ postId, variantId, issues }], so it says which added channels already fit their rules and which need edits (for example Instagram without media).
  • Send many drafts for review

  • Gửi duyệt in the bulk bar on the Drafts and Attention lists, for members and above.

  • It runs social.post.submit once per post, the way bulk approve calls social.variant.decide (runBulk).

  • submitResult sorts each post into one of these: submitted, nothing to submit (NOTHING_TO_SUBMIT), invalid (VARIANT_INVALID, listing each channel's issues), blocked word (BANNED_WORDS, with the words), or another refusal.
  • Bulk bar

  • Thêm kênh for members and above in the lists, the board, the calendar and the agenda.

  • It offers the live channels the member may use, sends batches of 100 (runAddChannel), and shows the skip reasons and the drafts that need edits with their issues.

  • New vi/en copy.
  • Folded in from #1062

  • Bulk assign checks the assignee's membership only when some post gets them as a new assignee. Due dates can now be set in bulk on posts of an assignee who has left.

  • One notification per bulk assignment:

  • - The nested social.post.assign gets a server-only bulk: true. The RPC contract's strict input does not carry it, and no agent may run the command.
    - Its event carries bulk: true and notifies nobody.
    - The bulk command emits social.post.bulk_assigned. The dispatcher sends one assigned notification covering the posts the assignee can see (postsVisibleTo, #1081). One post reads as a single assignment. Several posts give postId: null, detail.count, and the item opens the assignee's own posts (?mine=true).

    Folded in from #1099 (bulk label point only)

  • bulk_labels and bulk_assign report a post outside a limited member's channels as not_allowed before published, unchanged or too_many_labels.
  • No migration. MAX_CHANNELS_PER_POST moved to variants.ts (re-exported from posts.ts) so bulk-edit.ts can use it without a circular import.

    How it was tested

  • DB tests on a private PostgreSQL 17:

  • - new apps/kernel/test/social-bulk-add-channel.db.test.ts:
    - 30 posts each get a draft with the base content and planned time, an audit row and a version
    - Instagram needs edits
    - mixed outcomes, one per skip reason
    - channel scope: a limited member, a channel outside the scope, a hidden published post reported as not_allowed
    - viewer refused, a revoked or foreign channel refused, bounds
    - lock order while another transaction holds a post
    - social-bulk-edit.db.test.ts extended:
    - one notification per bulk assignment, with a count
    - a limited assignee is told only of the posts they can see
    - due dates kept for a departed assignee, refused for a new assignment (#1062)
    - not_allowed for hidden posts in bulk labels and bulk assign (#1099)
    - every apps/kernel/test/social-.db.test.ts file and notifications.db.test.ts: 65 files, 424 tests pass.
  • Unit and UI tests:

  • - apps/app/test/social-bulk.test.ts: submit requests, submitResult categories, runAddChannel batches
    - social-bulk-bar.test.tsx:
    Gửi duyệt and Thêm kênh are offered; Thêm kênh* is hidden when there is no channel to add
    - social-notifications.test.ts: the bulk assignment target
    - every skip reason has vi/en copy
  • pnpm typecheck, pnpm lint, pnpm docs:check pass.

  • Not checked in a browser.
  • Closes #1178

    🤖 Generated with Claude Code

    ---

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

    📌 TL;DR


    This PR introduces two new bulk actions to the Social module: "Submit for review" (sending drafts to review) and "Add a channel" (bulk-adding a channel to multiple posts). It also refines the notification system to handle bulk assignment notifications and updates the UI to support these new workflows with detailed result reporting.

    🎯 Type of Change


  • 🚀 New feature

  • 🐛 Bugfix

  • 🧹 Refactor

  • ⚡ Performance

  • 📚 Documentation

  • ⚙️ CI / Configuration
  • 🔍 Changes Walkthrough


    | File | Summary of Changes |
    | :--- | :--- |
    | apps/app/src/components/social-bulk.tsx | Adds UI logic for the new submit and addChannel actions. Includes new form states, result rendering cards, and integration with the new API endpoints. |
    | apps/app/src/i18n/messages/en.ts | Adds English translations for the new bulk actions, result messages, and the new assigned_many notification text. |
    | apps/app/src/i18n/messages/vi.ts | Adds Vietnamese translations for the new bulk actions, result messages, and the new assigned_many notification text. |
    | apps/app/src/lib/social-bulk.ts | Extends the BulkAction type to include submit and addChannel. Implements submitResult to categorize submission errors (invalid, blocked, skipped) and runAddChannel to handle batched channel additions with issue tracking. |
    | apps/app/src/lib/social-notifications.ts | Updates NotificationTarget to support a 'mine' target, allowing navigation to the user's assigned posts when a bulk assignment notification is clicked. |
    | apps/app/src/routes/social-notifications.tsx | Handles the new assigned notification kind, displaying a count of assigned posts and navigating to the "My Posts" view. |
    | apps/app/src/routes/social.tsx | Updates the BulkBar component usage to pass channelOptions and enables the submit and addChannel actions based on user roles and list tabs. |
    | apps/app/test/social-bulk-bar.test.tsx | Adds tests to verify that the submit and addChannel actions are correctly displayed in the UI for members and that the channel form behaves as expected. |
    | apps/app/test/social-bulk.test.ts | Adds unit tests for the new submitResult logic (categorizing errors) and runAddChannel (batching and issue tracking). |
    | apps/app/test/social-notifications.test.ts | Adds tests for the new assigned notification target resolution. |
    | apps/kernel/src/rpc.ts | Registers the new bulkAddChannel RPC handler, mapping it to the social.post.bulk_add_channel command. |
    | apps/kernel/test/social-bulk-add-channel.db.test.ts | New integration test file verifying the bulk_add_channel command against a real PostgreSQL database, covering permissions, edge cases (published posts, channel limits), and audit logging. |

    📊 Architectural Flow


    sequenceDiagram
        participant UI as Social Bulk Bar (UI)
        participant Lib as social-bulk.ts (Logic)
        participant API as Kernel RPC
        participant DB as Database
    
        Note over UI: User selects posts and clicks "Add Channel" or "Submit"
        
        alt Add Channel Action
            UI->>Lib: runAddChannel(postIds, connectionId)
            loop For each batch of posts
                Lib->>API: bulkAddChannel(postIds, connectionId)
                API->>DB: Execute social.post.bulk_add_channel
                DB-->>API: Result (done, skipped, added with issues)
                API-->>Lib: Result
            end
            Lib-->>UI: AddChannelResult (with added channel issues)
            UI->>UI: Render result card (fits vs needs edits)
        else Submit for Review Action
            UI->>Lib: runBulk(posts, 'submit')
            loop For each post
                Lib->>API: social.posts.submit(postId)
                API->>DB: Execute submit logic
                DB-->>API: Result or Error
                API-->>Lib: Result or Error
            end
            Lib->>Lib: submitResult() (Categorize errors: invalid, blocked, skipped)
            Lib-->>UI: SubmitResult
            UI->>UI: Render result card (sent, invalid, blocked)
        end
    

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

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: claude[bot] Review duration: 4m
    All Vouch review confidence checks passed
    Residual risk 0.42 = Change Risk (0.52) × (1 − Review Confidence (0.19)). 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: 25% · Reviewer familiarity: 35%
    19%
    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 #1184"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 19.4% 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: 19.4% · Lower = rushed or shallow review
    19.4%
    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: 41.9% · Moderate risk
    41.9%
    Repository