Skip to content

feat: complete M015 reference implementation with KPI, datasets, and edge-case test vectors#62

Open
brawlaphant wants to merge 2 commits intoregen-network:mainfrom
brawlaphant:pr/m015-reference-impl-complete
Open

feat: complete M015 reference implementation with KPI, datasets, and edge-case test vectors#62
brawlaphant wants to merge 2 commits intoregen-network:mainfrom
brawlaphant:pr/m015-reference-impl-complete

Conversation

@brawlaphant
Copy link
Copy Markdown
Contributor

Summary

  • Add m015_kpi.js KPI computation module with Gini coefficient, top earner share, stability utilization, and revenue/cap constraint checks
  • Add reference-impl/README.md documenting both score and KPI modules, inputs/outputs, and test vectors
  • Add datasets/schema.json (JSON Schema for M015 dataset format) and datasets/README.md
  • Add 3 new edge-case test vector pairs: early exit penalty, stability cap overflow, and zero activity
  • Update m015_score.js self-test to iterate all test vectors instead of only the sample

All 4 test vectors pass in both m015_score.js and m015_kpi.js. This brings M015 to parity with other mechanism implementations (M012 etc.) in terms of file structure and coverage.

Test plan

  • node mechanisms/m015-contribution-weighted-rewards/reference-impl/m015_score.js -- 4 vectors pass
  • node mechanisms/m015-contribution-weighted-rewards/reference-impl/m015_kpi.js -- 4 vectors pass
  • Review expected values in test vectors against SPEC.md formulas
  • Verify datasets/schema.json validates datasets/fixtures/v0_sample.json

🤖 Generated with Claude Code

…edge-case test vectors

Add missing files to bring M015 (Contribution-Weighted Rewards) to parity
with other mechanism implementations:

- reference-impl/m015_kpi.js: KPI computation module with Gini coefficient,
  top earner share, stability utilization, and security invariant checks
- reference-impl/README.md: documentation for score and KPI modules
- datasets/schema.json: JSON Schema for M015 dataset format
- datasets/README.md: dataset format documentation
- 3 new test vector pairs covering early exit penalty, stability cap
  overflow, and zero activity edge cases
- Updated m015_score.js self-test to iterate all test vectors

All 4 test vectors pass in both m015_score.js and m015_kpi.js.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the M015 contribution-weighted rewards mechanism by completing its reference implementation. It introduces a dedicated module for Key Performance Indicator (KPI) computation, provides thorough documentation for both the scoring and KPI modules, and establishes a formal JSON schema for datasets. Furthermore, it expands the test suite with critical edge-case scenarios, ensuring the mechanism's accuracy and reliability across diverse conditions and bringing it to full parity with other mechanism implementations.

Highlights

  • KPI Module: Introduced m015_kpi.js for comprehensive KPI computation, including Gini coefficient, top earner share, and stability utilization.
  • Documentation: Added detailed README.md files for both the reference implementation and datasets, outlining modules, inputs, outputs, and test vectors.
  • Dataset Schema: Implemented datasets/schema.json to define the JSON Schema for the M015 dataset format.
  • Expanded Test Coverage: Included three new edge-case test vectors (early exit penalty, stability cap overflow, zero activity) to enhance robustness.
  • Improved Self-Test: Updated m015_score.js to automatically iterate and validate against all available test vectors.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the m015 contribution-weighted rewards mechanism, including comprehensive documentation, a JSON schema for replay datasets, and a JavaScript reference implementation. The reference implementation provides modules for activity scoring, stability allocation, distribution, and KPI computation, along with an updated self-test harness that now iterates through various test vectors. Feedback indicates a documentation inconsistency in datasets/README.md regarding a referenced fixture file that is not included in the PR. Additionally, the m015_kpi.js self-test has misleading comments, redundant participant score validation, and lacks assertions for several key KPIs, which should be addressed for improved test focus and completeness.

## Files
- `schema.json` -- JSON schema for replay datasets
- `fixtures/v0_sample.json` -- single distribution period with 4 participants and 1 stability commitment
- `fixtures/v0_stability_sample.json` -- stability tier scenarios (committed, matured, early exit, cap overflow)
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.

medium

This line references fixtures/v0_stability_sample.json, but this file is not included in the pull request. To avoid confusion, please either add the file or update the documentation to indicate that it is planned for a future update.

Comment on lines +185 to +202
// Check that distribution rewards match
const scoredParticipants = input.participants.map((p) => {
const result = computeActivityScore({ activities: p.activities });
return { address: p.address, ...result };
});

for (const exp of expected.participant_scores) {
const actual = scoredParticipants.find((p) => p.address === exp.address);
if (!actual) {
console.error(` FAIL: participant ${exp.address} not found`);
vectorFailed = true;
continue;
}
if (Math.abs(actual.total_score - exp.total_score) > 0.001) {
console.error(` FAIL: ${exp.address} score expected ${exp.total_score}, got ${actual.total_score}`);
vectorFailed = true;
}
}
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.

medium

The comment on line 185, "Check that distribution rewards match", is misleading as the following code block validates participant scores, not distribution rewards.

More importantly, this self-test is re-validating participant scores, which is already covered in the m015_score.js self-test. This introduces redundancy.

Additionally, the test is missing assertions for several key KPIs computed by computeM015KPI, such as gini_coefficient, top_earner_share, and stability_utilization. These values are logged but not validated.

To improve the test's focus and completeness:

  1. Remove the redundant participant score validation logic (lines 186-202).
  2. Update the *.expected.json test vectors to include the expected values for all KPIs generated by computeM015KPI.
  3. Add assertions to validate all fields in the returned KPI object against the expected values.

…remove redundant validation

- Add assertions for gini_coefficient, top_earner_share, stability_utilization,
  total_distributed_uregen, and participant_count in m015_kpi.js self-test
- Fix comment "Check that distribution rewards match" which actually validated
  participant scores, not distribution rewards — replaced with accurate description
- Remove redundant participant score re-validation (already covered by m015_score.js
  self-test) — KPI self-test now focuses on KPI-level outputs only
- Add expected KPI values to all 4 test vector .expected.json files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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