From a1837d48f44321bbaf0c87565055d79ab1a5ef95 Mon Sep 17 00:00:00 2001 From: MoonCaves <144150401+MoonCaves@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:42:10 +0800 Subject: [PATCH 1/3] Match only the optional topic table's missing-table diagnostic SQLite reports unrelated SQL and view-resolution failures under the same generic error code. Match the exact diagnostic from the pinned driver. Return the original error to the caller on all other query failures. The missing-table, broken-view and closed-database checks exercise the store API. Ordered results are covered by existing session topic tests. Prior-Art: grafana/grafana pkg/services/sqlstore/migrator/sqlite_dialect.go L167-L173 (AGPL-3.0) @71ceb636f6405679f02c5f57c7fe222c801cad3b -> internal/store/topics.go Prior-Art: modernc-org/sqlite conn.go L626-L640 (BSD-3-Clause) @b8975b7dcf269f7c09929073c1feb64701066f41 -> internal/store/topics.go Prior-Art: sqlite/sqlite src/build.c L457-L467 (public domain) @c2aa8e3875907d84540af7624534e326b26b82ee -> internal/store/topics.go Prior-Art: sqlite/sqlite test/view.test L83-L99 (public domain) @c2aa8e3875907d84540af7624534e326b26b82ee -> internal/store/topics_test.go Prior-Art: MoonCaves/rawclaw internal/store/topics_test.go L192-L203 (MIT) @2e391b6af9901fb2e260a7552f05b68621437719 -> internal/store/topics_test.go Prior-Art: MoonCaves/rawclaw internal/store/topics_test.go L247-L259 (MIT) @2e391b6af9901fb2e260a7552f05b68621437719 -> internal/store/topics_test.go Prior-Art: MoonCaves/rawclaw internal/store/topics.go L138-L155 (MIT) @2e391b6af9901fb2e260a7552f05b68621437719 -> internal/store/topics.go Prior-Art: MoonCaves/rawclaw internal/store/verdict.go L135-L152 (MIT) @2e391b6af9901fb2e260a7552f05b68621437719 -> internal/store/topics.go --- docs/design/decision-references.md | 4 ++++ internal/store/topics.go | 6 +++++- internal/store/topics_test.go | 19 +++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/design/decision-references.md b/docs/design/decision-references.md index 68a8cff3..f0b39763 100644 --- a/docs/design/decision-references.md +++ b/docs/design/decision-references.md @@ -316,3 +316,7 @@ Source: `moby/moby@d217a0d97eb468d4d09260889bf78653ad953945`; upstream owns the - License: [Apache-2.0](https://github.com/moby/moby/blob/d217a0d97eb468d4d09260889bf78653ad953945/LICENSE), with upstream [NOTICE](https://github.com/moby/moby/blob/d217a0d97eb468d4d09260889bf78653ad953945/NOTICE). Complete source, license and notice bytes were fetched and checked before cataloging; any later adaptation must retain applicable attribution. The correspondence is bounded to exact identity before unique-prefix fallback. Moby's single container namespace and intermediate exact-name stage do not establish RawClaw's cross-source ambiguity rules, complete/incomplete metadata outcomes, retained/foreign/parent guards, or adapter SQL exactness. This entry grants no generic caller-policy approval, native Cline resume support, or implementation ACK; those require separate source review and the canonical gate. + +## Reading optional session topics + +Grafana [compares the exact missing-table diagnostic](https://github.com/grafana/grafana/blob/71ceb636f6405679f02c5f57c7fe222c801cad3b/pkg/services/sqlstore/migrator/sqlite_dialect.go#L167-L173) when a SQLite table is optional and propagates other failures. RawClaw uses this distinction for the unqualified `topic_segment` query. Its [pinned Go driver formats the SQLite message with the error description and numeric code](https://github.com/modernc-org/sqlite/blob/b8975b7dcf269f7c09929073c1feb64701066f41/conn.go#L626-L640). SQLite's [view regression](https://github.com/sqlite/sqlite/blob/c2aa8e3875907d84540af7624534e326b26b82ee/test/view.test#L89-L99) shows how a missing source table causes a different diagnostic when the view itself exists. [Grafana license](https://github.com/grafana/grafana/blob/71ceb636f6405679f02c5f57c7fe222c801cad3b/LICENSE) · [Driver license](https://github.com/modernc-org/sqlite/blob/b8975b7dcf269f7c09929073c1feb64701066f41/LICENSE) · [SQLite dedication](https://github.com/sqlite/sqlite/blob/c2aa8e3875907d84540af7624534e326b26b82ee/LICENSE.md). diff --git a/internal/store/topics.go b/internal/store/topics.go index b434339f..bcffa546 100644 --- a/internal/store/topics.go +++ b/internal/store/topics.go @@ -163,7 +163,11 @@ func TopicsForSession(con *sql.DB, sessionID string) ([]TopicSegment, error) { "SELECT session_id, start_uuid, end_uuid, topic, summary, tagged_at, origin_machine FROM topic_segment WHERE session_id=? ORDER BY id", sessionID) if err != nil { - return nil, nil // missing table / read error reads as no topics (non-fatal) + // SQLite uses the same error code for missing tables and other SQL errors. + if err.Error() == "SQL logic error: no such table: topic_segment (1)" { + return nil, nil // missing optional table reads as no topics (non-fatal) + } + return nil, err } defer rows.Close() var out []TopicSegment diff --git a/internal/store/topics_test.go b/internal/store/topics_test.go index b48250dd..2dc13895 100644 --- a/internal/store/topics_test.go +++ b/internal/store/topics_test.go @@ -259,6 +259,25 @@ func TestSessionHasRealSegments(t *testing.T) { }) } +func TestTopicsForSessionReadErrors(t *testing.T) { + con, _ := storetest.NewDB(t) + if got, err := store.TopicsForSession(con, "sess-1"); err != nil || len(got) != 0 { + t.Fatalf("missing optional table: got %v, %v; want no topics", got, err) + } + if _, err := con.Exec("CREATE VIEW topic_segment AS SELECT * FROM topic_segment_archive"); err != nil { + t.Fatal(err) + } + if _, err := store.TopicsForSession(con, "sess-1"); err == nil { + t.Fatal("expected an error for a view with a missing source table") + } + if err := con.Close(); err != nil { + t.Fatal(err) + } + if _, err := store.TopicsForSession(con, "sess-1"); err == nil { + t.Fatal("expected an error for a closed database") + } +} + func TestInsertTopicSegments(t *testing.T) { con, _ := storetest.NewDB(t) if err := store.EnsureTopicSchema(con); err != nil { From 4311b9951467e81d3b6ce1afbf2ccb6dea2d74d3 Mon Sep 17 00:00:00 2001 From: MoonCaves <144150401+MoonCaves@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:44:21 +0800 Subject: [PATCH 2/3] Record the exact modernc missing-table comparison precedent Prior-Art: autobrr/netronome internal/database/user.go L199-L202 (GPL-2.0-or-later) @200757072afce58ca0e0442984cff6860fa4360d -> internal/store/topics.go Prior-Art: autobrr/netronome internal/database/user.go L34-L38 (GPL-2.0-or-later) @200757072afce58ca0e0442984cff6860fa4360d -> internal/store/topics.go --- docs/design/decision-references.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/design/decision-references.md b/docs/design/decision-references.md index f0b39763..efee6049 100644 --- a/docs/design/decision-references.md +++ b/docs/design/decision-references.md @@ -319,4 +319,6 @@ The correspondence is bounded to exact identity before unique-prefix fallback. M ## Reading optional session topics +Netronome [compares the full SQLite error string for each optional table](https://github.com/autobrr/netronome/blob/200757072afce58ca0e0442984cff6860fa4360d/internal/database/user.go#L199-L202) and [returns other database errors](https://github.com/autobrr/netronome/blob/200757072afce58ca0e0442984cff6860fa4360d/internal/database/user.go#L34-L38). RawClaw uses the same comparison with its `topic_segment` table. [Netronome license](https://github.com/autobrr/netronome/blob/200757072afce58ca0e0442984cff6860fa4360d/LICENSE). + Grafana [compares the exact missing-table diagnostic](https://github.com/grafana/grafana/blob/71ceb636f6405679f02c5f57c7fe222c801cad3b/pkg/services/sqlstore/migrator/sqlite_dialect.go#L167-L173) when a SQLite table is optional and propagates other failures. RawClaw uses this distinction for the unqualified `topic_segment` query. Its [pinned Go driver formats the SQLite message with the error description and numeric code](https://github.com/modernc-org/sqlite/blob/b8975b7dcf269f7c09929073c1feb64701066f41/conn.go#L626-L640). SQLite's [view regression](https://github.com/sqlite/sqlite/blob/c2aa8e3875907d84540af7624534e326b26b82ee/test/view.test#L89-L99) shows how a missing source table causes a different diagnostic when the view itself exists. [Grafana license](https://github.com/grafana/grafana/blob/71ceb636f6405679f02c5f57c7fe222c801cad3b/LICENSE) · [Driver license](https://github.com/modernc-org/sqlite/blob/b8975b7dcf269f7c09929073c1feb64701066f41/LICENSE) · [SQLite dedication](https://github.com/sqlite/sqlite/blob/c2aa8e3875907d84540af7624534e326b26b82ee/LICENSE.md). From 23a25a809d7c75c0e8f7ae6289417f1c75681c72 Mon Sep 17 00:00:00 2001 From: MoonCaves <144150401+MoonCaves@users.noreply.github.com> Date: Sat, 21 Nov 2026 08:48:21 +0800 Subject: [PATCH 3/3] Group optional topic references with the SQLite readers --- docs/design/decision-references.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/design/decision-references.md b/docs/design/decision-references.md index efee6049..9c923b6a 100644 --- a/docs/design/decision-references.md +++ b/docs/design/decision-references.md @@ -168,6 +168,12 @@ Production source and license were fetched and independently checked on 2026-11- The Go port specializes `useResume=true` in a resume-only API and keeps RawClaw's existing argv builder and shell renderer. Only a known Claude source receives the configured fork capability; the ordinary unknown-source fallback does not confer it. CLI changes pass the explicit option and errors through existing selected local and foreign matches, preserving ambiguity, metadata guards, source-filter rejection and archive origin guidance. RawClaw renders a command; this source record does not establish native execution or creation of a new session ID. No OpenClaw package, checkpoint feature, transcript copying or new discovery policy is adopted. +## Reading optional session topics + +Netronome [compares the full SQLite error string for each optional table](https://github.com/autobrr/netronome/blob/200757072afce58ca0e0442984cff6860fa4360d/internal/database/user.go#L199-L202) and [returns other database errors](https://github.com/autobrr/netronome/blob/200757072afce58ca0e0442984cff6860fa4360d/internal/database/user.go#L34-L38). RawClaw uses the same comparison with its `topic_segment` table. [Netronome license](https://github.com/autobrr/netronome/blob/200757072afce58ca0e0442984cff6860fa4360d/LICENSE). + +Grafana [compares the exact missing-table diagnostic](https://github.com/grafana/grafana/blob/71ceb636f6405679f02c5f57c7fe222c801cad3b/pkg/services/sqlstore/migrator/sqlite_dialect.go#L167-L173) when a SQLite table is optional and propagates other failures. RawClaw uses this distinction for the unqualified `topic_segment` query. Its [pinned Go driver formats the SQLite message with the error description and numeric code](https://github.com/modernc-org/sqlite/blob/b8975b7dcf269f7c09929073c1feb64701066f41/conn.go#L626-L640). SQLite's [view regression](https://github.com/sqlite/sqlite/blob/c2aa8e3875907d84540af7624534e326b26b82ee/test/view.test#L89-L99) shows how a missing source table causes a different diagnostic when the view itself exists. [Grafana license](https://github.com/grafana/grafana/blob/71ceb636f6405679f02c5f57c7fe222c801cad3b/LICENSE) · [Driver license](https://github.com/modernc-org/sqlite/blob/b8975b7dcf269f7c09929073c1feb64701066f41/LICENSE) · [SQLite dedication](https://github.com/sqlite/sqlite/blob/c2aa8e3875907d84540af7624534e326b26b82ee/LICENSE.md). + ## Crush SQLite reader source candidate (2026-11-06) Source: `kenn-io/agentsview` at immutable revision `5f877363f3a7b911e73dc391692c66cd835da7be`; the linked files own these patterns. @@ -316,9 +322,3 @@ Source: `moby/moby@d217a0d97eb468d4d09260889bf78653ad953945`; upstream owns the - License: [Apache-2.0](https://github.com/moby/moby/blob/d217a0d97eb468d4d09260889bf78653ad953945/LICENSE), with upstream [NOTICE](https://github.com/moby/moby/blob/d217a0d97eb468d4d09260889bf78653ad953945/NOTICE). Complete source, license and notice bytes were fetched and checked before cataloging; any later adaptation must retain applicable attribution. The correspondence is bounded to exact identity before unique-prefix fallback. Moby's single container namespace and intermediate exact-name stage do not establish RawClaw's cross-source ambiguity rules, complete/incomplete metadata outcomes, retained/foreign/parent guards, or adapter SQL exactness. This entry grants no generic caller-policy approval, native Cline resume support, or implementation ACK; those require separate source review and the canonical gate. - -## Reading optional session topics - -Netronome [compares the full SQLite error string for each optional table](https://github.com/autobrr/netronome/blob/200757072afce58ca0e0442984cff6860fa4360d/internal/database/user.go#L199-L202) and [returns other database errors](https://github.com/autobrr/netronome/blob/200757072afce58ca0e0442984cff6860fa4360d/internal/database/user.go#L34-L38). RawClaw uses the same comparison with its `topic_segment` table. [Netronome license](https://github.com/autobrr/netronome/blob/200757072afce58ca0e0442984cff6860fa4360d/LICENSE). - -Grafana [compares the exact missing-table diagnostic](https://github.com/grafana/grafana/blob/71ceb636f6405679f02c5f57c7fe222c801cad3b/pkg/services/sqlstore/migrator/sqlite_dialect.go#L167-L173) when a SQLite table is optional and propagates other failures. RawClaw uses this distinction for the unqualified `topic_segment` query. Its [pinned Go driver formats the SQLite message with the error description and numeric code](https://github.com/modernc-org/sqlite/blob/b8975b7dcf269f7c09929073c1feb64701066f41/conn.go#L626-L640). SQLite's [view regression](https://github.com/sqlite/sqlite/blob/c2aa8e3875907d84540af7624534e326b26b82ee/test/view.test#L89-L99) shows how a missing source table causes a different diagnostic when the view itself exists. [Grafana license](https://github.com/grafana/grafana/blob/71ceb636f6405679f02c5f57c7fe222c801cad3b/LICENSE) · [Driver license](https://github.com/modernc-org/sqlite/blob/b8975b7dcf269f7c09929073c1feb64701066f41/LICENSE) · [SQLite dedication](https://github.com/sqlite/sqlite/blob/c2aa8e3875907d84540af7624534e326b26b82ee/LICENSE.md).