feat(harness): export stopReasonToUserMessage helper#60
Merged
khaliqgant merged 1 commit intomainfrom Apr 25, 2026
Merged
Conversation
…ntly drop turns Adds a tiny helper that maps every documented HarnessStopReason to a non-empty, end-user-facing message. Exported from @agent-assistant/harness so sage's slack-runner, cloud's specialist-worker fallback, and any future surface share one voice instead of each shipping its own ad-hoc table — the silent-failure footgun was when a consumer forgot a stop reason and posted an empty reply. Includes an optional `canRetry` switch so callers with a queued fallback path (e.g. sage's harness→swarm retry) can produce "retrying with a fallback" wording instead of dead-ending the user. Tests cover: - every documented stop reason returns a non-empty string - undefined / empty / unknown values fall through to a generic message - canRetry flips retryable reasons to retry-language - copy is distinct per reason (with one allowed collision for the max_iterations / max_tool_calls pair, which share UX intentionally)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
stopReasonToUserMessage(stopReason, options?)to@agent-assistant/harness, returning a one-line, end-user-facing string for every documentedHarnessStopReason(and a generic fallback for unknown/empty values).canRetryswitch flips retryable reasons (max_iterations_reached,max_tool_calls_reached,timeout_reached,model_invalid_response) to retry-language so consumers with a queued fallback path don't dead-end the user.StopReasonMessageOptionstype frompackages/harness/src/index.ts.Why
Today every harness consumer (sage's
slack-runner.ts, cloud's specialist-worker fallback, future CLI surfaces) writes its own ad-hoc switch fromresult.stopReason→ user-visible string. That's the silent-failure footgun: when a consumer forgets to map a new stop reason, the user gets an empty reply.Centralizing the mapping in
@agent-assistant/harnessmeans:HarnessStopReasonvariant only needs one copy update; consumers automatically get a sensible message.result.assistantMessage?.text || stopReasonToUserMessage(result.stopReason).Test plan
npx tsc -p tsconfig.json --noEmitsrc/stop-reason-message.test.ts— 8 cases passingcanRetryflips retryable reasonsbyoh-local-proof.test.ts) fails onorigin/maintoo —@agent-assistant/connectivitypackage entry resolution; unrelated to this change.Follow-up
A sibling PR will land in
AgentWorkforce/sageto use this helper fromslack-runner.tsand to add the empty-content guard atslack-webhooks.ts:452so an emptyresponse.contentnever produces a silent Slack reply.