Add opt-in tail reads to MCP job logs

What does this MR do and why?

Failure details often appear at the end of a CI job log. This adds an opt-in tail read to get_job and its get_job_log alias using from: "end".

Existing callers still read from byte 0 with a default and maximum limit of 512,000 bytes. The tool stays on version 0.1.0, and truncated still means that bytes remain after the returned range. Tail reads use the existing raw_range path, reject an explicit byte_offset, and return instructions for retrieving the preceding window.

Following review, this MR now covers tail reads only. Pattern search is deferred to a separate MR; this change does not close the whole issue. There are no dependency, database, or permission changes.

Validation results

Latest review follow-up (b57939e4df40): applied Terri's suggestion in the from schema description and its schema-lock expectation: “Reads from the start of the log unless set to end.” Rebased onto upstream f8bcb537d50f so the new schema guard is included in the branch. Before the fix, the unmodified guard ran 58 examples and failed only on get_job's stated default. After the fix, the full guard plus service/governance/toolset coverage passed 103 examples, 0 failures; all six MCP HTTP examples passed. RuboCop checked all four Ruby files without offenses; syntax, git diff --check, and normal commit/pre-push hooks passed. A range comparison confirms that the rebase preserves the feature patch apart from the two requested description lines. Runtime defaults, version, and continuation behavior are unchanged. The MR remains one commit with Changelog: added. Live SDK checks were not rerun for this description-only update.

CI investigation on the preceding head (47fc1754880f): source-head pipeline 2996771771 passed with warnings. Upstream merged-results pipeline 3000324621 failed in CNG E2E job 17548581362, while all three predictive RSpec child pipelines passed.

E2E failure evidence

The vulnerability-report CSV spec fails in its setup when vulnerabilityCreate returns “Tracked context is being updated. Please try again.” Its retry handler then raises NameError: uninitialized constant QA::EE::Runtime::Logger at line 45, before the CSV export assertions run. The QA helper in the tested merge commit is identical to the upstream parent. A minimal Ruby control loading the unmodified upstream helper with the same namespace structure and a simulated busy-context response reproduced the logger NameError. Runtime::Logger resolves through QA::EE::Runtime, while the logger is under QA::Runtime. This is an upstream QA setup/retry problem outside the MCP change. The job reports 44 examples, one failure, and one pending example. The helper was introduced by upstream commit 914cee45363a, which links test-failure issue 45482. That issue's current state was inaccessible to this account, so an active-incident match could not be confirmed. Full CNG E2E was not rerun locally, and no CI retry was started.

Terri confirmed that the stated-default sentence was the second review item. Pipeline 3001549387 passed with warnings for the preceding revision, 9c564d15e835. Pipeline 3005714452 is running for b57939e4df40; its final result is pending. Replied in the review thread with the published fix and validation results. Reviewer discussions remain unresolved for confirmation.

Prior tail-read follow-up (27cddf2b4a7b): the tail response now explains how to keep reading backwards to byte 0. The HTTP regression reconstructs the log through three preceding windows, including a shortened final window. The branch is squashed to one commit with a single Changelog: added trailer.

  • Service, governance, and toolset coverage: 43 examples, 0 failures on the revised code.
  • MCP HTTP endpoint coverage: 6 examples, 0 failures, including repeated backward continuation to byte 0.
  • Regression coverage includes unchanged defaults, the alias, invalid arguments, empty logs, UTF-8 boundaries, and debug-log permissions.
  • RuboCop: 4 files, no offenses. Commit and pre-push checks passed, including secret detection, commit-message lint, Markdownlint, Vale, Mermaid lint, documentation links, and OpenAPI documentation checks.
  • git diff --check: passed.
  • Pipeline 2996648704 passed for 27cddf2b4a7bf730a5ec45a2eb893e26394c2303, with one allowed failure (pajamas_adoption). Both predictive RSpec child pipelines passed. Maintainer review is still pending.

Earlier validation on c4a5bdbe included SimpleCov, Undercover with no missing service coverage, and 20 real MCP SDK checks. Those SDK checks reconstructed the complete 1,008,992-byte synthetic log in both directions. They were not rerun for this instruction-only follow-up; the service and HTTP suites above were rerun.

Automated validation commands
BUNDLE_FROZEN=true bundle exec rspec spec/services/mcp/tools/schema_defaults_spec.rb spec/services/mcp/tools/jobs/get_job_service_spec.rb ee/spec/lib/ai/tool_rules/governable_tools_container_spec.rb spec/services/mcp/tools/toolset_coverage_spec.rb --seed 264446
BUNDLE_FROZEN=true bundle exec rspec spec/requests/api/mcp/handlers/call_tool_spec.rb --example '#get_job' --seed 264446

The first command runs the full schema guard and focused suite (103 examples). The stable example-group selector runs the six endpoint examples separately.

References

Related to #633041 (closed)

Review direction: #633041 (comment 4077654294)

Screenshots or screen recordings

Not applicable: this changes MCP responses and documentation, with no UI change.

How to set up and validate locally

  1. Start a local GitLab instance with MCP enabled and connect an MCP client using a credential with the mcp scope.
  2. Choose a readable failed CI job with a log larger than 512,000 bytes. Call get_job with its project path, job ID, and include: ["log"]. Confirm the first 512,000 bytes are returned.
  3. Add from: "end" and byte_limit: 32768. Confirm the last 32 KiB are returned and metadata.truncated is false.
  4. Apply all arguments in log.system_instruction, including from: "start", while keeping the project, job ID, and log facet. Confirm the preceding window ends at the tail's start offset.
  5. Repeat with get_job_log without include. Confirm the same behavior.
  6. Combine from: "end" with byte_offset: 0. Confirm a tool error.

MR acceptance checklist

  • Focused implementation and review follow-up completed.
  • Default behavior, authorization, aliases, and tool version preserved.
  • Service, governance, endpoint, and documentation checks passed.
  • Documentation and changelog trailer included.
  • Rerun live MCP client validation for the revised API.
  • Confirm CI for the current revision.
  • Obtain maintainer approval.

/assign me /milestone %19.6

Edited by Deepak Reddy Gathpa

Merge request reports

Loading
Loading