Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Gradata/docs/getting-started/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ gradata --brain-dir ./my-brain audit # data-flow audit
```

For a non-mutating offline smoke test that exercises init, agent-install dry
run, correction, recall, stats, and audit:
run, correction, recall, stats, and audit. The script creates a temporary HOME
and ignores inherited live-brain variables such as `BRAIN_DIR`/`GRADATA_BRAIN`
so it can be run safely from an agent shell:

```bash
PYTHONPATH=src python examples/offline_quickstart_smoke.py
Expand Down
8 changes: 7 additions & 1 deletion Gradata/examples/offline_quickstart_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def main() -> int:
env["HOME"] = str(home)
env["GRADATA_BRAIN_DIR"] = str(brain)
env.setdefault("GRADATA_LOG", "WARNING")
# Make this smoke deterministic when run by developers/agents that already
# export a live Gradata brain path in their shell.
env.pop("BRAIN_DIR", None)
env.pop("GRADATA_BRAIN", None)

run(["--help"], env=env)
run(["init", str(brain), "--domain", "Smoke", "--name", "Quickstart Smoke", "--no-interactive"], env=env)
Expand All @@ -57,9 +61,11 @@ def main() -> int:
"Hey, check out what we just shipped.",
], env=env)
run(["--brain-dir", str(brain), "recall", "draft a launch email", "--max-tokens", "400"], env=env)
run(["--brain-dir", str(brain), "stats"], env=env)
stats = run(["--brain-dir", str(brain), "stats"], env=env)
run(["--brain-dir", str(brain), "audit"], env=env)

if f"Brain: {brain}" not in stats:
raise SystemExit(f"stats used the wrong brain directory:\n{stats}")
Comment on lines +64 to +68

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Move the stats brain-directory assertion before audit.

Line 65 runs audit before the guard on Line 67, so contamination is only detected after another command already executed. Reorder to fail fast before audit.

Proposed fix
         run(["--brain-dir", str(brain), "recall", "draft a launch email", "--max-tokens", "400"], env=env)
         stats = run(["--brain-dir", str(brain), "stats"], env=env)
-        run(["--brain-dir", str(brain), "audit"], env=env)

         if f"Brain: {brain}" not in stats:
             raise SystemExit(f"stats used the wrong brain directory:\n{stats}")
+        run(["--brain-dir", str(brain), "audit"], env=env)
         if not (brain / "system.db").exists():
             raise SystemExit(f"missing expected brain database: {brain / 'system.db'}")

Based on learnings: CLI brain resolution is env-first (GRADATA_BRAIN/BRAIN_DIR before CLI args), so this check should gate subsequent commands.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
stats = run(["--brain-dir", str(brain), "stats"], env=env)
run(["--brain-dir", str(brain), "audit"], env=env)
if f"Brain: {brain}" not in stats:
raise SystemExit(f"stats used the wrong brain directory:\n{stats}")
stats = run(["--brain-dir", str(brain), "stats"], env=env)
if f"Brain: {brain}" not in stats:
raise SystemExit(f"stats used the wrong brain directory:\n{stats}")
run(["--brain-dir", str(brain), "audit"], env=env)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@Gradata/examples/offline_quickstart_smoke.py` around lines 64 - 68, Move the
assertion that verifies stats used the correct brain directory to run
immediately after obtaining stats and before calling run(..., "audit") so the
script fails fast; specifically, after the call that assigns stats =
run(["--brain-dir", str(brain), "stats"], env=env) check if f"Brain: {brain}" is
in stats and raise SystemExit(...) if not, and only then invoke
run(["--brain-dir", str(brain), "audit"], env=env) — this ensures the stats
validation gates running audit and prevents contamination.

Source: Learnings

if not (brain / "system.db").exists():
raise SystemExit(f"missing expected brain database: {brain / 'system.db'}")

Expand Down
Loading