Skip to content
Closed
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
7 changes: 4 additions & 3 deletions skill-guides/orchestration/references/coordinator-loop.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ ORCA orchestration task-create --spec "<dependent work>" --deps <json_array> --j
ORCA orchestration task-list --ready --brief --json
```

`--brief` collapses whitespace and caps echoed specs at 160 characters;
`spec_truncated` identifies shortened rows. Omit it when full specs are needed or
when an older CLI rejects the flag. A nested worker must respect
`--brief` collapses whitespace and caps echoed specs and results at 160
characters; `spec_truncated` and `result_truncated` identify shortened fields.
Omit it when full specs or results are needed or when an older CLI rejects the
flag. A nested worker must respect
`nested_worker_depth_exceeded`; creating another Run does not reset depth.

## Launch preferences
Expand Down
4 changes: 2 additions & 2 deletions src/cli/bundled-skill-guides.ts

Large diffs are not rendered by default.

40 changes: 39 additions & 1 deletion src/cli/handlers/orchestration-task-list-brief.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,47 @@ describe('orchestration task-list brief output', () => {
expect(response.result.tasks[0].spec_truncated).toBe(true)
})

it('caps full results from runtimes that abbreviate only specs', async () => {
callMock.mockReset().mockResolvedValue({
result: {
// spec_truncated without result_truncated — a spec-only brief runtime.
tasks: [
{
id: 'task_1',
spec: 'already brief…',
status: 'completed',
spec_truncated: true,
result: 'finding '.repeat(1300)
}
],
count: 1
}
})

const response = await runTaskListBrief()
const [task] = response.result.tasks as {
spec: string
spec_truncated: boolean
result: string
result_truncated: boolean
}[]

expect(task.spec).toBe('already brief…')
expect(task.spec_truncated).toBe(true)
expect(task.result).toHaveLength(160)
expect(task.result_truncated).toBe(true)
})

it('passes server-abbreviated rows through untouched', async () => {
const serverTasks = [
{ id: 'task_1', spec: 'already brief…', status: 'ready', spec_truncated: true }
{
id: 'task_1',
spec: 'already brief…',
status: 'ready',
spec_truncated: true,
result: null,
result_truncated: false
}
]
callMock.mockReset().mockResolvedValue({ result: { tasks: serverTasks, count: 1 } })

Expand Down
6 changes: 4 additions & 2 deletions src/cli/handlers/orchestration/task-handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ export const ORCHESTRATION_TASK_HANDLERS: Record<string, CommandHandler> = {
status: string
assignee_handle?: string | null
dispatch_id?: string | null
result?: string | null
spec_truncated?: boolean
result_truncated?: boolean
}[]
count: number
runId?: string
Expand All @@ -62,9 +64,9 @@ export const ORCHESTRATION_TASK_HANDLERS: Record<string, CommandHandler> = {
run,
callerTerminalHandle
})
// Why: only older runtimes (no spec_truncated) skip server-side abbreviation and need this client-side fallback.
// Why: only older runtimes (no result_truncated) skip server-side abbreviation of some fields and need this client-side fallback.
const needsClientAbbreviation =
brief && result.result.tasks.some((task) => task.spec_truncated === undefined)
brief && result.result.tasks.some((task) => task.result_truncated === undefined)
const output = needsClientAbbreviation
? {
...result,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/specs/orchestration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ export const ORCHESTRATION_COMMAND_SPECS: CommandSpec[] = [
'orca orchestration task-list [--status <status>] [--ready] [--brief] [--run <run_id>] [--from <handle>] [--json]',
allowedFlags: [...GLOBAL_FLAGS, 'status', 'ready', 'brief', 'run', 'from'],
identityFlagRoles: { from: 'caller' },
notes: ['--brief collapses whitespace and caps each spec at 160 characters.']
notes: ['--brief collapses whitespace and caps each spec and result at 160 characters.']
},
{
path: ['orchestration', 'task-update'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,28 @@ describe('orchestration RPC methods', () => {
expect(short.spec).toBe('Short task')
expect(short.spec_truncated).toBe(false)
})

it('bounds completed-task results under brief and keeps them whole otherwise', async () => {
setup()
const report = `Report\n${'0123456789'.repeat(1000)}`
const done = db.createTask({ spec: 'Long report' })
db.updateTaskStatus(done.id, 'completed', report)
db.createTask({ spec: 'Not started' })

const brief = (await call('orchestration.taskList', { brief: true })) as {
tasks: { result: string | null; result_truncated: boolean }[]
}
const full = (await call('orchestration.taskList', {})) as {
tasks: { result: string | null; result_truncated?: boolean }[]
}

expect(brief.tasks[0].result).toHaveLength(160)
expect(brief.tasks[0].result_truncated).toBe(true)
expect(brief.tasks[1].result).toBeNull()
expect(brief.tasks[1].result_truncated).toBe(false)
expect(full.tasks[0].result).toBe(report)
expect(full.tasks[0]).not.toHaveProperty('result_truncated')
})
})

describe('orchestration.taskUpdate', () => {
Expand Down
57 changes: 55 additions & 2 deletions src/shared/orchestration-task-summary.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ describe('abbreviateOrchestrationTasks', () => {
it('preserves a short one-line spec', () => {
const [task] = abbreviateOrchestrationTasks([{ spec: 'Short task' }])

expect(task).toEqual({ spec: 'Short task', spec_truncated: false })
expect(task).toEqual({ spec: 'Short task', spec_truncated: false, result_truncated: false })
})

it('does not report whitespace normalization as truncation', () => {
const [task] = abbreviateOrchestrationTasks([{ spec: 'Short\n\n task' }])

expect(task).toEqual({ spec: 'Short task', spec_truncated: false })
expect(task).toEqual({ spec: 'Short task', spec_truncated: false, result_truncated: false })
})

it('does not split a surrogate pair at the truncation boundary', () => {
Expand All @@ -36,3 +36,56 @@ describe('abbreviateOrchestrationTasks', () => {
expect(task.spec.endsWith('…')).toBe(true)
})
})

describe('abbreviateOrchestrationTasks result field', () => {
it('caps a long completed-task result and flags it', () => {
const [task] = abbreviateOrchestrationTasks([
{ spec: 'Short task', result: `Report\n\n${'0123456789'.repeat(1000)}` }
])

expect(task.result).toHaveLength(160)
expect(task.result).not.toContain('\n')
expect(task.result?.endsWith('…')).toBe(true)
expect(task.result_truncated).toBe(true)
expect(task.spec_truncated).toBe(false)
})

it('keeps a null result and a short result untruncated', () => {
const [pending, done] = abbreviateOrchestrationTasks([
{ spec: 'Pending task', result: null },
{ spec: 'Done task', result: '{"ok": true}' }
])

expect(pending).toEqual({
spec: 'Pending task',
spec_truncated: false,
result: null,
result_truncated: false
})
expect(done.result).toBe('{"ok": true}')
expect(done.result_truncated).toBe(false)
})

it('does not split a surrogate pair at the result truncation boundary', () => {
const [task] = abbreviateOrchestrationTasks([
{ spec: 'Short task', result: `${'a'.repeat(158)}😀${'b'.repeat(40)}` }
])

expect(task.result_truncated).toBe(true)
expect(task.result?.isWellFormed()).toBe(true)
expect(task.result?.endsWith('…')).toBe(true)
})

it('leaves fields a runtime already abbreviated untouched', () => {
// Why: a server-capped spec fits the cap, so re-abbreviating it would
// flip spec_truncated back to false.
const [task] = abbreviateOrchestrationTasks([
{ spec: 'already brief…', spec_truncated: true, result: 'r'.repeat(400) }
])

expect(task.spec).toBe('already brief…')
expect(task.spec_truncated).toBe(true)
expect(task.result).toHaveLength(160)
expect(task.result_truncated).toBe(true)
})
})
43 changes: 34 additions & 9 deletions src/shared/orchestration-task-summary.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,48 @@
const TASK_SPEC_BRIEF_LENGTH = 160
const TASK_BRIEF_FIELD_LENGTH = 160

export function abbreviateOrchestrationTasks<T extends { spec: string }>(
type BriefTaskFields = {
spec: string
result?: string | null
spec_truncated?: boolean
result_truncated?: boolean
}

export function abbreviateOrchestrationTasks<T extends BriefTaskFields>(
tasks: readonly T[]
): (T & { spec_truncated: boolean })[] {
): (T & { spec_truncated: boolean; result_truncated: boolean })[] {
return tasks.map((task) => {
const spec = task.spec.replace(/\s+/g, ' ').trim()
const truncated = spec.length > TASK_SPEC_BRIEF_LENGTH
// Why: a runtime that already abbreviated a field marks it, and its capped
// text fits the cap, so re-abbreviating would flip the flag back to false.
const spec =
task.spec_truncated === undefined
? abbreviateText(task.spec)
: { text: task.spec, truncated: task.spec_truncated }
const result =
task.result_truncated === undefined && typeof task.result === 'string'
? abbreviateText(task.result)
: undefined
return {
...task,
spec: truncated ? `${truncateAtCodePoint(spec).trimEnd()}…` : spec,
spec: spec.text,
// Why: whitespace normalization alone is not truncation; flagging it
// would make agents re-fetch full specs that --brief already shows.
spec_truncated: truncated
spec_truncated: spec.truncated,
// Why: completed results are often full worker reports already delivered
// via worker_done; a brief listing should not re-ship them (#20701).
...(result ? { result: result.text } : {}),
result_truncated: result?.truncated ?? task.result_truncated ?? false
}
})
}

function truncateAtCodePoint(spec: string): string {
const sliced = spec.slice(0, TASK_SPEC_BRIEF_LENGTH - 1)
function abbreviateText(value: string): { text: string; truncated: boolean } {
const text = value.replace(/\s+/g, ' ').trim()
const truncated = text.length > TASK_BRIEF_FIELD_LENGTH
return { text: truncated ? `${truncateAtCodePoint(text).trimEnd()}…` : text, truncated }
}

function truncateAtCodePoint(text: string): string {
const sliced = text.slice(0, TASK_BRIEF_FIELD_LENGTH - 1)
// Why: a cut through a surrogate pair leaves a lone high surrogate that
// strict JSON consumers reject; drop it rather than emit malformed UTF-16.
const lastUnit = sliced.charCodeAt(sliced.length - 1)
Expand Down