fix: keep malformed arguments and account entries inside the error hierarchy

GL
3d ago
+49-7

What

  • StackOneTool._parse_arguments raises ToolArgumentsError ("Tool arguments for {tool} must have string keys") when the arguments dict has a non-string key, and StackOneToolSet.execute() raises ToolsetConfigError ("arguments must have string keys") for the same input.
  • StackOneToolSet._fetch_active_account_ids ignores GET /accounts entries that are not objects, and only treats a non-empty string id as an active account.

Why

Both paths could raise an AttributeError, which escapes the StackOneError hierarchy CLAUDE.md promises for every public method:

  • tool.execute({1: "x"}) reached _sanitise_header_arguments, which calls key.startswith("headers_") on every top-level key. The nested headers path already skipped non-string keys; the top level did not.
  • Discovery read each account with a.get(...), so a non-dict entry in the list crashed, and any truthy id (for example 5) was taken as an account id and sent as x-account-id. fetch_accounts() already skips such entries with isinstance guards when it records end users and providers; discovery now does the same.
InputBeforeAfter
tool.execute({1: "x"})AttributeError: 'int' object has no attribute 'startswith'ToolArgumentsError
accounts ["junk", {"id": 5, "status": "active"}, {"id": "acc", "status": "active", ...}]AttributeError: 'str' object has no attribute 'get'discovers ["acc"]
accounts with only malformed entries, e.g. ["junk", None]AttributeErrorToolsetConfigError: This API key has no linked accounts. ...

The two "must have string keys" messages are new and are not added to tests/vectors/messages.json, so the shared message vectors are unchanged.

How verified

  • Three new tests; all three fail on main with AttributeError and pass here.
  • uv run ruff check ., uv run ruff format --check ., uv run ty check stackone_ai examples: clean.
  • uv run pytest (Python 3.13, MCP mock via pnpm): 874 passed.

Gates (head f27f683)

GateResult
Repo skillsnone in repo
/forge:forgeran on cd284d5: test docstrings now state the contract; re-run on f27f683: 4 comment lines, longest block 1, 0 copies
Security scansecurity-reviewer agent: no finding at confidence 70 or above. Aikido: 31 open issues on main (lockfile CVEs, workflow SAST, one old test-fixture secret), none on lines this PR changes
Codex securityclean on e03e85a (job c8a37fd3) and f27f683 (job b2f55e81)
/security-reviewran: secrets, input validation, transport and DoS items clean; the server-side items do not apply to an SDK
/code-reviewmedium on cd284d5, 8 candidates. Fixed 4: entries that are not objects are no longer counted as accounts, a list of only such entries reads as "no linked accounts", toolset.execute() refuses non-string keys with ToolsetConfigError as its docstring promises, and the error says the keys must be strings. Declined 4: nested keys serialise through json.dumps as on main, the check stays at parse time (the contract every tool shares), the search/execute double parse is unchanged from main, and the test that asserted the old count is updated
CIgreen on f27f683: 10 pass, 3 skipped
Unresolved review threads0

Requested by guillaume@stackone.com in Slack (repo audit thread)

🤖 Generated with Claude Code


Summary by cubic

Fixes two paths where malformed input crashed with AttributeError instead of raising a StackOneError.

  • Tool calls whose arguments dict has a non-string key now raise ToolArgumentsError (from tool.execute()) or ToolsetConfigError (from toolset.execute()) instead of crashing during header sanitising.
  • Account discovery now skips non-dict entries and non-string account ids in GET /accounts responses; malformed entries are left out of the inactive-account count, and a list of only such entries reads as "no linked accounts".

The two "must have string keys" messages are new and are not added to the shared message vectors.