Skip to content

fix(mcp): include every retained inventory substep in prompt completion - #3292

Closed
sx4im wants to merge 4 commits into
morluto:mainfrom
sx4im:fix/3220-prompt-completion-substep-inventories
Closed

sx4im wants to merge 4 commits into
morluto:mainfrom
sx4im:fix/3220-prompt-completion-substep-inventories

Conversation

@sx4im

@sx4im sx4im commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Prompt completion for an imported artifact inspection only read the first inventory substep, so identifiers from later retained substeps never appeared. This collects candidates from every completed substep instead. Fixes #3220.

Problem and expected behavior

Importing an Evidence bundle with one inspection holding two inventory substeps offered only the first inventory's manifest and occurrence IDs in guided prompt completion. docs/mcp-prompts.md promises every matching value, sorted and deduplicated.

Change and scope

src/server/promptCompletion.ts: gather candidate identifiers from all retained substeps rather than substeps[0]. Malformed inventories are still skipped per-substep (safeParse + continue), so invalid payloads never yield candidates. Out of scope: coverage counting and producer output (already single-substep).

Scope decision: ordinary fix within existing boundaries; not applicable.

Contract and boundary impact

  • Semantic owner and earliest changed stage: MCP prompt completion projection; no contract change.

  • Contribution scope fit and linked maintainer decision: not applicable (ordinary fix).

  • CLI and MCP/tool-catalog contract: none.

  • Provider, bridge, target-format, or platform compatibility: none.

  • Evidence, artifact, provenance, or reconstruction contract: none.

  • Target selection, authority, upstream behavior, and cleanup details: not applicable.

  • Generated metadata, package, or installation impact: none.

  • Read existing files or captured data.

  • Launch or attach to a process.

  • Inject instrumentation or run scripts/code.

  • Change process memory, registers, files, or configuration.

  • Contact network services.

  • Recover protected code or work around protections.

  • Documentation or usability only; no target interaction.

  • Not sure yet; investigation or maintainer guidance needed.

Evidence and regression coverage

  • Tests added or updated: tests/boundary/mcp/promptCompletion.test.ts — new case with a two-substep imported inspection. It fails before the fix (only the first manifest ID is offered) and passes after.

  • Base reproduction: the new test reproduces the exact reported symptom on the base revision.

  • User-visible CLI/MCP output: not applicable (read-only projection over the evidence ledger).

  • Remaining proof gaps: no real-provider run; completion here is a local session projection.

  • Observed, derived, and inferred claims remain distinguishable.

  • Artifact identity, source provenance, and failed attempts remain preserved.

  • Unsupported, incomplete, unavailable, or uncertain outcomes remain visible.

Validation performed

  • npm run test:focused -- tests/boundary/mcp/promptCompletion.test.ts — 7/7 pass
  • npm run test:focused -- tests/boundary/mcp/promptMcp.test.ts — 9/9 pass
  • npm run test:focused -- tests/boundary/mcp/retainedApplicationEvidenceMcp.test.ts — 5/5 pass
  • npm run test:focused -- tests/boundary/mcp/applicationEvidenceMcp.test.ts — 1/1 pass
  • npm run verify:test-discovery — 1261 test files discovered exactly once
  • npm run lint — 0 errors
  • npx oxfmt --check on touched files — clean
  • npm run typecheck (tsc --noEmit) — 0 errors

Compatibility, safety, and release

  • Breaking changes or migration steps: none.
  • Real Hopper/Ghidra, browser, or OS coverage: not applicable (local session projection).
  • Package or release metadata impact: none.
  • Security, privacy, process, or containment review: read-only identifier projection; no new authority.

Author readiness

Human owner: @sx4im

  • I reviewed the final diff and relevant existing code, understand the change and its edge cases, and take responsibility for the complete PR, including AI-assisted work.
  • I checked the evidence above, confirmed it supports the current change, and recorded meaningful validation gaps.
  • I declare this PR ready for initial maintainer review.

Before merge

  • This PR addresses a concrete problem or an agreed enhancement.
  • Material scope and authority questions are resolved, and any required maintainer scope decision covers the final diff.
  • The PR has one focused outcome and the title follows type(scope): outcome.
  • Related issue is linked, or the reason for not linking one is stated above.
  • Tests cover changed observable behavior and meaningful failure paths.
  • Owning docs, contracts, and generated metadata are updated where needed.
  • User-visible CLI/MCP changes include representative output.
  • I checked the final diff for secrets, unrelated cleanup, and unsupported claims.

prompt completion for imported artifact inspections read only
substeps[0], omitting identifiers from later retained inventory
substeps. Collect candidates from all substeps instead, preserving
per-substep inventory validation so malformed payloads still yield
no candidates. Fixes morluto#3220.

Co-authored-by: Saim Shafique <[email protected]>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

@greptile-apps

greptile-apps Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no blocking issues remain.

Summary

Prompt completion now collects manifest and occurrence IDs from every retained inventory substep.

  • Prompt completion suggests manifest and occurrence IDs from every retained inventory substep.

Reviews (4) · Last reviewed commit: "style(mcp): format malformed-inventory t..." · Reviewed by Greptile

sx4im and others added 3 commits October 14, 2026 13:32
Greptile P2: guard the per-substep skip so a malformed inventory
substep cannot hide valid identifiers from later substeps.

Co-authored-by: Saim Shafique <[email protected]>
tsc --noEmit (noUncheckedIndexedAccess) flagged substeps[0] as possibly
undefined at tests/boundary/mcp/promptCompletion.test.ts:329. Extract the
first substep with an explicit guard instead.

Co-authored-by: Saim Shafique <[email protected]>
@morluto morluto added bug Something isn't working area: mcp MCP server, transport, and tool registration labels Oct 14, 2026

@rahul05ranjan rahul05ranjan 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.

Verified the drop: on the base, evidenceValues for inspect_artifact evidence read only substeps[0]?.evidence.normalized_result, so identifiers from any later retained substep never reached manifest/occurrence completion. Collecting from the whole substeps array is the right shape here — the inspection schema restricts substeps to operation: "inventory_artifact", status: "completed", so there is no other substep kind being missed, and candidates are derived from the schema-parsed data rather than a duplicated list.

The per-substep safeParse + continue is actually a small improvement beyond the reported case: previously a malformed first substep zeroed the entire evidence record, now a malformed substep is skipped while later valid ones still contribute. The second new test covers exactly that. Ordering/dedup are delegated to the outer uniqueSorted + prefix filter in complete(), which matches the sorted/deduplicated contract in docs/mcp-prompts.md, and the test expectations line up with it.

Ran npx vitest run tests/boundary/mcp/promptCompletion.test.ts on the PR head — 8/8 pass, both new multi-substep cases included.

One thing this fix surfaces but doesn't touch: parseArtifactInventoryEvidence (src/domain/artifactInventoryEvidence.ts, the inspect_artifact branch around line 64) still uses the identical substeps[0]?.evidence read, and it feeds compareArtifacts plus the android/apple application parsers. An imported multi-substep inspection passed there still silently compares only the first substep's inventory — same class of drop, with results-affecting rather than completion-only impact. I understand it's out of scope for this PR, but since multi-substep imports are a real retained shape (that's the premise of this fix), it'd be worth a follow-up issue so it doesn't get lost.

@sx4im

sx4im commented Oct 15, 2026

Copy link
Copy Markdown
Contributor Author

Closing this as superseded by main — the underlying issue is now handled directly: 9ac91e0c ("bind inspection provenance to every retained inventory") maps every retained substep in parseArtifactInventoryEvidence, and the promptCompletion rework aggregates completion inventories across all evidence records, so there is no longer a first-substep-only path.

Appreciate the review @rahul05ranjan — thanks for verifying it on your own machine.

@sx4im sx4im closed this Oct 15, 2026
@morluto

morluto commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Thanks @sx4im for finding that prompt completion stopped at the first retained inventory substep. Main now aggregates completion candidates across retained evidence records and covers the multi-step path at the MCP boundary (main).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: mcp MCP server, transport, and tool registration bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Prompt completion omits inventories after the first imported artifact inspection substep

3 participants