Repository navigation
fix(viewer): dashboard shows 0 sessions when unbounded KV scopes overflow iii invocation #1324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -865,24 +865,15 @@ export function registerApiTriggers( | |
| const filtered = filterAgentId | ||
| ? sessions.filter((s) => s.agentId === filterAgentId) | ||
| : sessions; | ||
| // Bounded fan-out: each kv.get is a full engine invocation, so | ||
| // Promise.all over hundreds of sessions saturates the invocation | ||
| // pool. Batch in chunks of 10 (parallel within a chunk, sequential | ||
| // across chunks); the summaries array stays index-aligned with | ||
| // `filtered`. | ||
| const summaries: Array<SessionSummary | null> = []; | ||
| for (let batch = 0; batch < filtered.length; batch += 10) { | ||
| const chunk = filtered.slice(batch, batch + 10); | ||
| const results = await Promise.all( | ||
| chunk.map((s) => | ||
| kv.get<SessionSummary>(KV.summaries, s.id).catch(() => null), | ||
| ), | ||
| ); | ||
| summaries.push(...results); | ||
| } | ||
| const withSummary = filtered.map((s, i) => | ||
| summaries[i] ? { ...s, summary: summaries[i] } : s, | ||
| ); | ||
| const summariesList = await kv.list<SessionSummary>(KV.summaries).catch(() => []); | ||
| const summaryBySessionId = new Map<string, SessionSummary>(); | ||
| for (const sm of summariesList) { | ||
| if (sm?.sessionId) summaryBySessionId.set(sm.sessionId, sm); | ||
| } | ||
| const withSummary = filtered.map((s) => { | ||
| const sum = summaryBySessionId.get(s.id); | ||
| return sum ? { ...s, summary: sum } : s; | ||
| }); | ||
| return { status_code: 200, body: { sessions: withSummary } }; | ||
| }, | ||
| ); | ||
|
|
@@ -2027,8 +2018,11 @@ export function registerApiTriggers( | |
| async (req: ApiRequest): Promise<Response> => { | ||
| const authErr = checkAuth(req, secret); | ||
| if (authErr) return authErr; | ||
| const semantic = await kv.list<import("../types.js").SemanticMemory>(KV.semantic); | ||
| return { status_code: 200, body: { semantic } }; | ||
| const limitParam = parseOptionalPositiveInt(req.query_params?.["limit"]); | ||
| const limit = limitParam ?? 100; | ||
|
Comment on lines
+2021
to
+2022
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚀 Performance & Scalability | 🟠 Major | ⚡ Quick win Enforce a bounded
Return As per coding guidelines, validate inputs at system boundaries, including REST endpoints. Also applies to: 2038-2039, 2055-2056 🤖 Prompt for AI AgentsSource: Coding guidelines |
||
| const allSemantic = await kv.list<import("../types.js").SemanticMemory>(KV.semantic); | ||
| const semantic = allSemantic.slice(0, limit); | ||
| return { status_code: 200, body: { semantic, total: allSemantic.length } }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: #!/bin/bash
set -euo pipefail
rg -n -P -C 12 "apiGet\\('(semantic|procedural|relations)(\\?|')" src/viewer/index.html
rg -n -P -C 12 "\\b(semantic|procedural|relations)\\b" src/viewer/index.html
rg -n -P -C 8 'api::(semantic-list|procedural-list|relations-list)|/agentmemory/(semantic|procedural|relations)' srcRepository: rohitg00/agentmemory Length of output: 19030 🏁 Script executed: #!/bin/bash
set -euo pipefail
printf '%s\n' '--- endpoint consumers ---'
rg -n -P -C 10 "apiGet\\(['\"](?:semantic|procedural|relations)(?:\\?|['\"])" src
rg -n -P -C 8 "/agentmemory/(?:semantic|procedural|relations)|api::(?:semantic-list|procedural-list|relations-list)" src
printf '%s\n' '--- dashboard state, counts, and collection iteration ---'
rg -n -P -C 8 "dashboard\\.(semantic|procedural|relations)|d\\.(semantic|procedural|relations)|semFacts|procItems|relItems|semantic.*length|procedural.*length|relations.*length|total" src/viewer/index.htmlRepository: rohitg00/agentmemory Length of output: 40800 Use The dashboard correctly unwraps 🤖 Prompt for AI Agents |
||
| }, | ||
| ); | ||
| sdk.registerTrigger({ | ||
|
|
@@ -2041,8 +2035,11 @@ export function registerApiTriggers( | |
| async (req: ApiRequest): Promise<Response> => { | ||
| const authErr = checkAuth(req, secret); | ||
| if (authErr) return authErr; | ||
| const procedural = await kv.list<import("../types.js").ProceduralMemory>(KV.procedural); | ||
| return { status_code: 200, body: { procedural } }; | ||
| const limitParam = parseOptionalPositiveInt(req.query_params?.["limit"]); | ||
| const limit = limitParam ?? 100; | ||
| const allProcedural = await kv.list<import("../types.js").ProceduralMemory>(KV.procedural); | ||
| const procedural = allProcedural.slice(0, limit); | ||
| return { status_code: 200, body: { procedural, total: allProcedural.length } }; | ||
| }, | ||
| ); | ||
| sdk.registerTrigger({ | ||
|
|
@@ -2055,8 +2052,11 @@ export function registerApiTriggers( | |
| async (req: ApiRequest): Promise<Response> => { | ||
| const authErr = checkAuth(req, secret); | ||
| if (authErr) return authErr; | ||
| const relations = await kv.list<import("../types.js").MemoryRelation>(KV.relations); | ||
| return { status_code: 200, body: { relations } }; | ||
| const limitParam = parseOptionalPositiveInt(req.query_params?.["limit"]); | ||
| const limit = limitParam ?? 100; | ||
| const allRelations = await kv.list<import("../types.js").MemoryRelation>(KV.relations); | ||
| const relations = allRelations.slice(0, limit); | ||
| return { status_code: 200, body: { relations, total: allRelations.length } }; | ||
| }, | ||
| ); | ||
| sdk.registerTrigger({ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win
Run the independent KV reads in parallel.
kv.list(KV.summaries)does not depend on the session list. Start both reads withPromise.allto avoid adding a full KV round-trip to every/agentmemory/sessionsrequest.As per coding guidelines, run independent KV reads or writes in parallel with
Promise.allwhere possible.Suggested fix
🤖 Prompt for AI Agents
Source: Coding guidelines
🚀 Performance & Scalability | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: rohitg00/agentmemory
Length of output: 29738
🏁 Script executed:
Repository: rohitg00/agentmemory
Length of output: 13190
🌐 Web query:
iii-sdk 0.11.2 StateKV list limit count API💡 Result:
In the iii-sdk (version 0.11.2), the StateKV
state::listfunction does not supportlimitorcountparameters [1][2][3]. Thestate::listAPI is designed to retrieve all values stored within a specific scope [1][4]. According to official documentation, it returns a flat array of every value present in that scope [3]. Because it returns the entire dataset for a scope, it is explicitly recommended to be used sparingly and is considered best suited for cron-driven batch operations rather than hot paths [2]. There is no pagination, limit, or count functionality available for thestate::listoperation [1][3]. If you require only specific keys or a subset of data, you may need to fetch the full list and perform filtering within your application logic, or utilize other State operations such asstate::getif you know the specific keys required [2][3].Citations:
🏁 Script executed:
Repository: rohitg00/agentmemory
Length of output: 6346
🌐 Web query:
site:iii.dev/docs/0-11-2 state::list StateKV pagination limit count💡 Result:
state::listin iii v0.11.2 does not support pagination parameters such aslimit,count, oroffset. Its request contains only:{ "scope": "your-scope" }It returns a flat array of all values in that scope.
StateKVlikewise does not expose built-in pagination for this operation. (iii.dev)To paginate, store/query records using another system or implement application-level slicing after retrieval.
Citations:
🏁 Script executed:
Repository: rohitg00/agentmemory
Length of output: 18020
Avoid unbounded
state::liston paged endpoints.StateKV.list()sends only{ scope }tostate::list. iii-sdk 0.11.2 returns the complete scope and provides no server-sidelimit,offset, pagination, orcountAPI. Theslice()andfiltered.lengthcalls therefore materialize the full memory, semantic, procedural, relation, session, and summary scopes before limiting the response. Large scopes can exhaust invocation memory or time even for small pages. Redesign these reads with indexed paging andstate::getrather than adding parameters tokv.list.🤖 Prompt for AI Agents