Fix double-encoded jsonb breaking dream cycle slug lookup#745
Open
joelwp wants to merge 1 commit intogarrytan:masterfrom
Open
Fix double-encoded jsonb breaking dream cycle slug lookup#745joelwp wants to merge 1 commit intogarrytan:masterfrom
joelwp wants to merge 1 commit intogarrytan:masterfrom
Conversation
…okup
persistToolExecPending/Failed/Complete called JSON.stringify(input) before
passing to a $N::jsonb parameter. When input is already an object, this
produces a JSON string which ::jsonb stores as a jsonb scalar -- not a
jsonb object. Downstream queries like input->>slug then return NULL
because the operator does not traverse scalar strings.
Root cause fix: skip JSON.stringify when input is already a string.
Query fix: use COALESCE with (input #>> '{}')::jsonb->>slug fallback
to handle both old double-encoded rows and new properly-encoded rows.
Affects: dream cycle synthesize phase (pages_written always 0) and
patterns phase (same slug collection query).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Open
5 tasks
garrytan
added a commit
that referenced
this pull request
May 9, 2026
Codex-mandated test gate (C6 from /codex review of v0.30.3 plan). Pins behavior of collectChildPutPageSlugs() under both jsonb shapes: - jsonb_typeof='object' (post-#745, normal write path) - jsonb_typeof='string' (pre-#745 double-encoded, the bug shape) Without this guard, a future regression of #745 would silently drop slugs: child jobs finish, queue looks healthy, orchestrator writes nothing. Worst on-call shape — silent failure with no alerting surface. Adds an `__testing` namespace to src/core/cycle/synthesize.ts re-exporting collectChildPutPageSlugs at unit-test granularity. Not part of the runtime contract; matches the v0_29_1.ts `__testing` precedent for engine-internal helpers.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
persistToolExecPending/Failed/Completeinsubagent.tscallJSON.stringify(input)before passing to a$N::jsonbparameter. Wheninputis already an object, this produces a JSON string which::jsonbstores as a jsonb scalar — not a jsonb object. Downstream queries likeinput->>'slug'then return NULL.pages_written: 0even when subagents successfully write pages viabrain_put_page. The summary page shows "Pages written: 0" despite pages existing in the DB.patterns.tsslug collection query.Fix
subagent.ts): SkipJSON.stringifywhen input/output is already a string, preventing future double-encoding.synthesize.ts,patterns.ts): UseCOALESCE(input->>'slug', (input #>> '{}')::jsonb->>'slug')to handle both old double-encoded rows and new properly-encoded rows.Files changed
src/core/minions/handlers/subagent.ts— persist functionssrc/core/cycle/synthesize.ts—collectChildPutPageSlugssrc/core/cycle/patterns.ts— same query patternTest plan
gbrain dream --date <date>with existing double-encoded rows — summary should now show correct page countsubagent_tool_executions.inputis stored as jsonb object (not scalar string)input->>'slug'returns the slug for both old and new rows🤖 Generated with Claude Code
Need help on this PR? Tag
@codesmithwith what you need.