Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/1190.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A job's model-and-role line now marks a claimed seat the instance never observed — "claimed, not observed" / “声称,未观察”, or "claimed, not verified" when the row predates the observation record — on both the job page's "Why this change" block and the console's job rows, including after the console's live stream updates them. The two surfaces and the stream now take the mark from one reconstruction of the record, so the job page, the change story and the console cannot disagree about whether a seat was seen; a claim is no longer printed as a fact in either place.
7 changes: 5 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,11 @@ the browser.
comment otherwise. The snapshot includes `bots` (with `tool`, `step`, `since`,
`lastActivityAt`), `questions` (with `id`, `sessionId`, `question`, `detail`,
`options`, `multiSelect`), `timeline` (active/ended role activity), `jobs`
(summary, status, issue/PR and attribution) and quota. Clients should fall back to the
5-second JSON poll if the stream drops.
(summary, status, issue/PR, `attribution` and the server-rendered
`attributionText`, which carries the claim marker in the request's language) and
quota. The 5-second JSON poll carries the same `attributionText` on its job
entries, so the answer does not change when the stream drops. Clients should fall
back to the 5-second JSON poll if the stream drops.

`POST /api/repos/:id/team/answer` takes JSON:

Expand Down
14 changes: 9 additions & 5 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -2381,11 +2381,15 @@ Team attribution is grounded in the DSH per-role call counts, which prove that a
seat worked and never that it wrote a file. `jobs.attribution_json` holds what the
job claimed; `jobs.attribution_ground_json` records the observation beside it, per
attribution key, as `claimed` / `observed` / `state` (`grounded`, `unobserved`,
`no-observation`), so an observation never overwrites a claim. The job page and the
dashboard job row mark a claimed seat the instance did not see as
`claimed, not observed`, a claim nothing observed as `claimed, not verified`, and
leave a grounded seat unmarked; a seat only the instance saw is shown from the
observation. The PR automation comment uses the observed roles and falls back to
`no-observation`), so an observation never overwrites a claim. Every reader of the
claim marks it with the same vocabulary: the job page and the dashboard job row,
the job page's change-story `Model and role` row (the marker goes in the row's
note, because the model half is not what the claim is about), and the console's
live job rows, whose snapshot and 5-second fallback both carry the server-rendered
`attributionText` so a stream tick cannot replace a marked seat with the bare
claim. A claimed seat the instance did not see reads `claimed, not observed`, a
claim nothing observed reads `claimed, not verified`, and a grounded seat is
unmarked; a seat only the instance saw is shown from the observation. The PR automation comment uses the observed roles and falls back to
the claim only when there was no observation. None of this blocks a merge: an
instance exists only where one is configured, so the marker describes the record
rather than gating it. A claimed role with zero calls still records a
Expand Down
Binary file added docs/images/1190/after-A-job-page-zh-1280.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/1190/before-A-job-page-zh-1280.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 5 additions & 1 deletion public/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,11 @@
}
const attr = row.querySelector('[data-job-attribution]')
if (attr) {
const text = attribution(job.attribution)
// #1190: the server-rendered string is authoritative when it is present —
// it already carries the claim marker, in this reader's language. The
// structured fallback stays for an older payload that has no text.
const rendered = typeof job.attributionText === 'string' ? job.attributionText : ''
const text = rendered !== '' ? rendered : attribution(job.attribution)
if (text) attr.textContent = text
}
}
Expand Down
53 changes: 38 additions & 15 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ import {
agentWorkspacePage,
settingsPage,
inboxSection,
jobAttribution,
errorPage,
type InboxQuestion,
type ScheduledNext,
Expand Down Expand Up @@ -1063,7 +1064,14 @@ export async function buildApp(options: BuildOptions): Promise<BuiltApp> {
// #793: which model and role did the work is on the job row, so it is read
// here rather than from the pull request body. The row can be read even when
// GitHub cannot, which is why every branch below carries it.
const attribution = changeStoryAttribution({ modelJson: job.model_json, attributionJson: job.attribution_json })
const attribution = changeStoryAttribution({
modelJson: job.model_json,
attributionJson: job.attribution_json,
// #1190: the record decides whether the claim was observed, and the same
// reconstruction the job page uses keeps a pre-#1186 row honest.
groundJson: job.attribution_ground_json,
teamStatsJson: job.team_stats_json,
})
const parsed = parsePrUrl(repo, job.pr_url, config.github.apiBase)
let story: ChangeStory
let tip: PullTip | null = null
Expand Down Expand Up @@ -3584,7 +3592,14 @@ export async function buildApp(options: BuildOptions): Promise<BuiltApp> {
requireAdvanced(viewer)
try {
const state = await instances.teamState(repo.id, 15_000)
return { ...state, jobs: localizedJobs(store.listJobsForRepo(repo.id).slice(0, 5), request.locale ?? 'zh') }
const t = translator(request.locale ?? 'zh')
// #1190: the poll and the stream must agree about a marked claim, so both
// carry the same rendered `attributionText`.
return {
...state,
jobs: localizedJobs(store.listJobsForRepo(repo.id).slice(0, 5), request.locale ?? 'zh')
.map((job) => ({ ...job, attributionText: jobAttribution(t, job) })),
}
} catch (error) {
return reply.code(503).send({ error: error instanceof Error ? error.message : String(error) })
}
Expand Down Expand Up @@ -3854,19 +3869,27 @@ export async function buildApp(options: BuildOptions): Promise<BuiltApp> {
remainingCny: quota.remainingCny,
exhausted: quota.exhausted,
},
jobs: localizedJobs(store.listJobsForRepo(repo.id, 5), request.locale ?? 'zh').map((job) => ({
id: job.id,
kind: job.kind,
status: job.status,
summary: job.summary,
error: job.error,
issueUrl: job.issue_url,
prUrl: job.pr_url,
reviewScore: job.review_score,
attribution: parseAttributionJson(job.attribution_json),
createdAt: job.created_at,
finishedAt: job.finished_at,
})),
jobs: (() => {
const t = translator(request.locale ?? 'zh')
return localizedJobs(store.listJobsForRepo(repo.id, 5), request.locale ?? 'zh').map((job) => ({
id: job.id,
kind: job.kind,
status: job.status,
summary: job.summary,
error: job.error,
issueUrl: job.issue_url,
prUrl: job.pr_url,
reviewScore: job.review_score,
attribution: parseAttributionJson(job.attribution_json),
// #1190: the server-rendered text is what the console shows, so the
// first tick cannot replace a marked claim with the bare seat. The
// structured field keeps its type; the script contains no marker
// vocabulary of its own.
attributionText: jobAttribution(t, job),
createdAt: job.created_at,
finishedAt: job.finished_at,
}))
})(),
}
const text = JSON.stringify(snapshot)
if (text !== last) {
Expand Down
50 changes: 50 additions & 0 deletions src/lib/attribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,53 @@ export function parseAttributionGroundJson(value: string | null): AttributionGro
return null
}
}

// #368/#1190: one reconstruction of the ground record, shared by every reader of
// the claim. A row written before `attribution_ground_json` exists carries the
// observation in `attribution_json` itself when team stats were recorded (the
// old writer overwrote the claim), and a claim nothing checked otherwise. The
// reconstruction is a rule, not a guess: a stored record always wins.
export function attributionGroundFor(input: {
groundJson: string | null
attributionJson: string | null
teamStatsJson: string | null
}): AttributionGround | null {
const stored = parseAttributionGroundJson(input.groundJson)
if (stored !== null) return stored
const recorded = parseAttributionJson(input.attributionJson)
if (recorded === null) return null
const observedOnly = input.teamStatsJson !== null
return {
steps: ATTRIBUTION_FIELDS
.filter((field) => recorded[field.key] !== undefined)
.map((field) => ({
key: field.key,
claimed: observedOnly ? null : (recorded[field.key] as string),
observed: recorded[field.key] as string,
state: observedOnly ? 'grounded' as const : 'no-observation' as const,
})),
}
}

const CLAIM_STATE_ORDER: Record<AttributionGroundState, number> = { grounded: 0, unobserved: 1, 'no-observation': 2 }

/**
* How the record judges the seat's claim on `role`, or null when the role is not
* claimed at all (an observation-only seat). The worst state among the claiming
* steps speaks for the role, the same rule `jobAttribution` applies to one seat
* on several kinds of work: a seat seen on one kind of work and not on another
* is not a grounded seat.
*/
export function claimedRoleState(
ground: AttributionGround | null,
role: string | null,
keys: readonly AttributionKey[] = ['writtenBy', 'implementedBy'],
): AttributionGroundState | null {
if (ground === null || role === null || role === '') return null
let worst: AttributionGroundState | null = null
for (const step of ground.steps) {
if (step.claimed !== role || !keys.includes(step.key)) continue
if (worst === null || CLAIM_STATE_ORDER[step.state] > CLAIM_STATE_ORDER[worst]) worst = step.state
}
return worst
}
37 changes: 34 additions & 3 deletions src/lib/changeStory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
// it parses the body the agent wrote and adds the diff totals. Pure, no model
// call, no network.

import { parseAttributionJson } from './attribution.js'
import { attributionGroundFor, claimedRoleState, parseAttributionJson } from './attribution.js'
import type { AttributionGroundState } from './attribution.js'
import { parseModelRun } from './modelRun.js'

// #793: the body also carries what was considered instead, what remains
Expand Down Expand Up @@ -45,9 +46,17 @@ export interface ChangeStorySection {
// #793: which model answered and which role wrote the change, read from the job
// row. `null` for a half means the row does not record it; it is never inferred
// from the other half or from the body.
//
// #1190: `state` is how the ground record judges that claimed role, or null when
// the role is not claimed (an observation-only seat cannot be a false claim) or
// when the record says the claim was observed. The row's note uses it; the value
// never changes, because the model half is not what the claim is about.
export interface ChangeStoryAttribution {
model: string | null
role: string | null
// Optional so a caller that has no record yet (an older fixture, a unit test of
// the pair alone) states "no judgement" rather than inventing `grounded`.
state?: AttributionGroundState | null
}

export type ChangeStoryDiffState = 'ok' | 'capped' | 'unreadable'
Expand All @@ -71,6 +80,10 @@ export interface ChangeStoryLabels {
capped?: string
duplicate?: string
files?: (count: number) => string
// #1190: the two marker words #1186 renders on the job page's team line. The
// change-story row uses the same vocabulary rather than inventing a second one.
claimedNotObserved?: string
claimedNotVerified?: string
}

export interface ChangeStoryFact {
Expand Down Expand Up @@ -200,12 +213,21 @@ export function parseChangeStoryBody(body: string): ChangeStorySection[] {
export function changeStoryAttribution(input: {
modelJson: string | null
attributionJson: string | null
groundJson?: string | null
teamStatsJson?: string | null
}): ChangeStoryAttribution | null {
const model = parseModelRun(input.modelJson)?.model?.label ?? null
const attribution = parseAttributionJson(input.attributionJson)
const role = attribution?.writtenBy ?? attribution?.implementedBy ?? null
if (model === null && role === null) return null
return { model, role }
// #1190: the record, not the page, decides whether the claim was observed. A
// row that predates the ground column is reconstructed by the same rule.
const ground = attributionGroundFor({
groundJson: input.groundJson ?? null,
attributionJson: input.attributionJson,
teamStatsJson: input.teamStatsJson ?? null,
})
return { model, role, state: claimedRoleState(ground, role) }
}

// `totals` is the caller's sum (the reader owns the file walk and its cap);
Expand Down Expand Up @@ -237,6 +259,8 @@ const DEFAULT_LABELS: Required<ChangeStoryLabels> = {
capped: 'the file list exceeded the cap',
duplicate: 'a repeated heading; the last one is shown',
files: (count: number) => `${count} files`,
claimedNotObserved: 'claimed, not observed',
claimedNotVerified: 'claimed, not verified',
}

export function changeStoryFacts(story: ChangeStory, labels: ChangeStoryLabels = {}): ChangeStoryFact[] {
Expand All @@ -254,6 +278,13 @@ export function changeStoryFacts(story: ChangeStory, labels: ChangeStoryLabels =
// "not stated" (nothing recorded) rather than "not available" (nothing read).
const recorded = [story.attribution?.model ?? null, story.attribution?.role ?? null]
.filter((part): part is string => part !== null && part !== '')
facts.push({ key: 'attribution', value: recorded.length === 0 ? l.notStated : recorded.join(' · '), note: '' })
// #1190: the row keeps `model · role` (the claim is about the role, not the
// model) and puts the claim's state in the note, so a seat nothing observed is
// not printed as a fact.
const state = story.attribution?.state ?? null
const claimNote = state === 'unobserved'
? l.claimedNotObserved
: state === 'no-observation' ? l.claimedNotVerified : ''
facts.push({ key: 'attribution', value: recorded.length === 0 ? l.notStated : recorded.join(' · '), note: claimNote })
return facts
}
26 changes: 15 additions & 11 deletions src/views/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ import { diffContextBundles, readContextBundle, verifyContextBundle } from '../l
import type { AdherenceRecord, AdherenceStatus, ClauseStatus, ClauseResult } from '../lib/instructions.js'
import { WORK_ITEM_STATES, WORK_ITEM_TRANSITIONS, workItemStateLabel, type WorkItemState } from '../lib/workItems.js'
import { PAT_EXPIRY_CHOICES } from '../lib/tokens.js'
import { ATTRIBUTION_FIELDS, parseAttributionGroundJson, parseAttributionJson } from '../lib/attribution.js'
import { ATTRIBUTION_FIELDS, attributionGroundFor } from '../lib/attribution.js'
import type { AttributionGround, AttributionGroundState, AttributionKey } from '../lib/attribution.js'
import { reconstructAttributionGround } from '../lib/teamStats.js'
import { followUpLinks, summariseDeliveries, type DeliveryOutcomeRow } from '../lib/deliveryOutcome.js'
import { parseEvidenceJson } from '../lib/evidence.js'
import { planPacketHash } from '../lib/planDecision.js'
Expand Down Expand Up @@ -527,19 +526,22 @@ function jobTeamStats(job: JobRow): Array<{ role: string; label: string; calls:
}

// #368: what the job claimed and what the instance observed are two facts, and the
// page must not print the first as the second. A stored ground record answers per
// attribution key; a row written before that column exists is reconstructed by the
// one rule in `reconstructAttributionGround`, which the dataset export also reads.
// page must not print the first as the second. The reconstruction of a row that
// predates the ground column lives in `attributionGroundFor` (#1190), shared with
// the change-story row and the console so the three cannot answer differently;
// the stored record still wins, which is the rule the dataset export reads too.
const GROUND_STATE_ORDER: Record<AttributionGroundState, number> = { grounded: 0, unobserved: 1, 'no-observation': 2 }

function attributionGroundFor(job: JobRow): AttributionGround | null {
const stored = parseAttributionGroundJson(job.attribution_ground_json)
if (stored !== null) return stored
return reconstructAttributionGround(parseAttributionJson(job.attribution_json), job.team_stats_json !== null)
function groundOf(job: JobRow): AttributionGround | null {
return attributionGroundFor({
groundJson: job.attribution_ground_json,
attributionJson: job.attribution_json,
teamStatsJson: job.team_stats_json,
})
}

function jobAttribution(t: Translate, job: JobRow): string {
const ground = attributionGroundFor(job)
export function jobAttribution(t: Translate, job: JobRow): string {
const ground = groundOf(job)
if (ground === null) return ''
const byRole = new Map<string, { role: string; keys: AttributionKey[]; state: AttributionGroundState }>()
const add = (role: string, key: AttributionKey, state: AttributionGroundState): void => {
Expand Down Expand Up @@ -4219,6 +4221,8 @@ export function jobPage(input: {
capped: t('读不到:改动文件超过读取上限', 'not available: the file list exceeded the read cap'),
duplicate: t('标题重复,显示最后一处', 'a repeated heading; the last one is shown'),
files: (count) => t(`${count} 个文件`, `${count} files`),
claimedNotObserved: t('声称,未观察', 'claimed, not observed'),
claimedNotVerified: t('声称,未核实', 'claimed, not verified'),
}).map((fact) => `<div class="list-row"><div class="list-main"><strong>${escapeHtml(changeStoryLabel(t, fact.key))}</strong><small class="job-report">${escapeHtml(fact.value)}</small>${fact.note === '' ? '' : `<small class="muted">${escapeHtml(fact.note)}</small>`}</div></div>`).join('')}
</div>
</section></details>`
Expand Down
Loading
Loading