Skip to content

Fix embedded page jargon regressions#215

Closed
EterUltimate wants to merge 2 commits into
NickCharlie:mainfrom
EterUltimate:codex/fix-jargon-embedded-page
Closed

Fix embedded page jargon regressions#215
EterUltimate wants to merge 2 commits into
NickCharlie:mainfrom
EterUltimate:codex/fix-jargon-embedded-page

Conversation

@EterUltimate

@EterUltimate EterUltimate commented Jun 16, 2026

Copy link
Copy Markdown
Collaborator

Fixes #211
Fixes #212
Fixes #213

Summary

  • replace embedded Plugin Page batch window.confirm() calls with the existing in-page <dialog> modal, so sandboxed AstrBot iframes do not silently cancel batch actions
  • hide approve/reject controls for already confirmed jargon rows
  • protect completed/manual jargon definitions from automatic relearning upserts, and have V2 jargon inference skip completed entries before calling the LLM

Evidence

Validation

  • python -m pytest tests\integration\test_webui_static_assets.py::test_embedded_plugin_page_uses_astrbot_bridge_and_module_dashboard tests\unit\test_database_engine.py::test_jargon_relearning_upsert_preserves_completed_manual_definition tests\unit\test_provider_registry_rebind.py::test_v2_jargon_batch_skips_completed_terms_and_preserves_candidate_count -q
  • python -m py_compile services\core_learning\v2_learning_integration.py services\database\facades\jargon_facade.py
  • python -m ruff check services\core_learning\v2_learning_integration.py services\database\facades\jargon_facade.py tests\integration\test_webui_static_assets.py tests\unit\test_database_engine.py tests\unit\test_provider_registry_rebind.py
  • git diff --check

Notes

  • Local install copy into C:\Users\zacza\Desktop\x\AstrBot\data\plugins\astrbot_plugin_self_learning was attempted but blocked by Windows ACL Access denied on the installed plugin directory/files.
  • Companion plugin repos were pulled first: LivingMemory fast-forwarded to c503048; Group Chat Plus official main fast-forwarded to 0a4a00d while the local embed branch remains separate.

Summary by Sourcery

Replace blocked native confirmation dialogs in the embedded dashboard with in-page modals and harden jargon learning so completed/manual definitions are preserved and skipped by automatic relearning.

New Features:

  • Add a reusable in-page confirmation dialog helper for batch actions in the dashboard UI.

Bug Fixes:

  • Hide approve/reject controls for jargon entries that are already confirmed in the dashboard.
  • Prevent jargon relearning upserts from overwriting completed/manual jargon definitions while still updating inference metadata.
  • Ensure V2 jargon batch processing skips already completed terms and preserves/updates candidate frequency counts correctly.
  • Avoid use of window.confirm in sandboxed embedded plugin pages so batch actions work inside restricted iframes.

Enhancements:

  • Style the new confirmation dialog content and action buttons for better usability in the dashboard.

Tests:

  • Extend integration tests for the embedded plugin page to assert the new confirmation flow and confirmed-row rendering, and add unit tests covering jargon upsert preservation and V2 jargon batch behavior.

@EterUltimate EterUltimate added the bug Something isn't working label Jun 16, 2026
@sourcery-ai

sourcery-ai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Replaces window.confirm-based batch actions in the embedded dashboard with an in-page dialog-based confirmation flow, hides review controls for already-confirmed jargon entries, and updates jargon persistence/inference logic so completed or manually-defined jargon is preserved and skipped during automatic relearning, with tests covering the new behavior.

Sequence diagram for in-page dialog batch confirmation flow

sequenceDiagram
    participant User
    participant DashboardPage
    participant showConfirm
    participant apiPost

    User->>DashboardPage: trigger handleBatchReviewAction/handleJargonBatchAction/handleStyleBatchAction
    DashboardPage->>showConfirm: showConfirm(title, message, confirmText)
    showConfirm-->>DashboardPage: Promise<boolean>
    alt user_confirms
        DashboardPage->>apiPost: apiPost("review/action" | "jargon/action" | "style/action", payload)
        apiPost-->>DashboardPage: result
        DashboardPage-->>User: update list UI
    else user_cancels
        DashboardPage-->>User: no-op
    end
Loading

Sequence diagram for V2 jargon batch preserving completed definitions

sequenceDiagram
    participant V2Integration as _jargon_batch
    participant db
    participant llm
    participant JargonFacade

    V2Integration->>db: get_jargon(group_id, candidate.term)
    db-->>V2Integration: existing_jargon
    alt existing_jargon.is_complete
        V2Integration->>V2Integration: skip candidate
    else not_completed
        V2Integration->>llm: generate_response(term context prompt)
        llm-->>V2Integration: meaning
        V2Integration->>db: save_or_update_jargon(group_id, term, { meaning, raw_content: "[]", is_jargon: True, count: observed_count, is_complete: True, _preserve_completed: True })
        db->>JargonFacade: _jargon_update_values(jargon_data, now_ts)
        JargonFacade-->>db: update_values with _completed_preserving_value/_completed_preserving_count
        db-->>V2Integration: upsert complete
    end
Loading

File-Level Changes

Change Details Files
Replace window.confirm batch prompts with an in-page -backed confirmation helper so embedded plugin pages work in sandboxed iframes.
  • Introduce an async showConfirm(title, message, confirmText) helper that reuses the existing detail modal, wires cancel/ok buttons, and falls back to non-modal open when showModal is unavailable.
  • Refactor handleBatchReviewAction, handleJargonBatchAction, and handleStyleBatchAction to await showConfirm instead of calling window.confirm, passing localized titles/messages and action labels.
  • Add modal-specific styles for confirmation messages and action buttons in the dashboard stylesheet.
  • Extend the embedded plugin page static-asset test to assert the presence of showConfirm wiring and the absence of window.confirm in the bundled script.
pages/dashboard/app.js
pages/dashboard/styles.css
tests/integration/test_webui_static_assets.py
Hide approve/reject jargon review controls for rows that are already confirmed.
  • Change jargon list row rendering to compute reviewActions only when item.is_confirmed is false and inject an empty string otherwise, so confirmed rows show edit/global/delete but not approve/reject.
  • Extend the embedded plugin page asset test to assert the expected conditional rendering snippet for reviewActions in the bundled script.
pages/dashboard/app.js
tests/integration/test_webui_static_assets.py
Preserve completed/manual jargon definitions and counts during relearning upserts and skip completed terms in V2 jargon batch inference.
  • In the ORM-backed _save_or_update_jargon_select_then_write path, gate meaning/raw_content/is_jargon/count/is_complete/is_global updates behind a preserve_completed flag when the existing record is_complete.
  • For the SQLAlchemy upsert path, add helpers to detect _preserve_completed in the payload and to build CASE expressions that keep existing column values (and count) when Jargon.is_complete is true.
  • Update _jargon_update_values to use these helpers for meaning/raw_content/is_jargon/count/is_complete/is_global so relearning payloads cannot overwrite completed records when _preserve_completed is set.
  • In V2LearningIntegration._jargon_batch, fetch existing jargon per candidate, skip ones already marked is_complete, compute observed_count as the max of candidate frequency and existing count, and pass _preserve_completed in the upsert payload.
  • Add unit tests to verify that V2 jargon batch skips completed terms and preserves the candidate count, and that the database upsert logic preserves completed manual definitions when relearning is attempted.
services/database/facades/jargon_facade.py
services/core_learning/v2_learning_integration.py
tests/unit/test_provider_registry_rebind.py
tests/unit/test_database_engine.py

Assessment against linked issues

Issue Objective Addressed Explanation
#211 Replace usage of window.confirm in the embedded Plugin Page batch actions with a confirmation mechanism that works inside sandboxed iframes so that batch actions are no longer silently cancelled.
#211 Apply this confirmation fix to all affected batch handlers in the embedded Plugin Page: handleBatchReviewAction (审查队列), handleJargonBatchAction (黑话学习), and handleStyleBatchAction (表达方式学习).
#212 Prevent automatic jargon relearning from overwriting manually completed (is_complete=True) jargon entries when v2_learning_integration._jargon_batch upserts meanings.
#212 Preserve the existing count for existing jargon records during relearning instead of resetting it to 1.
#213 Update the jargon learning page UI so that for already confirmed jargon entries the '确认' (confirm) and '驳回' (reject) buttons are hidden, while for unconfirmed entries all action buttons remain visible.

Possibly linked issues


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

@sourcery-ai sourcery-ai Bot left a comment

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.

Hey - I've left some high level feedback:

  • The integration test assertion assert "window.confirm" not in script is quite brittle and may fail if any unrelated bundled dependency or future feature legitimately uses window.confirm; consider scoping this to the specific dashboard module or a more targeted check (e.g., absence in the batch handlers) instead of the entire script string.
  • The _preserve_completed control flag is currently a magic string used in multiple places (SQLAlchemy upsert and the select-then-write path); consider centralizing this key name and its semantics behind a small helper or constant to avoid divergence or typos in future changes.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The integration test assertion `assert "window.confirm" not in script` is quite brittle and may fail if any unrelated bundled dependency or future feature legitimately uses `window.confirm`; consider scoping this to the specific dashboard module or a more targeted check (e.g., absence in the batch handlers) instead of the entire script string.
- The `_preserve_completed` control flag is currently a magic string used in multiple places (SQLAlchemy upsert and the select-then-write path); consider centralizing this key name and its semantics behind a small helper or constant to avoid divergence or typos in future changes.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@EterUltimate EterUltimate force-pushed the codex/fix-jargon-embedded-page branch from 8bc7e03 to a3ccdbe Compare June 16, 2026 15:44
@EterUltimate EterUltimate deleted the codex/fix-jargon-embedded-page branch June 18, 2026 05:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

1 participant