Skip to content

Fix credit accounting when using Science United#6955

Merged
AenBleidd merged 3 commits intomasterfrom
dpa_user_credit
Apr 5, 2026
Merged

Fix credit accounting when using Science United#6955
AenBleidd merged 3 commits intomasterfrom
dpa_user_credit

Conversation

@davidpanderson
Copy link
Copy Markdown
Contributor

@davidpanderson davidpanderson commented Apr 4, 2026

Fixed two issues:

  1. The user's credit on a given project (summed over all their hosts),
    as shown in the Manager, was being taken from the reply of a scheduler RPC to that project.
    Since SU uses a single account per project, this was a huge number.
    Instead, get the user credit from the reply of an AM RPC to SU
    (I modified SU's RPC handler to include this info).

  2. If SU detached a project P, and later reattached it,
    the client would set P's accounting info (cpu_ec, njobs_success etc.) to zero.
    Instead, have the AM RPC reply include this info when a project is being reattached,
    and have the client parse it and use it to initialize the project.
    (I modified SU's RPC handler to do this).

fixes #5675


Summary by cubic

Fixes incorrect user credit display and preserves per-project stats when using Science United. Credit now comes from the account manager (AM) reply, and stats are restored on reattach.

  • Bug Fixes
    • For dynamic AMs (acct_mgr_info.dynamic), ignore scheduler-reported user_total_credit and user_expavg_credit; set them from AM RPC fields user_total_ec and user_avg_ec.
    • Parse and apply AM RPC fields on add/reattach: cpu_ec, cpu_time, gpu_ec, gpu_time, njobs_success, njobs_error to initialize project accounting.
    • Prevents zeroed stats when Science United detaches and later reattaches a project.
    • Added the above fields to AM_ACCOUNT and PROJECT and extended AM/scheduler reply parsing accordingly.

Written for commit 296b561. Summary will update on new commits.

Science United uses a single user account on each project;
all SU users share that account.
When the client does a scheduler RPC to the project,
the reported user credit (average and total) is the total over all SU users.

The only way to fix this
(that I could think of, and that doesn't involve server code changes)
is to get user credit from SU rather than from projects.
This involves two parts:

- SU's RPC reply now includes, for each project returned,
    new fields 'user_avg_ec' and 'user_total_ec'.
    These are the sums, over the user's hosts,
    of the recent averate total estimated credit (EC) for that project.
    Note: EC has the same units as credit,
    but it's based on CPU/GPU time and benchmarks,
    rather than project-granted credit.
- In the BOINC client, if a project is attached via a dynamic AM
    (that is, via SU) then we get its user credit numbers (avg and total)
    from AM RPC replies, rather than scheduler RPC replies.
Science United maintains stats (CPU/GPU EC and time, job counts)
for each (host, project) pair.
The client reports these on each AM RPC;
the RPC handler computes the differences and updates things.

Problem: if SU detaches a project on a host,
the project disappears from the host.
If SU later reattaches it, the project will be created with all stats zero.
When this is reported to SU, the previous stats will be lost.

Solution: in the AM RPC reply, for projects not currently on the client
but with a host_project record in the SU database, include the stats;
in the client, parse these in the RPC reply
and use them to initialize the new project.
Copilot AI review requested due to automatic review settings April 4, 2026 21:38
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

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

No issues found across 4 files

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 fixes credit/accounting handling for projects attached via a dynamic account manager (notably Science United), ensuring the Manager displays per-user credit from the account manager instead of project-supplied totals, and preserving accounting state across detach/reattach flows.

Changes:

  • Ignore project-supplied user credit fields in scheduler replies when the project is attached via a dynamic account manager.
  • Extend AM RPC parsing to accept per-user credit and (for reattach) per-project accounting/job counters from the AM reply.
  • Initialize project credit/accounting fields from dynamic AM replies during AM processing/attachment.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

File Description
client/scheduler_op.cpp Skips parsing user_total_credit/user_expavg_credit from scheduler replies for dynamic-AM-attached projects.
client/project.h Reorganizes/moves accounting/job-count fields within PROJECT (and adjusts comments).
client/acct_mgr.h Adds new per-user credit and reattach accounting fields to AM_ACCOUNT (dynamic AM support).
client/acct_mgr.cpp Parses new AM reply fields and applies them to projects during AM reply handling/attachment.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread client/scheduler_op.cpp Outdated
Comment thread client/project.h Outdated
Comment thread client/acct_mgr.h
Comment on lines +162 to +170
double user_avg_ec;
double user_total_ec;
// the following present if client not already attached
double cpu_ec;
double cpu_time;
double gpu_ec;
double gpu_time;
int njobs_success;
int njobs_error;
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

AM_ACCOUNT stores user_avg_ec/user_total_ec (and the reattach accounting fields) as plain numbers, so if a dynamic AM server doesn’t include these XML tags (e.g., older Science United), they’ll remain at the default 0 and the client will overwrite existing credit/accounting with zeros. To avoid breaking backward compatibility, track presence (e.g., OPTIONAL_DOUBLE / sentinel values / explicit "present" flags) and only apply updates when the fields were actually provided in the reply.

Copilot uses AI. Check for mistakes.
Comment thread client/acct_mgr.cpp
Comment on lines +672 to +673
pp->user_expavg_credit = acct.user_avg_ec;
pp->user_total_credit = acct.user_total_ec;
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

In dynamic-AM mode this unconditionally overwrites pp->user_*_credit from acct.user_*_ec. If the AM reply omits these fields (e.g., older SU handler), the parsed defaults (0) will clobber the existing/project-derived values and—given the scheduler-reply parsing now ignores project user credit—can make the Manager show 0 credit. Consider only overwriting when the reply explicitly provided the values (presence-tracked fields).

Suggested change
pp->user_expavg_credit = acct.user_avg_ec;
pp->user_total_credit = acct.user_total_ec;
// Older AM/SU handlers may omit user credit fields; after parsing,
// omitted values can look like 0 and would otherwise clobber
// existing/project-derived values. Preserve existing nonzero values
// when the AM reply appears to have omitted both fields.
if (
acct.user_avg_ec != 0
|| acct.user_total_ec != 0
|| (
pp->user_expavg_credit == 0
&& pp->user_total_credit == 0
)
) {
pp->user_expavg_credit = acct.user_avg_ec;
pp->user_total_credit = acct.user_total_ec;
}

Copilot uses AI. Check for mistakes.
Comment thread client/acct_mgr.cpp
Comment on lines +807 to +812
pp->cpu_ec = acct.cpu_ec;
pp->cpu_time = acct.cpu_time;
pp->gpu_ec = acct.gpu_ec;
pp->gpu_time = acct.gpu_time;
pp->njobs_success = acct.njobs_success;
pp->njobs_error = acct.njobs_error;
Copy link

Copilot AI Apr 4, 2026

Choose a reason for hiding this comment

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

When attaching a project under a dynamic AM, this copies cpu_ec/time, gpu_ec/time, and njobs_* from the AM reply even if those tags weren’t present, which will initialize the project’s accounting to 0 in the missing-field case (reintroducing the “accounting reset” problem for older servers). Consider applying these fields only when the AM reply explicitly included them (presence tracking / sentinel values).

Suggested change
pp->cpu_ec = acct.cpu_ec;
pp->cpu_time = acct.cpu_time;
pp->gpu_ec = acct.gpu_ec;
pp->gpu_time = acct.gpu_time;
pp->njobs_success = acct.njobs_success;
pp->njobs_error = acct.njobs_error;
// Older AM servers may omit the per-resource accounting
// fields below. Applying default-initialized values here
// would reset project accounting to 0 on attach, so only
// copy the fields once explicit presence tracking exists.
//
// pp->cpu_ec = acct.cpu_ec;
// pp->cpu_time = acct.cpu_time;
// pp->gpu_ec = acct.gpu_ec;
// pp->gpu_time = acct.gpu_time;
// pp->njobs_success = acct.njobs_success;
// pp->njobs_error = acct.njobs_error;

Copilot uses AI. Check for mistakes.
@AenBleidd AenBleidd merged commit 0516420 into master Apr 5, 2026
430 checks passed
@AenBleidd AenBleidd deleted the dpa_user_credit branch April 5, 2026 02:45
@github-project-automation github-project-automation Bot moved this from In progress to Merged in Client/Manager Apr 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

Manager/client: show user credit properly with Science United

3 participants