Skip to content

feat(069-A1): byte capture on ActivityRecord (pre-truncation RequestBytes/ResponseBytes) - #553

Merged
Dumbris merged 4 commits into
mainfrom
069-observability-usage-graphs
Jun 1, 2026
Merged

Dumbris merged 4 commits into
mainfrom
069-observability-usage-graphs

Conversation

@Dumbris

@Dumbris Dumbris commented May 31, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds request_bytes and response_bytes (int, omitempty) to ActivityRecord — foundational byte data for Spec 069 usage graphs.
  • Captures both sizes pre-truncation: rawByteSize(result) and rawByteSize(activityArgs) measured before forwardContentResult / the legacy truncation loop in mcp_routing.go.
  • Legacy records without the fields decode to 0 (unknown), preserving backwards compatibility.
  • Fixes ListActivities field copy to propagate the new fields from storage.
  • EmitActivityToolCallCompleted / emitActivityToolCallCompleted wrappers extended with requestBytes, responseBytes int; error call sites pass 0, 0.

Test plan

  • TestActivityRecord_ByteFieldsRoundTrip — JSON round-trip + legacy decode-to-0 (T001)
  • TestHandleToolCallCompleted_ByteCapture — service stores pre-truncation sizes from event payload (T003)
  • Full internal/... suite green (approval-hash canary, required by tasks.md T025)

Blocks: A2 aggregate work (T005+).

Dumbris and others added 3 commits May 31, 2026 16:56
Surface existing activity-log data (per-call server/tool/status/duration/bytes)
as Web UI graphs so users see where agents spend tokens: per-tool call
histogram, response-size token-sink ranking, error rate, latency, timeline,
behind a dashboard switcher. Fast via actor-owned incremental stats aggregate +
TTL cache (no per-request full scan). v1 uses bytes as token proxy; accurate
per-call tokens deferred (FR-010). Roadmap PILLAR A. Paperclip goal d7164fdf.
Run /speckit.plan + /speckit.tasks. Codebase verification corrected three
spec assumptions: ActivityRecord stores no byte sizes (capture two int
fields at the write path), chart.js/vue-chartjs already installed (reuse,
no library selection), and /activity/stats does not exist (add
/activity/usage). Aggregation is actor-owned + incremental + snapshot +
TTL cache + cold-start rebuild (CN-002/CN-003/FR-005). Cross-lane
decomposition: backend streams A1->A2->A3 (my lane), frontend B1/B2
delegated, blocked by A3.

Related #745

Co-Authored-By: Paperclip <noreply@paperclip.ing>
…re-truncation capture

- Add `request_bytes` and `response_bytes` (omitempty int) fields to ActivityRecord;
  legacy records missing the fields decode to 0.
- Populate both fields in ActivityService.handleToolCallCompleted from event payload.
- Emit pre-truncation byte sizes in EmitActivityToolCallCompleted and its server
  wrappers; compute rawByteSize(result) and rawByteSize(activityArgs) before
  forwardContentResult is called so truncated responses still report full sizes.
- Fix ListActivities to copy the new fields when constructing result records.
- TDD: TestActivityRecord_ByteFieldsRoundTrip (T001) and
  TestHandleToolCallCompleted_ByteCapture (T003) written before implementation.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented May 31, 2026 •

Copy link
Copy Markdown

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7784c77
Status: ✅  Deploy successful!
Preview URL: https://2760dab2.mcpproxy-docs.pages.dev
Branch Preview URL: https://069-observability-usage-grap.mcpproxy-docs.pages.dev

View logs

@codecov-commenter

codecov-commenter commented May 31, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 38.88889% with 22 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/server/mcp.go 38.09% 11 Missing and 2 partials ⚠️
internal/runtime/event_bus.go 0.00% 5 Missing ⚠️
internal/server/mcp_routing.go 0.00% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented May 31, 2026 •

Copy link
Copy Markdown
Contributor

📦 Build Artifacts

Workflow Run: View Run
Branch: 069-observability-usage-graphs

Available Artifacts

  • archive-darwin-amd64 (28 MB)
  • archive-darwin-arm64 (25 MB)
  • archive-linux-amd64 (16 MB)
  • archive-linux-arm64 (14 MB)
  • archive-windows-amd64 (27 MB)
  • archive-windows-arm64 (24 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (21 MB)
  • installer-dmg-darwin-arm64 (19 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 26737509838 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

Dual-AI review of #553 flagged that TestHandleToolCallCompleted_ByteCapture
only asserts the activity service stores values handed to it — it never
exercises the A1 invariant that handleCallToolVariant measures rawByteSize on
the RAW result/args BEFORE forwardContentResult truncates.

Add TestRawByteSize_MeasuredBeforeTruncation (internal/server): drive an
over-threshold response + args through the real measure-then-truncate sequence
and assert (a) RequestBytes/ResponseBytes equal the full pre-truncation
json.Marshal size, (b) the forwarded body is actually truncated and shorter
than the raw response, (c) the captured ResponseBytes strictly exceeds the
post-truncation payload — proving measurement precedes truncation.

Also note the double-Marshal overhead on rawByteSize for future profiling
(review's optional ask).

Related: MCP-786, MCP-748, spec 069
Dumbris added a commit that referenced this pull request Jun 1, 2026
* docs(064): Glass Cockpit — transparent & steerable agent cockpit spec

Spec, plan, and design artifacts for making the existing Paperclip
"MCPProxy" cockpit (spec 045) transparent and steerable: invert the
default from "proceed" to "checkpoint at every design-decision
boundary" via three human gates (plan-of-attack, per-spec design,
pre-merge) mapped to Paperclip native primitives (executionPolicy
approval stages, request_confirmation/suggest_tasks interactions,
issue_tree_holds), with reasoning visible before each gate and a
single "waiting on you" view.

Phased rollout: A) config + agent-instruction only (the dry-run
target), B) a Paperclip plugin for the fused transparency UI, C) a
fork only if A/B fall short. SynapBus is log/wiki only, never on the
critical path. Includes rewritten gate-aware agent instructions,
consumed-API + executionPolicy + agent-instruction contracts, data
model, research, and operator quickstart.

Supersedes spec 062's fresh-dev-instance approach; extends spec 045.

* docs(064): amend gate model — human-merge → dual-AI auto-merge + human veto

Session 2 amendment to FR-005 + US3: replace the mandatory human-merge gate
(throughput bottleneck) with draft-PR + dual-AI-review consensus auto-merge.
Two reviewers on different model families (Gemini 2.5-pro Critic + Codex),
never the implementer; tests-green + both-accept → auto-merge; human is an
optional 3rd reviewer with veto (request-changes/hold freezes auto-merge).
Prerequisite flagged: a bot GitHub identity (agents currently = author's gh,
and GitHub forbids self-approval) — interim fallback is 2-AI-review-as-
required-check with the human merging. codex-local Paperclip adapter exists.

* docs(064): dual-AI-review auto-merge — reviewer doctrine + engineer draft-PR + setup

Adds the Session-2 gate-model deliverables: reviewer/REVIEWER.md (shared
RV-1..RV-6 dual-review doctrine), codex-reviewer/AGENTS.md (2nd reviewer on
codex-local), amends engineer ENG-4 to open DRAFT PRs + request 2 AI reviewers
(no self-merge), and auto-merge-setup.md (GitHub branch-protection config +
the bot-identity prerequisite + interim human-merge fallback + open items).

* docs(064): reviewers on subscription auth only; Gemini quota-exhausted, Codex gpt-5.5 ready

Per user directive: both AI reviewers use paid SUBSCRIPTION logins, not API keys.
- Gemini Critic: subscription/OAuth, pin gemini-2.5-pro (3.5/3 UNVERIFIED — quota
  exhausted on every probe today; switch if confirmed). TWO blockers: quota +
  empty-prompt adapter bug → cannot accept yet.
- Codex reviewer: ChatGPT subscription, gpt-5.5 (codex-cli 0.46.0) — READY now.
- Live two-reviewer set today = Codex + human (FR-005f) until Gemini recovers.

* docs(064): Critic GEMINI.md — subscription-only, quota-blocked; Kimi+Codex as live pair

Gemini settings pin gemini-3.1-pro-preview (subscription/OAuth) but quota is
exhausted (no reset hint) + empty-prompt adapter bug → Critic can't accept yet.
Live 2-AI reviewer pair = Codex gpt-5.5 + Kimi-K2.5 (opencode_local, Gcore key
present); Gemini rejoins as 3rd reviewer when quota returns.

* docs(064): stand up Codex+Kimi reviewer agents; codex config fix

Live dual-AI reviewer pair created in the running Paperclip cockpit and
verified responding (2026-05-31):
- CodexReviewer  — codex_local / gpt-5-codex   (5b94562c-…)
- KimiReviewer   — opencode_local / Kimi-K2.5  (fdaa1d4c-…)
Both carry managed instruction bundles (shared doctrine + RV-1..RV-6 +
role notes), report to CEO, idle, heartbeat off (woken by review-stage).

Docs:
- add canonical kimi-reviewer/AGENTS.md (the design lacked it)
- correct codex-reviewer/AGENTS.md model facts (gpt-5.5 -> gpt-5-codex)
- auto-merge-setup.md: live pair is Codex+Kimi; Gemini Critic becomes the
  3rd reviewer when its subscription quota recovers

codex config fix (~/.codex/config.toml, not in repo): model_reasoning_effort
xhigh->high and model gpt-5.5->gpt-5-codex. On codex-cli 0.46.0 + ChatGPT
subscription auth, gpt-5.5 needs a newer CLI and gpt-5.4/5.3-codex/5.2 are
auth-restricted; gpt-5-codex/gpt-5 are the working models. Backup at
~/.codex/config.toml.bak.pre-reviewer-fix.*

* docs(064): engineers drive PRs green + bundle docs/ updates (ENG-8/9)

engineer/AGENTS.md:
- ENG-8: drive every required check to green before review — run local
  verification before push, watch `gh pr checks --watch`, push fixes until
  all green; never leave/hand off a red PR, never --no-verify or weaken a
  check. Green CI is the engineer's job, not the reviewer's.
- ENG-9: when a change touches CLI/REST/MCP API/config/defaults/security or
  anything under docs/, the SAME PR must update docs/ (+ CLAUDE.md/
  oas/swagger.yaml/README where mirrored). Docs-only changes exempt from TDD.
- ENG-5 reworked to dual-AI merge-readiness (Codex+Kimi accept + all CI green).

reviewer/REVIEWER.md RV-3: red/pending check = automatic request_changes;
missing docs when the change warrants them = request_changes.

Applied to the live Paperclip brains: 3 engineers (Backend/Frontend/MacOS)
re-flattened from canonical; Codex+Kimi reviewer brains refreshed.

* docs(064): record applied CI-context branch protection on main

Phase-1 gate live on main (no bot identity needed): required_status_checks
strict=false with 8 always-run, non-path-conditional contexts (Lint, Unit
Tests ubuntu, Build ubuntu/macos/windows, Build Frontend, Validate PR title,
Verify OpenAPI Artifacts). Existing 1-review + enforce_admins=false kept.
Verified: green PR #553 satisfies all 8 (blocked only by review); in-flight
PR #555 blocked on pending required checks. Documents the deliberately-
excluded checks and the Go-version-pinned context-name fragility.

* docs(064): ENG-3 — branch from origin/main, never from a feature branch

Forking a work branch from another feature branch drags its unmerged
commits into the PR (root cause of spec-064 docs leaking into the
MCP-770 race fix #556). ENG-3 now mandates fetch + branch from
origin/main explicitly, in both the engineer bundle and the contract.
@Dumbris
Dumbris merged commit a5b5efc into main Jun 1, 2026
37 checks passed
@Dumbris
Dumbris deleted the 069-observability-usage-graphs branch June 1, 2026 08:48
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