Skip to content

Initialize TaskProcessor on-demand and simplify task history#114

Merged
ehennestad merged 7 commits into
devfrom
lazy-task-processor-load
Jun 7, 2026
Merged

Initialize TaskProcessor on-demand and simplify task history#114
ehennestad merged 7 commits into
devfrom
lazy-task-processor-load

Conversation

@ehennestad

@ehennestad ehennestad commented Jun 6, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Lazy TaskProcessor init: Start TaskProcessor on first-time use to reduce time when starting nansen.App
  • Simplify history items: task history no longer stores the full Session handle object. Instead, entityId (the session ID string(s)) is extracted before the item is added to history, and args{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.
  • Reassign to Queue: preserved via ReconstructEntityFcn on BatchProcessorUI. When a history item is re-queued, the session object is reconstructed from the live MetaTable using the stored entityId.
  • Bug fixes:
    • onTaskProcessorStatusChanged previously called setBusy without capturing the return value, leaving an orphaned UUID in StatusItems that setIdle() could never remove — causing the app to stay permanently in busy state after any task ran. Fixed by storing the onCleanup handle in TaskProcessorBusyCleanup_.

Files changed

  • App.m — lazy init guards, new reconstructEntityObjects/reconstructEntityFromTask helpers, ReconstructEntityFcn wiring, onTaskAddedEventTriggered fix, onTaskProcessorStatusChanged busy-state fix
  • TaskProcessor.mextractEntityId static, entityId field in task items, addTaskToHistory strips entity from args
  • BatchProcessorUI.mReconstructEntityFcn property, onReassignToQueueMenuItemClicked reconstruction logic, getStoredEntityId helper

ehennestad and others added 3 commits June 6, 2026 21:55
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>
Comment thread code/apps/+nansen/BatchProcessorUI.m Fixed
Comment thread code/apps/+nansen/BatchProcessorUI.m Fixed
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown

Test Results

254 tests  ±0   254 ✅ ±0   22s ⏱️ -3s
 16 suites ±0     0 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit f79fec2. ± Comparison against base commit 65857d5.

♻️ This comment has been updated with latest results.

@ehennestad ehennestad changed the title Lazy-load TaskProcessor and slim task history Lazy-load TaskProcessor and simplify task history Jun 6, 2026
@ehennestad ehennestad requested a review from Copilot June 6, 2026 23:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 entityId and stripping args{1} (entity handle) before archiving.
  • Enable “Reassign to Queue” for stripped history items via a ReconstructEntityFcn callback that reconstructs entities from MetaTable.

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 thread code/apps/+nansen/@TaskProcessor/TaskProcessor.m
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

Comment thread code/apps/+nansen/@App/App.m Outdated
ehennestad and others added 2 commits June 7, 2026 21:49
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>
@ehennestad ehennestad changed the title Lazy-load TaskProcessor and simplify task history Initialize TaskProcessor on-demand and simplify task history Jun 7, 2026
@ehennestad ehennestad merged commit 91ff8e5 into dev Jun 7, 2026
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.

3 participants