Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/functions/graph-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import { logger } from "../logger.js";
// duplicating. Provenance is kept on properties.source so imported structure
// is distinguishable from session-derived entities.

// Bounds protect the KV store and the iii invocation budget from very large
// graphs (graphify caps graph.json at 512MiB; a 100k-node import would blow
// the invocation window). Truncation is reported loudly in the result.
// Bounds protect the KV store and the import request from very large graphs
// (graphify caps graph.json at 512MiB; a 100k-node import would stall the
// request). Truncation is reported loudly in the result.
const MAX_FILE_BYTES = 32 * 1024 * 1024;
const MAX_NODES = 5000;
const MAX_EDGES = 20000;
Expand Down
8 changes: 3 additions & 5 deletions src/functions/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ const MAX_GRAPH_QUERY_LIMIT = 5000;
const SNAPSHOT_TOP_NODES = DEFAULT_GRAPH_QUERY_LIMIT;
const SNAPSHOT_KEY = "current";

// `state::list` over a 75K-node scope can exceed the iii invocation
// timeout. The query handler races the enumeration against this budget
// and falls back to the snapshot (or a warning envelope) when the live
// path is too slow. 6000ms leaves headroom under the default 8s engine
// invocation deadline.
// `state::list` over a 75K-node scope is slow. The query handler races
// the enumeration against this budget and falls back to the snapshot (or
// a warning envelope) when the live path is too slow.
const LIVE_ENUMERATION_BUDGET_MS = 6000;

function withTimeout<T>(p: Promise<T>, ms: number, label: string): Promise<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/functions/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ async function findJsonlFiles(
let walked = 0;
// Hard bound on entries visited (regardless of extension) so trees
// dominated by non-jsonl files (node_modules, lockfiles, etc.) cannot
// lock the 30s function timeout. `discovered` may underrepresent the
// stall the request walking them. `discovered` may underrepresent the
// true count when traversalCapped fires — callers should surface that
// distinction to the user.
const traversalCap = Math.max(limit * 50, 50_000);
Expand Down
10 changes: 4 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,10 @@ function clearWorkerPidfile(): void {
} catch {}
}

// Top-level safety net for state invocation timeouts (issue #204).
// Under sustained write load (e.g. Claude Code hooks across many
// projects) `state::set` can occasionally exceed its 30s timeout.
// We don't want one such timeout to terminate the long-lived memory
// service — the rejection is surfaced to the relevant call site via
// .catch() where it matters; everything else is logged-and-continued.
// Top-level safety net (rohitg00/agentmemory#204): one stray rejection
// must not terminate the long-lived memory service. The rejection is
// surfaced to the relevant call site via .catch() where it matters;
// everything else is logged-and-continued.
// Throttle logs to avoid spamming on bursts.
let lastUnhandledLogAt = 0;
process.on("unhandledRejection", (reason) => {
Expand Down
8 changes: 4 additions & 4 deletions src/state/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ export const KV = {
claudeBridge: "mem:claude-bridge",
graphNodes: "mem:graph:nodes",
graphEdges: "mem:graph:edges",
// #814: precomputed snapshot of the top-degree subgraph and aggregate
// type counts. Saves /graph/query and /graph/stats from a full
// kv.list enumeration over 75K+ node corpora, which exceeds the iii
// invocation timeout and surfaces as "Invocation stopped" 500s.
// rohitg00/agentmemory#814: precomputed snapshot of the top-degree
// subgraph and aggregate type counts. Saves /graph/query and
// /graph/stats from a full kv.list enumeration over 75K+ node corpora,
// too slow to run per request.
// Single fixed key ("current") so writes are read-modify-write under
// the same keyed mutex as graph-extract.
graphSnapshot: "mem:graph:snapshot",
Expand Down
4 changes: 2 additions & 2 deletions src/triggers/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1565,8 +1565,8 @@ export function registerApiTriggers(
if (authErr) return authErr;
// mem::export already supports maxSessions/offset internally,
// but the HTTP endpoint hardcoded an empty payload — so /export on a
// real corpus (40 sessions × 34K observations × 8K memories) hit the
// iii engine invocation timeout and `agentmemory status` reported 0.
// real corpus (40 sessions × 34K observations × 8K memories) had to
// load the whole store in one request.
// Pass through the query-string pagination so callers can chunk.
const rawMax = req.query_params?.["maxSessions"];
const rawOffset = req.query_params?.["offset"];
Expand Down
8 changes: 4 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,10 +537,10 @@ export interface GraphQueryResult {
// detect when the default was applied vs an explicit `limit`.
limit?: number;
offset?: number;
// #814: indicates the response came from the precomputed top-degree
// snapshot rather than a live kv.list enumeration. Set only on the
// empty-body / nodeType-only branch on large corpora where the
// unbounded enumeration would exceed the iii invocation timeout.
// rohitg00/agentmemory#814: indicates the response came from the
// precomputed top-degree snapshot rather than a live kv.list
// enumeration. Set only on the empty-body / nodeType-only branch on
// large corpora where the unbounded enumeration is too slow.
fromSnapshot?: boolean;
// #814: when the snapshot is stale or absent and the live fallback
// also failed, expose an explanatory note so the viewer can surface
Expand Down
4 changes: 2 additions & 2 deletions src/viewer/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2651,8 +2651,8 @@ <h1>agentmemory</h1>
var el = document.getElementById('view-memories');
if (!state.memories.loaded) el.innerHTML = '<div class="loading">Loading memories...</div>';
// cap at 2000 so the viewer remains responsive on large
// corpora. Older endpoints returned the full unbounded list which
// hit the iii invocation timeout and the UI fell through to 0.
// corpora. Older endpoints returned the full unbounded list, too
// slow to load on a large store.
var result = await apiGet('memories?latest=true&limit=2000');
var items = (result && result.memories) || [];
// Newest first — server returns KV-insertion order.
Expand Down
Loading