Skip to content

fix: derive code-grader score from assertions when score field is absent #1211

@christso

Description

@christso

Bug

When a code-grader script returns assertions but omits score, the score defaults to 0 — even if all assertions pass:

// packages/core/src/evaluation/graders/code-grader.ts
const score = clampScore(typeof parsed?.score === 'number' ? parsed.score : 0);

So {"assertions": [{"text": "ok", "passed": true}]} → score 0. Wrong.

Expected Behaviour

  • score present → use it (explicit override for weighted/non-binary scoring)
  • score absent + assertions present → derive as passing / total
  • Neither present → score 0

Impact

Scripts currently must redundantly compute score themselves to avoid getting 0:

passed = sum(1 for a in assertions if a["passed"])
score = passed / len(assertions) if assertions else 0.0
print(json.dumps({"score": score, "assertions": assertions}))

With the fix, the score line becomes optional boilerplate — scripts can just return assertions and the framework computes the score.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions