Skip to content

feat: report unique resource IDs - #2769

Closed
rsynek wants to merge 1 commit into
TimefoldAI:mainfrom
rsynek:feat/unique-entity-metering
Closed

rsynek wants to merge 1 commit into
TimefoldAI:mainfrom
rsynek:feat/unique-entity-metering

Conversation

@rsynek

@rsynek rsynek commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes https://github.com/TimefoldAI/timefold-solver-enterprise/issues/930.

The PR covers resource reporting for standard operations.

  • POST compute or solve
  • POST score analysis

Also model-specific operations are covered by exposing the UniqueResourceReporter bean to send the data.

Related:
https://github.com/TimefoldAI/timefold-solver-enterprise/pull/948

Copilot AI 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.

🟡 Changes recommended

Reporter exceptions can mark valid datasets as failed and prevent normal completion.

1 open issue
What changed in this PR

Adds unique resource ID reporting to the service layer for usage metering.

Changes:

  • Adds resource collection and reporting APIs.
  • Reports resources after worker output computation.
  • Adds event definitions and tests for resource collection behavior.
File Description
service/​worker/​src/​main/​java/​ai/​timefold/​solver/​service/​worker/​impl/​SolverWorker.java Reports resources after computation.
service/​definition/​src/​test/​java/​ai/​timefold/​solver/​service/​definition/​api/​usage/​UniqueResourcesTest.java Tests deduplication, immutability, builders and JSON.
service/​definition/​src/​main/​java/​ai/​timefold/​solver/​service/​definition/​internal/​events/​UniqueResourceReportEvent.java Adds the resource reporting event.
service/​definition/​src/​main/​java/​ai/​timefold/​solver/​service/​definition/​internal/​events/​SolverChannels.java Defines the reporting channel.
service/​definition/​src/​main/​java/​ai/​timefold/​solver/​service/​definition/​internal/​events/​AbstractEvent.java Permits the new event type.
service/​definition/​src/​main/​java/​ai/​timefold/​solver/​service/​definition/​api/​usage/​UniqueResources.java Stores immutable, deduplicated resource IDs.
service/​definition/​src/​main/​java/​ai/​timefold/​solver/​service/​definition/​api/​usage/​UniqueResourceReporter.java Defines reporting methods.
service/​definition/​src/​main/​java/​ai/​timefold/​solver/​service/​definition/​api/​usage/​UniqueResourceAware.java Lets models expose their resources.

Review effort: Balanced

}

if (uniqueResources != null) {
uniqueResourceReporter.reportUniqueResources(OperationId.SCHEDULE, datasetId, uniqueResources);
Copilot AI balanced review requested due to automatic review settings October 21, 2026 11:28

Copilot AI 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.

🟡 Changes recommended

Worker reporting and its fallback paths need regression tests before approval.

2 open issues

Review effort: Balanced

extractOutputMetrics(solverModel));

// We report the unique resources once we compute the outputs of the valid dataset.
reportUniqueResources(id, solverModel);
@timefold-automations

Copy link
Copy Markdown
Contributor

This pull request, as it stands, would leave the Solver documentation stale in the place below. An automated check found this and can be wrong.

  1. Code change: timefold-solver, service/definition/src/main/java/ai/timefold/solver/service/definition/api/usage/UniqueResources.java:13 (and the added UniqueResourceAware.java:6 and UniqueResourceReporter.java:6) — added public usage-metering API types, including UniqueResources.from, UniqueResources.builder, UniqueResourceAware#getUniqueResources, and UniqueResourceReporter#reportUniqueResources.
    Docs location: no mention found under docs/src/modules/ROOT/pages/.
    Confidence: high.
    Suggested edit: Add a short service-specific section, for example to pages/running-timefold-solver/service/overview.adoc:

    [#uniqueResourceReporting]
    == Reporting unique resources
    
    A service model can implement `UniqueResourceAware` to identify the unique resources used by an operation:
    
    [source,java]
    ----
    public class EmployeeSchedule implements UniqueResourceAware {
        @Override
        public UniqueResources getUniqueResources() {
            return UniqueResources.from("employee", employeeIds);
        }
    }
    ----
    
    Use the injected `UniqueResourceReporter` to report resources for model-specific operations. Use `UniqueResources.builder()` when a model has multiple resource types.

The documentation fix belongs in this pull request. A new commit on the branch updates this comment, and drift that is still there when the group merges gets a docs pull request against main.

Generated by Solver Docs Drift Review · copilot · gpt56 · 11.3 AIC · ⌖ 2.99 AIC · ⊞ 25.2K · ◷

/**
* Contains IDs of unique resources identified by the optimization model.
*/
public record UniqueResources(Map<String, Collection<String>> uniqueResourceIdsPerType) {

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.

just a thought, would it be easier to have UniqueResources(String type, Collection<String> uniqueResourceIds) and then we could have collection of it? Bit better from type perspective - having map by unknown keys might bite us soon.

In addition, since the issue says there should be one billable at the moment - how do we know that? will this come from here or?

storageService.storeSolution(id, modelOutput, metadata, extractInputMetrics(solverModel),
extractOutputMetrics(solverModel));

// We report the unique resources once we compute the outputs of the valid dataset.

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.

the document says we should only do this on successful runs - what would it do when compute is fine and then the solving fails?

@rsynek

rsynek commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #2779

@rsynek rsynek closed this Oct 27, 2026

This branch was previously deployed

1 inactive deployment
internal — 3c82c2ec Deployed Oct 21, 2026 by rsynek via approval_required #1086
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