Debugging failed invocations
How to diagnose a failing invocation from the portal trace, how to replay it against a fix, and the top patterns that cause silent failures.
The invocation trace view#
Every invocation produces a trace. In the portal:
- Open the instanceInstance → Invocations tab.
- Open the traceClick any row to open the trace.
- Read it top to bottomThe trace shows each section below, chronologically.
| Trace section | What it shows |
|---|---|
| Request | invocationId, input, payload, config |
| Kernel calls | every ctx.* call with args, result, latency, cost |
| LLM calls | full prompt + response + token counts + model + cost |
| Capability calls | canonical name, resolved connector, request/response |
| Reviewer actions (if HITL) | who acted, decision, decision reason |
| Exception (if raised) | type, message, stack trace, line numbers |
Everything in the trace is retained per the tenant's retention policy (default 90 days).
Three debugging recipes#
Start from the symptom:
| Symptom | Look first at | Usual culprit |
|---|---|---|
| Wrong answer | The trace's LLM call | Prompting / grounding, not a bug |
| Raised an exception | The trace's Exception section | Missing await, unguarded optional capability, missing null-check |
| Silently did nothing | Invocation count, kernel calls, instance status | Upstream trigger, direct-run no-ops, disabled instance |
"The agent returned the wrong answer"#
Likely a prompting / grounding issue, not a bug. Check the trace's LLM call:
- Was the right context included? Common cause:
ctx.vector.query()returned 0 hits (empty index? wrong namespace?) and the LLM answered without grounding. - Was the prompt what you expected? The trace shows the full
system+userstrings. Easy to spot f-string formatting bugs where a variable was None and the literal"None"ended up in the prompt. - Did temperature affect it? For deterministic tasks, set
temperature=0.0inctx.llm.complete().
"The agent raised an exception"#
Check the trace's Exception section:
- Type + message: often tells you the fix inline. See Error catalog for the catalogue of common exceptions.
- Last successful kernel call: tells you where in
handle()it got. - Line numbers: map back to your source. Common causes:
- Missing
awaiton actx.*call (the coroutine is treated as truthy; subsequent code accesses attributes on the coroutine) - Unguarded optional capability (
CapabilityUnbound) - Null-check missing on a kernel service that can return
None(e.g.ctx.semantic.*returning None when the Context Service is disabled)
- Missing
"The agent silently did nothing"#
Nothing in the inbox, no exception, no visible change. Three places to look:
- Was
handle()actually called? Check the invocation count. If zero, the issue is upstream — maybe the webhook HMAC failed, or the schedule isn't firing (check the schedules tab in the portal). - Did a kernel call fail silently? Fire-and-forget services
(
ctx.log.*,ctx.cost.record) can silently no-op in direct-run mode. If you're testing locally and never see logs — checkKONSTERA_KERNEL_MCP_URLis set. - Was the agent in a disabled instance? Instance in state
disabled(ADR-006) still accepts /invoke calls but the kernel returns a specific error. Check instance status in the portal.
Replay for root-cause analysis#
The killer feature. From the invocation trace:
- Click ReplayFrom the invocation trace.
- Choose a targetCurrent version, previous version, or a draft agent.
- Click RunThe same input is sent to the version you chose.
Replay sends the exact same input (req payload) to the chosen agent
version. All kernel-side side effects are replayed from the original
invocation's trace — the same LLM response is returned, the same vector
hits, the same capability results. So you're testing your handler's
reaction to the same inputs, not re-running the LLM.
Deploy a draft agent with the fix, replay the failing invocation against the draft, see if it works.
Compare two versions on the same real-world input.
konstera invocation replay <id> in CLI pulls the trace and runs it against a local-dev agent container.
Top five silent-failure patterns#
awaiton everyctx.*call — especiallyctx.capability.available(...)purpose=instead of a hard-codedmodel=ctx.capability.call(...)instead of vendor SDK imports- Log that you fetched a credential, never its value
- Keep
capabilities.needs[]minimal
1. Missing await on a ctx.* call#
# BUG:
if ctx.capability.available("orders.lookup_by_id"): # coroutine is truthy!
order = await ctx.capability.call("orders.lookup_by_id", id=oid)
# FIX:
if await ctx.capability.available("orders.lookup_by_id"):
order = await ctx.capability.call("orders.lookup_by_id", id=oid)
2. Hard-coded model= across tenants#
# BAD: tenant admin can't swap provider without a redeploy
result = await ctx.llm.complete(model="claude-sonnet-4-6", prompt=user_q)
# GOOD: use purpose; tenant binds it in the portal
result = await ctx.llm.complete(purpose="narrator", prompt=user_q)
3. Vendor SDK imports#
# BAD: tightly couples the agent to Shopify
import shopify
orders = shopify.Order.find(email=customer.email)
# GOOD: capability indirection — works with any connector the tenant binds
orders = await ctx.capability.call("orders.lookup_by_email", email=customer.email)
See the capability catalogue for every canonical name an agent can call — one stable key per purpose, swappable connectors behind each.
4. Logging secrets#
# BAD: credential value lands in the audit log
stripe_key = await ctx.credentials.get("stripe-api-key")
await ctx.log.info("got key", key=stripe_key) # NO
# GOOD: log that you fetched the key, not the key
await ctx.log.info("stripe key fetched")
5. Over-declared capabilities.needs[]#
- Keep
needs[]minimal — only what the agent actually uses. - Add a capability via a new version when a feature actually needs it.
- Over-declare "just in case". The manifest's
needs[]is a permission list — anything listed may be checked by compliance tooling, and over-declaring blurs the agent's actual capability footprint.