Preserve MCP log continuation cursors and episode coverage by pelikhan · Pull Request #70856 · github/gh-aw · GitHub
Skip to content

Preserve MCP log continuation cursors and episode coverage - #70856

Merged
pelikhan merged 6 commits into
mainfrom
pelikhan-didactic-eureka
Oct 21, 2026
Merged

pelikhan merged 6 commits into
mainfrom
pelikhan-didactic-eureka

Conversation

@pelikhan

@pelikhan pelikhan commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fix the MCP logs response wrapper so collection boundaries already recorded by the CLI remain visible to callers:

  • Preserve single-target and per-target continuation cursors, including repository and cursor parameters, independently of optional episode metadata.
  • Surface coverage_status (partial or unknown) and deduplicated coverage_reasons for episode gaps and parse uncertainty. Malformed reports expose invalid_report_json; malformed sections never erase valid independent cursors.
  • Keep known partial evidence when another section is malformed. Parse uncertainty alone remains unknown, not a fabricated partial collection or resume cursor.
  • Share retrieval coverage reason naming and update tool guidance and reference documentation.

The cached report remains byte-for-byte unchanged, including intentional-failure markers. No permissions, artifact selection, filtering, raw stderr retention, or workflow sources are changed.

ADR: ADR-70856: Surface Logs Collection State in the MCP Logs Response

Evidence and scope

Bounded collection and episode retrieval already exist in current source. The remaining adapter defect inspected only singular continuation, hiding multi-target cursors and episode gaps. This follows the collection limitations in discussion #70014, without claiming that the adapter caused every historical timeout or establishes fleet-wide coverage.

Review follow-up commit 3dc9202ecc makes cursor/coverage parsing independent, explicitly reports unknown parse state, adds malformed-input regression cases, and finalizes the generated ADR as Proposed without implying human approval.

Validation

  • Build passed in the final repository gate.
  • Focused MCP response/handler tests passed after the final parsing refactor: GOMAXPROCS=2 go test ./pkg/cli -run 'Test(BuildLogsFileResponse|ExtractLogsCollectionState|NewLogsTool|LogsTool)' -count=1.
  • Impacted tests and schema freshness passed in make agent-report-progress; the follow-up changed-file custom linter check passed after extracting the decoder helpers.
  • Full golangci-lint remains unverified on the shared machine. The first stalled process was stopped; the follow-up gate reported another linter already running. No lint pass is claimed.
  • make fmt completed Go formatting but its unrelated JavaScript stage lacks Prettier in this worktree. Changed Go files are formatted and git diff --check passes.
  • A broader retrieval test selection exposed timing sensitivity in the unchanged 100ms TestEpisodeRetrievalTimeoutAndCancellation fixture. The same failure was reproduced using a Go overlay of both committed pre-fix production files, without changing the workspace. That pre-existing test is not modified by this batch.

Surface per-target resume cursors and partial or unknown episode evidence in the logs file response without changing retained report data.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pelikhan
pelikhan marked this pull request as ready for review October 21, 2026 11:58
Copilot AI max review requested due to automatic review settings October 21, 2026 11:58
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible.

Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.

Generated from Ponytail Reviewer · gpt56 · 7.01 AIC · ⌖ 7.67 AIC · ⊞ 14.8K · ◷

Generated by Ponytail Reviewer for #70856

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft.

Commit pushed: 5ef3e08

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

Copy link
Copy Markdown
Contributor

Comment Memory

Peek at saved memory (pr-code-quality-reviewer)
reviewed_at: 2026-10-21T12:03:00Z
review_event: REQUEST_CHANGES
top_themes: [cursor preservation under malformed/forward-incompatible coverage data]
files_reviewed: [pkg/cli/mcp_logs_guardrail.go, pkg/cli/mcp_logs_guardrail_test.go, pkg/cli/mcp_tools_privileged.go, docs/src/content/docs/reference/gh-aw-as-mcp-server.md]
comment_count: 1

Note

This comment is managed by comment memory.

Expand the saved memory block to view or edit the persistent context for this thread.
Edit only the text inside the backtick fences; workflow metadata and the footer are regenerated automatically.

Learn more about comment memory

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · 2.23 AIC · ⌖ 0.544 AIC · ⊞ 1.6K · ◷
Comment /review to run again

@github-actions github-actions Bot 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.

Request changes

The adapter can silently discard valid continuation cursors when an episode coverage field is malformed or evolves incompatibly: the single unmarshal returns an error and the function returns an empty response. Preserve cursor extraction independently from optional coverage parsing, and add a regression test. Static review only; no commands/tests were run.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · 2.23 AIC · ⌖ 0.544 AIC · ⊞ 1.6K
Comment /review to run again

Comment thread pkg/cli/mcp_logs_guardrail.go Outdated
@github-actions

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (195 new lines in pkg/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/70856-surface-logs-collection-state-in-mcp-response.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff (decision: the MCP logs envelope summarizes recorded collection state — all per-target continuations, coverage_status partial/unknown, deduplicated coverage_reasons — while the cached report stays byte-for-byte unchanged)
  2. Complete the missing sections — add context the AI couldn't infer, refine the decision rationale, and list real alternatives you considered
  3. Commit the finalized ADR to docs/adr/ on your branch
  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-70856: Surface Logs Collection State in the MCP Logs Response

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number.

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · pi · opus55 · 26.3 AIC · ⌖ 35.9 AIC · ⊞ 1.9K · ◷
Comment /review to run again

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.

🟢 Approval recommended

The adapter matches the report structures and regression cases; only non-blocking documentation clarifications remain.

No open issues 🎉

What changed in this PR

Updates the MCP logs adapter to expose collection boundaries and episode coverage without altering cached reports.

Changes:

  • Preserves single-target and per-target continuation cursors.
  • Surfaces episode coverage status and deduplicated reasons.
  • Adds regression tests and updates caller guidance.
File Description
pkg/​cli/​mcp_tools_privileged.go Clarifies continuation and coverage guidance.
pkg/​cli/​mcp_logs_guardrail.go Preserves cursors and summarizes collection state.
pkg/​cli/​mcp_logs_guardrail_test.go Tests cursors, coverage gaps, and unchanged report bytes.
docs/​src/​content/​docs/​reference/​gh-aw-as-mcp-server.md Documents response fields and recovery behavior.

Review effort: Max

@github-actions github-actions Bot 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.

Skills-Based Review 🧠

Applied /tdd and /codebase-design (skill selection used the fallback heuristic — pr-triage was not invoked for this review; classification was done manually against the diff and change type was determined to be a feature/refactor touching MCP logs guardrail response shaping). Two non-blocking findings posted inline; overall the PR is solid.

📋 Key Themes & Highlights

Key Themes

  • Untested error path: extractLogsCollectionState silently swallows JSON parse failures (debug-log only), returning a zero-value response indistinguishable from 'fully collected, no gaps'. Verified locally that malformed/truncated CLI output yields Partial:false, CoverageStatus:"" — worth either an explicit regression test or an "unknown" coverage status on parse failure.
  • Minor duplication: the "retrieval_" + reason prefixing convention is reimplemented inline rather than reusing the pattern already established in logs_episode_retrieval.go. Low risk today, but a seam that could drift if the reason vocabulary changes.

Positive Highlights

  • ✅ 9 new table-driven subtests (TestBuildLogsFileResponse_CollectionCoverage) give solid coverage of the happy-path cursor/coverage-status transitions, truncation flag, and reason dedup/sort behavior.
  • ✅ (nolint/redacted):largefunc on the now-109-line buildLogsFileResponse is consistent with existing repo conventions (same pattern used in zizmor.go, grype.go, mcp_inspect.go).
  • ✅ Reuse of EpisodeCoverage (rather than reinventing coverage semantics) keeps the new response shape aligned with the existing episode-coverage model.
  • ✅ Doc and MCP tool-description updates accurately describe the new continuations/coverage_status/coverage_reasons fields for both human and MCP-client readers.

Nothing here blocks merge; the missing error-path test is the one item I'd actually want addressed before the gap compounds further.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · 147.8 AIC · ⌖ 15.1 AIC · ⊞ 10.2K
Comment /matt to run again

Comment thread pkg/cli/mcp_logs_guardrail.go Outdated
Comment thread pkg/cli/mcp_logs_guardrail.go Outdated
@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot address the following outstanding work in one pass:

  1. Update this branch with the latest main using make merge-main, resolving any conflicts and preserving the intended changes.
  2. Review (pkg/cli/mcp_logs_guardrail.go:63): A type error in any episode coverage entry causes json.Unmarshal to return an error and this function to discard every otherwise-valid continuation cursor, so malformed or forward-incompatible episode data can make callers lose the resume path this adapter is meant to preserve. - Preserve MCP log continuation cursors and episode coverage #70856 (comment)
  3. Review (pkg/cli/mcp_logs_guardrail.go:63): [/tdd] Parse failures in extractLogsCollectionState are silently swallowed: the function logs at debug level and returns a zero-value response with Partial: false, CoverageStatus: \"\". A caller receiving truncated/non-JSON CLI output (e.g. mid-stream error) gets no signal that collection state is unknown rather than complete. - Preserve MCP log continuation cursors and episode coverage #70856 (comment)
  4. Review (pkg/cli/mcp_logs_guardrail.go:82): [/codebase-design] The \"retrieval_\" + reason prefixing here duplicates the identical pattern already used in logs_episode_retrieval.go (episode.Coverage.addGap(\"retrieval_\" + reason)). Also, EpisodeRetrieval/EpisodeRetrievalIssue are fully reused as named types elsewhere, but here they're re-declared as anonymous inline structs — inconsistent with the EpisodeCoverage field a few lines up, which is reused directly. - Preserve MCP log continuation cursors and episode coverage #70856 (comment)

Push the necessary fixes, reply to each listed review thread and resolve it when addressed. Ignore feedback already answered or resolved. Use the pr-finisher skill and stop when only human review or CI remains; do not trigger CI.

Sous-chef head: 5ef3e08
Sous-chef work: 29e410e59f8c2b38d1f9c75148835b2484468d5288a3740e8488a72309f95db2 8775e72c0090054c7e084655dac6a2cbd71177c29f25a5734b42672d359b002c de80fb883e4bb375fb07aeb68eccd84bd853aac4b2436908c1c03b8b71697351
Sous-chef state: 64e07c170772ce19d96a1ecb617c53ae7bb0eb519f6cea26744bcf64305bea36

Generated by 👨‍🍳 PR Sous Chef · pi · haiku45 · 8.89 AIC · ⌖ 8.84 AIC · ⊞ 1.1K · ◷
Comment /souschef to run again

Copilot AI and others added 2 commits October 21, 2026 12:49
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Expose unknown collection state on invalid reports, share retrieval reason naming, and finalize ADR-70856.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@pelikhan

Copy link
Copy Markdown
Collaborator Author

Regarding Test Quality Sentinel's report: no code change is needed for this informational no-action result. I did not treat it as proof of completeness; the batch adds explicit malformed-output regressions and has its own validation.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

Regarding PR Code Quality Reviewer's completion notice: the actionable inline feedback is accepted. Cursor sections now decode independently from optional coverage, with regression cases for malformed coverage and preserved resume paths.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

Regarding Ponytail Reviewer's no-action report: no implementation change is requested by this status notice. I did not infer that the PR is fully verified from the no-op result and validated the review fixes separately.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

Regarding Matt Pocock Skills Reviewer's completion notice: both related inline suggestions are accepted. Parse failures now expose unknown collection state, and retrieval coverage reasons share a helper while retaining named retrieval types.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

Regarding the generated ADR commit: reviewed and finalized the ADR's rationale, alternatives, and consequences. Its status is Proposed rather than implying human approval, and the PR body links it.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

Regarding the saved review theme: accepted the cursor-preservation finding and added independent parsing plus malformed-section regressions. The managed comment-memory block is unchanged.

@pelikhan

Copy link
Copy Markdown
Collaborator Author

Copilot AI and others added 2 commits October 21, 2026 13:07
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
…elikhan-didactic-eureka

# Conflicts:
#	pkg/cli/logs_episode_retrieval.go
#	pkg/cli/mcp_logs_guardrail.go
#	pkg/cli/mcp_logs_guardrail_test.go

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI requested a review from gh-aw-bot October 21, 2026 13:23
@pelikhan
pelikhan merged commit 1b294ed into main Oct 21, 2026
2 checks passed
@pelikhan
pelikhan deleted the pelikhan-didactic-eureka branch October 21, 2026 14:13
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.

4 participants