Skip to content

Harden WorkBuddy risk controls - #96

Merged
maiphucgiang merged 8 commits into
mainfrom
feature/workbuddy-risk-hardening
Oct 26, 2026
Merged

maiphucgiang merged 8 commits into
mainfrom
feature/workbuddy-risk-hardening

Conversation

@maiphucgiang

@maiphucgiang maiphucgiang commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Expand always-on DSH role adaptation across the official fixed identity, shared/minimal personas and current/legacy Web GUI contexts, preserving model IDs, plan rules and unrelated brand references without a separate mode switch.
  • Add hot empty / prepend system prompt modes through WebUI, CLI and CODEBUDDY2API_PROMPT_MODE: default to no gateway-added prompt, or prepend concise official WorkBuddy/CodeBuddy prefixes after routing without duplicating them on retries.
  • Classify upstream business codes before HTTP status: stop cross-account replay for 11128/11140/11148 and model-scoped 11129/11134/11150/11158, persist 11140 account disables, cool 11148 per account/model, and retain only the dedicated console-confirmed 11102 failover.
  • Apply the same 11140 restriction policy to check-in, travel, growth and daily-chat automation, stopping the current sweep and remaining growth claims immediately.
  • Isolate legacy conversation IDs by account while preserving stable same-account sessions and existing client API behavior.
  • Align domestic and international CLI/WorkBuddy identities with the verified official packages, and use independent WorkBuddy message/request UUIDs and trace IDs without hardware fingerprints.
  • Update English and Chinese documentation and add regression coverage across all three protocols, streaming failover, restart persistence, background automation, DSH presets and prompt modes.

Tests

  • for s in tests/test_*.py; do uv run python -B "$s"; done — 86 standalone files, 2083 tests passed.
  • git diff --check main...HEAD

@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Sorry @maiphucgiang, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 2 days and 23 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Oct 26, 2026

Copy link
Copy Markdown

Reviewer's Guide

Hardens WorkBuddy request handling by adding a narrow always-on channel-identity scrub, classifying upstream business codes before transport status to prevent unsafe replay and persist account restrictions, propagating those restrictions through automation, isolating legacy sessions by account, and aligning regional client identities and WorkBuddy tracing with verified package behavior; documentation and regression coverage are updated accordingly.

Sequence diagram for account restriction propagation

sequenceDiagram
    participant Automation
    participant RestrictionSync
    participant CredentialPool
    participant Ledger
    participant NextTask
    Automation->>RestrictionSync: _sync_restriction(result)
    RestrictionSync->>CredentialPool: note_restriction(cm, 11140)
    CredentialPool->>CredentialPool: cooldown(cm)
    CredentialPool->>CredentialPool: _auto_disable(cm)
    RestrictionSync->>Ledger: note_error(account, phase)
    RestrictionSync-->>Automation: stop current sweep
    Automation-->>NextTask: skip remaining claims and tasks
Loading

Flow diagram for upstream business-code risk controls

flowchart TD
    A[Upstream response] --> B[Parse business code]
    B --> C{Code classification}
    C -->|11140| D[Persistently disable account]
    C -->|11148| E[Cool account and model for 30 minutes]
    C -->|11128| F[No cross-account replay]
    C -->|11129 11134 11150 11158| G[Return upstream response]
    C -->|11102| H[Allow console-confirmed model failover]
    C -->|Other| I[Apply HTTP status policy]
Loading

Flow diagram for always-on channel identity scrubbing

flowchart TD
    A[Chat request] --> B[_chat_body_desensitize]
    B --> C[desensitize_channel_body]
    C --> D{Message role}
    D -->|system developer assistant| E[desensitize_channel_text]
    E --> F[Replace DSH identity sentence]
    D -->|user or tool| G[Preserve content]
    F --> H[Continue normal desensitization switch]
    G --> H
Loading

File-Level Changes

Change Details Files
Added an always-on, narrowly scoped channel-identity scrub before optional desensitization.
  • Replaces the known DeepSeek Harness sentence in system, developer, and assistant string or text-block content.
  • Leaves user/tool content, non-text blocks, message fields, and broader desensitization behavior unchanged.
  • Applies consistently across chat, responses, and other generation protocols, including assistant history.
app/desensitize.py
converter.py
tests/test_workbuddy_filter.py
tests/test_workbuddy_templates.py
tests/test_request_context.py
Reworked upstream business-code classification and failover policy to prevent unsafe cross-account replay.
  • Parses business codes before HTTP status handling, including codes embedded in error envelopes.
  • Persistently disables accounts for 11140, applies 30-minute account/model cooldowns for 11148, and avoids penalties for model-scoped codes.
  • Restricts failover to the dedicated console-confirmed 11102 model-missing path; blocks replay for 11128, 11140, 11148, 11129, 11134, 11150, and 11158.
  • Preserves account/model-specific 11102 model-block behavior and updates streaming and console fallback handling.
converter.py
tests/test_credential_cooldowns.py
tests/test_stream_failover.py
tests/test_upstream_compat.py
Propagated account restrictions into background automation and made growth sweeps stop immediately.
  • Carries structured business-code diagnostics through growth HTTP failures.
  • Uses the shared persistent restriction path for check-in, travel, growth, and daily chat.
  • Stops the active sweep before subsequent claims or balance work and leaves unrelated business errors unaffected.
app/growth_tasks.py
converter.py
tests/test_credential_automation.py
tests/test_growth_tasks.py
Isolated legacy conversation sessions by account while preserving stable same-account behavior.
  • Includes account identity in legacy conversation derivation so same-profile failover receives a different conversation ID.
  • Keeps the selected account's conversation ID stable across later requests and preserves existing client-facing request-context modes.
converter.py
app/request_context.py
docs/advanced.md
docs/advanced.zh-CN.md
tests/test_request_context.py
Aligned upstream client identities and separated WorkBuddy request tracing identifiers.
  • Uses region-specific verified CLI and WorkBuddy package versions and updates cache revisions accordingly.
  • Adds the WorkBuddy private-data marker without reading hardware fingerprints.
  • Generates independent WorkBuddy message, request, and trace UUIDs while retaining CLI identifier relationships.
app/client_profiles.py
app/request_context.py
converter.py
docs/advanced.md
docs/advanced.zh-CN.md
tests/test_identity_sync.py
tests/test_request_context.py
Expanded documentation and regression coverage for the new security and routing contracts.
  • Documents channel scrubbing, business-code precedence, automation disablement, identity versions, and failover boundaries in English and Chinese.
  • Adds coverage for all protocols, streaming, restart persistence, account/model cooldowns, automation short-circuiting, identity headers, and legacy failover isolation.
  • Validates the full standalone test suite and whitespace cleanliness.
docs/advanced.md
docs/advanced.zh-CN.md
tests/test_credential_automation.py
tests/test_credential_cooldowns.py
tests/test_growth_tasks.py
tests/test_identity_sync.py
tests/test_request_context.py
tests/test_stream_failover.py
tests/test_upstream_compat.py
tests/test_workbuddy_filter.py
tests/test_workbuddy_templates.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@maiphucgiang
maiphucgiang merged commit bba619d into main Oct 26, 2026
9 checks passed
@maiphucgiang
maiphucgiang deleted the feature/workbuddy-risk-hardening branch October 26, 2026 19:07
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