Skip to content

AI agent skill that researches any topic across Reddit, X, YouTube, HN, Polymarket, and the web - then synthesizes a grounded summary

fix(render): keep the synthesis contract reachable when stdout is truncated (#726)

nnhhoangb201aa52c27e
diff --git a/skills/last30days/scripts/lib/render.py b/skills/last30days/scripts/lib/render.py
index fae62f28..ffae45d4 100644
--- a/skills/last30days/scripts/lib/render.py
+++ b/skills/last30days/scripts/lib/render.py
@@ -731,6 +731,8 @@ def render_compact(
# block below) vs "synthesize from" (this block).
lines.append("<!-- EVIDENCE FOR SYNTHESIS: read this, do not emit verbatim. Transform into `What I learned:` prose per LAW 2. -->")
lines.append("")
+ # Echo the synthesis contract early so it survives tail truncation (#726).
+ lines.extend(_render_synthesis_directive())
visible_clusters = evidence_report.clusters[:cluster_limit]
solid_clusters = _clusters_clearing_relevance_floor(
evidence_report,
@@ -1031,6 +1033,36 @@ def _append_html_footer(lines: list[str], report: schema.Report, save_path: str
lines.append("<!-- END PASS-THROUGH FOOTER -->")
+def _render_synthesis_directive() -> list[str]:
+ """Echo the synthesis contract at the TOP of the evidence envelope.
+
+ Added 2026-06-30 for issue #726 (Grok Build v0.2.67 emitted only logs and
+ raw evidence clusters instead of the canonical synthesis). Root cause: the
+ strong directive only lived in `_render_canonical_boundary` — the very END
+ of stdout, AFTER the whole evidence block and footer. Hosts that truncate
+ the tail (`engine | head -N`, timeout-backgrounding that captures partial
+ output, scrollback caps) keep the badge and the `### N.` clusters but never
+ reach the instruction that says "synthesize, don't dump", so they fall into
+ the LAW 6 failure mode and emit the raw evidence.
+
+ This block restates the contract in the head region that survives
+ truncation. It lives INSIDE the EVIDENCE FOR SYNTHESIS envelope (a model
+ instruction, not user output), mirroring how the DEGRADED RUN WARNING is
+ positioned early so the pass-through contract still carries it.
+ """
+ return [
+ "> **SYNTHESIS CONTRACT — read before emitting anything.** Everything below this",
+ "> line, up to where this evidence envelope closes, is raw evidence for you to",
+ "> READ, not text to emit. Transform it into `What I learned:` prose paragraphs",
+ "> per LAW 2. Do NOT pass the `### N.` evidence clusters or the stats and",
+ "> source-coverage blocks through verbatim. The ONLY block you emit verbatim is",
+ "> the PASS-THROUGH FOOTER (the emoji tree) lower down. The full contract repeats",
+ "> at the end-of-output boundary near the bottom; if your captured output was",
+ "> truncated and never reached it, this contract still binds.",
+ "",
+ ]
+
+
def _render_canonical_boundary() -> list[str]:
"""Emit the explicit END-OF-CANONICAL-OUTPUT boundary.
@@ -1316,6 +1348,8 @@ def render_comparison_multi(
"`What I learned:` prose per LAW 2. Each entity has its own evidence subsection. -->"
)
lines.append("")
+ # Echo the synthesis contract early so it survives tail truncation (#726).
+ lines.extend(_render_synthesis_directive())
resolved_block = _render_resolved_entities_block(entity_reports)
if resolved_block:
diff --git a/tests/test_render_v3.py b/tests/test_render_v3.py
index 1e660b88..2132b1b4 100644
--- a/tests/test_render_v3.py
+++ b/tests/test_render_v3.py
@@ -488,6 +488,55 @@ class OutputEnvelopeTests(unittest.TestCase):
)
+class SynthesisDirectiveSurvivesTruncationTests(unittest.TestCase):
+ """Issue #726: a host that truncates the engine's stdout (`| head -N`,
+ timeout-backgrounding, scrollback caps) used to lose the synthesis
+ instructions entirely, because the only strong directive lived at the
+ `# END OF last30days CANONICAL OUTPUT` boundary AFTER the whole evidence
+ block. Left holding only raw `### N.` clusters with no directive, the host
+ dumps them — the LAW 6 failure mode. A concise synthesis contract must
+ therefore ALSO appear at the TOP of the evidence, in the region that
+ survives head-truncation.
+ """
+
+ def _head_before_clusters(self, text: str) -> str:
+ # Everything a `engine | head -N` capture keeps when N lands inside the
+ # evidence block: the badge, metadata, and the directive must live here.
+ return text[: text.index("## Ranked Evidence Clusters")]
+
+ def test_synthesis_contract_present_before_evidence_block(self):
+ head = self._head_before_clusters(render.render_compact(sample_report()))
+ self.assertIn("SYNTHESIS CONTRACT", head)
+
+ def test_early_directive_restates_what_i_learned_and_dump_self_check(self):
+ head = self._head_before_clusters(render.render_compact(sample_report()))
+ # LAW 2 target shape...
+ self.assertIn("What I learned:", head)
+ # ...and the concrete "do not emit the cluster headings" self-check, so
+ # the directive is actionable without the tail boundary.
+ self.assertIn("### N.", head)
+ self.assertIn("PASS-THROUGH FOOTER", head)
+
+ def test_early_directive_sits_inside_evidence_envelope(self):
+ # It is a model instruction, not user output, so it belongs in the
+ # read-don't-emit zone (after the open comment, before the close).
+ text = render.render_compact(sample_report())
+ open_idx = text.index("<!-- EVIDENCE FOR SYNTHESIS:")
+ close_idx = text.index("<!-- END EVIDENCE FOR SYNTHESIS -->")
+ marker = text.index("SYNTHESIS CONTRACT")
+ self.assertLess(open_idx, marker)
+ self.assertLess(marker, close_idx)
+
+ def test_comparison_render_also_carries_early_directive(self):
+ report = sample_report()
+ text = render.render_comparison_multi([("Topic A", report), ("Topic B", report)])
+ self.assertIn("SYNTHESIS CONTRACT", text)
+ self.assertLess(
+ text.index("SYNTHESIS CONTRACT"),
+ text.index("<!-- END EVIDENCE FOR SYNTHESIS -->"),
+ )
+
+
class RenderTopCommentsTests(unittest.TestCase):
"""Tests for the top-3 comments rendering in compact cluster view."""