Skip to content

import: stage only the target night - #791

Merged
abdulsaheel merged 1 commit into
mainfrom
fix/auto-import-target-day
Nov 20, 2026
Merged

abdulsaheel merged 1 commit into
mainfrom
fix/auto-import-target-day

Conversation

@abdulsaheel

@abdulsaheel abdulsaheel commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

User description

import derive called calendarDays(sub) with no target, so every imported day also re-staged the prior evening it carries as context and then threw that result away. that's two nights of sleep staging per day, on the ui isolate.

when deriveImportedDays gets one date (every NoopIngest call) it now passes targetDay + skipUnusedDays like the live path does. multi-date calls keep the full walk. test checks only one night gets segmented.

Summary by Sourcery

Optimize single-date imports to avoid unnecessary staging of contextual evenings.

Bug Fixes:

  • Ensure single-date imports stage only the requested night instead of redundantly staging the buffered prior evening.

Tests:

  • Add coverage verifying that an imported date segments exactly one night.

PR Type

Bug fix, Tests


Description

  • Single-date imports now stage only the target night, not the buffered prior evening

  • Eliminates redundant sleep staging (two nights per import day) on the UI isolate

  • Test added verifying exactly one night is segmented for a single-date import


Diagram Walkthrough

flowchart LR
  A["deriveImportedDays()"]
  B["dates.length == 1?"]
  C["calendarDays(sub, targetDay, skipUnusedDays=true)"]
  D["calendarDays(sub) — full walk"]
  E["Stage target night only"]
  F["Stage all nights including prior evening"]
  A -- "check date count" --> B
  B -- "yes (NoopIngest)" --> C
  B -- "no (multi-date)" --> D
  C -- "result" --> E
  D -- "result" --> F
Loading

File Walkthrough

Relevant files
Bug fix
derivation_engine.dart
Pass targetDay to calendarDays for single-date imports     

lib/compute/derivation_engine.dart

  • When dates.length == 1, extracts target and passes targetDay +
    skipUnusedDays: true to calendarDays()
  • Multi-date calls retain the existing full-walk behavior
  • Prevents redundant staging of the buffered prior evening on the UI
    isolate for every single-date import
+6/-1     
Tests
derive_day_window_test.dart
Test that single-date import segments exactly one night   

test/derive_day_window_test.dart

  • Adds test 'an import stages only the requested date, not the buffered
    evening'
  • Synthesizes a substrate spanning the prior evening into the target
    date
  • Asserts deriveImportedDays returns 1 and debugSegmentedDayCount equals
    1
+15/-0   

Summary by CodeRabbit

  • Bug Fixes
    • Imported-day calculations now target the specified calendar day when exactly one date is selected. With zero or multiple dates, calculations continue across the full calendar.

@sourcery-ai

sourcery-ai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Implementation

For single-date imports, stage only the target night while preserving the full walk for multi-date imports.

  • lib/compute/derivation_engine.dart L6662-6667

Tests

Verify that importing one requested date segments only one night, not the buffered prior evening.

  • test/derive_day_window_test.dart L363-377

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

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

deriveImportedDays now targets the requested calendar day when given one import date. For zero or multiple dates, it retains full calendarDays traversal.

Changes: Imported-day derivation

Layer / File(s) Summary
Select calendar days for import derivation
lib/compute/derivation_engine.dart
When one date is provided, deriveImportedDays passes it as targetDay and enables skipUnusedDays. With zero or multiple dates, it calls calendarDays without a target.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related PRs

  • OpenStrap/edge#656: Adds the targetDay and skipUnusedDays controls that this change passes to calendarDays.

Suggested reviewers: droptabl

Merge Risk: Minimal · up to 3f88f

Single-date imports now stage only the target night, which avoids redundant work, and results are unchanged for the production import paths. No actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "import: stage only the target night" matches the main change. The PR makes deriveImportedDays target the requested day for single-date calls and enable skipUnusedDays, so only the target ni…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "import: stage only the target night" matches the main change. The PR makes deriveImportedDays target the requested day for single-date calls and enable skipUnusedDays, so only the target night is staged and the carried-over prior evening is no longer staged. The title is specific and short, and it uses the conventional scope-prefix style.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
Fix failing CI checks

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7a9f3ed and 3f88f52.

Files ignored due to path filters: 1

  • test/derive_day_window_test.dart is excluded by !test/**
Files selected for processing: 1

  • lib/compute/derivation_engine.dart

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

UI Isolate Compute

The PR description explicitly states this staging was happening "on the UI isolate" and the fix reduces the work done there. However, the fix still runs calendarDays + the full derivation pipeline inside _withRunLock on whatever isolate calls deriveImportedDays. If this is still called from the UI isolate (as the description implies), the fix only halves the work rather than moving it off the UI isolate entirely. Per AGENTS.md §3.10 and §4.4, heavy compute must go through Isolate.run. The PR does not address whether the caller has been moved to a background isolate.

return _withRunLock(0, () async {
  // One date (every NoopIngest call): stage only that night, like the
  // live path. The full walk re-staged the buffered prior evening on the
  // UI isolate and then threw it away, so an import paid two nights per day.
  final target = dates.length == 1 ? dates.single : null;
  final days = calendarDays(sub,
      targetDay: target, skipUnusedDays: target != null);
Multi-date Regression

For dates.length > 1, the code falls back to calendarDays(sub) with no targetDay and skipUnusedDays=false, which is the old behavior. But the old behavior was described as a bug (re-staging the prior evening and throwing it away). Multi-date import calls will still pay the extra staging cost and potentially derive days outside the requested dates set. If the loop inside _withRunLock already filters by dates, the extra days computed by calendarDays(sub) are wasted work; if it does not filter, it may derive and persist results for days not in dates, which is a correctness issue.

final target = dates.length == 1 ? dates.single : null;
final days = calendarDays(sub,
    targetDay: target, skipUnusedDays: target != null);

@github-actions

Copy link
Copy Markdown
Contributor

PR Code Suggestions ✨

No code suggestions found for the PR.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've reviewed your changes and they look great!

Sourcery assessment

Approved.


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@abdulsaheel
abdulsaheel merged commit 8051a52 into main Nov 20, 2026
5 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant