All Agent Engineering

Error, cost and observability boundaries for Cline SDK production runs

Use the official production guide to separate runtime and core result fields and check tool errors, cost limits, observability records and shutdown.

AINavWritten / Updated
On this page

At a glance

This checklist is for a host application that already embeds the Cline SDK. The official guide has a distinction that is easy to blur: a direct AgentRuntime result reports status, while the host-facing AgentResult used by core reports finishReason. If logs, metrics and alerts read only one of those fields, failures on the other path can go unrecorded. The steps below place error data, run limits, cost aborts, observability events and exit behaviour into the host code one at a time, each with a completion check and a stop condition.

Runtime and applicability

Article type
Engineering practice
Verified
Applies to
  • Cline Error, cost and observability boundaries for Cline SDK production runs

Execution locations and responsibilities

  • Host application embedding Cline SDK Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Engineering workflow order
Engineering workflow order1. Confirm the call path and write down the result field → 2. Check tool error data and tool boundaries → 3. Set run limits and name the failure signal per path → 4. Connect cost estimation to an abort action → 5. Give every run one terminal observability record → 6. Define exit and shutdown behaviour. Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.1. Confirm the call path and write down the result field2. Check tool error data and tool boundaries3. Set run limits and name the failure signal per path4. Connect cost estimation to an abort action5. Give every run one terminal observability record6. Define exit and shutdown behaviour

Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.

When to use

  • A direct AgentRuntime result reports status, with error and iterations available on failure. The AgentResult used by core reports finishReason, and a run stopped by consecutive recoverable mistakes ends with finishReason: "mistake_limit". A host using both paths needs to handle each separately.

When not to use

  • In the official snippets status and finishReason appear in different places: check which result type your host code uses, and do not merge them into one generic status.
  • Cost estimates depend on the current prices you supply; the documentation gives no prices and does not promise the estimate equals the actual bill, so an over-limit abort is only your own protection.
  • The documentation says only that loop detection is available through core/session execution settings and gives no setting name, so this article assumes no specific parameter; check the core settings when you need it.
  • The official blocklist example is a demonstration, and a substring check cannot prove a command safe; do not record it as a release conclusion, and rely on a container or restricted environment.
  • Telemetry event names and plugin hooks come from documentation examples; whether your version exposes the same fields needs confirming in your own environment.

Prerequisites and input

  • An SDK host application about to go live, where you can say whether it calls AgentRuntime directly or runs through core (for example ClineCore).
  • At least one sample run result or log containing the terminal field, error information and usage.
  • A source for current model pricing (configuration or a pricing service). The official example also loads pricing externally, and this article supplies no prices.
  • A tool inventory listing which files, commands or external services each tool can reach.

Engineering checks

Result contract: know which field to read — A direct AgentRuntime result reports status, with error and iterations available on failure. The AgentResult used by core reports finishReason, and a run stopped by consecutive recoverable mistakes ends with finishReason: "mistake_limit". A host using both paths needs to handle each separately.

Boundary settings: errors, limits and cost — The guide recommends returning tool errors as data. output with isError:true is one example, while a file tool shows {error:text}; follow each tool’s verified result contract. Run limits include maxTokensPerTurn and maxIterations; loop detection belongs to core/session execution settings. For cost, recompute and replace, rather than sum, from usage-updated events and call agent.abort when your own threshold is exceeded.

Observability and exit: every run leaves a terminal record — Pass clientName, telemetry and logger to ClineCore.create, or use the plugin hooks onRunEnd, onToolCall and onError, or listen for run-finished and run-failed through agent.subscribe. A stateless worker has no explicit shutdown method; a persistent service calls cline.dispose on SIGTERM.

1. Confirm the call path and write down the result field

Where: the host entry point that runs the agent. Input: the entry code and a real run-result sample. Action: decide whether the entry uses a direct AgentRuntime or core, and record whether it should read status or finishReason; if both paths exist, write one line for each. Completion check: every entry has exactly one named terminal field, plus the source of the failure detail: error for runtime, or the matching core field. Stop condition: if you cannot tell which contract an entry follows, or the sample lacks the expected field, pause the release until that is settled.

2. Check tool error data and tool boundaries

Where: tool execute and host boundaries. Input: tools, their actual result contracts and resources. Follow the documented recommendation to return handleable errors as data; output/isError:true is not a universally required shape and the file example uses error. Verify success and failure paths per tool. Separately check constrained command execution, allowed file paths and environment-injected secrets. This release gate is a local design choice, not a product rule banning every thrown exception. Completion: each tool has verified success/error results and input/permission ownership. Stop release on unknown contracts, unconstrained external actions or hardcoded real secrets.

3. Set run limits and name the failure signal per path

Where: the agent construction config and the core/session execution settings. Input: the expected size of a single task. Action: fill in maxTokensPerTurn and maxIterations with values you decide; on the core path, check whether the consecutive-mistake limit (terminal finishReason: "mistake_limit") and loop detection are enabled; on the direct runtime path, confirm failure shows up in status and error. Completion check: the configured values and their origin are recorded, and the terminal signal expected when each limit trips is written down. Stop condition: if a path has no limit at all, or you do not know what signal appears when one trips, do not release that path.

4. Connect cost estimation to an abort action

Where: the host code subscribed to usage-updated events. Input: the usage in the event (input and output tokens, possibly totalCost) and the current unit prices read from configuration or a pricing service. Action: use totalCost when present, otherwise convert input and output tokens with per-million-token prices; when your limit is exceeded, call agent.abort with a reason. The official example uses a 1.00 USD threshold for demonstration only; your own budget sets the real value. Completion check: in a limit-exceeded scenario, both the abort reason and the estimated amount are recorded. Stop condition: if current prices are unavailable, do not substitute guesses; rely on token limits only and mark the cost alert as not enabled. Recompute and replace sessionCost from the current event.usage on each update; never add each estimate again.

5. Give every run one terminal observability record

Where: telemetry and logger in ClineCore.create, or plugin hooks and agent.subscribe. Input: the result fields fixed in the previous step. Action: confirm the agent_created, tool_usage, model_api_call and session_ended events are received; in a plugin, use onRunEnd to record duration, tokens and finishReason, and onError to separate recoverable from non-recoverable errors; with subscription, record status on run-finished and the error message on run-failed. Completion check: after any run ends, a record carrying the terminal field of its own contract can be found. Stop condition: if some path ends without a record, or a metric reads the other contract's field, fix it first.

6. Define exit and shutdown behaviour

Where: the service process entry and the request handler. Input: the deployment form. Action: a stateless worker creates an agent per request and reads result.outputText; the documentation says it has no explicit shutdown method, so do not write a cleanup call that does not exist. A persistent service uses backendMode: "hub", with sessions persisting across restarts, and on SIGTERM calls cline.dispose before exiting the process. Completion check: each deployment form has its exit path and the corresponding call written down. Stop condition: if a persistent service does not handle SIGTERM, or a stateless path depends on a shutdown interface absent from the documentation, do not release.

Task example

Synthetic, unexecuted walkthrough: a summarization service records direct AgentRuntime status/error separately from Core finishReason. A timed-out tool returns error data with isError:true; first check whether the agent received and adapted to it, without predicting a failed run. Record failure fields only if the run actually fails. Prepare a separate run-limit case and preserve its actual outcome. On every usage-updated event recompute and replace the current cost estimate from usage; if it exceeds the chosen budget issue abort with a reason and separately record the final run outcome. These are future walkthrough conditions, not observed output.

Completion checks

  • Each entry names its terminal field: direct runtime reads status, core reads finishReason, and neither is applied to the other.
  • Record failures through each tool’s actual result contract, separating the error-as-data recommendation from sample fields; host exception handling and external-action permissions have owners.
  • When a limit trips (iterations, tokens, consecutive mistakes, cost abort), a searchable terminal outcome or abort reason exists for it.
  • Success, failure and abort each leave one record with duration, usage and the terminal field.
  • The exit path matches the deployment form: stateless code calls no nonexistent shutdown method, and a persistent service calls cline.dispose on SIGTERM.

Verification scope

Written from the official Going to Production documentation, which was read. Installation, login, API execution and output were not tested, and the example is synthetic, so its expected observations are not verification results.

Sources

All links are official pages; verification dates are listed per source, and links point to the version checked.

  1. Cline · Cline documentation: cline-prod

Found an error? Tell us →