Skip to content

[WIP] Refactor extract functions in token-parsers file#5310

Merged
lpcox merged 2 commits into
mainfrom
copilot/refactor-token-parsers
Jun 20, 2026
Merged

[WIP] Refactor extract functions in token-parsers file#5310
lpcox merged 2 commits into
mainfrom
copilot/refactor-token-parsers

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor
  • Run baseline tests/build for affected area
  • Refactor extractCacheReadTokens with helper extraction
  • Refactor extractUsageFromJson into a small orchestrator
  • Refactor extractUsageFromSseLine to reduce complexity
  • Add/update focused parser tests
  • Run targeted tests and finalize

Copilot AI requested a review from lpcox June 19, 2026 23:03
@lpcox lpcox marked this pull request as ready for review June 19, 2026 23:21
Copilot AI review requested due to automatic review settings June 19, 2026 23:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors token-usage extraction logic in the API proxy parser to reduce complexity and improve maintainability, while extending cache-read token parsing to handle deeper/nested token-entry structures.

Changes:

  • Refactored cache-read token extraction by introducing recursive helpers to sum token_type: "cache_read" across nested details arrays.
  • Refactored JSON/SSE usage parsing into small “builder” helpers plus a shared Copilot-breakdown merge step.
  • Added a focused test covering nested cache_read token entries in OpenAI Responses usage.*_tokens_details.details.
Show a summary per file
File Description
containers/api-proxy/token-parsers.js Extracted helper functions for cache-read summing and usage object construction/merging to simplify extractUsageFromJson/extractUsageFromSseLine.
containers/api-proxy/token-tracker.parsing.test.js Added coverage for nested cache_read token entries to validate the new recursive extraction behavior.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

@github-actions

Copy link
Copy Markdown
Contributor

✅ Coverage Check Passed

Overall Coverage

Metric Base PR Delta
Lines 97.62% 97.66% 📈 +0.04%
Statements 97.56% 97.60% 📈 +0.04%
Functions 98.85% 98.85% ➡️ +0.00%
Branches 93.24% 93.27% 📈 +0.03%
📁 Per-file Coverage Changes (1 files)
File Lines (Before → After) Statements (Before → After)
src/workdir-setup.ts 92.7% → 94.5% (+1.82%) 92.7% → 94.5% (+1.82%)

Coverage comparison generated by scripts/ci/compare-coverage.ts

@lpcox

lpcox commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator

@copilot address the review feedback and fix the pr title and summary

@lpcox

lpcox commented Jun 20, 2026

Copy link
Copy Markdown
Collaborator

@copilot address the review feedback and fix the pr title and summary

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Smoke Gemini completed. All facets verified. 💎

Testing safeoutputs

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

📡 Smoke OTel Tracing completed. All tracing scenarios validated. ✅

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Security Guard failed. Please review the logs for details.

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Build Test Suite completed successfully!

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Contribution Check completed successfully!

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Chroot tests passed! Smoke Chroot - All security and functionality tests succeeded.

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK completed. Copilot BYOK mode operational. 🔓

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

🔑 Smoke Copilot PAT PAT auth validated. All systems operational. ✅

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (Entra) reports failed. AOAI BYOK (Entra) mode investigation needed...

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

🔌 Smoke Services — All services reachable! ✅

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Smoke Copilot BYOK AOAI (api-key) completed. Copilot AOAI BYOK (api-key) mode operational. 🔓

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Smoke Claude failed

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: Copilot BYOK (Direct Mode) ✅

✅ GitHub MCP connectivity (tested)
✅ GitHub.com HTTP 200
✅ BYOK inference (api-proxy → api.githubcopilot.com)
✅ Running in direct BYOK mode

Status: PASS

cc/ @lpcox @Copilot

🔑 BYOK report filed by Smoke Copilot BYOK

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test Results

PR: [WIP] Refactor extract functions in token-parsers file
Author: @Copilot | Assignees: @lpcox @Copilot

Test Result
GitHub MCP connectivity
GitHub.com HTTP connectivity
File write/read

Overall: PASS

📰 BREAKING: Report filed by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test: Copilot PAT Auth — Results

Test Status
GitHub MCP connectivity
GitHub.com HTTP connectivity ❌ template vars not expanded
File write/read ❌ template vars not expanded

Overall: FAIL — Pre-step outputs (SMOKE_HTTP_CODE, SMOKE_FILE_PATH, SMOKE_FILE_CONTENT) were not passed to the agent (workflow template substitution failed).

Auth mode: PAT (COPILOT_GITHUB_TOKEN)
PR: "[WIP] Refactor extract functions in token-parsers file" — @Copilot (author), @lpcox (assignee)

🔑 PAT report filed by Smoke Copilot PAT

@github-actions

Copy link
Copy Markdown
Contributor

Gemini Engine Smoke Test Results

  • GitHub MCP Testing: ❌ (Tools missing)
  • GitHub.com Connectivity: ❌ (Status 000, Exit 35)
  • File Writing Testing: ✅
  • Bash Tool Testing: ✅

Overall Status: FAIL

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • localhost

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "localhost"

See Network Configuration for more information.

💎 Faceted by Smoke Gemini

@github-actions

Copy link
Copy Markdown
Contributor

[WIP] Refactor extract functions in token-parsers file
✅ PR reads
✅ Browser title
✅ File write
✅ Build
✅ Discussion lookup
Overall: PASS

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • registry.npmjs.org

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "registry.npmjs.org"

See Network Configuration for more information.

🔮 The oracle has spoken through Smoke Codex

@github-actions

Copy link
Copy Markdown
Contributor

🔬 Smoke Test: API Proxy OpenTelemetry Tracing

Scenario Result Notes
1. Module Loading ✅ Pass otel.js loads cleanly; exports: startRequestSpan, setTokenAttributes, setBudgetAttributes, endSpan, endSpanError, shutdown, isEnabled
2. Test Suite ✅ Pass otel.test.js: 39/39 tests passed (1 suite)
3. Env Var Forwarding ✅ Pass OTEL_* vars forwarded via observability-environment.ts; GH_AW_OTLP_ENDPOINTS, OTEL_EXPORTER_OTLP_ENDPOINT, GITHUB_AW_OTEL_TRACE_ID/PARENT_SPAN_ID forwarded via api-proxy-service-config.ts
4. Token Tracker Integration ✅ Pass onUsage callback present in token-tracker-http.js (line 324); otel.js setTokenAttributes sets gen_ai.usage.* semantic conventions
5. OTEL Diagnostics ✅ Pass (graceful degradation) No OTEL endpoint configured in this run; module degrades gracefully (file exporter fallback to /var/log/api-proxy/otel.jsonl)

All scenarios pass. Parent context propagation reads GITHUB_AW_OTEL_TRACE_ID / GITHUB_AW_OTEL_PARENT_SPAN_ID env vars and injects them as W3C trace context on each span.

📡 OTel tracing validated by Smoke OTel Tracing

@github-actions

Copy link
Copy Markdown
Contributor

Chroot Version Comparison Results

Runtime Host Version Chroot Version Match?
Python Python 3.12.13 Python 3.12.3
Node.js v24.16.0 v22.22.3
Go go1.22.12 go1.22.12

Overall: ❌ Not all tests passed — Python and Node.js versions differ between host and chroot environments.

Tested by Smoke Chroot

@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Build Test Suite Results

Ecosystem Project Build/Install Tests Status
Bun elysia 1/1 passed ✅ PASS
Bun hono 1/1 passed ✅ PASS
C++ fmt N/A ✅ PASS
C++ json N/A ✅ PASS
Deno oak N/A 1/1 passed ✅ PASS
Deno std N/A 1/1 passed ✅ PASS
.NET hello-world N/A ✅ PASS
.NET json-parse N/A ✅ PASS
Go color 1/1 passed ✅ PASS
Go env 1/1 passed ✅ PASS
Go uuid 1/1 passed ✅ PASS
Java gson 1/1 passed ✅ PASS
Java caffeine 1/1 passed ✅ PASS
Node.js clsx passed ✅ PASS
Node.js execa passed ✅ PASS
Node.js p-limit passed ✅ PASS
Rust fd 1/1 passed ✅ PASS
Rust zoxide 1/1 passed ✅ PASS

Overall: 8/8 ecosystems passed — ✅ PASS

Generated by Build Test Suite for issue #5310 · 41.1 AIC · ⊞ 7.7K ·

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test: GitHub Actions Services Connectivity

Check Result
Redis PING ❌ timeout (no response on port 6379)
PostgreSQL pg_isready ❌ no response on port 5432
PostgreSQL SELECT 1 ❌ no response (pg_isready failed)

Overall: FAIL

host.docker.internal resolves to 172.17.0.1 but TCP connections to both ports time out. No local listeners on 6379/5432 either — the GitHub Actions service containers do not appear to be running in this environment.

🔌 Service connectivity validated by Smoke Services

@github-actions

Copy link
Copy Markdown
Contributor

@Copilot

  • GitHub MCP connectivity: ✅
  • GitHub.com HTTP response: ✅
  • Agent file I/O: ✅
  • Direct BYOK mode via api-proxy (Azure OpenAI, o4-mini-aw): ✅

PASS: Running in direct BYOK mode (COPILOT_PROVIDER_API_KEY + COPILOT_PROVIDER_BASE_URL) via api-proxy → Azure OpenAI (Foundry)

🔑 BYOK (AOAI api-key) report filed by Smoke Copilot BYOK AOAI (api-key)

Copilot finished work on behalf of lpcox June 20, 2026 03:15
@lpcox lpcox merged commit 29f8e2a into main Jun 20, 2026
87 of 93 checks passed
@lpcox lpcox deleted the copilot/refactor-token-parsers branch June 20, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants