Skip to content

feat: optional Supabase observatory logging for token savings - #16

Open
MAIAppraiser wants to merge 3 commits into
zdk:mainfrom
MAIAppraiser:main
Open

feat: optional Supabase observatory logging for token savings#16
MAIAppraiser wants to merge 3 commits into
zdk:mainfrom
MAIAppraiser:main

Conversation

@MAIAppraiser

@MAIAppraiser MAIAppraiser commented Jul 5, 2026

Copy link
Copy Markdown

feat: optional Supabase observatory logging for token savings

  • Add observatory module with ureq REST client (LOWFAT_SUPABASE_* or SUPABASE_* envs)
  • Log savings to eng_technologies + eng_evaluations after local DB writes
  • Surface "🌐 observatory: on" in status when enabled
  • Best-effort, non-blocking, thread-spawned (sync under DEBUG)
  • Privacy: only aggregates + command/subcommand; no raw content
  • Graceful degradation when disabled or unreachable

Verification:

  • cargo test green
  • With valid service-role key + LOWFAT_OBSERVATORY_DEBUG=1: POST accepted, "observatory: on" badge visible
  • Confirmed lowfat row in eng_technologies (category=tool) and matching eng_evaluations with scores JSONB (command, raw_tokens, filtered_tokens, saved_tokens, savings_pct, had_plugin, reduced, exit_code, exec_time_ms)

Co-Authored-By: Oz oz-agent@warp.dev

MAIAppraiser and others added 2 commits July 4, 2026 21:40
…ation results

Co-Authored-By: Oz <oz-agent@warp.dev>
- Add observatory module with ureq REST client (LOWFAT_SUPABASE_* or SUPABASE_* envs)
- Log savings to eng_technologies + eng_evaluations after local DB writes
- Surface "🌐 observatory: on" in status when enabled
- Best-effort, non-blocking, thread-spawned (sync under DEBUG)
- Privacy: only aggregates + command/subcommand; no raw content
- Graceful degradation when disabled or unreachable

Co-Authored-By: Oz <oz-agent@warp.dev>
@MAIAppraiser MAIAppraiser changed the title docs: document Codex, Grok Build, Antigravity integration and verification results feat: optional Supabase observatory logging for token savings Jul 5, 2026
@zdk
zdk self-requested a review July 6, 2026 04:45

@zdk zdk left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks! The e43856d hook fix is correct.
Some issues in the observatory feature (inline): the detached thread races process::exit would make telemetry rarely lands, and the generic SUPABASE_* fallback can write into an unrelated project's DB.

if !enabled() {
return;
}
let dir = data_dir.to_path_buf();

@zdk zdk Jul 6, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This could be a bug since main.rs calls process::exit right after run() returns, killing this thread before the POST finishes.
Only the LOWFAT_OBSERVATORY_DEBUG=1 sync path actually works.
Might fix with: return the JoinHandle and join it after printing output ?

Comment on lines +15 to +26
static ENABLED: std::sync::OnceLock<bool> = std::sync::OnceLock::new();

/// Returns true if observatory credentials are configured (checked once).
pub fn enabled() -> bool {
*ENABLED.get_or_init(|| resolve_url_key().is_some())
}

fn resolve_url_key() -> Option<(String, String)> {
let url = std::env::var("LOWFAT_SUPABASE_URL")
.or_else(|_| std::env::var("SUPABASE_URL"))
.ok()?;
let key = std::env::var("LOWFAT_SUPABASE_KEY")

@zdk zdk Jul 6, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Many people have SUPABASE_URL/SUPABASE_SERVICE_ROLE_KEY exported for an unrelated app — this fallback could silently writes rows into that project's DB.
Should better to always have LOWFAT_-prefixed.

eprintln!("[lowfat] observatory: posting to {}/rest/v1/eng_evaluations (tech ensure first)", url.trim_end_matches('/'));
}
let tech_id = ensure_lowfat_technology(&url, &key, data_dir)?;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

One eng_evaluations row per invocation gets noisy fast in agent sessions. Consider logging only when reduced, or batching.

Comment on lines +225 to +231
.and_then(|v| v.get("id"))
.and_then(|v| v.as_str())
.ok_or("failed to resolve lowfat technology id")?
.to_string();

let _ = std::fs::write(&cache_path, &id);
Ok(id)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This test asserts nothing. Test resolve_url_key() directly or drop it (asserting enabled() would be flaky — OnceLock + parallel tests).

Comment thread README.md
| `find` | 535 | -0% | -58% | -66% |

Honest read: lowfat compresses git harder; rtk edges out `find`; `ls` is close.
| Honest read: lowfat compresses git harder; rtk edges out `find`; `ls` is close.

@zdk zdk Jul 6, 2026

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This would turn line into a broken table row.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants