Repository navigation
Conversation
There was a problem hiding this comment.
Request changes (1 P1, 1 P2, 1 P3)
Scope: base main, merge base 1ffbcd28; 1 commit and 4 files reviewed at 212f6279. Helper skills loaded: coderbook, ponytail-review, karpathy-guidelines. Ran in a separate session.
Findings
P1
1. The HTTP route rejects the new cursors, so page 2 always fails (apps/node-services/src/memory/server.ts:717)
parseMemoryEntryListRequeststill requirescursorto match/^[0-9]{1,9}$/uand throwsTypeErrorotherwise.onError(server.ts:85) turns that into HTTP 400.MemoryCatalog.listnow returnsnext_cursorfromencodeCursor(memory-catalog.ts:256), which is base64url JSON and never all digits. When TeamHub sends that cursor back, Node Services answers 400. TeamHub treats it as an internal error (apps/teamhub/internal/memoryclient/client.go:196,handlers_personal_wiki.go:93).- Who is affected:
listReportsinapps/web/src/features/memory/wiki-period-reports.ts:33-50loops over every page withlimit: 100. Any Agent with more than 100 daily pages (about three months of history) gets an error for the whole Daily report list instead of a second page. Before this PR, the numeric offset cursor passed this check. - Why the tests miss it:
memory-browser.test.tscallslistMemoryEntriesdirectly and never goes through the HTTP parser. - Fix: drop the cursor format check from
parseMemoryEntryListRequest, or relax it to the contract's opaqueCursor(1 to 1024 chars,contracts/openapi/components/common.yaml:40).cursorStartalready throwsTypeErroron a malformed cursor. Add an HTTP-level test inserver.test.tsthat followsnext_cursorto the second page.
P2
2. MEMORY_REVISION_FILE is defined a second time (apps/node-services/src/memory/memory-catalog.ts:10)
fs-utils.ts:8already exportsMEMORY_REVISION_FILE, andmarkMemoryChangedwrites it. The catalog's whole invalidation scheme depends on both copies naming the same file. If one is renamed and the other is not, the catalog stops seeing writes and falls back to the 5-second staleness scan without any error.- Fix:
import { MEMORY_REVISION_FILE, walkFiles } from "./fs-utils.js";and delete the local constant.
P3
3. Unused injection options and exports (apps/node-services/src/memory/memory-catalog.ts:41-45, 246, 251, 261)
- The
stat,walkandnowconstructor options have no caller. The tests inject onlyreadFileandmaxStalenessMs(tests/memory/memory-catalog.test.ts:62-68). resetMemoryCatalogssays "tests use it between cases", but nothing calls it.encodeCursorandcursorStartare exported but used only inside this module.- Fix: delete the three options and
resetMemoryCatalogs, and make the cursor helpers module-private. That removes about 15 lines.
Verified as fine
- The revision token is the same file the writers bump.
agentWorkspaceRoot(dataRoot, agentId)/memory.revision(memory-catalog.ts:208) matchesmarkMemoryChanged(fs-utils.ts:18-20), which writes it through an atomic rename with a fresh UUID. Service writers call it after their writes (apply.ts:123,sync-runners.ts:153,published-memory-files.ts:201,rebuild.ts:171). - Entry IDs,
kindclassification,dateextraction and sort order are moved unchanged from the oldmemory-browser.ts: sameentryIdhash input, sameclassifyPathregexes, sameupdatedAt desc, relativePath asccomparator (memory-catalog.ts:191-195). The published IDs stay stable. - Only one scan runs at a time.
#refreshand#rescanboth join#refreshing(memory-catalog.ts:119, 132).#sortedand#byIdare swapped only at the end of#scan, so a scan that fails partway leaves the previous snapshot in place.#refreshingis cleared infinally. - A page that disappears between the walk and the
stat/readFileis skipped onENOENT, and any other error still propagates (memory-catalog.ts:153-171). - A missing
timeline/*directory gives an empty walk (walkFilescheckspathExists,fs-utils.ts:97-100). - The cursor sort key compares the same
updatedAtISO strings andrelativePaththat the list is sorted by, so it skips correctly across an inserted page. A legacy numeric cursor is clamped to the list length (memory-catalog.ts:267-268). - The LRU cache is bounded at 32 workspaces, and its key is derived from
agentWorkspaceRoot, which runsassertSafeAgentIdfirst (paths.ts:7-9). - No CJK in the added lines. No contract, generated or env changes.
Process notes
- The commit
212f6279has only a subject. The repo's commit convention also asks for a body that says what changed and which problem it solves. No merge or fixup commits. The branch is up to date withmain.
CI
The checks that ran passed (changes, repository-gate, check (web)); every other lane was skipped. The Node Services tests are not in PR CI, as the PR body notes, so the new catalog and browser tests and the HTTP path were not run in CI. I did not run tests myself: finding 1 is clear from the parser regex in server.ts:717 and the cursor format in memory-catalog.ts:256.
Automated review by Claude Code
Automated review of 212f627 by Claude Code.
|
Thanks for this one. The design looks right to me: entry IDs, sort order and the API shape are unchanged, legacy numeric cursors keep working, and the I checked out the head (212f627) and ran it locally on macOS: node-services Blocking: one new test is flaky
The two pages are written back to back without explicit times, so their mtimes often land in the same millisecond. The sort then falls back to Non-blocking
|
|
Follow-up now that #374 has merged (e777e3e). Two more things are needed before this can land, plus two smaller ones. Needed
Smaller
|
212f627 to
bf6f37f
Compare
|
Thanks — all of it is in Needed
Smaller
Bot P3: dropped the unused On merge order: with #374 in, the fallback runs before the catalog, so a damaged report cannot fail the whole list. The only remaining trade-off is the mixed-version cursor note. If you would rather keep old processes working during a rollout, I can make |
There was a problem hiding this comment.
Request changes (1 P1, 1 P2, 1 P3)
Scope: follow-up on 212f627. Base main, merge base 2f03b64f, 1 commit (bf6f37f7), 5 files reviewed. The previous head was rebased onto a newer main, so I compared the memory files across both heads and re-read the full merge-base diff. Loaded coderbook, ponytail-review and karpathy-guidelines. Ran in a separate session.
Previous findings
- P1 HTTP layer rejects the new base64url cursor: Not resolved.
apps/node-services/src/memory/server.ts:717still requirescursorto match^[0-9]{1,9}$. The internal contractcontracts/openapi/node-services-internal/openapi.yaml:656also still declares that pattern. Everynext_cursorthe catalog now returns is base64url JSON (memory-catalog.ts:246-252), so fetching page 2 still returns 400 (Memory entry list request is invalid). TeamHub passes the cursor through unchanged: its publicCursoris an opaque string of up to 1024 chars (contracts/openapi/components/common.yaml:40-44). Once a Human has more than one page of reports (limit at most 100, default 50), "load more" in the Web Memory list fails. No test sends a catalog cursor through the HTTP route. The new tests callMemoryCatalog/listMemoryEntriesdirectly. - P2
MEMORY_REVISION_FILEdefined twice: Not resolved.memory-catalog.ts:10still declares its own"memory.revision", whilefs-utils.ts:8exports the same constant thatmarkMemoryChangedwrites. These are two sources of truth for the invalidation token. - P3 unused injection points and exports: Resolved. The
walkoption andresetMemoryCatalogsare gone, andencodeCursor/cursorStartare now module-private.stat/noware used by the stat-only refresh test (memory-catalog.test.ts:284-291).
Findings
P1
apps/node-services/src/memory/server.ts:717: see the previous finding above. It still blocks merge. Fix: accept the opaque cursor here (for example^[A-Za-z0-9_-]{1,1024}$, or just a length bound, sincecursorStartalready rejects malformed input withTypeError). Relax thecursorpattern incontracts/openapi/node-services-internal/openapi.yaml, runpnpm contracts:generate, and add an HTTP-level test that pages twice through/internal/v1/memory/entries.
P2
apps/node-services/src/memory/memory-catalog.ts:10: the duplicateMEMORY_REVISION_FILE(previous finding). Import it from./fs-utils.jsand delete the local constant.
P3
apps/node-services/src/memory/memory-catalog.ts:277: the cursor tie-break uses code-unit comparison (file.relativePath > p), but the list is sorted withlocaleCompare(:194-198). Example:timeline/daily/a.mdandtimeline/daily/B.mdhave the same mtime to the millisecond, and a page ends ata.md.localeCompareputsB.mdaftera.md, but"B.md" > "a.md"is false, so the next page silently skipsB.md. Service-written date names don't hit this, but externally created pages can. Fix: compare paths with the same function in both places (plain</>in the sort, orlocaleCompareincursorStart).
Verified as fine
- Invalidation token location: the catalog reads
<workspace>/memory.revisionviaagentWorkspaceRoot(memory-catalog.ts:207,:225). This is the same filemarkMemoryChangedrenames into place (fs-utils.ts:18-30). - A cache miss in
getforces one rescan, so a page written without a revision bump is still found (memory-catalog.ts:98-105). Concurrent refreshes share one in-flight scan (:115-135). - A page that disappears between walk, stat and read is skipped during the scan (
:151-172).getMemoryEntrymapsENOENTon read to not-found (memory-browser.ts:61-69). - Entry IDs (
sha256(agentId\0relativePath)truncated to 24 hex chars), path classification, date derivation and sort order match the deletedcollectMemoryFileslogic. Published IDs are therefore unchanged. - Legacy numeric cursors are still honored inside the catalog (
memory-catalog.ts:261-262). - The per-process LRU is capped at 32 workspaces (
:238-241). Catalogs are keyed by workspace root, so tests that use separate temp data roots do not share state. - No CJK in added lines or the commit message. The commit is a single conventional commit.
Process notes
- None. The branch is a single commit with no merge or fixup commits.
CI
changes,check (web)andrepository-gatepass. Everything else was skipped. Node Services tests (check-node-services) are a heavy lane, so PR CI did not run the new catalog or browser tests or any HTTP-route test. I ran no tests myself: the P1 follows directly from the regex atserver.ts:717and the base64url cursor format.
Automated review by Claude Code
Automated review of bf6f37f by Claude Code.
bf6f37f to
b4694cc
Compare
|
Fixed in P1 (blocking) — P2 — P3 — the cursor tie-break uses Local: 24 tests across catalog/browser/HTTP/server-http pass; typecheck, eslint, prettier and |
There was a problem hiding this comment.
Approve with nits (1 P2, 1 P3)
Scope: base main, merge base 2f03b64f, 1 commit, 8 files reviewed. Follow-up on bf6f37f. Loaded the review recipe's criteria (coderbook §二/三/五, ponytail-review §1–3, karpathy-guidelines §2–3); ran in a separate session.
Previous findings
- Resolved: cursor comparison didn't match the sort order.
apps/node-services/src/memory/memory-catalog.ts:274-276now comparesrelativePathwithlocaleCompare, the same comparator#scansorts with (memory-catalog.ts:192-196). The new testpages across paths that localeCompare orders differently from code units(a.md/B.mdwith the same mtime) fails without the fix: the old>comparison returns an empty second page.
Since bf6f37f the commit also widened the server's cursor validation (server.ts:717) and the request-parameter pattern, and added memory-http-cursor.test.ts. That test pages through the real HTTP server with the cursor the response returned, so the new cursor format is now accepted end to end.
Findings
P2
contracts/openapi/node-services-internal/openapi.yaml:1741: the response schemaMemoryEntryPage.next_cursorstill sayspattern: ^[0-9]{1,9}$, but the server now returns a base64url JSON key (memory-catalog.ts:248-254, e.g.eyJwIjoi...). The PR widened only the request parameter (line 656). The internal contract now describes a response the server can't produce. Any consumer or contract test that validates responses against it would reject every non-final page. Nothing validates this response at runtime today: the generated Go/TS code carries no pattern, and there's no embedded spec. Fix: givenext_cursorthe same^[A-Za-z0-9_-]{1,1024}$pattern, or$refthe sharedcommon.yaml#/components/schemas/Cursorthe publicMemoryEntryPagealready uses.
P3
apps/node-services/src/memory/README.md:24: "The published entry IDs, sort order and cursor semantics are unchanged." The cursor did change, from an array offset to anupdated_at+ path key, and older servers reject the new format. The PR body says the same in its Boundary section. Say what the cursor is now (an opaque sort key, stable across inserts, with numeric offsets still accepted) instead of calling it unchanged.
Verified as fine
- Invalidation keys off the real token:
markMemoryChangedwritesagentWorkspaceRoot(dataRoot, agentId)/memory.revision(fs-utils.ts:18-30). The catalog reads the same path through the sharedMEMORY_REVISION_FILE(memory-catalog.ts:5,205), with the sameagentManagementIdsubject key the old walk used (memory-browser.ts:29-32). - Only one scan runs at a time:
#rescanjoins any in-flight#refreshingpromise (memory-catalog.ts:127-133).#sortedand#byIdare swapped only at the end of a scan, so a concurrentlistnever sees a half-built index. If a write lands mid-scan, the scan records the old revision and the nextlistrescans. - A page removed between walk and stat/read is skipped on
ENOENT(memory-catalog.ts:149-153,165-168). A deleted page served from the cache answers not-found rather than 500 (memory-browser.ts:61-69). - Entry IDs are unchanged:
entryIdis moved verbatim (memory-catalog.ts:292-298), and so areclassifyPath,metadataDateandpathDate. The old helpers are gone frommemory-browser.ts, so nothing dead is left behind. - Cursors: numeric legacy cursors are still served (
memory-catalog.ts:258-260). A base64url cursor of{"p":...}always starts witheyJ, so it can't be mistaken for a numeric one. Malformed cursors throwTypeError, which maps to 400 (covered byrejects a cursor that is not opaque page data). The worst-case cursor length (a 255-byte file name) is about 420 characters, well under the 1024 limit on both the internal and public (common.yaml:40-44) contracts. - TeamHub passes the cursor through as an opaque string (
handlers_personal_wiki.go:78-88,memoryclient/client.go:175-177), and the public contract already types it as an opaqueCursorof at most 1024 characters. No TeamHub or Web change is needed. - The LRU cap of 32 workspaces is enforced on insert (
memory-catalog.ts:237-240). - No CJK in added lines or the commit message, and no merge or fixup commits.
Process notes
mainis 8 commits ahead of the merge base. The branch needs a rebase before it can merge.
CI
changesandcheck (web)pass;check (contracts),check (teamhub-cli)andrepository-gatewere still pending at review time. Node Services tests run in the heavy lane, so PR CI doesn't run them.- Ran locally:
vitest run tests/memory/memory-catalog.test.ts tests/memory/memory-http-cursor.test.ts tests/memory/memory-browser.test.ts: 3 files, 18 tests passed.
Automated review by Claude Code
Automated review of b4694cc by Claude Code.
|
Thanks for the thorough work on this — the design is clean and directly addresses the full-walk overhead by building on Just a few small things to tidy up before we merge:
Once these are in and the branch is rebased on |
Memory browsing walked and parsed every daily and weekly page per request. This keeps one per-Agent catalog keyed by memory.revision and re-reads only pages whose size or mtime changed. The internal response cursor now refs the shared opaque Cursor; get() does not scan twice after a refresh; list guards a zero limit; the README describes the keyset cursor. Rejected drafts and published entry IDs are unchanged.
b4694cc to
de8f651
Compare
|
Thanks — all four are in, rebased onto
Local: 13 catalog + 5 browser + 2 HTTP-cursor + 6 server-HTTP tests pass; typecheck, contracts generate/verify, eslint and prettier are clean. |
There was a problem hiding this comment.
Approve (0 findings)
Follow-up on b4694cc. Merge base 1c35212b (current main tip), 1 commit, 10 files reviewed.
- Resolved: response
next_cursordeclared digit-only (contracts/openapi/node-services-internal/openapi.yaml:1740now refscommon.yaml#/components/schemas/Cursor, generated Go/TS regenerated) - Resolved: README claimed cursor semantics unchanged (
apps/node-services/src/memory/README.md:21-26now describes the opaque keyset cursor and numeric fallback)
Verified as fine
- The catalog reads the same
memory.revisionthat every writer bumps:memoryCatalogForusesagentWorkspaceRoot(dataRoot, agentManagementId)(apps/node-services/src/memory/memory-catalog.ts:236), and writers callmarkMemoryChanged(root, memorySubjectKey)wherememorySubjectKey === agentManagementId(apps/node-services/src/memory/subject.ts:11-12,fs-utils.ts:14-20). - Keyset cursor matches the sort order (
updated_atdesc, path asc):cursorStart(memory-catalog.ts:286-290) vs. the sort atmemory-catalog.ts:205-209. A base64url cursor of{"…can never collide with the legacy numeric form, and it fits the 1024-charCursorlimit that TeamHub passes through unchanged (apps/teamhub/internal/app/handlers_personal_wiki.go:79-88). #refresh()/get()scan at most once per miss, andlistswaps#sortedatomically, so readers never see a half-built index (memory-catalog.ts:99-146,201-209).
CI: all required checks pass. check-node-services is a heavy check that CI does not run. I ran vitest run tests/memory/memory-catalog.test.ts tests/memory/memory-browser.test.ts tests/memory/memory-http-cursor.test.ts myself: 20/20 passed.
Automated review by Claude Code
Automated review of de8f651 by Claude Code.
What and why
listMemoryEntriesandgetMemoryEntrywalkedtimeline/dailyandtimeline/weekly, read every Markdown page, parsed its frontmatter and stat'ed it, on every request. One page per day plus weekly pages means the cost grows with the Agent's history, andgetMemoryEntrypaid the whole walk to find a single page.This adds
apps/node-services/src/memory/memory-catalog.ts: one in-process catalog per Agent workspace that keeps each page's metadata and re-reads a page only when its size or modification time changed. It keys offmemory.revision, the tokenmarkMemoryChangedalready writes after every batch of Memory writes, so a service write invalidates the list immediately. A write that skipped the token is still caught by a 5-second staleness scan and by a forced rescan whengetmisses.memory-browser.tsnow maps catalog pages to the API response, andgetMemoryEntryreads only the requested page. A page deleted outside the service inside the window answers not-found instead of failing on the read.Cursors move from an array offset to the sort key of the last item (
updated_at+ path), so a page inserted between two requests cannot shift or repeat items; numeric cursors from older servers are still accepted.Review fixes (rebased onto 1c35212)
MemoryEntryPage.next_cursornow refscomponents/common.yaml#/components/schemas/Cursorinstead of the digit-only pattern; regenerated Go and TypeScript contracts.#refresh()now reports whether it scanned. Aget(id)miss right after a refresh no longer rescans the whole tree; only a miss with no fresh scan forces a rescan. Added a test that countsstatcalls: one miss after the initial scan stats once.listguards that the page is non-empty before encoding a cursor, so a programmaticlimit: 0returns an empty page instead of throwing. Added a test.updated_at+ path), stable across inserts, with numeric offset cursors still accepted.Measurements
2000 daily pages, local ext4, median of 5 runs:
getby idThe "under 1 ms" row holds inside the five-second metadata window. After it, or after any
memory.revisionbump,listwalks and stats every page but still reads none; the cold row covers that path. The tests assert the read and stat counts deterministically, so the gain does not depend on a benchmark machine.How it was verified
memory-catalog.test.ts(13): cached index not re-read; only a changed page re-read; add/remove after a revision bump; a page written without a bump found; stable cursor across an insertion; legacy offset cursor; invalid cursor; fresh content; published entry IDs; stat-only refresh window;getmiss scans once;limit: 0.memory-browser.test.ts(5),memory-http-cursor.test.ts(2),server-http.test.ts(6): API mapping, HTTP paging with the returned cursor, not-found cases.pnpm --filter @linger/node-services typecheck;pnpm contracts:generateandcontracts:verify; eslint/prettier on the changed files. 26 tests pass across the four files.Boundary
memory.revision; writes that go through the service stay immediate.next_cursorline for meetings. The reviewer asked to land perf(memory): serve the memory browser from an incremental catalog #433 first; after this merges, fix(memory): page meetings by cursor and search their summaries #494 rebases and the shared contract line collapses to one change.