Fix CodeEditor annotations overwritten by Ace worker - #8505
Merged
philippjfr merged 2 commits intoMar 14, 2026
Conversation
Since the Ace upgrade to v1.40.1 (holoviz#7874), the background syntax-checking worker overwrites user-set annotations. This fix disables the worker when user annotations are set and re-enables it when cleared. Key changes: - Toggle Ace worker off when annotations are non-empty to prevent overwrites - Call _add_annotations() during render for constructor-provided annotations - Re-apply annotations after language/mode changes to prevent worker races - Order setUseWorker before setAnnotations (disabling worker clears session) Closes holoviz#7967
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8505 +/- ##
===========================================
+ Coverage 70.34% 86.09% +15.75%
===========================================
Files 348 349 +1
Lines 55198 55292 +94
===========================================
+ Hits 38828 47606 +8778
+ Misses 16370 7686 -8684 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Remove duplicate _add_annotations() call in render() (already called via _update_language()) - Replace hardcoded sleeps with multi-checkpoint stability assertions - Add worker state verification (useWorker toggle assertions) - Add tests: language change, annotation replacement, value change, and full worker lifecycle (resume after clear with invalid JS)
philippjfr
approved these changes
Mar 14, 2026
Contributor
Author
|
Thanks for the merge and review!! 😊 |
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #7967
Since the Ace upgrade (v1.4.11 to v1.40.1 in #7874), explicitly setting
annotationson aCodeEditorgets overwritten by Ace's background syntax-checking worker. The worker fires asynchronously aftersession.setMode()and callssession.setAnnotations()with its own results, wiping out user-set annotations.I traced the issue to
panel/models/ace.ts:_update_language()callssession.setMode()which spawns a worker that overwrites annotationsThe fix:
setUseWorker(false)so it cannot overwrite them_add_annotations()in_update_language()aftersetMode()so annotations persist across language/mode changesImportant ordering detail:
setUseWorker(false)clears the session's annotations as a side effect, so the worker must be toggled before callingsetAnnotations().Known Limitations
When user annotations are set (non-empty), Ace's built-in syntax checking worker is disabled to prevent it from overwriting custom annotations. This means real-time syntax error/warning markers from Ace will not appear alongside user-set annotations. Syntax checking resumes automatically when annotations are cleared back to
[]. This matches the behavior of Panel < 1.7.0 where theannotationsparameter gave users full control over the annotation system.Reproducer (from the issue):
Before fix (annotations never appear after clicking "Add Annotations"):

After fix (annotations appear and persist after clicking "Add Annotations"):
After fix (annotations cleared after clicking "Clear Annotations"):
How Has This Been Tested?
test_codeeditor.pyUI tests passtest_ace.pyunit tests passtest_code_editor_annotations: sets annotations dynamically, verifies worker is disabled, checks persistence across multiple checkpoints, clears and verifies worker re-enablestest_code_editor_annotations_constructor: verifies constructor-provided annotations are applied, worker is disabled, and annotations persisttest_code_editor_annotations_persist_on_language_change: sets annotations then changes language, verifies annotations survive the mode/worker respawntest_code_editor_annotations_replacement: replaces one set of annotations with another, verifies the new set is applied correctlytest_code_editor_annotations_persist_on_value_change: sets annotations then changes code value programmatically, verifies annotations survivetest_code_editor_worker_resumes_after_clear: full lifecycle test — verifies Ace's JS worker produces syntax errors on invalid code, user annotations override them (worker disabled), and after clearing the worker resumes producing its own annotationsAI Disclosure
Tools: Claude, used to help scaffold the fix and tests after I identified the root cause.
Checklist