Repository navigation
feat(score): score finished sessions in the background - #1364
Conversation
score --session re-resolves the session's scope from its directory, but dropped the workspace children before reading the scoring settings, so a namespace only a child selects never applied its isolation.
When no judge tool here reaches verified isolation, score --session now says which file asks for it, with the scorer's own path, as a lease refusal does.
The parser and the unknown-key problem read one list, and the parser's switch fails to compile on a key it does not handle.
One read of a session gives the evidence and the label context, so a session judge lease can build both as score --session does. Output is unchanged.
An attempt is now a workflow attempt or a session attempt. A session attempt keeps the label context of the session read its lease took, which only an unreadable session may lack. Workflow attempt files are written as before, without a source. judgeLease takes the time it settles at from its caller.
A member who sets scoring.sessions: true now gets each captured session that has been idle for six hours as judge work for every scorer with sessions: true. score --next hands out workflow work first, then sessions, and the lease carries source and the cwd to submit from. A session key is tried once. The session is read before the attempts lock and the lease is written in one step under it. A failed local judge closes the key, a lease left out of running lapses rather than being handed back, and a late answer is refused once a judge has labelled the session.
A member can set scoring.daily_limit to bound how many sessions one data home leases per local day; 0 turns session scoring off. Every session attempt counts, including ones that failed or could not be read, so a broken session cannot spend the budget again. Once the day is spent, idle no longer counts sessions as open.
A team can now turn session scoring on, and bound it, for every member from scorers/scoring.yaml or a namespace's scoring.yaml. A member's config.yaml still wins. Between active namespaces the cautious value wins: sessions: false, and the lowest daily_limit.
A namespace scorer should only judge sessions that were delivered its namespace. Each capture's recorded selection is overlaid on the scope and resolved with the same namespace resolver pull uses. Workspace children count only while their fingerprint still matches. A session whose captures record no selection, or disagree, gets root and shared scorers only.
Finished sessions need a driver that runs without anyone asking. This one takes session work only, for the project scope and then the user scope, judges each lease with a local tool, tries verified tools first and then every tool at best-effort, and stops taking work after 30 minutes. A per-data-home lock keeps two runs from overlapping. Labels stay pending; the next pull publishes them, so a background run never pushes per label.
Without a trigger, finished sessions would only be judged when someone runs a driver. The session-start pull now starts score-sessions as a detached process once the pull and its late usage report have settled, and only when the session's project or the user scope scores sessions, so members who never turn it on pay nothing.
A judge started from the background hook pass may not inherit the member's shell, so a moved Claude, Codex or CodeBuddy home was missing and the tool judged with the wrong account or none. When the variable is unset, the judge now gets the home teamai recorded for the tool. Its settings were already read from there.
Session attempts are kept so a key is tried only once, which would let them grow without end. Once no capture of a session is left it can never be judge work again, so its attempts are removed under the attempts lock, from the captures already listed for the lease, unless one is live or was leased today and still counts towards the daily limit.
|
No confident findings in the specified PR diff. The PR description documents sufficient testing: a build, targeted e2e tests, and a representative real-CLI run at Review was read-only; I did not run, build, or install anything from the PR. |
|
No confident findings in the specified PR diff. The earlier review raised no findings, so there are none to mark resolved. The PR description documents sufficient testing: a build, targeted e2e tests, and a representative real-CLI run at head Review was read-only. I did not run, build, or install anything from the PR. |
jeff-r2026
left a comment
There was a problem hiding this comment.
Reviewed (agent review) and verified on main stacked with this batch: tsc / lint / build pass, related unit tests and E2E score-sessions pass. No blocking findings.
Non-blocking follow-ups worth considering:
evidence_emptyfailures are recorded withleasedAtand count towarddaily_limit, so unreadable sessions can use up the day's budget.- A failed judge run is never retried for that session/rubric; worth stating in the docs.
- When a platform records no
sessionFileand emits no dashboard events, idle detection falls back tocapturedAt, so a long-running session could be judged while still active. - No test races two drivers on the same session key.
* fix(score): keep workspace children when scoring a session score --session re-resolves the session's scope from its directory, but dropped the workspace children before reading the scoring settings, so a namespace only a child selects never applied its isolation. * fix(score): name the scorer file that asks for verified isolation When no judge tool here reaches verified isolation, score --session now says which file asks for it, with the scorer's own path, as a lease refusal does. * refactor(scorers): list the scoring.yaml keys once The parser and the unknown-key problem read one list, and the parser's switch fails to compile on a key it does not handle. * refactor(score): share the session read, evidence and label One read of a session gives the evidence and the label context, so a session judge lease can build both as score --session does. Output is unchanged. * refactor(scorers): name each attempt's source An attempt is now a workflow attempt or a session attempt. A session attempt keeps the label context of the session read its lease took, which only an unreadable session may lack. Workflow attempt files are written as before, without a source. judgeLease takes the time it settles at from its caller. * feat(score): hand out finished sessions as judge work A member who sets scoring.sessions: true now gets each captured session that has been idle for six hours as judge work for every scorer with sessions: true. score --next hands out workflow work first, then sessions, and the lease carries source and the cwd to submit from. A session key is tried once. The session is read before the attempts lock and the lease is written in one step under it. A failed local judge closes the key, a lease left out of running lapses rather than being handed back, and a late answer is refused once a judge has labelled the session. * feat(score): cap session launches per day A member can set scoring.daily_limit to bound how many sessions one data home leases per local day; 0 turns session scoring off. Every session attempt counts, including ones that failed or could not be read, so a broken session cannot spend the budget again. Once the day is spent, idle no longer counts sessions as open. * feat(score): team defaults for session scoring A team can now turn session scoring on, and bound it, for every member from scorers/scoring.yaml or a namespace's scoring.yaml. A member's config.yaml still wins. Between active namespaces the cautious value wins: sessions: false, and the lowest daily_limit. * feat(score): scope session scorers by the capture's selection A namespace scorer should only judge sessions that were delivered its namespace. Each capture's recorded selection is overlaid on the scope and resolved with the same namespace resolver pull uses. Workspace children count only while their fingerprint still matches. A session whose captures record no selection, or disagree, gets root and shared scorers only. * feat(score): add the hidden score-sessions driver Finished sessions need a driver that runs without anyone asking. This one takes session work only, for the project scope and then the user scope, judges each lease with a local tool, tries verified tools first and then every tool at best-effort, and stops taking work after 30 minutes. A per-data-home lock keeps two runs from overlapping. Labels stay pending; the next pull publishes them, so a background run never pushes per label. * feat(hooks): score finished sessions after a session start's pull Without a trigger, finished sessions would only be judged when someone runs a driver. The session-start pull now starts score-sessions as a detached process once the pull and its late usage report have settled, and only when the session's project or the user scope scores sessions, so members who never turn it on pay nothing. * fix(score): give background judges the recorded tool homes A judge started from the background hook pass may not inherit the member's shell, so a moved Claude, Codex or CodeBuddy home was missing and the tool judged with the wrong account or none. When the variable is unset, the judge now gets the home teamai recorded for the tool. Its settings were already read from there. * fix(score): prune attempts of sessions that are gone Session attempts are kept so a key is tried only once, which would let them grow without end. Once no capture of a session is left it can never be judge work again, so its attempts are removed under the attempts lock, from the captures already listed for the lease, unless one is live or was leased today and still counts towards the daily limit.
Summary
Closes #1179.
A member who sets
scoring.sessions: truegets their finished sessions judged in the background. A session counts as finished once nothing has happened in it for six hours. Every scorer withsessions: truejudges it, sampled by itssamplingRate.Session work goes through the same judge leases as workflow passes, so any driver takes it with
score --next. After a session start's pull, a hidden local driver judges the rest and leaves the labels pending for the next pull to publish.A session key is
(scorer, rubric sourceHash, session), and it is tried once:The settings, from first to last precedence:
config.yaml(scoring.sessions,scoring.daily_limit). A workspace's children count when the background driver resolves its scope.scorers/<ns>/scoring.yaml; between them,sessions: falseand the lowestdaily_limitwin.scorers/scoring.yaml.sessions: false,daily_limit: 10.A namespace scorer judges a session only when every capture of it had that namespace active under the capture's own
team.selection. Workspace children count only when the capture's fingerprint matches.Type of Change
Commits
Each commit passes the type check, lint and its tests on its own.
fix(score): keep workspace children when scoring a sessionscore --sessionnow sees the namespaces that a workspace's children activate.fix(score): name the scorer file that asks for verified isolationscorers/<ns>/<name>.md, as the lease path already does.refactor(scorers): list the scoring.yaml keys oncerefactor(score): share the session read, evidence and labelscore --sessionand session leases share one builder. There is no output change.refactor(scorers): name each attempt's sourcesource. Old files read as workflow attempts.feat(score): hand out finished sessions as judge workfeat(score): cap session launches per dayscoring.daily_limit. Every session attempt leased today counts, including failed ones.feat(score): team defaults for session scoringsessionsanddaily_limitinscoring.yaml.feat(score): scope session scorers by the capture's selectionfeat(score): add the hidden score-sessions driverfeat(hooks): score finished sessions after a session start's pullfix(score): give background judges the recorded tool homesCLAUDE_CONFIG_DIR,CODEX_HOMEorCODEBUDDY_CONFIG_DIRfrom the recorded home.fix(score): prune attempts of sessions that are goneTest Plan
npx tsc --noEmitpasses. This includes the new type testsrc/__tests__/scorers-attempts.type-test.ts.npm run lintpasses.npx vitest runpasses: 549 files, 15805 tests, 21 skipped.session-work.test.ts,score-sessions.test.tsande2e/score-sessions.test.ts.session-scoring,scorers-settings,scorers-attempts,scorers-judgeandhook-handlers.TZ=Australia/SydneyandTZ=Pacific/Honolulu.npm run build, then the e2e filese2e/score-sessions,e2e/score-sessionande2e/score-external-driver: 3 files pass.hook-dispatch session-start --bg-only. The label waits as pending, with nothing onteamai-reports, and the nextteamai pullpublishes it.Real CLI at head
22d9faf9e, withnode dist/index.js, on a temporaryHOMEwith a local bare team repo (providergit, agent Claude):sessions: trueandsamplingRate: 100. The member setscoring.sessions: true.claudeonPATH, which reports the verified version, so nothing was spent.Not run here:
gitlabandgithub, and agents Codex, CodeBuddy and OpenCode. These are left to CI.Related Issues
Closes #1179. Part of #1137, builds on #1178.
Notes for Reviewers
Departures from the issue body. The first is new here; the issue comment records the rest:
AgentSession.listupdatedAt: the Claude adapter reads only the first 200 records, and compaction ofevents.jsonldrops the events of idle sessions. A session whose file is gone is not a candidate.scores/daily.json. The limit is checked underscores/attempts.lock, right before the write.score --next. A lease carriessourceand thecwdto submit from. For the user scope, thatcwdis the data home.scoring.yaml, as listed above.Decisions worth checking:
runningis neither handed back nor released. It lapses, so a restarted driver cannot launch a second, uncounted judge on it.score --sessionmeanwhile. Without this, the background label would replace theirs in the outbox, since both share one label key.judgeLeasemarks the session lease withjudgingSince, under the attempts lock. A secondscore --lease <ref>is refused withlease_judging, even after a crash.--submitcan still settle the lease.judgeLease, keeping the judge's own code. A judge that ran below the required isolation closes it too.judgeLease(..., { publish: false })leaves its labels pending.--submit,--lease <ref>and on-demand scoring publish as before.judgeLeasetakes an optionalclockand stamps the settle time after the judge returns. That matches the oldnew Date()behaviour, and lets tests control it.workflow-scoringtests are unchanged and pass. Workflow leases now also carrysource: 'workflow'.verifiedfirst, then every tool atbest-effort. It never offers a tool at a level that tool cannot reach, because that would spend the key and a slot.Merge Danger
Door: Two-way for the code. Session attempt files, written only when a member turns sessions on, are a new on-disk shape. Reverting leaves them, and an older CLI skips them.
Blast Radius: Background session judging is opt-in.
scoring.sessionsresolves to true.source.score --sessiongets the workspace-children and isolation-message fixes.sessionsbecause the frontmatter is strict. An older CLI that takes judge work in the same data home removes the rubrics of session leases. So update teamai everywhere before a team adds a session scorer or a member turns sessions on.