Skip to content

feat(#527,#528): /namespaces?with_counts=true + GET /recent endpoint - #530

Merged
ajianaz merged 4 commits into
developfrom
feat/issue-527-namespaces-with-counts
Jul 2, 2026
Merged

ajianaz merged 4 commits into
developfrom
feat/issue-527-namespaces-with-counts

Conversation

@ajianaz

@ajianaz ajianaz commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Fixes #527, Fixes #528

#527 — GET /namespaces?with_counts=true

Problem

No lightweight way to get per-namespace memory counts. Clients must fetch full memory arrays (limit:500) per namespace just to count them.

Solution

Enrich existing /namespaces endpoint with optional query param:

```
GET /namespaces → ["default", "cto", "kai"]
GET /namespaces?with_counts=true → [{"name":"default","count":432},{"name":"cto","count":28}]
```

Core: new list_namespaces_with_counts() in tags.rs + operations.rs.

#528 — GET /recent

Problem

No endpoint for recent memories across all namespaces. Dashboard clients fan out N requests.

Solution

```
GET /recent?limit=20&offset=0&namespace=cto
```

Thin GET wrapper over list() — leverages the cross-namespace fix from #526.

  • Default: all namespaces, limit 20
  • Optional: namespace filter, offset for pagination

Files changed

  • crates/uteke-core/src/memory/tags.rs — list_namespaces_with_counts()
  • crates/uteke-core/src/operations.rs — expose new method
  • crates/uteke-server/src/handlers.rs — enriched /namespaces + new /recent

Depends on

@github-actions

github-actions Bot commented Jul 1, 2026 •

Copy link
Copy Markdown

🔍 Cora AI Code Review

⚠️ Review recommended — warnings found.

🟡 Warning (1)

  • unknown:? — Cora AI review could not complete: failed to parse LLM JSON response: duplicate field prompt_tokens at line 1 column 2993: {"id":"chatcmpl-202607020054486374144418268d9d6jMqIC03Z","model":"gpt-5.4","object":"chat.completion","created":1782953689,"choices":[{"index":0,"message":{"role":"assistant","content":"[\n {\n "file": "crates/uteke-server/src/handlers.rs",\n "line": 444,\n "severity": "major",\n "issue_type": "bugs",\n "title": "with_counts detection matches unrelated query values",\n "body": "The new /namespaces handler enables count mode with let with_counts = path.contains(\\\"with_counts=true\\\");. This checks the raw path as a substring, so requests like /namespaces?foo=with_counts=true or /namespaces?with_counts=trueish will incorrectly activate the counted response. Since this endpoint already uses query parsing helpers elsewhere, this is a concrete correctness bug in how the request is interpreted.",\n "suggested_fix": "Parse the query parameter explicitly, e.g. extract the query string and use parse_query_param(query, \\\"with_counts\\\") == Some(\\\"true\\\".to_string()) or equivalent."\n },\n {\n "file": "crates/uteke-server/src/handlers.rs",\n "line": 468,\n "severity": "major",\n "issue_type": "bugs",\n "title": "Unbounded recent endpoint allows arbitrary large limits",\n "body": "The /recent handler parses limit directly from the query string and passes it to uteke.list(None, limit, offset, ns.as_deref()), defaulting only when parsing fails. Unlike a fixed page size, this accepts any usize, so a client can request an extremely large limit and force the server to fetch and serialize a huge result set. This is a concrete input-validation gap on a public endpoint and can cause resource exhaustion or severe latency spikes.",\n "suggested_fix": "Clamp limit to a reasonable maximum before calling uteke.list, for example let limit = parsed_limit.unwrap_or(20).min(100);."\n },\n {\n "file": "crates/uteke-core/src/memory/tags.rs",\n "line": 372,\n "severity": "minor",\n "issue_type": "bugs",\n "title": "Namespace count is read as u32 and may truncate large totals",\n "body": "In list_namespaces_with_counts, the query result is converted with row.get::\u003c_, u32\u003e(1)? as usize. COUNT(*) in SQLite can exceed u32::MAX, and using u32 here will fail or truncate for sufficiently large datasets before widening to usize. Since the API returns usize, the intermediate narrowing is unnecessary and risks incorrect results on large databases.",\n "suggested_fix": "Read the count as a wider integer type such as u64 or i64, then convert carefully to usize."\n }\n]"},"finish_reason":"stop"}],"usage":{"prompt_tokens":2615,"completion_tokens":581,"total_tokens":3196,"prompt_tokens_details":{"cached_tokens":0,"text_tokens":0,"audio_tokens":0,"image_tokens":0},"completion_tokens_details":{"text_tokens":0,"audio_tokens":0,"image_tokens":0,"reasoning_tokens":0},"input_tokens":2615,"output_tokens":581,"input_tokens_details":null,"claude_cache_creation_5_m_tokens":0,"claude_cache_creation_1_h_tokens":0}}. Review was skipped; no code quality issues were found by the automated check.

Review powered by cora-cli · BYOK · MIT

ajianaz added 2 commits July 2, 2026 06:46
#527 — GET /namespaces?with_counts=true
Returns [{name, count}] per namespace instead of plain string array.
Eliminates N× full-list fetches by clients just to get counts.
Core: list_namespaces_with_counts() in tags.rs + operations.rs

#528 — GET /recent?limit=20&namespace=X&offset=0
Returns most recent memories across all (or specified) namespaces.
Thin GET wrapper over list() — leverages #526 cross-namespace fix.
Params: limit (default 20), offset (default 0), namespace (optional)
@ajianaz
ajianaz force-pushed the feat/issue-527-namespaces-with-counts branch from f9a8fe8 to f00d485 Compare July 1, 2026 23:46
if with_counts {
match uteke.list_namespaces_with_counts() {
Ok(counts) => {
#[derive(serde::Serialize)]

// ── Recent (#528) ──────────────────────────────────────────────
(Method::Get, p) if p == "/recent" || p.starts_with("/recent?") => {
let ns = parse_query_namespace(&path);
ajianaz added 2 commits July 2, 2026 07:48
Namespace count query returned integer from SQLite but tried to
deserialize as usize — rusqlite doesn't implement FromSql for
usize. Use u32 which is safe for any realistic count and supported
by rusqlite directly.
handlers.rs passed Option<String> ns to list() which expects
Option<&str>. Use .as_deref() for the conversion.
@ajianaz
ajianaz merged commit 4b59f0b into develop Jul 2, 2026
9 checks passed
@ajianaz
ajianaz deleted the feat/issue-527-namespaces-with-counts branch July 2, 2026 01:00
ajianaz added a commit that referenced this pull request Aug 13, 2026
…th-counts

feat(#527,#528): /namespaces?with_counts=true + GET /recent endpoint
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.

feat: /recent endpoint — recent memories across all namespaces feat: /count endpoint or /namespaces?with_counts=true

2 participants