Skip to content

fix(achievements): per-session badges no longer crash on set/secret definitions - #1

Merged
CliffWade merged 2 commits into
mainfrom
feat/ach-session-badges-fix
Aug 12, 2026
Merged

fix(achievements): per-session badges no longer crash on set/secret definitions#1
CliffWade merged 2 commits into
mainfrom
feat/ach-session-badges-fix

Conversation

@CliffWade

@CliffWade CliffWade commented Aug 12, 2026

Copy link
Copy Markdown
Owner

What broke

GET /api/plugins/hermes-achievements/sessions/{id}/badges ("Badges this session") returned 500 Internal Server Error for every session.

The endpoint loops every achievement definition and evaluates it against the session's aggregate. The engine's set-collection badges (set_autonomy, set_debugging, set_vibe, set_hermes_native, set_research, set_tools, set_models, set_lifestyle) and secret achievements carry no metric / threshold_metric / requirements keys. evaluate_definition falls through to evaluate_boolean, which does definition["metric"] and raises KeyError: 'metric'. One definition crashes the whole response, so the page always showed "No badges this session yet" even when the session had plenty of unlocks.

The fix

session_badges now skips definitions that cannot be evaluated against a single session instead of crashing. That's the correct behavior for the per-session view: sets and secrets are account-level badges, not per-session ones. The response still returns every genuinely earned per-session badge.

Verification

  • Plugin test suite: 43/43 passing
  • Simulated the patched endpoint against a real session (894 tool calls, 1,846 messages): returns 12 per-session badges (Let Him Cook, This Was Supposed To Be Quick, Rebase Acrobat, Screenshot Hunter, Test Suite Tamer, and 7 more) instead of a 500

Scope note

This branch carries the enhanced achievements engine (full-history scan, evaluate_all, secret/collection definitions, rewards, quests, custom goals, XP levels, challenges) whose new definition kinds exposed the crash. The committed engine predating it never had those definitions, so the fix and the engine ship together.


Update: Added a compatibility commit (18aa959). The enhanced engine
calls list_sessions_rich(include_archived=...) and
get_messages(include_inactive=...), which the repo's integration suite
(tests/plugins/test_achievements_plugin.py) proved break on SessionDB
variants without those params. Both calls now fall back to the narrower
signature on TypeError. Repo integration suite 5/5 green, engine suite
43/43 green. The fix's headline behavior is unchanged: per-session badges
skip unevaluable definitions instead of 500ing.

…efinitions

session_badges iterated every achievement definition and assumed each one
could be evaluated against a single session. The engine's set-collection
badges (set_autonomy, set_debugging, set_vibe, set_hermes_native, set_research,
set_tools, set_models, set_lifestyle) and secret achievements carry no
metric/threshold/requirements keys, so evaluate_boolean raised KeyError:
'metric' and the whole endpoint 500'd. 'Badges this session' therefore
never populated for ANY session.

Definitions that cannot be evaluated per-session are now skipped instead of
crashing the response; the per-session view is correct to omit them (sets
and secrets are account-level).

Carries the enhanced achievements engine (full-history scan, evaluate_all,
secret/collection definitions, rewards, quests, custom goals, XP levels,
challenges) whose new definition kinds exposed the crash.

Verified: plugin test suite 43/43; live session simulation returns 12
per-session badges.
…ed or include_inactive

The scan previously crashed on SessionDB implementations (older Hermes
cores, test fakes) whose list_sessions_rich lacks include_archived or
whose get_messages lacks include_inactive. Both calls now fall back to
the narrower signature on TypeError, so the engine keeps the archive and
soft-deleted-message coverage on new backends and degrades gracefully on
old ones. Repo integration suite (tests/plugins/test_achievements_plugin.py)
5/5 green; engine suite 43/43 green.
@CliffWade
CliffWade merged commit 990155c into main Aug 12, 2026
42 checks passed
@CliffWade
CliffWade deleted the feat/ach-session-badges-fix branch August 12, 2026 22:43
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