Graph-Native Infrastructure for Context and Accountable AI Systems
Python agent-memoryaiai-governanceai-infrastructureartificial-intelligencecontext-engineeringcontext-graphsdata-engineeringdecision-intelligencedeveloper-toolsexplainable-aigenerative-aigraph-ragknowledge-graphllmontologyprovenancepythonreasoningsemantic-search
fix(explorer): end the temporal scrubber at now instead of inventing 2030 (#1541)
Wei Tao6b55cf1101e5
diff --git a/explorer/package.json b/explorer/package.jsonindex fb4132c5..9290271a 100644--- a/explorer/package.json+++ b/explorer/package.json@@ -9,7 +9,7 @@"lint": "eslint .","preview": "vite preview","test:graph-store": "node --test tests/graphStore.multi-edge.test.mjs",- "test:graph-workspace": "node --import tsx --test tests/markdownContentViewer.test.ts tests/markdownEditorInteraction.test.tsx tests/markdownEditorState.test.ts tests/nodeMarkdownSync.test.ts tests/graphSceneState.display.test.ts tests/temporalLifecycle.test.ts tests/deterministicExplorerRendering.test.ts tests/explorerCapabilities.test.tsx tests/smallGraphLayout.test.ts tests/realtimeGraphAttributes.test.ts tests/ontologyEditorModel.test.ts tests/graphColorLegend.test.ts",+ "test:graph-workspace": "node --import tsx --test tests/markdownContentViewer.test.ts tests/markdownEditorInteraction.test.tsx tests/markdownEditorState.test.ts tests/nodeMarkdownSync.test.ts tests/graphSceneState.display.test.ts tests/temporalLifecycle.test.ts tests/temporalScrubberBounds.test.ts tests/deterministicExplorerRendering.test.ts tests/explorerCapabilities.test.tsx tests/smallGraphLayout.test.ts tests/realtimeGraphAttributes.test.ts tests/ontologyEditorModel.test.ts tests/graphColorLegend.test.ts","test:deterministic-e2e": "node --import tsx --test tests/deterministicExplorerRendering.e2e.ts","test:graph-legend-e2e": "node --import tsx --test tests/graphColorLegend.e2e.ts","test:plugin-registry": "node --import tsx --test tests/pluginRegistry.temporal.test.mjs"diff --git a/explorer/src/workspaces/GraphWorkspace/TimelinePanel.tsx b/explorer/src/workspaces/GraphWorkspace/TimelinePanel.tsxindex 6535c2f3..24c3dbc2 100644--- a/explorer/src/workspaces/GraphWorkspace/TimelinePanel.tsx+++ b/explorer/src/workspaces/GraphWorkspace/TimelinePanel.tsx@@ -4,6 +4,7 @@ import { Timeline } from "vis-timeline";import type { TimelineOptions } from "vis-timeline";import "vis-timeline/styles/vis-timeline-graph2d.css";import { GRAPH_THEME } from "./graphTheme";+import { DEFAULT_MIN_DATE, resolvePlayStepMs, resolveScrubberBounds } from "./temporalScrubberBounds";export interface TimelinePanelProps {onTimeChange: (time: Date) => void;@@ -11,11 +12,9 @@ export interface TimelinePanelProps {maxDate?: string;}-const DEFAULT_MIN_DATE = new Date("1970-01-01T00:00:00Z");-const DEFAULT_MAX_DATE = new Date("2030-01-01T00:00:00Z");const PLAYHEAD_ID = "playhead";const PLAY_INTERVAL_MS = 500;-const PLAY_STEP_MONTHS = 6;+const ONE_DAY_MS = 1000 * 60 * 60 * 24;const VIS_OVERRIDE_CSS = `.sem-timeline-wrap .vis-timeline { border: none !important; background: transparent !important; overflow: visible !important; }@@ -54,12 +53,6 @@ const VIS_OVERRIDE_CSS = `.sem-timeline-wrap .vis-panel.vis-left { display: none !important; }`;-function safeDate(value: string | undefined, fallback: Date): Date {- if (!value) return fallback;- const parsed = new Date(value);- return Number.isNaN(parsed.getTime()) ? fallback : parsed;-}-function formatPlayheadLabel(value: Date): string {return `${value.getFullYear()}/${String(value.getMonth() + 1).padStart(2, "0")}`;}@@ -72,9 +65,13 @@ export function TimelinePanel({ onTimeChange, minDate, maxDate }: TimelinePanelPconst [isPlaying, setIsPlaying] = useState(false);const [displayDate, setDisplayDate] = useState(formatPlayheadLabel(DEFAULT_MIN_DATE));- const minBound = useMemo(() => safeDate(minDate, DEFAULT_MIN_DATE), [minDate]);- const maxBound = useMemo(() => safeDate(maxDate, DEFAULT_MAX_DATE), [maxDate]);- const defaultTime = useMemo(() => new Date(Math.round((minBound.getTime() + maxBound.getTime()) / 2)), [maxBound, minBound]);+ // Captured once per mount so re-renders keep the same reference and do not+ // retrigger the timeline effect below.+ const now = useMemo(() => new Date(), []);+ const { minBound, maxBound, defaultTime } = useMemo(+ () => resolveScrubberBounds({ minDate, maxDate, now }),+ [maxDate, minDate, now],+ );useEffect(() => {if (!containerRef.current) return;@@ -91,12 +88,10 @@ export function TimelinePanel({ onTimeChange, minDate, maxDate }: TimelinePanelPshowCurrentTime: false,zoomable: true,moveable: true,- zoomMin: 1000 * 60 * 60 * 24 * 365,+ zoomMin: ONE_DAY_MS,zoomMax: 1000 * 60 * 60 * 24 * 365 * 80,showMajorLabels: true,showMinorLabels: true,- timeAxis: { scale: "year", step: 5 },- format: { minorLabels: { year: "YYYY" }, majorLabels: { year: "YYYY" } },orientation: { axis: "bottom" },margin: { item: 0, axis: 0 },selectable: false,@@ -134,8 +129,7 @@ export function TimelinePanel({ onTimeChange, minDate, maxDate }: TimelinePanelPplayIntervalRef.current = setInterval(() => {const timeline = timelineRef.current;if (!timeline) return;- const next = new Date(playheadRef.current);- next.setMonth(next.getMonth() + PLAY_STEP_MONTHS);+ const next = new Date(playheadRef.current.getTime() + resolvePlayStepMs(minBound, maxBound));if (next >= maxBound) {next.setTime(minBound.getTime());}diff --git a/explorer/src/workspaces/GraphWorkspace/temporalScrubberBounds.ts b/explorer/src/workspaces/GraphWorkspace/temporalScrubberBounds.tsnew file mode 100644index 00000000..a62bb8bb--- /dev/null+++ b/explorer/src/workspaces/GraphWorkspace/temporalScrubberBounds.ts@@ -0,0 +1,46 @@+export interface ScrubberBoundsInput {+ minDate?: string;+ maxDate?: string;+ now: Date;+}++export interface ScrubberBounds {+ minBound: Date;+ maxBound: Date;+ defaultTime: Date;+}++export const DEFAULT_MIN_DATE = new Date("1970-01-01T00:00:00Z");+const ONE_DAY_MS = 1000 * 60 * 60 * 24;+const PLAY_FRAMES = 60;++function parseBound(value: string | undefined, fallback: Date): Date {+ if (!value) return fallback;+ const parsed = new Date(value);+ return Number.isNaN(parsed.getTime()) ? fallback : parsed;+}++function clamp(value: Date, minBound: Date, maxBound: Date): Date {+ if (value < minBound) return minBound;+ if (value > maxBound) return maxBound;+ return value;+}++/**+ * `/api/temporal/bounds` reports `max: null` for graphs whose nodes carry+ * `valid_from` instants and no `valid_until`, which is the common case rather+ * than malformed data. Such a graph is known up to the present and no further,+ * so `now` is the honest upper bound and the honest starting playhead.+ */+export function resolveScrubberBounds({ minDate, maxDate, now }: ScrubberBoundsInput): ScrubberBounds {+ const minBound = parseBound(minDate, DEFAULT_MIN_DATE);+ const maxBound = parseBound(maxDate, now);+ const orderedMax = maxBound > minBound ? maxBound : minBound;+ return { minBound, maxBound: orderedMax, defaultTime: clamp(now, minBound, orderedMax) };+}++/** Keeps a play-through at ~PLAY_FRAMES steps whatever the span, with a one-day floor. */+export function resolvePlayStepMs(minBound: Date, maxBound: Date): number {+ const span = maxBound.getTime() - minBound.getTime();+ return Math.max(ONE_DAY_MS, Math.round(span / PLAY_FRAMES));+}diff --git a/explorer/tests/temporalScrubberBounds.test.ts b/explorer/tests/temporalScrubberBounds.test.tsnew file mode 100644index 00000000..98fe4de4--- /dev/null+++ b/explorer/tests/temporalScrubberBounds.test.ts@@ -0,0 +1,113 @@+import test from "node:test";+import assert from "node:assert/strict";++import {+ DEFAULT_MIN_DATE,+ resolvePlayStepMs,+ resolveScrubberBounds,+} from "../src/workspaces/GraphWorkspace/temporalScrubberBounds.ts";++const NOW = new Date("2026-09-09T10:30:00Z");++// ── resolveScrubberBounds ────────────────────────────────────────────────────++test("scrubber bounds: open max ends the window at now, not at a future year", () => {+ const { minBound, maxBound } = resolveScrubberBounds({ minDate: "2026-01-15T00:00:00Z", now: NOW });++ assert.equal(minBound.toISOString(), "2026-01-15T00:00:00.000Z");+ assert.equal(+ maxBound.getTime(),+ NOW.getTime(),+ "a graph carrying only valid_from instants is known up to the present and no further",+ );+});++test("scrubber bounds: playhead starts at now so the first snapshot describes the present", () => {+ const { defaultTime } = resolveScrubberBounds({ minDate: "2026-01-15T00:00:00Z", now: NOW });++ assert.equal(defaultTime.getTime(), NOW.getTime());+});++test("scrubber bounds: playhead is not the midpoint of the range", () => {+ const { minBound, maxBound, defaultTime } = resolveScrubberBounds({+ minDate: "2020-01-01T00:00:00Z",+ maxDate: "2030-01-01T00:00:00Z",+ now: NOW,+ });+ const midpoint = Math.round((minBound.getTime() + maxBound.getTime()) / 2);++ assert.notEqual(defaultTime.getTime(), midpoint, "the midpoint was the source of the future start time");+ assert.equal(defaultTime.getTime(), NOW.getTime());+});++test("scrubber bounds: reported max is honoured when the data supplies one", () => {+ const { maxBound } = resolveScrubberBounds({+ minDate: "2020-01-01T00:00:00Z",+ maxDate: "2030-06-01T00:00:00Z",+ now: NOW,+ });++ assert.equal(maxBound.toISOString(), "2030-06-01T00:00:00.000Z");+});++test("scrubber bounds: playhead clamps into a range that ends before now", () => {+ const { maxBound, defaultTime } = resolveScrubberBounds({+ minDate: "2019-01-01T00:00:00Z",+ maxDate: "2020-01-01T00:00:00Z",+ now: NOW,+ });++ assert.equal(defaultTime.getTime(), maxBound.getTime());+});++test("scrubber bounds: playhead clamps into a range that starts after now", () => {+ const { minBound, defaultTime } = resolveScrubberBounds({+ minDate: "2030-01-01T00:00:00Z",+ maxDate: "2031-01-01T00:00:00Z",+ now: NOW,+ });++ assert.equal(defaultTime.getTime(), minBound.getTime());+});++test("scrubber bounds: min ahead of an open max keeps the window ordered", () => {+ const { minBound, maxBound } = resolveScrubberBounds({ minDate: "2031-01-01T00:00:00Z", now: NOW });++ assert.ok(maxBound >= minBound, "vis-timeline requires min <= max");+});++test("scrubber bounds: malformed and missing dates fall back without producing Invalid Date", () => {+ const { minBound, maxBound } = resolveScrubberBounds({ minDate: "not-a-date", maxDate: "also-bad", now: NOW });++ assert.equal(minBound.getTime(), DEFAULT_MIN_DATE.getTime());+ assert.equal(maxBound.getTime(), NOW.getTime());+});++// ── resolvePlayStepMs ────────────────────────────────────────────────────────++test("play step: a one-year span advances in ~60 frames, not 2", () => {+ const minBound = new Date("2026-01-01T00:00:00Z");+ const maxBound = new Date("2027-01-01T00:00:00Z");+ const span = maxBound.getTime() - minBound.getTime();++ const frames = span / resolvePlayStepMs(minBound, maxBound);++ assert.ok(frames > 50 && frames < 70, `expected ~60 frames, got ${frames}`);+});++test("play step: a decade-long span also advances in ~60 frames", () => {+ const minBound = new Date("2016-01-01T00:00:00Z");+ const maxBound = new Date("2026-01-01T00:00:00Z");+ const span = maxBound.getTime() - minBound.getTime();++ const frames = span / resolvePlayStepMs(minBound, maxBound);++ assert.ok(frames > 50 && frames < 70, `expected ~60 frames, got ${frames}`);+});++test("play step: a span of hours still advances by at least a day", () => {+ const minBound = new Date("2026-09-09T00:00:00Z");+ const maxBound = new Date("2026-09-09T06:00:00Z");++ assert.equal(resolvePlayStepMs(minBound, maxBound), 1000 * 60 * 60 * 24);+});