Skip to content

fix(cli): planner create/schedule send correct class and calendar refs - #22

Merged
IamCoder18 merged 4 commits into
mainfrom
fix/planner-attached-to-class-and-calendar-ref
Aug 5, 2026
Merged

fix(cli): planner create/schedule send correct class and calendar refs#22
IamCoder18 merged 4 commits into
mainfrom
fix/planner-attached-to-class-and-calendar-ref

Conversation

@IamCoder18

Copy link
Copy Markdown
Owner

Summary

Two bugs in the Planner (huly action ...) that prevented CLI-created todos from appearing in the right places:

Bug 1 — action create: wrong attachedToClass

resolveEmployeeId() returns either an Employee or Person ref depending on the workspace model (after ff2ae6f it prefers Employee), but createAction hardcoded attachedToClass as 'contact:class:Person'. The class/ref mismatch was rejected by addCollection or routed the todo to the wrong collection.

Fix: resolveEmployeeId now returns { ref, class }. createAction mirrors the resolved class into attachedToClass. When the email lookup helper returns just a ref, createAction probes each candidate class to find the actual one.

Bug 2 — action schedule: WorkSlot.calendar set to Employee ref

scheduleAction set calendar: todo.user (an Employee ref), but Event.calendar is a Ref<Calendar>. The Schedule Calendar UI filters events by the user's PersonalCalendar ref, so CLI-created WorkSlots were invisible.

Fix: new resolvePrimaryCalendar() helper that mirrors findPrimaryCalendar from plugins/time-resources/src/utils.ts: queries calendar:class:Calendar for user: primarySocialId, hidden: false, access ∈ {owner, writer} and honors the calendar:class:PrimaryCalendar preference's attachedTo.

Verification

  • action create --owner iamcoder18@gmail.comattachedToClass=contact:class:Person (matches the resolved ref)
  • action schedule HULY-1 --start 2026-08-04T21:00:00-06:00 --duration 30 → WorkSlot's calendar=22608698-..._calendar (matches the user's PersonalCalendar, identical to UI-created HULY-2 slot)
  • HULY-1 now appears in the Schedule Calendar UI alongside HULY-2
  • pnpm typecheck clean

Test artifacts cleaned up

The first action create smoke-test todo (6a72a80922356b1f1835bda5) became un-deletable via huly action delete because the SDK's removeCollection validates the stored attachedToClass (the buggy value the fix had stored before the second-pass fix). Removed via a direct removeDoc RPC.

Two bugs that prevented CLI-created todos from appearing in the right places:

1. action create: resolveEmployeeId() returns either an Employee or Person
   ref depending on the workspace model, but createAction hardcoded
   attachedToClass as 'contact:class:Person'. Mismatch rejected by
   addCollection or routed the todo to the wrong collection. Now returns
   { ref, class } and mirrors the resolved class into attachedToClass,
   probing the actual class when the lookup helper returns just a ref.

2. action schedule: set WorkSlot.calendar to todo.user (an Employee ref),
   but Event.calendar is a Ref<Calendar>. The Schedule Calendar UI
   filters by the user's PersonalCalendar ref, so slots were invisible.
   Now resolves the PersonalCalendar via findPrimaryCalendar logic
   (Calendar docs for user + PrimaryCalendar preference).
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@IamCoder18, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 44 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5379753f-66ba-4366-a904-d0de5ac8c939

📥 Commits

Reviewing files that changed from the base of the PR and between 5ab1bb4 and 4851233.

📒 Files selected for processing (1)
  • packages/cli/src/resources/todo.ts
📝 Walkthrough

Walkthrough

The todo resource now resolves owner references with their classes, uses those classes for action operations, and assigns scheduled work slots to a configured, writable, external, or synthetic account calendar.

Changes

Todo resource updates

Layer / File(s) Summary
Owner identity and action ownership
packages/cli/src/resources/todo.ts
Owner resolution returns both the document reference and its Employee or Person class. Action listing, creation, and updates use the resolved reference and class.
Primary calendar scheduling
packages/cli/src/resources/todo.ts
Calendar resolution honors the configured calendar, then selects a writable external calendar, and otherwise creates or uses a synthetic account calendar. Scheduled work slots store the resolved calendar reference.

Estimated code review effort: 4 (Complex) | ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the two main fixes: correct class references and calendar references for Planner CLI actions.
Description check ✅ Passed The description directly explains both bugs, their fixes, and verification results described in the changeset.
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.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/planner-attached-to-class-and-calendar-ref

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

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/cli/src/resources/todo.ts`:
- Around line 169-171: Update the default-owner branch in the surrounding
account-resolution function to query CLASS.Person using { personUuid:
account.uuid }, return the matched document’s _id with CLASS.Person, and throw
an explicit error when no Person document was provisioned; do not return
account.uuid directly.
- Around line 57-85: Update resolvePrimaryCalendar to match the UI scheduler’s
primary-calendar selection order when the PRIMARY_CALENDAR_PREF lookup does not
yield a matching calendar: select the eligible ExternalCalendar first, then fall
back to the accountUuid-based default calendar before using the first writable
calendar. Reuse the shared selection helper if available, and preserve the
existing preference match as the highest-priority choice.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: aed4cfa4-2de9-4a0d-9175-2d859fe4f6c0

📥 Commits

Reviewing files that changed from the base of the PR and between c1c9735 and 3e7ae9c.

📒 Files selected for processing (1)
  • packages/cli/src/resources/todo.ts
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
  • GitHub Check: Kilo Code Review
🔇 Additional comments (1)
packages/cli/src/resources/todo.ts (1)

197-197: LGTM!

Also applies to: 433-433

Comment thread packages/cli/src/resources/todo.ts Outdated
Comment thread packages/cli/src/resources/todo.ts Outdated
…ry-calendar order

1. resolveEmployeeId default-owner branch previously returned account.uuid
   as if it were a workspace-local Person _id. Now queries contact:class:Person
   with { personUuid: account.uuid }, mirroring resolveEmailToLocalId, and
   throws an explicit error if no Person was provisioned for the current
   account.

2. resolvePrimaryCalendar previously fell back to the first writable Calendar
   when neither the preference nor a Person-local match was found. The UI
   scheduler's getPrimaryCalendar (plugins/calendar/src/utils.ts:432) instead
   returns the first eligible ExternalCalendar (default: true, hidden: false)
   and, failing that, the synthetic ${accountUuid}_calendar. Match that
   order so CLI-scheduled WorkSlots land in the same calendar the UI would
   use. Shared helper is inlined because @hcengineering/calendar is not a
   CLI dependency.
Comment thread packages/cli/src/resources/todo.ts Outdated
Comment thread packages/cli/src/resources/todo.ts
Comment thread packages/cli/src/resources/todo.ts
Comment thread packages/cli/src/resources/todo.ts Outdated
Comment thread packages/cli/src/resources/todo.ts
Comment thread packages/cli/src/resources/todo.ts Outdated
@kilo-code-bot

kilo-code-bot Bot commented Aug 5, 2026

Copy link
Copy Markdown

Code Review Summary

Status: 3 Issues Remaining | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
packages/cli/src/resources/todo.ts 104 findOne(PRIMARY_CALENDAR_PREF, {}) uses empty filter; if PrimaryCalendar is per-user, returns arbitrary user's preference, silently skipping the current user's own preference. Author declined, citing UI contract match.
packages/cli/src/resources/todo.ts 116 c._class === EXTERNAL_CALENDAR_CLASS strict equality misses subclasses (e.g., GoogleCalendar, OutlookCalendar), causing CLI to fall through to synthetic fallback. Author declined, citing no OSS subclasses.

SUGGESTION

File Line Issue
packages/cli/src/resources/todo.ts 196 Workspace-local fallback limit: 500 may silently miss target users in workspaces with >500 Employees or Persons. Author deferred, out of scope for this PR.
Files Reviewed (1 file)
  • packages/cli/src/resources/todo.ts - 3 issues (2 previously raised and author-skipped with justification, 1 previously raised and author-deferred as out of scope)

Fix these issues in Kilo Cloud

Reviewed by minimax-m3

Previous Review Summaries (2 snapshots, latest commit 5ab1bb4)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 5ab1bb4)

Status: 5 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 2
SUGGESTION 3
Issue Details (click to expand)

WARNING

File Line Issue
packages/cli/src/resources/todo.ts 100 findOne(PRIMARY_CALENDAR_PREF, {}) uses empty filter; if PrimaryCalendar is per-user, returns arbitrary user's preference, silently skipping the current user's own preference
packages/cli/src/resources/todo.ts 112 c._class === EXTERNAL_CALENDAR_CLASS strict equality misses subclasses (e.g., GoogleCalendar, OutlookCalendar), causing CLI to fall through to synthetic fallback instead of user's actual default

SUGGESTION

File Line Issue
packages/cli/src/resources/todo.ts 57 New isDomainNotFound helper uses fragile err.message.includes('domain not found') substring match; false positives would silently swallow real errors, reintroducing the broad-catch problem this helper was added to solve
packages/cli/src/resources/todo.ts 192 Workspace-local fallback limit: 500 may silently miss target users in workspaces with >500 Employees or Persons
packages/cli/src/resources/todo.ts 212 Default-owner probe order is ['contact:class:Person', 'contact:class:Employee'], inconsistent with the email branch (line 166) which probes Employee first per the ff2ae6f preference noted in the PR description
Files Reviewed (1 file)
  • packages/cli/src/resources/todo.ts - 5 issues

Fix these issues in Kilo Cloud

Previous review (commit 0e2044c)

Status: 6 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 4
SUGGESTION 2
Issue Details (click to expand)

WARNING

File Line Issue
packages/cli/src/resources/todo.ts 77 Broad catch in resolvePrimaryCalendar swallows all errors from findAll, silently returning synthetic ${accountUuid}_calendar fallback for network/auth/server failures
packages/cli/src/resources/todo.ts 83 findOne(PRIMARY_CALENDAR_PREF, {}) uses empty filter; if PrimaryCalendar is per-user, returns arbitrary user's preference, silently skipping the current user's own preference
packages/cli/src/resources/todo.ts 94 c._class === EXTERNAL_CALENDAR_CLASS strict equality misses subclasses (e.g., GoogleCalendar, OutlookCalendar), causing CLI to fall through to synthetic fallback instead of user's actual default
packages/cli/src/resources/todo.ts 158, 179 Broad catches in resolveEmployeeId probe and fallback loops silently swallow network/auth/server errors as "class not in workspace", producing misleading NotFound errors

SUGGESTION

File Line Issue
packages/cli/src/resources/todo.ts 173 Workspace-local fallback limit: 500 may silently miss target users in workspaces with >500 Employees or Persons
packages/cli/src/resources/todo.ts 190 Default-owner branch only queries contact:class:Person; will throw NotFound if the current user is modeled only as Employee, unlike the email branch which probes both
Files Reviewed (1 file)
  • packages/cli/src/resources/todo.ts - 6 issues

Fix these issues in Kilo Cloud


Reviewed by minimax-m3 · Input: 55.8K · Output: 4K · Cached: 276.5K

…obe Employee in default owner

Address 3 of 6 review findings; skip 3 with reasons:

Fixes:
- resolvePrimaryCalendar.findAll: catch now only swallows 'domain not
  found' errors so network/auth failures surface instead of silently
  falling back to the synthetic ${accountUuid}_calendar.
- resolveEmployeeId probe loop (email branch): same narrow-to-domain-
  not-found fix so a transient findOne failure doesn't masquerade as
  'class not in this workspace'.
- resolveEmployeeId workspace-local fallback: same narrow-to-domain-
  not-found fix.
- resolveEmployeeId default-owner branch: previously only queried
  contact:class:Person; if the workspace models the current user only
  as Employee, it threw NotFound. Now probes both Person and Employee,
  mirroring the email branch.

Skipped:
- findOne(PrimaryCalendar, {}) empty filter: matches platform UI's
  findPrimaryCalendar exactly; Preference is treated as a workspace
  singleton there.
- ExternalCalendar strict-equality check: OSS platform defines no
  ExternalCalendar subclasses (only ExternalCalendar extends Calendar);
  the UI uses the same strict equality. Revisit if subclasses land.
- resolveEmployeeId workspace-local limit: 500: matches the
  resolveEmailToLocalId pattern; pagination refactor out of scope.
Comment thread packages/cli/src/resources/todo.ts Outdated
Comment thread packages/cli/src/resources/todo.ts Outdated
…mployee-first probe

Two leftover SUGGESTION findings from the second review pass:

1. isDomainNotFound: switch err.message.includes('domain not found')
   to /domain not found/i so a future SDK message tweak (casing,
   translation) doesn't silently break the discriminator. The platform's
   Hierarchy error is exact-cased today; the change is purely defensive.

2. resolveEmployeeId default-owner branch was probing
   ['contact:class:Person', 'contact:class:Employee'] while the email
   branch (and the post-ff2ae6f preference) probes Employee first.
   Reorder for consistency. Behaviorally a no-op when only one class is
   provisioned (findOne returns undefined, loop falls through), but
   matches the comment and the email branch.
@IamCoder18
IamCoder18 merged commit 4f0c37c into main Aug 5, 2026
2 checks passed
@IamCoder18
IamCoder18 deleted the fix/planner-attached-to-class-and-calendar-ref branch August 7, 2026 01:28
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.

1 participant