fix: keep malformed arguments and account entries inside the error hierarchy
GL
3d ago+49+49+01234567890123456789-7-7-0123456789
What
StackOneTool._parse_argumentsraisesToolArgumentsError("Tool arguments for {tool} must have string keys") when the arguments dict has a non-string key, andStackOneToolSet.execute()raisesToolsetConfigError("arguments must have string keys") for the same input.StackOneToolSet._fetch_active_account_idsignoresGET /accountsentries that are not objects, and only treats a non-empty stringidas 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 callskey.startswith("headers_")on every top-level key. The nestedheaderspath 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 example5) was taken as an account id and sent asx-account-id.fetch_accounts()already skips such entries withisinstanceguards when it records end users and providers; discovery now does the same.
| Input | Before | After |
|---|---|---|
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] | AttributeError | ToolsetConfigError: 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
mainwithAttributeErrorand 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)
| Gate | Result |
|---|---|
| Repo skills | none in repo |
| /forge:forge | ran on cd284d5: test docstrings now state the contract; re-run on f27f683: 4 comment lines, longest block 1, 0 copies |
| Security scan | security-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 security | clean on e03e85a (job c8a37fd3) and f27f683 (job b2f55e81) |
| /security-review | ran: secrets, input validation, transport and DoS items clean; the server-side items do not apply to an SDK |
| /code-review | medium 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 |
| CI | green on f27f683: 10 pass, 3 skipped |
| Unresolved review threads | 0 |
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(fromtool.execute()) orToolsetConfigError(fromtoolset.execute()) instead of crashing during header sanitising. - Account discovery now skips non-dict entries and non-string account ids in
GET /accountsresponses; 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.