Initialize TaskProcessor on-demand and simplify task history#114
Merged
Conversation
The task list was loaded eagerly on startup, deserialising thousands of
Session handle objects (each carrying a DataLocationModel) and causing
15-20s startup delays.
Two changes:
1. Lazy-load TaskProcessor: BatchProcessor is no longer created during
app startup. It is initialised on first use — when the TaskProcessor
tab is opened, or when a session method is submitted or run directly.
All call sites that previously assumed BatchProcessor was always live
are guarded with isempty/isvalid checks or route through
initializeBatchProcessor().
2. Slim history items: addTaskToHistory now extracts the entity
identifier(s) from args{1} into a new entityId field, then drops
args{1} (the expensive Session handle object) and keeps args(2:end)
(options struct and any trailing args). History items are never
re-executed, so the live handle is unnecessary; entityId allows the
object to be reconstructed on demand from the MetaTable when a user
reassigns a history item back to the queue via BatchProcessorUI.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
onTaskAddedEventTriggered assumed args{1} (the session object) was still
present on history task items, but addTaskToHistory now strips it before
firing the event. Introduced reconstructEntityFromTask to look up the
live session from the MetaTable via entityId instead.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
setBusy() always registers a UUID in StatusItems, but only creates the matching onCleanup when nargout > 0. onTaskProcessorStatusChanged was calling setBusy without capturing the return value, leaving an orphaned UUID in StatusItems. The subsequent setIdle() call (without a statusId) could never remove it, so ~isempty(StatusItems) kept returning early, and the app remained permanently in busy state after the first task ran. Fix: store the onCleanup handle in TaskProcessorBusyCleanup_. Assigning [] to the property destroys the handle, which triggers onCleanup and calls setIdle(statusId), correctly removing the entry from StatusItems. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR improves app startup time and task history storage by lazy-initializing the TaskProcessor and by removing heavy/stale entity handle objects from archived history items, while preserving the ability to re-queue history items by reconstructing entities from the live MetaTable.
Changes:
- Lazy-initialize
nansen.TaskProcessor(init on Task Processor tab open or on task submission) and add guards where the processor may be absent/invalid. - Simplify archived history items by extracting/storing
entityIdand strippingargs{1}(entity handle) before archiving. - Enable “Reassign to Queue” for stripped history items via a
ReconstructEntityFcncallback that reconstructs entities fromMetaTable.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
code/apps/+nansen/BatchProcessorUI.m |
Adds ReconstructEntityFcn and reconstructs entity objects when re-queuing history items. |
code/apps/+nansen/@TaskProcessor/TaskProcessor.m |
Stores entityId in history items and strips entity handles from archived args. |
code/apps/+nansen/@App/App.m |
Implements lazy TaskProcessor init, entity reconstruction helpers, and fixes busy/idle cleanup handling. |
.github/badges/code_issues.svg |
Updates the “code issues” badge value. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+642
to
+646
| taskItem.entityId = obj.extractEntityId(taskItem.args); | ||
| if ~isempty(taskItem.args) | ||
| taskItem.args = taskItem.args(2:end); % drop entity, keep opts | ||
| end | ||
|
|
Older task_list.mat files lack the entityId field added in the lazy-load
refactor. Appending a new (fully-fielded) item to an unpatched struct
array throws "dissimilar structures". Fix: add a normalizeTaskItems
static helper that backfills entityId = {} on any item missing it, and
call it for both TaskQueue and TaskHistory immediately after loading from
disk.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
entityId(the session ID string(s)) is extracted before the item is added to history, andargs{1}(the entity) is dropped. This keeps history items small regardless of how many sessions they reference. Storing session handle objects was expensive and unnecessary.ReconstructEntityFcnonBatchProcessorUI. When a history item is re-queued, the session object is reconstructed from the live MetaTable using the storedentityId.onTaskProcessorStatusChangedpreviously calledsetBusywithout capturing the return value, leaving an orphaned UUID inStatusItemsthatsetIdle()could never remove — causing the app to stay permanently in busy state after any task ran. Fixed by storing theonCleanuphandle inTaskProcessorBusyCleanup_.Files changed
App.m— lazy init guards, newreconstructEntityObjects/reconstructEntityFromTaskhelpers,ReconstructEntityFcnwiring,onTaskAddedEventTriggeredfix,onTaskProcessorStatusChangedbusy-state fixTaskProcessor.m—extractEntityIdstatic,entityIdfield in task items,addTaskToHistorystrips entity from argsBatchProcessorUI.m—ReconstructEntityFcnproperty,onReassignToQueueMenuItemClickedreconstruction logic,getStoredEntityIdhelper