Skip to content

Commit ab92c2d

Browse files
leifericfclaude
andcommitted
fix(artifacts): stale data on prompt chunking transitions + query list regression
Two bugs from the artifacts-in-datomic refactor: 1. save-prompt! didn't retract the old storage format when switching between chunked and non-chunked templates. A small→chunked save left the old :artifact.prompt/template value, which load-prompt would return instead of the new chunks. Fixed by always retracting old chunks and clearing the template string when switching formats. 2. do-query wrapped `query list` inside with-existing-db, requiring a repo path for a command that only needs the meta database. Moved list-queries handling back outside the repo-dependent path. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c279b48 commit ab92c2d

2 files changed

Lines changed: 29 additions & 14 deletions

File tree

src/noumenon/artifacts.clj

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,13 +157,27 @@
157157
;; --- Writing ---
158158

159159
(defn save-prompt!
160-
"Write a prompt template to Datomic. Handles chunking transparently."
160+
"Write a prompt template to Datomic. Handles chunking transparently.
161+
Retracts the opposite storage format to prevent stale data."
161162
[conn prompt-name template source]
162-
(let [tx-data (merge {:artifact.prompt/name prompt-name}
163-
(chunk-template template))]
164-
(d/transact conn {:tx-data [tx-data
165-
{:db/id "datomic.tx"
166-
:tx/artifact-source source}]})))
163+
(let [db (d/db conn)
164+
entity (d/pull db '[:db/id :artifact.prompt/template
165+
{:artifact.prompt/chunks [:db/id]}]
166+
[:artifact.prompt/name prompt-name])
167+
eid (:db/id entity)
168+
chunked? (> (count template) chunk-size)
169+
;; Retract stale data: old template string and/or old chunks
170+
retracts (when eid
171+
(into (when (and chunked? (:artifact.prompt/template entity))
172+
[[:db/retract eid :artifact.prompt/template
173+
(:artifact.prompt/template entity)]])
174+
(map (fn [chunk] [:db/retractEntity (:db/id chunk)]))
175+
(:artifact.prompt/chunks entity)))
176+
tx-data (merge {:artifact.prompt/name prompt-name}
177+
(chunk-template template))]
178+
(d/transact conn {:tx-data (into [tx-data {:db/id "datomic.tx"
179+
:tx/artifact-source source}]
180+
retracts)})))
167181

168182
(defn save-rules!
169183
"Write rules to Datomic."

src/noumenon/main.clj

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,15 @@
247247
(defn do-query
248248
"Run the query subcommand. Returns {:exit n :result map-or-nil}."
249249
[{:keys [query-name list-queries params] :as opts}]
250-
(with-valid-repo
251-
opts
252-
(fn [ctx]
253-
(with-existing-db
254-
ctx
255-
(fn [{:keys [db meta-db]}]
256-
(if list-queries
257-
(do-query-list meta-db)
250+
(if list-queries
251+
(let [meta-conn (db/ensure-meta-db (util/resolve-db-dir opts))]
252+
(do-query-list (d/db meta-conn)))
253+
(with-valid-repo
254+
opts
255+
(fn [ctx]
256+
(with-existing-db
257+
ctx
258+
(fn [{:keys [db meta-db]}]
258259
(let [kw-params (into {} (map (fn [[k v]] [(keyword k) v])) params)
259260
{:keys [ok error]} (query/run-named-query meta-db db query-name kw-params)]
260261
(if error

0 commit comments

Comments
 (0)