Skip to content

M10: query remote traces through Athena#16

Merged
huronat merged 3 commits into
mainfrom
feat/athena-trace
Jul 24, 2026
Merged

M10: query remote traces through Athena#16
huronat merged 3 commits into
mainfrom
feat/athena-trace

Conversation

@huronat

@huronat huronat commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What this does

  • Adds a zero-copy Glue external table over the existing immutable
    events/<stream>/chunks/track.<day>/ JSONL layout. Partition projection
    discovers stream/day paths without a crawler or data migration.
  • Adds an opt-in Athena trace backend for synty_trace_*. It issues only
    generated SELECT statements, folds bounded raw envelopes through the
    existing Rust trace model, and reuses the existing role/scope/redaction
    enforcement before rendering.
  • Keeps semantic ColBERT/next-plaid search unchanged. Athena-backed MCP readers
    pull the semantic index and compact analysis projection but deliberately omit
    trace.json.
  • Adds Glue/Athena CloudFormation, query-only IRSA permissions, Helm wiring,
    fail-closed AWS endpoint egress, release/CI feature coverage, readiness
    checks, and the architecture diagram in docs/design.md.

Safety and bounds

  • Workload IAM has no S3 write action: only bucket Get/List, four
    workgroup-scoped Athena query actions, and Glue GetDatabase/GetTable/
    GetPartitions.
  • Athena uses service-managed query results and an enforced 20 GiB per-query
    scan cutoff.
  • Each generated selection is limited to 7 days, 50,000 events, 64 MiB of
    returned envelopes, 200 sessions, 50 seconds, and bounded AWS SDK calls.
  • Search loads literal matches plus one deduplicated session metadata row per
    kind; show/compare expand only resolved sessions. Partial search/list
    stores cannot satisfy a later show.
  • MCP readiness now fails when either dispatcher exits.

Live validation

Deployed to sie-gw-cfg, namespace synty, as Helm revision 17:

851725219920.dkr.ecr.eu-central-1.amazonaws.com/synty:athena-trace-20260723-8

  • /ready: semantic read model, mediated analysis, and both dispatchers ready;
    trace_backend=athena.
  • Authenticated synty_trace_search("libxcb.so.1") returned four real
    tool_call events.
  • synty_trace_show opened the first hit as a paired 193 ms exec span with
    bounded surrounding evidence.
  • SQL kind pushdown reduced the live match selection from 184 rows to 14;
    deduplicated session metadata returned 2 rows.
  • Removed the obsolete 4.1 GiB trace.json from the PVC. A fresh authenticated
    search still succeeded afterward, and no trace.json exists on the volume.
  • The source bucket was not modified. The deployed role's effective policy was
    inspected and contains no S3 Put/Delete action.

Verification

  • cargo test --locked — 285 passed
  • cargo test --locked --no-default-features — 264 passed
  • cargo test --locked --features s3,gcs,mcp-http,athena — 298 passed
  • cargo clippy --locked --all-targets --features s3,gcs,mcp-http,athena
    (no branch-introduced warnings)
  • scripts/mcp-http-smoke.sh target/debug/synty
  • Linux amd64 Rust 1.97 zig cross-build with all shipped features
  • Helm lint, Athena render assertions, invalid-config failure, and Kubernetes
    server-side dry-run
  • AWS validation for both CloudFormation templates

Scaling note

This is deliberately the no-migration bootstrap. Athena still scans the
selected raw JSONL objects; the current broad live selection scanned about
15.3 GB. Before daily volume reaches the workgroup cutoff, a follow-up should
write a separate immutable Parquet projection partitioned for session lookup.
That derived prefix can improve scan cost without changing or deleting the
authoritative raw events.

Remove the remote MCP dependency on a generated trace projection by cataloging the existing immutable event chunks with Glue partition projection and folding bounded SELECT results through the existing trace model and read-scope policy.

Live sie-gw-cfg validation returned four matching tool events and opened one as a paired 193 ms span. Kind pushdown reduced the match selection from 184 rows to 14, and metadata deduplication reduced its context selection to 2 rows. The 4.1 GiB legacy trace.json was removed from the PVC; authenticated search still succeeded afterward.

Keep every request within 7 days, 50,000 events, 64 MiB of returned envelopes, 50 seconds per SELECT, and a 20 GiB workgroup scan cutoff. The workload role retains only S3 Get/List plus workgroup-scoped Athena and Glue read-query actions.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds optional Athena-backed raw trace queries for MCP, including bounded SQL execution, Glue/Athena deployment resources, selective read-model downloads, readiness tracking, Helm configuration, and Athena-enabled CI, release builds, Docker builds, and documentation.

Changes

Athena-backed MCP trace support

Layer / File(s) Summary
Athena infrastructure and deployment configuration
Cargo.toml, deploy/aws/*, deploy/helm/synty/*
Adds the Athena dependency, Glue database/table, Athena workgroup, scoped reader permissions, Helm settings, AWS API CIDR validation, container flags, and egress rules.
Bounded Athena trace backend
src/trace_athena.rs, src/trace.rs
Adds bounded Athena queries, pagination and result limits, stream selection, trace reconstruction, caching, validation, and store-based rendering helpers.
MCP backend routing and selective refresh
src/main.rs, src/mcp.rs, src/sync.rs
Adds Athena CLI configuration, routes trace tools through local or Athena backends, and selectively omits trace.json from Athena-mode refreshes.
HTTP dispatcher readiness
src/mcp_http.rs, src/readmodel.rs
Tracks dispatcher liveness and updates readiness checks for dispatcher, read-model, analysis, and trace-projection state.
Build, release, documentation, and validation
.github/workflows/*, AGENTS.md, Dockerfile, README.md, docs/design.md
Enables Athena in CI and release builds and documents deployment, query, readiness, networking, and build configuration.

Sequence Diagram(s)

sequenceDiagram
  participant CLI as synty MCP CLI
  participant Sync as Read-model sync
  participant MCP as MCP Server
  participant Athena as Athena Backend
  participant AWS as Athena and Glue
  CLI->>Sync: Select read-model files
  CLI->>MCP: Start with Athena options
  MCP->>Athena: Route trace tool request
  Athena->>AWS: Execute bounded SELECT
  AWS-->>Athena: Return event rows
  Athena-->>MCP: Render trace result
Loading

Possibly related PRs

  • superlinked/synty#4: Introduces the trace query surface that this change refactors for store-based and Athena-backed execution.
  • superlinked/synty#15: Overlaps with the MCP dispatching, worker, and readiness plumbing updated here.

Suggested reviewers: svonava

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 70.42% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding Athena-backed remote trace queries.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/athena-trace

Comment @coderabbitai help to get the list of available commands.

Helm renders the workgroup as a quoted shell argument. Assert the exact safe rendering so the deploy job verifies the intended value instead of failing on the missing unquoted form.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
src/trace_athena.rs (1)

643-653: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Skip unparseable rows instead of failing the whole query.

event_sessions propagates an error on the first line that fails strict Event deserialization, yet the downstream reconstruction (TraceStore::from_textfold_text) tolerates malformed lines. A single non-conforming envelope in the immutable lake would abort an entire trace list/show/search here, before reconstruction runs. Consider skipping rows that don't parse so session discovery matches the tolerant fold.

♻️ Tolerate malformed rows
 fn event_sessions(lines: &[String]) -> Result<BTreeSet<String>> {
     let mut sessions = BTreeSet::new();
     for line in lines {
-        let event: crate::event::Event =
-            serde_json::from_str(line).context("parse Athena event row")?;
-        if !event.session_id.is_empty() {
-            sessions.insert(event.session_id);
-        }
+        if let Ok(event) = serde_json::from_str::<crate::event::Event>(line) {
+            if !event.session_id.is_empty() {
+                sessions.insert(event.session_id);
+            }
+        }
     }
     Ok(sessions)
 }
🤖 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 `@src/trace_athena.rs` around lines 643 - 653, Update event_sessions to skip
rows that fail serde_json deserialization instead of propagating the parse
error; continue collecting non-empty session_id values from successfully parsed
Event records and return the collected sessions so malformed Athena rows do not
abort discovery.
🤖 Prompt for all review comments with 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.

Inline comments:
In `@src/mcp_http.rs`:
- Around line 219-234: Validate the Athena configuration at the start of run()
before starting refreshes or dispatchers: when --athena-workgroup is supplied in
a build without the athena feature, return an error immediately instead of
constructing an unavailable trace backend. Add a scenario test covering this
no-athena configuration and asserting that startup fails.

In `@src/readmodel.rs`:
- Around line 127-132: Add scenario-style unit tests for mediated_ready covering
both trace modes: with a current format-2 build containing analysis.json but no
trace.json, assert readiness when require_trace is false and unready when
require_trace is true. Use the existing readmodel test setup and
fixtures/helpers, preserving the implementation in mediated_ready.

---

Nitpick comments:
In `@src/trace_athena.rs`:
- Around line 643-653: Update event_sessions to skip rows that fail serde_json
deserialization instead of propagating the parse error; continue collecting
non-empty session_id values from successfully parsed Event records and return
the collected sessions so malformed Athena rows do not abort discovery.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5236b8fe-4530-493d-bb2d-e2b5c3ac3bd5

📥 Commits

Reviewing files that changed from the base of the PR and between be18a0c and 9c6b7b4.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (19)
  • .github/workflows/ci.yml
  • .github/workflows/release.yml
  • AGENTS.md
  • Cargo.toml
  • Dockerfile
  • README.md
  • deploy/aws/athena-trace.yaml
  • deploy/aws/mcp-reader.yaml
  • deploy/helm/synty/templates/mcp.yaml
  • deploy/helm/synty/values-sie-gw-cfg.yaml
  • deploy/helm/synty/values.yaml
  • docs/design.md
  • src/main.rs
  • src/mcp.rs
  • src/mcp_http.rs
  • src/readmodel.rs
  • src/sync.rs
  • src/trace.rs
  • src/trace_athena.rs

Comment thread src/mcp_http.rs
Comment thread src/readmodel.rs
Reject configured Athena mode before HTTP startup when its backend or required bucket is unavailable. Keep remote readiness independent of the retired trace snapshot, and tolerate malformed raw rows while discovering otherwise valid sessions. Adds three scenarios; the full feature suite passes 298 tests.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with 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.

Inline comments:
In `@src/readmodel.rs`:
- Around line 127-132: Align the feature gating for mediated_ready and
mediated_ready_from: either apply #[cfg(feature = "mcp-http")] to the public
mediated_ready wrapper or remove the gate from mediated_ready_from. Ensure
non-mcp-http builds do not reference an unavailable helper.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ad5fb335-41b5-4f1c-aaff-691acc3a90f2

📥 Commits

Reviewing files that changed from the base of the PR and between ac68b8f and d29248c.

📒 Files selected for processing (3)
  • src/mcp_http.rs
  • src/readmodel.rs
  • src/trace_athena.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/trace_athena.rs
  • src/mcp_http.rs

Comment thread src/readmodel.rs
@huronat
huronat requested a review from svonava July 24, 2026 07:37
@svonava

svonava commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

btw just to make sure you are aware @huronat this is a public repo

@huronat

huronat commented Jul 24, 2026

Copy link
Copy Markdown
Contributor Author

btw just to make sure you are aware @huronat this is a public repo

@svonava even better then

@huronat
huronat merged commit 2cc9eea into main Jul 24, 2026
3 checks passed
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