Skip to content

fix(tools): list_task_credentials emits invalid "required": [""] and breaks workers on strict LLM providers - #130

Merged
BaaRai merged 2 commits into
BaaRai:mainfrom
kiserufetch:fix/list-task-credentials-empty-required
Nov 10, 2026
Merged

BaaRai merged 2 commits into
BaaRai:mainfrom
kiserufetch:fix/list-task-credentials-empty-required

Conversation

@kiserufetch

@kiserufetch kiserufetch commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

list_task_credentials takes no parameters but builds its JSON Schema with obj(map[string]any{}, ""), which emits:

{"type": "object", "required": [""], "properties": {}}

The required array contains an empty string. Strict function-call validators reject this. Reproduced with DeepSeek through an OpenAI-compatible gateway (profile format openai):

openai: status 400 {"error":{"message":"Invalid tool specification at index 6: function.parameters.required must be an array of non-empty strings","type":"invalid_request_error","param":"tools","code":"invalid_tool_spec"}}

Because the tool is in the worker toolset, every worker run fails before the first tool call (terminal state model_error, retries exhausted). The planner and main agent are unaffected — they don't load this tool, which is exactly why only workers die while the rest of the task looks healthy. Anthropic / OpenAI accept the malformed schema silently, so the bug is invisible on those providers and only surfaces on stricter ones (DeepSeek, some gateways).

It was the only malformed tool in the worker's 36-tool payload (verified against a captured raw_request).

Fix

Pass no required args so obj omits the required key entirely:

obj(map[string]any{})  // -> {"type":"object","properties":{}}

Note for existing deployments

Tool schemas are cached in the tools table and SeedTool is insert-only, so this code change only fixes fresh databases. Existing instances also need a one-time DB fix:

UPDATE tools SET schema = schema - 'required' WHERE key = 'list_task_credentials';

(then restart), or a migration that re-seeds this tool's schema into the catalog.

🤖 Generated with Claude Code

Takeover and credit

The fix and the report are by @kiserufetch (first commit a66c716, the obj(map[string]any{}) change). This PR was taken over on the maintainer side to finish it:

  • obj drops blank required names after trimming, and omits the key when nothing is left, so the bug cannot come back through another tool.
  • A one-time, idempotent heal on startup removes the bad required key from list_task_credentials only, when it is exactly [""]. It does not bump tool_schema_refresh_v7 and changes no other tool, description or binding.
  • Tests: schema has no blank required (seeded catalog), obj drops blank names, heal removes the key and is a no-op on a second run, other tools and probe rows are untouched (Postgres).

Verified locally: go build, go vet, go test ./agent/; the heal and its tests were run on a throwaway Postgres 16, with mutation checks. The CI for head a44af3c has not run yet: it is a fork PR awaiting workflow approval.

list_task_credentials takes no parameters but built its JSON Schema with
obj(map[string]any{}, ""), emitting {"type":"object","required":[""],
"properties":{}}. The required array contains an empty string, which strict
function-call validators reject. Observed with DeepSeek through an
OpenAI-compatible gateway (format "openai"):

  openai: status 400 invalid_tool_spec -
  "function.parameters.required must be an array of non-empty strings"

Because the tool is in the worker toolset, every worker run fails before the
first tool call (terminal state model_error); the planner and main agent are
unaffected since they don't load it. Anthropic/OpenAI accept the malformed
schema silently, so it only surfaces on stricter providers.

Pass no required args so obj omits the required key entirely:
{"type":"object","properties":{}}.

Co-Authored-By: Claude Opus 4.8 <[email protected]>

@BaaRai BaaRai left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks, this is a real bug and the one-line fix is correct. I verified it on main: with an empty required argument the seeded schema is {"type":"object","properties":{},"required":[""]}, it is the only one of the 27 builtin seeds with that defect, and after the patch it becomes {"type":"object","properties":{}}. go build ./..., go vet ./agent and go test ./agent pass.

Two things I would like in this PR before merging, both because the fix otherwise does not reach running deployments.

1. Regression test. A small test that walks agent.BuiltinToolSeeds() and fails when any entry of required is the empty string. That is exactly how I confirmed this is the only affected seed today, and it keeps the class from coming back the next time a no-argument tool is added.

2. Self-healing for existing databases. SeedTool is insert-only, so the code change only fixes fresh installs, while the runtime sends the schema stored in the tools row: server/assembly.go unmarshals row.Schema over the code default. I confirmed the bad row exists in a deployed instance ({"type": "object", "required": [""], "properties": {}}), so the bug stays live on every existing install until an operator runs SQL by hand.

The repository already has the pattern for this: the one-time, settings-flag guarded block in server/orchestration.go that refreshes goal_met, insert_assets and list_facts for exactly this reason (SeedTool is first-insert-only, so old rows never pick up new code-defined schemas). A new flag-guarded block calling RefreshToolDefaults("list_task_credentials", ...) would heal upgrades automatically with no operator action. RefreshToolDefaults only rewrites the description and the schema, so agent bindings and the enabled flag are preserved.

The SQL in the description stays useful as a manual workaround, but it should not be the only path.

The diagnosis and the capture are precise, nothing else to change.

@BaaRai

BaaRai commented Nov 2, 2026

Copy link
Copy Markdown
Owner

One caveat on the heal, so you do not get caught by it.

Bumping the shared tool_schema_refresh_v7_* flag also re-runs RefreshToolDefaults over every orchestration and platform tool plus the allow-list, which overwrites descriptions an operator may have edited on those unrelated tools. A dedicated one-time flag that only rewrites this row is safer, or an UPDATE that removes the empty string from required and leaves the description alone.

The substance of the two asks is unchanged: the schema on main is {"type":"object","required":[""],"properties":{}}, list_task_credentials is the only affected seed, and the runtime reads the schema out of the tools row, so an upgraded install keeps the broken one until something rewrites it.

@BaaRai

BaaRai commented Nov 6, 2026

Copy link
Copy Markdown
Owner

Hey, checking in on this. The one-line fix is right, but as noted it only reaches fresh installs. Two small things left before merge:

  1. A regression test that walks agent.BuiltinToolSeeds() and fails when any entry of required is the empty string.
  2. A one-time heal for existing rows, done in code as a step guarded by a settings flag, like the existing ones in server/orchestration.go (not a manual SQL statement). The body of that guarded step is an idempotent UPDATE: UPDATE tools SET schema = schema - 'required' WHERE key = 'list_task_credentials' AND schema->'required' = '[""]'::jsonb. It leaves descriptions untouched and does not rely on RefreshToolDefaults.

If you're short on time, say so and I'll finish it here or in a follow-up that credits you. Otherwise a push this week would be great.

…ist_task_credentials rows

The previous commit stops list_task_credentials from building its schema
with obj(map[string]any{}, ""). Two gaps remained:

- obj still emitted whatever it was given, so the same typo on another tool
  would again produce "required": [""]. obj now drops names that are blank
  after strings.TrimSpace and omits the "required" key when nothing is left.

- Tool schemas are cached in the tools table and SeedTool is insert-only, so
  the code fix only reached fresh installs. Existing databases kept the
  malformed row and strict providers kept rejecting every worker run.
  healListTaskCredentialsSchema runs at startup next to the other tool
  seeds and removes the "required" key from that one row, only when it is
  exactly [""]:

    UPDATE tools SET schema = schema - 'required', updated_at=now()
    WHERE key='list_task_credentials' AND schema->'required' = '[""]'::jsonb

  It is idempotent (a healed row no longer matches), needs no settings flag,
  and leaves the description, bindings, enabled flag and every other tool
  untouched. tool_schema_refresh_v7 is not bumped.

Tests: TestObjDropsBlankRequired and
TestListTaskCredentialsSchemaHasNoBlankRequired (agent),
TestHealListTaskCredentialsSchema (server, Postgres).
@BaaRai
BaaRai merged commit 00f5d8c into BaaRai:main Nov 10, 2026
3 checks passed
@BaaRai BaaRai mentioned this pull request Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants