Repository navigation
fix(storage): raise on unknown get_stats_by group_by; close #476 - #527
Conversation
Closes #476. Three of the five sub-issues in #476 are already resolved on master: - _clamp_limit (mcp/server_support.py:87) already caps at min(limit, 1000), so the "no upper bound → gigabyte JSON response" DoS path is gated. - resolve_id (storage/backends/queries/conversations_identity.py:15) already exposes a `strict: bool = False` parameter, and every destructive MCP call site (server_mutation_tools.py: add_tag, remove_tag, set_meta, delete_conversation, etc.) already passes strict=True. - The MCP wrapper already declares group_by as Literal["provider", "month", "year"] (server_tools.py:214). Two large items remain — asymmetric search/list_conversations filter surfaces (which calls for unifying the tools) and bulk_tag_conversations O(N×M) batching — both are larger refactors and tracked separately in the next slice of MCP work. This change tightens defense-in-depth on the deeper get_stats_by implementation: it previously fell back to provider grouping for any unknown group_by string. Each branch in the SQL is a literal, so no interpolation occurs today, but a future contributor adding a branch that does interpolate would inherit a silent fallback as their input validation. Raise ValueError on unknown group_by instead — the validated top-level Literal never delivers an unknown value, so the only callers who'd hit the raise are misuses worth surfacing. Co-Authored-By: Claude <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~5 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@codex review |
|
Codex Review: Didn't find any major issues. Nice work! ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
## Summary Closes #476. Three of the five sub-issues are already resolved on master; one defense-in-depth tightening remaining. ## Problem #476 catalogued five MCP/storage surface issues. Three are already fixed on master: | Sub-item | Status | | --- | --- | | \`_clamp_limit\` had no upper bound | Already capped at \`min(limit, 1000)\` (\`mcp/server_support.py:87\`) | | \`resolve_id\` prefix-matched on destructive ops | Already exposes \`strict: bool = False\`; every MCP destructive call site (\`server_mutation_tools.py\`: \`add_tag\`, \`remove_tag\`, \`set_meta\`, \`delete_conversation\`, …) already passes \`strict=True\` | | \`get_stats_by\` user string with fragile whitelist | MCP wrapper already declares \`group_by: Literal["provider", "month", "year"]\` (\`server_tools.py:214\`); deeper layer still accepts \`str\` and silently falls back | Two remaining items are larger refactors and tracked separately: - Asymmetric \`search\`/\`list_conversations\` filter surfaces (calls for unifying the tools or extending parameter sets — design choice). - \`bulk_tag_conversations\` O(N×M) in separate transactions (needs batched single-transaction implementation with a size limit). ## Solution Tighten the deeper \`get_stats_by\` (\`storage/backends/queries/stats.py\`) to raise \`ValueError\` on unknown \`group_by\` instead of silently falling back to provider grouping. Each SQL branch is a literal — no interpolation — but a future contributor adding a branch that *does* interpolate would inherit a silent fallback as their input validation. Closing the door on that. ## Verification \`\`\` $ nix develop -c devtools verify --quick verify: all checks passed $ nix develop -c pytest -q tests/ --ignore=tests/integration 5596 passed, 10 xfailed in 160.24s \`\`\` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Enhanced parameter validation to provide explicit error messages for invalid inputs instead of silently defaulting to alternative behavior. <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Claude <[email protected]>
Summary
Closes #476. Three of the five sub-issues are already resolved on master; one defense-in-depth tightening remaining.
Problem
#476 catalogued five MCP/storage surface issues. Three are already fixed on master:
Two remaining items are larger refactors and tracked separately:
Solution
Tighten the deeper `get_stats_by` (`storage/backends/queries/stats.py`) to raise `ValueError` on unknown `group_by` instead of silently falling back to provider grouping. Each SQL branch is a literal — no interpolation — but a future contributor adding a branch that does interpolate would inherit a silent fallback as their input validation. Closing the door on that.
Verification
```
$ nix develop -c devtools verify --quick
verify: all checks passed
$ nix develop -c pytest -q tests/ --ignore=tests/integration
5596 passed, 10 xfailed in 160.24s
```
Summary by CodeRabbit