Skip to content

Fix VibeScript publication UI starvation - #168

Merged
10-X-eng merged 2 commits into
mainfrom
bugfix/vibescript-publish-freeze-final
Sep 4, 2026
Merged

Fix VibeScript publication UI starvation#168
10-X-eng merged 2 commits into
mainfrom
bugfix/vibescript-publish-freeze-final

Conversation

@10-X-eng

@10-X-eng 10-X-eng commented Sep 4, 2026

Copy link
Copy Markdown
Owner

User-visible outcome

Large VibeScript publication no longer runs as one monolithic FreeCAD/Qt callback. The captured 307-member Assembly is published one member per bounded document-thread dispatch, with progress and cancellation between slices, while Tree/Timeline and VibeCAD observer work are coalesced once for the logical operation.

Closes #167

Why

The old path held the GUI thread through publication and triggered redundant whole-document projection and observer work for per-object notifications. Merely yielding inside the existing transaction was unsafe because Undo, Redo, Recompute, document close, or another command could alter the document between slices.

This change adds an explicit nested cooperative-mutation state to App::Document, separates bulk-projection blocking from ordinary edit/history guards, and makes the publication transaction both cooperative and atomic.

What changed

  • Added a shared cooperative document-thread step runner with cancellation, item-level progress, slice telemetry, and document-thread generator teardown.
  • Added additive generator-based VibeScript publication while preserving the existing synchronous publication entry point.
  • Added nested document-change batching with commit/rollback outcomes.
  • Coalesced selector refresh, reference-snapshot invalidation, dependency-staleness scans, recompute, redraw, Tree refresh, and Feature Timeline refresh.
  • Added App::Document cooperative-mutation state and Python bindings.
  • Disabled/refused Undo, Redo, Recompute, and document close while cooperative publication is active; restored them on the outermost end.
  • Kept ordinary Part Design/task-panel transactions incrementally visible by separating the narrow projection predicate from the wider history-mutation predicate.
  • Added exact target/document revalidation between publication slices.
  • Merged all 307 Assembly members into publication progress rather than treating the Assembly container as one opaque item.
  • Fixed cancellation/error teardown so a suspended publication generator is finalized on the document thread, never the worker thread.

Red/green development

RED cases were added before implementation for:

  • cooperative cancellation between document-thread slices;
  • generator finalization on the document thread after worker-side progress failure;
  • rollback discarding batched observer work;
  • normal open transaction/edit lock preserving incremental Tree projection;
  • nested cooperative mutation deferring one authoritative projection refresh;
  • close/Undo refusal during cooperative publication;
  • 307-member Assembly item-level publication and dispatch count.

Observed RED for the teardown regression:

assert finalized == [True]
E assert [False] == [True]

GREEN verification:

C:\Users\robit\vibecad\.pixi\envs\default\python.exe -m pytest src\Mod\VibeCAD\vibecad_tests -q
4380 passed, 9 skipped in 84.80s
ctest --test-dir build -C Release -R ^Gui_tests_run$ --output-on-failure
138/138 tests passed

Focused cooperative/publication suite:

C:\Users\robit\vibecad\.pixi\envs\default\python.exe -m pytest src\Mod\VibeCAD\vibecad_tests\test_cooperative_document_execution.py src\Mod\VibeCAD\vibecad_tests\test_vibescript_publication_progress.py -q
13 passed

Full Windows build through the repository's normal Rattler/Pixi path:

cd package\rattler-build
C:\Users\robit\.pixi\bin\pixi.exe reinstall --frozen -e default vibecad

Result: exit 0; vibecad-26.3.1RC6-h3c70cbc_1.conda produced; default environment reinstalled.

Packaged runtime smoke:

VibeCAD 26.3.1-RC6 (Build 1)
COOP_METHODS True True
COOP_INITIAL False
COOP_ACTIVE True
COOP_ENDED False

The packaged Windows GUI is currently running in normal (non-safe) mode for owner acceptance testing.

Risk and mitigation

The principal risk is changing document transaction/projection behavior. The implementation uses a new explicit cooperative state only for bulk cooperative mutation; existing normal transactions and edit locks retain incremental Tree behavior. Native tests cover nesting, normal edit compatibility, close refusal, and Undo refusal/recovery. Exact live document/object validation protects every inter-slice continuation.

Deliberate non-goals

  • No public tool/schema/preference names changed.
  • No provider or capability was removed.
  • No unrelated UI or packaging behavior was refactored.
  • This PR establishes the shared cooperative mechanism and applies it to the reproduced VibeScript publication path; remaining long-running Native capabilities can adopt the additive cooperative_commit adapter independently.

Compatibility checklist

  • Existing public functions/APIs remain present and behaviorally compatible.
  • No preference keys, tool names, or schema fields were renamed or removed.
  • Defaults preserve previous behavior for callers that do not use cooperative publication.
  • Existing synchronous publication is retained through an additive adapter.
  • No breaking changes are included.

Publish large VibeScript results as bounded document-thread slices, coalesce document projections and observers, and guard cooperative mutations from conflicting user actions. Preserve synchronous callers through additive adapters and cover rollback, cancellation, normal edit transactions, and the captured 307-member Assembly workload.

Refs #167
@10-X-eng
10-X-eng marked this pull request as ready for review September 4, 2026 18:33
@10-X-eng

10-X-eng commented Sep 4, 2026

Copy link
Copy Markdown
Owner Author

Owner acceptance on the packaged Windows build passed with the captured 307-member Assembly.

Observed live behavior:

  • 153/153 joints constructed;
  • worker transitioned into the native static solve and remained CPU-active;
  • VibeCAD continued reporting progress and stayed usable during the long worker phase;
  • cooperative publication completed and the resulting Assembly is working;
  • no cancellation, restart, or direct intervention was required.

This validates the real workload in addition to the unit, native GUI, full Python, packaged-runtime, and Rattler build gates documented in the PR body.

@10-X-eng
10-X-eng marked this pull request as draft September 4, 2026 18:34
@10-X-eng
10-X-eng marked this pull request as ready for review September 4, 2026 18:54
@10-X-eng
10-X-eng enabled auto-merge September 4, 2026 18:54
@10-X-eng
10-X-eng merged commit 7289751 into main Sep 4, 2026
2 checks passed
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.

Prevent UI starvation during large VibeScript publication

1 participant