Skip to content

fix(memory): answer graph requests from the layout and catch it up in the background - #47816

Open
buluoray wants to merge 1 commit into
crew/slack/graph-stored-picturefrom
crew/slack/graph-catch-up
Open

buluoray wants to merge 1 commit into
crew/slack/graph-stored-picturefrom
crew/slack/graph-catch-up

Conversation

@buluoray

@buluoray buluoray commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The Memory graph answers from its layout at once and brings the layout up to date in the background, with real counts on screen, and never shows a forgotten memory's words or dot while it does.

Today every graph request (overview, dots, nodes, search, box count) first brings the layout file up to date with the store when the store changed. On a store that was written to since the last read, a person waits for that work before anything is drawn, and Refresh blocks the request that asked for it.

Why it matters

Opening the graph after a gateway restart, or after an agent wrote many memories, is the slow moment people see. The design in RFC #47713 (the memory graph's server layout) makes the layout file the answer and the catch-up background work; this PR is that step for the requests.

Not a goal

  • Arranging the topic discs at open and at Refresh, and box selection one disc at a time (later in this stack).
  • Changing how a full build lays out a store.
  • A forget made in another tab or by an agent reaching an open page before its next answer (a stated limit of the base PR).

What changed (motivation → approach → change)

Requests waited for the catch-up → they now read the layout file as it is, and the catch-up runs in the background in batches of PLACE_BATCH rows under the file's lock (memory_graph_service.py, memory_graph_sidecar.py). The design follows RFC #47713.

  • Answers from the layout. Overview, dots and nodes pages, search and box count answer without waiting. A pass is numbered (pass_asked, pass_done) and writes only into the build it planned against (same_build, LayoutReplaced).
  • No forgotten memory in any reply while the catch-up runs. The layout file can still hold a row the store forgot until the pass removes it. Each pass records in the layout file's meta where the store's revision log and event log stood when it began (forget_marks). Every reply reads only the log entries after those marks, keeps the ones not live now, and leaves them out (memory_graph_forgotten.forgotten_in): a dots page and a node page leave the dot out, a link to it goes with it, a box (memory_edit._with_box) leaves it out, and a topic that holds it goes unnamed in every overview and poll. So the cost follows the number of changes since the last pass, not the size of the store. Each reply reads the forgotten rows before it reads the layout, so a pass that ends between the two reads has already removed the row (and cleared its topic's name) from what is read after. A layout file with no marks yet (a fresh build before its first pass) is compared with the store whole. Main today never shows these, because it waited for the catch-up; this PR keeps it that way.
  • Refresh waits for its own pass by number, not for "no catch-up", so a second tab that keeps asking cannot hold it; its polls ask for no pass of their own (poll=1). At most REFRESH_WAIT_MS (60 s).
  • A lost poll is asked again. A poll during a read (a build's, or Refresh's wait) whose answer is lost (the network, a 500, 502 or 504) is asked again with back-off up to 8 s, for at most REFRESH_WAIT_MS; a 503 and a pass the server reports failed stay answers (graphPicture.ts, poll).
  • A box count waits for the pass that is due (at most SELECT_WAIT_SECS, 10 s; StoreGraph.wait_for_due_pass), so the layout it names is the one its hand-off to the list and Copy to reads next; main refuses a box after placements on purpose, so the hand-off keeps its exact layout check. The count's reply names the revision it was counted at, never one read after it, so the hand-off takes exactly the rows counted (test a box count names the revision it counted at).
  • What the person sees while a box count waits (from the code, MemoryGraphTab.tsx):
    1. In the count's place: the catch-up's own stage and counts when the server reports them (Laying out N memories · x of N, the same strings beside the age), else "Loading graph data…". Never blank, never the old number: a recount over a swap or a forget shows the same state in the chip's number. No bar is drawn for it.
    2. At 10 s the server answers the count as the layout stands (SELECT_WAIT_SECS), so the person always gets a number; a failed count shows the read-error notice with Retry.
    3. During the wait Escape drops the box (the shared Escape stack covers a pending count), and drawing another box replaces it; a count that answers after either is not taken.
  • Copy notes: no new string. The waiting state reuses pages.overview.memoryGraphTab.loading_graph_data, build_title and build_count, joined by " · " as the topic line already joins its parts.
  • A reply read across a catch-up batch names the newer placement of the same build instead of "changed", so a first open during a long catch-up does not restart its read (_read_at_one_layout).
  • The page shows the work with real counts: Laying out N memories with rows placed of N while it catches up, Reading memories with memories read of the total on a first open, beside the age when nothing waits on it (useGraphPicture.ts, GraphAge.tsx). The catch-up poll goes through the base PR's forget check (startedBeforeForget) like every other graph read.
  • Placement keeps main's free-slot rule in batches (this is why L41-L43 of the line ride along: L44-L47 build on their slot code): a row placed again is read on its old slot, released, then takes its topic's nearest free slot; a layout built before the counts were kept gets them worked out once; a full topic's next dot takes the next slot of its sunflower; a build's dots are checked once for a wrong place.
  • A box count whose revision moved between its two reads (a batch landed) reads the box again, at most three times, instead of answering stale_memory_box.

Backwards compatibility

Compatible: every route keeps its fields; the overview adds catchup, pass_asked and pass_done, and accepts poll=1; an older page that ignores them reads as before.

Removes nothing: no route, field or stored data is removed; the layout file gains meta keys (slots, slots_checked) that an older gateway ignores.

Tests

  • test/test_memory_graph_serve.py: requests answer while a pass is held; one pass at a time; Refresh's pass by number while another reader asks for more; a forgotten memory's text, raw id, opaque id and a topic name made from it are in no reply before, during or after the pass, and a box counts only live memories in every phase; the forgotten rows read from the logs since the marks equal the whole comparison (an experience and a fact), and a memory written again is not held back; a pass that ends between a reply's two reads leaks nothing (overview, dots page, node-page links, box count); a reply read across a placement batch names the newer placement and one read across a rebuild says "changed"; a box count reads the box again when a batch lands between its reads; a box counted while a pass is due hands off under the layout that pass leaves (the list answers 200, not 409). A count whose due pass outlasts the wait answers anyway (test_a_box_count_answers_when_the_due_pass_outlasts_its_wait); the tab shows the waiting state and Escape still drops the box (says the box is being counted while the count waits, and Escape still drops it).
  • test/test_memory_graph_slots.py: slot counts for an older layout, a full topic's next slot, the once-per-build check.
  • website/src/test/memoryGraphCatchUp.test.tsx: the stages and counts, a catch-up end moves nothing, a failed progress poll is asked again, a poll asked before a forget is dropped and asked again, Refresh asks a lost catch-up poll again and swaps once, Refresh takes a 503 on its poll as the answer, Refresh waits for its own pass.
  • Mutations: the name filter, the dots filter, the link filter, the box filter, the read order at each of those four, the build-only layout check, the 503 rule, the forget check on the catch-up poll, the poll retry and the box re-read each turned their test red with the change removed.

Overview open time, 30,368-memory synthetic store (store O's 26,479 rows plus copies of its facts with their vectors, 227 topics), one host, serial, the handler timed in process. Cold is a new StoreGraph as after a gateway restart, with the OS file cache warm; warm is three opens after it. Three runs each:

head cold (ms) warm (ms)
#47741 a7a4ae393c57 320, 324, 377 24-36
this PR f7498e5907ed (the filter as in this head; the head after it only reorders reads) 100, 49, 89 26-33
this PR, forgotten filter off 36, 90, 36 27-38

The forgotten filter alone takes 0.5-0.7 ms per reply. A first version that compared every layout row with the store on each overview added about 65 ms (cold 148-175 ms, warm 93-102 ms) and was replaced by the marks above.

Proof: not provable -- other: prove.py was not run from this scratch clone; each new test was mutation-checked red instead

Local: backend graph, copy and edit files 787 passed (serial, homes pinned to scratch); 14 graph frontend files 287 passed; tsc -b; eslint with no warnings; docs-lint.

Manual verification

Pod frames from this head follow in this description.

Real-machine verification

Machine: one cloud host, Linux x86_64, 32 vCPU; a throwaway pod on a fresh home with a synthetic store, headless Chromium.
Before (base): a graph request after a store write waits for the catch-up.
After (this head): frames follow in this description.
Cleanup: the pod is brought down and its worktree removed after the frames.

Screenshots / video

Frames from this head follow.

Related Issues

Stacked on #47741; base crew/slack/graph-stored-picture. Design: RFC #47713.

Known limits:

  • A first read while a batch moves a memory from a page not yet read into one already read can save a picture without that memory; its topic count still includes it, and the next read draws it (fixed later in this stack).
  • A Refresh whose pass fails while another read has already queued the next pass reads the layout as it is (the old one) instead of showing the failure; the queued pass runs at once, and a failure of it shows with Retry.
  • On a large store whose memories fade, refreshing the weights holds the layout file's lock for the whole store, so a graph request in that moment waits for it.
  • A forget made without a revision or event row (a write that bypasses the store's own writers) is not in the logs, so a reply can still carry that row until the next pass removes it; the catch-up itself does not see such a write either.

Sibling sweep

Swept: git grep -n "nodes_in_box|sidecar.links|ids_at_revision|sidecar.clusters" -- src/kiro_crew/
Sibling: src/kiro_crew/dashboard/handlers/memory_graph_layout_api.py -- changed here
Sibling: src/kiro_crew/memory_edit.py -- changed here
Sibling: src/kiro_crew/memory_graph_selection.py -- not affected -- it reads placed matches of live search scores only

Pattern harvest

Rule candidate: review-prompt
Pattern: a reply built from a derived index (layout file, cache) must filter by the live source when the index can lag it

Checklist

  • A Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...); PR Hygiene does not count commits
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

Contribution License Agreement

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

@buluoray
buluoray requested review from a team and KiroCrewCaptain as code owners December 5, 2026 14:47
@buluoray
buluoray requested review from iamwhatever and removed request for a team December 5, 2026 14:47
@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Dec 5, 2026
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS (a BLOCK with no Trigger and no Outcome does not block)

Design-level review of 96d204053a51d94231139db51a19fa08aac3dab8 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

cannot evaluate: missing screenshot or recording of the new catch-up bar beside the graph age and the box-count waiting chip. This PR adds both, and the evidence list for this revision is empty.

Blockers

No rendered evidence for new graph surfaces
Trigger: GraphAge.tsx now renders "(refreshing || steps) && <GraphBar …>" with no read running, and MemoryGraphTab.tsx adds "data-testid="memory-graph-counting"" showing "Laying out N memories · x of N" in place of the count.
Outcome: a progress bar with counts now appears over the drawn picture after a restart, and the selection chip changes during a box count → design-evidence.txt lists 0 images and 0 recordings, with 0 transport failures → I could not judge where the bar sits next to the age, whether it reads as "graph loading" over a picture that is already drawn, or how the muted chip compares with the lit chip.
Fix: attach to the description a screenshot or recording of this revision showing the bar and counts beside the age during a background catch-up, and the counting chip (both the lit and the picked variant) while a box count waits.
Clears when: design-evidence.txt lists a downloaded user-attachments image or recording, or a committed one under temp-screenshots/ or .github/screenshots/ at this SHA, that shows the catch-up bar and the counting chip.

Notes

  • The description was cut off before the end of its Tests list. Its Backwards compatibility section is complete, and the patch removes no route, field or stored data.

[DESIGN-REVIEWED] 96d2040

Description read

[DESCRIPTION-READ] ec1393f9042270dda44a709c968a998ac5dd338a3280bc2c1ff1c935f54b7856

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS (a BLOCK with no Trigger and no Outcome does not block)

UX-level review of 96d204053a51d94231139db51a19fa08aac3dab8 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

UX-Verdict: PASS

cannot evaluate: missing screenshots of the Memory graph's new states. The PR supplies no image, so the blind read was not performed and nobody has seen what this diff adds.

Evidence gaps

  • Box-count waiting chip (memory-graph-counting): no screenshot shows the chip text that stands in for the count, either "Laying out N memories · x of N" or "Loading graph data…". It appears in the lit chip's place and inside the picked chip's graph_selected span. A screenshot of a box drawn while a catch-up is due would close this gap.
  • Background catch-up bar beside the age (GraphAge, the (refreshing || steps) bar): no screenshot shows the bar drawn over a still picture when no read is waiting. A screenshot of the graph mid catch-up, with the age, bar and stage line visible, would close this gap.
  • "Reading memories · x of N" stage under the bar on first open (readingSteps): no screenshot shows it. A screenshot of a first open of a large store would close this gap.
  • Catch-up failed notice with Retry over the picture (CatchUpFailed / the 503 path): no screenshot shows it. A screenshot of the failure state would close this gap.

Notes

  • When the stage is missing, the count chip falls back to "Loading graph data…". After drawing a box, a person expects to see a count. Something like "Counting selection…" would describe the wait better than a whole-graph loading message, but it needs a new catalog string, and the PR says it adds none on purpose.

[UX-REVIEWED] 96d2040

Description read

[DESCRIPTION-READ] 19196efac8255ae1b39534aaaf826fb8a1b7c7219aada1637d0c782acf7450e5

That sha256 names everything this verdict read: the PR description, plus the 3 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 96d204053a51d94231139db51a19fa08aac3dab8 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: PASS

The main change, answering from the layout and catching up in the background, holds up. Two things are notes, not blockers: placement changes ride along without a reported defect, and the change reverses a step the base RFC still records.

Notes

  • Item 9/10 — rides along, oversized: the only reason given is "L44-L47 build on their slot code", which is about later PRs. ## Not a goal excludes "Changing how a full build lays out a store", yet _correct_misplaced moves a build's dots after the build. On base, _Slots.take leaves an overflow row where it was placed, and no defect against that is cited. Subtraction: defer misplaced_plan/_correct_misplaced/apply_moves, slots_checked, _Slots._between/grow and derived_slots to the stack PR that uses them.
  • Item 1 — inherited: the description cites "the design in RFC docs(rfc): record the memory graph decisions the next graph PRs build #47713". That RFC is not on base. The base RFC (rfc-memory-graph-server-layout.md, implemented) says in §5.3 "each graph read first brings the file up to date" and in §8 "each graph read places new and changed rows first". This PR reverses that recorded step.

What this change ships

Inventory (10 items) — 8 justified

Intent: open the Memory graph without waiting for the layout to catch up with the store, and never show a forgotten memory. FIX.

  1. Graph reads answer from the layout right away; catch-up runs in the background — justified
  2. Replies leave out memories forgotten since the last pass — justified
  3. Refresh waits for its own numbered pass, up to 60 s — justified
  4. A lost poll is asked again with back-off — justified
  5. A box count waits up to 10 s for the due pass and shows a waiting state — justified
  6. A box count reads again, up to three times, when a batch lands between its reads — justified
  7. A read across a batch takes the newer placement instead of "changed" — justified
  8. Catch-up progress shows real counts beside the age — justified
  9. A full topic's rows go between slots, then grow the disc; older layouts get slot counts worked out — rides along, oversized
  10. After each build, dots in a wrong place move to free slots of their topic — rides along, oversized

[FIRST-PRINCIPLES-REVIEWED] 96d2040

Description read

[DESCRIPTION-READ] bad5f072e59ce74468f85f58600dd2bc19f3474be9bd032d6b602498a8a0e43f

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 48b1f48348ef5f638f036764476de6a94577733f — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 48b1f48

Verdict parsed from the review's SHA-scoped output markers for commit 48b1f48348ef5f638f036764476de6a94577733f.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 48b1f48348ef5f638f036764476de6a94577733f false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 48b1f48348ef5f638f036764476de6a94577733f and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 48b1f48

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 48b1f48348ef5f638f036764476de6a94577733f false-positive: <reason, 20 to 500 characters>

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Dec 5, 2026
@buluoray
buluoray force-pushed the crew/slack/graph-catch-up branch from 7d782e3 to f095f18 Compare December 5, 2026 15:36
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Dec 5, 2026
@buluoray
buluoray force-pushed the crew/slack/graph-stored-picture branch from f6128dd to d95f1fb Compare December 5, 2026 17:00
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Dec 5, 2026
@buluoray
buluoray force-pushed the crew/slack/graph-catch-up branch from f095f18 to f24f2e1 Compare December 5, 2026 17:13
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Dec 5, 2026
@buluoray

buluoray commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author
  • A box counted while a catch-up pass is due names a layout the pass then moves, so the list and Copy to refuse it as stale

fixed in f24f2e1, by the review's second suggestion: a box count first waits (at most SELECT_WAIT_SECS, 10 s) for the pass that is running or asked for (StoreGraph.wait_for_due_pass), so the layout it names is the one its hand-off reads next. The first suggestion (accept a newer placement in ids_at_revision) is not taken: main refuses a box after placements on purpose (test_box_revision_tracks_reconciled_placements), because a backfill moves a row, and a bulk forget must not reach a memory the person never saw in the box.
Test: "a box counted while a pass is due hands off under the layout it leaves" (test_memory_graph_serve.py) holds the pass, counts, releases it, then lists the box: 200 with the new memory. It fails with the wait taken out.

@buluoray

buluoray commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author
  • Queued progress hides the failed pass Refresh awaited (F1, downgraded by the adjudication)

stated limit, no change: it needs a pass that raises while another read has queued a follow-up. Refresh then reads the layout as it is, which is the old layout, not a corrupt one, and the queued pass runs at once; if it fails too, the next answer says so with Retry. Added to the description's Known limits.

@buluoray

buluoray commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author
  • Refresh assertion depends on background-thread scheduling (F2)

fixed in f24f2e1: the test holds the forced pass (Held) until its first answer is read, then releases it, so pass_asked > pass_done no longer depends on thread timing.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Dec 5, 2026
@buluoray
buluoray force-pushed the crew/slack/graph-stored-picture branch from d95f1fb to 889dcaa Compare December 5, 2026 17:37
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Dec 5, 2026
@buluoray
buluoray force-pushed the crew/slack/graph-catch-up branch from f24f2e1 to 3fcab1f Compare December 5, 2026 17:52
@buluoray

buluoray commented Dec 5, 2026

Copy link
Copy Markdown
Contributor Author
  • Box counts are labelled with a revision they did not count

fixed in 3fcab1f: the box count's reply names the revision it was counted at (filters["box_layout"]), and _read_at_one_layout keeps a layout the read named instead of overwriting it. The hand-off reads the box at exactly that revision, so it refuses the box once a later placement moved it, and never takes a row the count did not hold.
Test: "a box count names the revision it counted at" (test_memory_graph_serve.py) lands a placement batch right after the count. It fails with the reply relabelled.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Dec 5, 2026
@buluoray
buluoray force-pushed the crew/slack/graph-stored-picture branch from 889dcaa to cdca114 Compare December 5, 2026 18:28
@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Dec 5, 2026
@buluoray
buluoray force-pushed the crew/slack/graph-catch-up branch from 3fcab1f to 48b1f48 Compare December 5, 2026 18:42
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running labels Dec 5, 2026
… the background

Restacked onto #47741 as one commit (its seven commits each conflicted
with the removal of the signed-in person there). It holds:
- answer graph requests from the layout and catch it up in the background
- keep forgotten words and ids out while the layout catches up
- read forgotten rows before the layout; a placement batch is no new build
- a box count waits for the pass that is due; hold Refresh's pass in its test
- show the count's in-progress state while a box count waits
- a box count names the revision it counted at
- the box-count revision test is held at the box read the hand-off uses
@buluoray
buluoray force-pushed the crew/slack/graph-catch-up branch from 48b1f48 to 96d2040 Compare December 5, 2026 19:45
@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Dec 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: checking Automated validation is still running

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant