fix(brainstorm/lsd): --save writes the advertised .md file, not just a DB page#1634
fix(brainstorm/lsd): --save writes the advertised .md file, not just a DB page#1634garrytan-agents wants to merge 3 commits into
Conversation
The judgeSignificance trimming (slice at 4000 chars) could split a UTF-16 surrogate pair when an emoji sits exactly at the boundary, producing a lone high surrogate that Anthropic's JSON parser rejects with 'no low surrogate in string'. Add safeSliceEnd() helper that backs up by one char when the cut lands between a high and low surrogate. Apply to: - judgeSignificance transcript trimming (the direct cause) - findBoundary hard-split fallback (defense-in-depth) Fixes: dream cycle SYNTH_PHASE_FAIL on 2026-05-24 caused by 🤖 emoji at pos 3999 in telegram/2026-05-20-topic-1-topic-1.md
…g>.md file, not just a DB page The --save path called engine.putPage() (DB-only) while the help text and success message both promised a 'wiki/ideas/<date>-lsd-<slug>.md' FILE that was never written. Worse, 'Saved to ...' printed even when the DB putPage silently failed (observed under PgBouncer transaction-mode), so callers believed an idea was persisted when nothing landed in either sink. Fix: write to BOTH sinks and report honestly. - DB page via putPage (unchanged, queryable via 'gbrain get'). - File at sync.repo_path/<slug>.md when a local repo is configured, so the saved idea is a committable artifact matching the advertised path. - Success message now states exactly which sinks succeeded; if BOTH fail it prints an explicit 'NOT persisted' error instead of a false success. Resolves the 'gbrain lsd --save claims saved but writes nothing' bug.
|
Superseded — loading this work into worktree branch The novel fix here is the brainstorm/lsd The Thanks @garrytan-agents — brainstorm.ts contribution preserved via Co-Authored-By on the landing PR. |
|
Superseded by #1655 (v0.41.30.0). The brainstorm/lsd |
The bug
gbrain lsd --save(andbrainstorm --save) printedSaved to <slug>but nowiki/ideas/<slug>.mdfile ever appeared. The help text promises a file (Persist to wiki/ideas/<date>-lsd-<slug>.md), but the code only calledengine.putPage()— a DB write. Two failure modes:.mdartifact (to push to the brain repo) got nothing on disk.console.log("Saved to ...")fired unconditionally after theputPagetry-block, so whenputPagefailed (observed under PgBouncer transaction-mode), it still claimed success. Verified: a real LSD run reported "saved" butgbrain get <slug>returnspage_not_found— nothing landed in either sink.The fix
Write to both sinks and report honestly:
putPage(unchanged — queryable viagbrain get).sync.repo_path/<slug>.mdwhen a local repo is configured (resolved the same wayautopilot.ts/notability-eval.tsdo), so the saved idea is a real committable artifact at the advertised path.NOT persistederror instead of a false success.Test
bunx tsc --noEmitclean (no new errors).Notes for reviewer
src/commands/brainstorm.ts(shared bybrainstormandlsdprofiles).sync.repo_pathis unset beyond a clearer message (DB-only, as before).sync.repo_pathset.