Skip to content

feat(collab): add batch settlement thresholds - #169

Merged
239573049 merged 4 commits into
AIDotNet:mainfrom
shizhenwei1984-cell:feat/collab-batch-thresholds
Dec 1, 2026
Merged

239573049 merged 4 commits into
AIDotNet:mainfrom
shizhenwei1984-cell:feat/collab-batch-thresholds

Conversation

@shizhenwei1984-cell

Copy link
Copy Markdown
Contributor

Changes

  • Add the any and milestone join policies to the public batches from feat(collab): add public batch delegation #164. The first explicit report satisfies any. A milestone can use a count, a ratio of sealed members, a named task or session, or a delegated stage.
  • Validate milestone inputs and reachability at seal time. Evaluate ratios against the frozen membership and preserve exact boundaries, including 0.28 of 25 members.
  • Count explicit member reports retained in the batch after task retention removes the corresponding task row. Use the same count before and after reload and count each member once.

Verification

  • Release App test build, Git whitespace checks, and 136 focused batch, keyed reply, and report-read tests passed on the submitted revision.
  • An independent review reproduced both retained-report regressions on the prior revision and confirmed they pass with the fix.

Replay the exact threshold-only delta
(6b8134c310824eeb15821afe4d75181bc3f568d3..94c16e5253296ed09b2b1e19acdb127a3f79db9c,
matching reviewed net delta
48791d883220ba59a17f96584aee628f9216645c..2765fe4cfa63836c1e92ab1c0e55dc6d4cea1fd7)
onto the updated ordinary batch base
9bb6059d6f7fcb2f1a40fc87dc4c576e737e01e8.

Includes:
- join_policy "any" (first explicit report) and "milestone"
  (milestone_count, milestone_ratio, milestone_tasks, milestone_stage)
- Reachable milestone seal validation and exact ratio member comparison
- Optional delegate_task stage label and durable member report_text
- Strict milestone numeric/string argument validation while preserving
  AIDotNet#153 nonnegative long cursor parsing, structured cross-host reply,
  AIDotNet#156 GUI peer status, and 9bb6059d ordinary batch same-key/receipt fixes
- Threshold, acceptance, ledger, and wake regression coverage

Excludes manual/resume, exception and other wake policies, deadline,
lease, quota, dependency, and launch permission work.
…uateBatch

CollabLedger.EvaluateBatch previously skipped incrementing Reached when
a sealed batch member's task had been pruned by task retention, even
though member.Reported remained durably true and MilestoneCriterionReachable
as well as named/stage milestones already honored it.

Count member.Reported toward Reached once independently of Tasks lookup,
preserve the compatible !member.Reported && task.Status == Completed
fallback when the task is still retained, and leave failed, tentative,
ordinary all/any, and Expected denominator counts unchanged.

Add live and restored retention regressions in CollabBatchLedgerTests
covering count=2, ratio=1.0, exact 0.28 of 25 boundary, no false counts
on pruned tentative members, no double count on reported+completed
members, and ordinary all/any retention semantics.

@239573049 239573049 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this PR — the threshold semantics, exact ratio ceiling handling, and thorough test coverage are well structured. Before merging, please address the following issues:

Blocking

  1. isImplicitFallback overwrites explicit ReportText and ReportStatus (src/Octopus.App/Collab/CollabCoordinator.cs, around line 5261)

    • member.ReportText = TruncateBody(message, _policy.MaxReplyChars); (and member.ReportStatus = status;) runs unconditionally for both explicit reports and isImplicitFallback.
    • If a worker sends an explicit reply_thread (e.g. status: "continue") and its turn subsequently ends via NotifyTurnCompleted, the implicit fallback text will overwrite the explicit ReportText (and ReportStatus).
    • Also consider storing recordSummary rather than raw message so it stays consistent with task.ResultSummary, and guard implicit fallback updates with if (!member.Reported).
  2. Retained explicit reports with pruned tasks are still counted as failed and rendered as cancelled (src/Octopus.App/Collab/Ledger/CollabLedger.cs EvaluateBatch & src/Octopus.App/Collab/CollabCoordinator.cs DeliverBatchSettlementAsync)

    • In EvaluateBatch, when !Tasks.TryGetValue(member.TaskId, out var task), a member with member.Reported == true increments reached, but then falls into failed++; continue;.
    • Likewise, DeliverBatchSettlementAsync computes (task?.Status ?? CollabTaskStatus.Cancelled).ToString().ToLowerInvariant(), so a member that explicitly reported agreed before task retention pruning is presented to the parent as cancelled and counted under failed or stopped.
    • Please derive both the status label and settled/failed counts from member.ReportStatus when task is missing and member.Reported is true.
  3. join_policy: "any" lacks reachability validation at batch_seal (src/Octopus.App/Collab/CollabCoordinator.cs BatchSealAsync)

    • Milestone rejects sealing when no criterion can still be reached, but Any does not perform an equivalent check. If all members are already Failed / Cancelled without an explicit report prior to sealing, batch_seal transitions the batch to Sealed where it can never trigger.
    • Please reject sealing an any batch when no member has reported and none remain in a non-terminal state (matching the milestone guard).

Minor

  1. Non-finite MilestoneRatio check (src/Octopus.App/Collab/CollabCoordinator.cs BatchOpenAsync)
    • request.MilestoneRatio is <= 0 or > 1 evaluates to false for double.NaN. Please check request.MilestoneRatio is { } ratio && (!double.IsFinite(ratio) || ratio <= 0 || ratio > 1) so programmatic callers cannot persist NaN into the ledger.

239573049 and others added 2 commits December 1, 2026 12:35
- keep an explicit member report when a turn-end fallback arrives later
- count and label a pruned member by its retained explicit report
- reject sealing an any batch that can no longer receive a report
- reject non-finite milestone_ratio

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@239573049
239573049 merged commit d7bdee4 into AIDotNet:main Dec 1, 2026
1 of 4 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.

2 participants