From bdea12e6f2b894979dfef6a1706457a54adecdf7 Mon Sep 17 00:00:00 2001 From: ChemaVX Date: Fri, 8 May 2026 15:18:09 +0000 Subject: [PATCH] fix: nombre de archivo .md usa topic del output, no del session pre-cacheado MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit El session dict se obtiene antes de generator.generate() y puede contener datos de la sesión anterior. Ahora se extrae el topic directamente de la línea "Topic:" del header del output generado, que siempre refleja la sesión actual usada en la generación. Co-Authored-By: Claude Sonnet 4.6 --- src/bot/bot.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bot/bot.py b/src/bot/bot.py index da35205..b3bca69 100644 --- a/src/bot/bot.py +++ b/src/bot/bot.py @@ -341,6 +341,7 @@ async def cmd_generate(update: Update, ctx: ContextTypes.DEFAULT_TYPE): # Send as file if very long if len(output) > 8000: import tempfile + import re as _re ext_map = { OutputType.PODCAST: "script.md", OutputType.BLOG: "post.md", @@ -350,7 +351,11 @@ async def cmd_generate(update: Update, ctx: ContextTypes.DEFAULT_TYPE): OutputType.BLOG_EXTENDED: "blog_extended.md", OutputType.PODCAST_EXTENDED: "script_extended.md", } - filename = f"researchowl_{session['topic'][:30].replace(' ', '_')}_{ext_map[output_type]}" + # Use the topic from the output header (written at generation time) + # instead of the pre-fetched session dict which may be stale. + _m = _re.search(r'^Topic:\s*(.+)$', output[:500], _re.MULTILINE) + _topic = _m.group(1).strip() if _m else session["topic"] + filename = f"researchowl_{_topic[:30].replace(' ', '_')}_{ext_map[output_type]}" with tempfile.NamedTemporaryFile(mode="w", suffix=".md", delete=False) as f: f.write(output)