Skip to content
Draft
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions apps/worker/src/run-task/subscribe-harness-callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ export function subscribeHarnessCallbacks({
costSource: event.costSource,
messageCreatedAt: event.messageCreatedAt ?? null,
messageCompletedAt: event.messageCompletedAt ?? null,
details: event.workflowSkill
? { workflowSkill: event.workflowSkill }
: null,
})
.then(() => {
consecutivePersistenceFailures = 0;
Expand Down
2 changes: 2 additions & 0 deletions apps/worker/src/sandbox-server/lib/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ export interface HarnessInferenceUsageEvent {
* `build`) or a subagent name (for example `explore` or `visual`).
*/
agent?: string;
/** Packaged workflow active for a primary-session inference request. */
workflowSkill?: string;
inputTokens: number;
outputTokens: number;
reasoningTokens: number;
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ function createInferenceUsageEvent(
info: OpenCodeMessageInfo,
tokenUsage: Record<string, unknown>,
fallbackAgent?: string,
workflowSkill?: string,
): HarnessInferenceUsageEvent {
const messageCreatedAt = openCodeTimestampToDate(info.time?.created);
const messageCompletedAt = openCodeTimestampToDate(info.time?.completed);
Expand All @@ -766,6 +767,7 @@ function createInferenceUsageEvent(
: {}),
...(typeof info.modelID === 'string' ? { modelId: info.modelID } : {}),
...(agent ? { agent } : {}),
...(workflowSkill ? { workflowSkill } : {}),
inputTokens: Number(tokenUsage.inputTokens ?? 0),
outputTokens: Number(tokenUsage.outputTokens ?? 0),
reasoningTokens: Number(tokenUsage.reasoningTokens ?? 0),
Expand Down Expand Up @@ -5445,7 +5447,14 @@ export class OpenCodeServerHarness
});
this.emit(
'runtimeInferenceUsage',
createInferenceUsageEvent(message.info, tokenUsage, options?.agentType),
createInferenceUsageEvent(
message.info,
tokenUsage,
options?.agentType,
message.info.sessionID === this.sessionId

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReconnectableHarness creates a fresh OpenCodeServerHarness with only initialSessionId after any disconnect, while activeWorkflowSkill is initialized to null and is not rehydrated. Once a workflow task reconnects, subsequent primary-session messages take this branch with no workflow skill and are persisted with details: null, losing the attribution this change is meant to preserve. Carry the active workflow through reconnect (or recover it from the session) and cover that path.

? (this.activeWorkflowSkill ?? undefined)
: undefined,
),
);
if (options?.finalizeParentTurn !== false) {
this.finalizedAssistantTurn = finalized;
Expand Down
Loading