From 85ac71b9754da15c41e081c48ac0814eca3bd9da Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 15:51:11 +0000 Subject: [PATCH 01/14] Start working record for issue 585 --- specs/issue-585/log.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 specs/issue-585/log.md diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md new file mode 100644 index 00000000..c8d98601 --- /dev/null +++ b/specs/issue-585/log.md @@ -0,0 +1,8 @@ +# Log: issue #585 + +One line per pipeline step: date and time of day (UTC), step, member, result. Lead decisions and escalations +are quoted in full. + +| Date | Step | Member | Result | +| ---- | ---- | ------ | ------ | +| 2026-11-28 15:51 | 1 Intake | Orchestrator | Bug #585 (label bug, open, milestone v1.3.11): non-array root of Engine container list / image history reads unexpected error; branch claude/happy-wozniak-73m7oe off main 0261f5d | From 3f649fb3cbe2b55694804f88af24f0ca88c7acec Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 15:56:30 +0000 Subject: [PATCH 02/14] Plan issue 585 --- ...m-that-is-not-a-json-object-is-left-out.md | 3 +- ...ot-a-json-object-is-an-invalid-response.md | 7 +- ...not-a-json-array-is-an-invalid-response.md | 57 ++++++ docs/decisions/README.md | 1 + specs/issue-585/log.md | 1 + specs/issue-585/plan.md | 184 ++++++++++++++++++ 6 files changed, 249 insertions(+), 4 deletions(-) create mode 100644 docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md create mode 100644 specs/issue-585/plan.md diff --git a/docs/decisions/0069-a-docker-engine-list-item-that-is-not-a-json-object-is-left-out.md b/docs/decisions/0069-a-docker-engine-list-item-that-is-not-a-json-object-is-left-out.md index df7c977f..ad4ce7c0 100644 --- a/docs/decisions/0069-a-docker-engine-list-item-that-is-not-a-json-object-is-left-out.md +++ b/docs/decisions/0069-a-docker-engine-list-item-that-is-not-a-json-object-is-left-out.md @@ -42,7 +42,8 @@ still read. The rules are in [Docker instances](../areas/docker-instances.md). samples no container and succeeds with count 0, and a history succeeds without entries, after which derived runtime findings that rested on history text can be deactivated instead of kept. An Engine able to send such items can send an empty list to the same effect today. -- A root that is not a JSON array keeps failing the call. An item of an unexpected kind inside an entry's string list +- A root that is not a JSON array keeps failing the call, with `invalid response` by + [0075](0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md). An item of an unexpected kind inside an entry's string list (a number among a history entry's tags, say) is decided by [0071](0071-a-docker-engine-string-list-item-that-is-not-a-json-string-is-left-out.md). - Revisit, with a warning per left-out item, if operators need to find an Engine that sends such items. diff --git a/docs/decisions/0074-a-docker-engine-stats-or-image-inspect-answer-that-is-not-a-json-object-is-an-invalid-response.md b/docs/decisions/0074-a-docker-engine-stats-or-image-inspect-answer-that-is-not-a-json-object-is-an-invalid-response.md index fcda54e5..4dd251d1 100644 --- a/docs/decisions/0074-a-docker-engine-stats-or-image-inspect-answer-that-is-not-a-json-object-is-an-invalid-response.md +++ b/docs/decisions/0074-a-docker-engine-stats-or-image-inspect-answer-that-is-not-a-json-object-is-an-invalid-response.md @@ -33,7 +33,8 @@ The planning of #581 found the difference. 3. **Refuse a non-object host info answer too** — 0068 rejected it (its option 4): the collector takes a failed and a zero host memory alike as 0, so only a log entry would change. 4. **Refuse a container list or image history root that is not an array in the same change** — the same kind of - defect, but a new parse rule for arrays beyond what the issue asks; proposed as a follow-up issue. + defect, but a new parse rule for arrays beyond what the issue asks; decided by + [0075](0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md). 5. **Map the reader's `InvalidOperationException` to `invalid response`** — rejected by 0019 and 0029 for the misuse the runtime reports with the same type. @@ -48,5 +49,5 @@ in [Docker instances](../areas/docker-instances.md) and - Warnings 3111 and 3112 and the failed inspect result read `invalid response` for such a body instead of `unexpected error`; which container or image is affected, and how, does not change. -- A container list or image history whose root is not an array still reads `unexpected error` until the follow-up - issue decides it. \ No newline at end of file +- A container list or image history whose root is not an array reads `invalid response` by + [0075](0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md). \ No newline at end of file diff --git a/docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md b/docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md new file mode 100644 index 00000000..d223e84e --- /dev/null +++ b/docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md @@ -0,0 +1,57 @@ +# 0075: A Docker Engine container list or image history that is not a JSON array is an invalid response + +- **Status:** Proposed +- **Date:** 2026-11-28 +- **Area:** Docker instances +- **Source:** Issue #585 +- **Supersedes:** — + +## Context + +Discovery and resource sampling read the Engine's container list, the image history reads the list of history +entries; each answer is a JSON array, and each item that is not a JSON object is left out +([0069](0069-a-docker-engine-list-item-that-is-not-a-json-object-is-left-out.md)). The client enumerated the root +without checking its kind, so a root of another kind (an object, a string, a number, `true`/`false`, `null`) made the +reader throw `InvalidOperationException`, and the fixed reason +([0009](0009-integration-results-carry-fixed-failure-reasons.md)) of the failed discovery, resource collection or +history was `unexpected error`. Since +[0074](0074-a-docker-engine-stats-or-image-inspect-answer-that-is-not-a-json-object-is-an-invalid-response.md) a stats +or image inspect answer that is not a JSON object reads `invalid response`, so two malformed answers of the same Engine +read differently. Only a broken or hostile Engine, or a proxy in front of it, sends such a body. The planning of #583 +found the difference. + +## Options considered + +1. **Parse the container list and the image history as a JSON array where the body is parsed (chosen)** — the rule of + 0074 and [0073](0073-a-registry-answer-that-is-not-a-json-object-is-an-invalid-response-and-an-entry-that-is-not-one-is-left-out.md) + for the other root kind: the root is refused as malformed JSON is, so the existing handlers answer + `invalid response` without a new handler; the outcome (a failed call) is unchanged. +2. **Keep `unexpected error`** — two reasons for one malformed Engine answer, depending on its root kind, and a reason + that reads like an error of the application. +3. **Read a root that is not an array as an empty list, as 0069 does for an item** — discovery would succeed without + containers, a resource round with no samples and a history without entries, so a malformed answer would read as an + Engine without containers and derived runtime findings resting on history text could be deactivated; an item is left + out because the other items still carry data, a root carries none. +4. **Check the root kind at each of the three call sites** — three copies of one check and its message where the + object check of 0073 sits in one place, so a later call site could miss it. +5. **Map the reader's `InvalidOperationException` to `invalid response`** — rejected by + [0019](0019-remote-json-with-undecodable-strings-is-an-invalid-response.md) and + [0029](0029-registry-calls-answer-every-error-but-the-callers-cancellation-as-failed.md) for the misuse the runtime + reports with the same type. + +## Decision + +Option 1: the Engine's container list, for discovery and for resource sampling, and its image history are parsed as a +JSON array and refused as an invalid response otherwise; the host info keeps the rule of +[0068](0068-an-unreadable-docker-engine-stats-or-host-memory-number-counts-as-missing.md). The reasons are in +[Docker instances](../areas/docker-instances.md) and +[Integration failures](../areas/integration-failures.md#fixed-failure-reasons). + +## Consequences + +- A failed discovery, resource collection or history caused by such a body reads `invalid response` instead of + `unexpected error`, in its result and in a scan run's error message; the calls still fail as before, and warnings + 3104, 3107 and 3109 still name the instance, now with the refusal's fixed message `The remote response is not a JSON + array` as their error. +- Every Engine answer the client reads as an object or an array now refuses the other kinds; only the host info reads + any root. \ No newline at end of file diff --git a/docs/decisions/README.md b/docs/decisions/README.md index 705f616b..69b3439a 100644 --- a/docs/decisions/README.md +++ b/docs/decisions/README.md @@ -135,4 +135,5 @@ once in the [area document](../areas/README.md) of the record's area, and the re | [0072](0072-a-registry-string-list-item-that-is-not-a-json-string-is-left-out.md) | A registry string list item that is not a JSON string is left out | Accepted | 2026-11-28 | | [0073](0073-a-registry-answer-that-is-not-a-json-object-is-an-invalid-response-and-an-entry-that-is-not-one-is-left-out.md) | A registry answer that is not a JSON object is an invalid response, and an entry that is not one is left out | Accepted | 2026-11-28 | | [0074](0074-a-docker-engine-stats-or-image-inspect-answer-that-is-not-a-json-object-is-an-invalid-response.md) | A Docker Engine stats or image inspect answer that is not a JSON object is an invalid response | Accepted | 2026-11-28 | +| [0075](0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md) | A Docker Engine container list or image history that is not a JSON array is an invalid response | Proposed | 2026-11-28 | \ No newline at end of file diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index c8d98601..9965b368 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -6,3 +6,4 @@ are quoted in full. | Date | Step | Member | Result | | ---- | ---- | ------ | ------ | | 2026-11-28 15:51 | 1 Intake | Orchestrator | Bug #585 (label bug, open, milestone v1.3.11): non-array root of Engine container list / image history reads unexpected error; branch claude/happy-wozniak-73m7oe off main 0261f5d | +| 2026-11-28 15:56 | 2 Plan | Lead | RESULT: DONE. Tier standard; plan.md, decision record 0075 (Proposed), 0069/0074 amended; ParseArrayAsync for container list, sampling, image history (opus/medium · 133,205 tokens · 41 tool uses · 311 s · 72 in · 28,039 out · 3,248,907 cache read · 131,104 cache write · 933,185 weighted) | diff --git a/specs/issue-585/plan.md b/specs/issue-585/plan.md new file mode 100644 index 00000000..e2edf99d --- /dev/null +++ b/specs/issue-585/plan.md @@ -0,0 +1,184 @@ +# Plan: A Docker Engine container list or image history body that is not a JSON array reads `unexpected error` + +Source: Issue #585 +Tier: standard — the fixed failure reason of three Engine calls changes for a malformed body (a behavior change), and no security control is created, changed or removed: a parser's root-kind check is input handling. +Security areas touched: Docker Engine access (`Docker/DockerInstanceClient.cs`: how the Engine's container list and image history answers are parsed); Registry and Docker Scout calls (`Infrastructure/RemoteJsonDocument.cs`, the shared remote JSON parser, gains a method; its existing methods keep their behavior) + +## Problem / root cause + +`DockerInstanceClient` parses three array answers with `RemoteJsonDocument.ParseAsync`, which accepts any root, and +then calls `JsonElement.EnumerateArray()` on the root: + +- discovery: `DiscoverContainersAsync` parses at `DockerInstanceClient.cs:1218`, `ParseContainers` enumerates at `:958`; +- resource sampling: `CollectContainerResourceUsageAsync` parses at `:1285`, `ReadContainerSamplesAsync` enumerates at `:1137`; +- image history: `ReadImageHistoryAsync` parses at `:922` and enumerates at `:926`. + +For a root that is not an array `EnumerateArray` throws `InvalidOperationException`; the call's catch-all +(`:1242`, `:1302`, `:1380`) turns it into *failed* with `FailureReason.FromException`, which maps only `JsonException` +to `invalid response` and everything else to `unexpected error` (`Infrastructure/FailureReason.cs:78-83`). Since #583 +the stats body and the image inspect answer are parsed with `ParseObjectAsync` (`:499`, `:869`) and read +`invalid response` for the wrong root kind; the array answers have no counterpart. + +## Verified facts + +| # | Claim | Evidence | Status | +| - | ----- | -------- | ------ | +| 1 | The three array answers are parsed with `ParseAsync` and enumerated without a kind check | `DockerInstanceClient.cs:1218`/`:958`, `:1285`/`:1137`, `:922`/`:926` | confirmed | +| 2 | A root that is not an array reads `unexpected error` today | `JsonElement.EnumerateArray` throws `InvalidOperationException` for another `ValueKind` (.NET API reference); `DockerInstanceClientGetImageHistoryAsyncWhenBodyIsNoArrayReturnsUnexpectedErrorAsync` (`DockerInstanceClientListItemsTests.cs:536`) pins it for the history with `{}`, `"text"`, `7` | confirmed | +| 3 | `FailureReason.FromException` maps `JsonException` to `invalid response`, any other exception (after cancellation, timeout, transport) to `unexpected error` | `Infrastructure/FailureReason.cs:78-83` | confirmed | +| 4 | A `JsonException` thrown by the parse reaches the call's catch-all in all three calls: `ReadImageHistoryAsync` catches only `OperationCanceledException` (`:939-946`), the outer `GetImageHistoryAsync` catches `Exception` (`:1380`); discovery and sampling parse inside their own `try` (`:1196-1247`, `:1265-1307`) | code | confirmed | +| 5 | The failures are logged as warnings 3104, 3107 and 3109 with the exception; their message templates carry no reason | `DockerInstanceClientLogging.cs:65-68`, `:101-104`, `:127-130` | confirmed | +| 6 | The failure messages are `Docker container discovery failed for '': `, `Docker container resource sampling failed for '': `, `Docker image history failed for '': ` | `DockerInstanceClient.cs:1246`, `:1306`, `:1384` | confirmed | +| 7 | The object rule sits in one place: `RemoteJsonDocument.ParseObjectAsync` runs `ParseAsync`, disposes the document and throws `JsonException("The remote response is not a JSON object")` without inner exception for another root | `Infrastructure/RemoteJsonDocument.cs:56-68`; `RemoteJsonDocumentTests.cs:166-176` | confirmed | +| 8 | After the change `ParseAsync` is called in production only by the host info (`:1423`), whose non-object root reads as no total memory (0068) | `grep RemoteJsonDocument.ParseAsync src/DockerUpdateGuard` | confirmed | +| 9 | The Engine answers `GET /containers/json` and `GET /images/{name}/history` with a JSON array | Docker Engine API v1.41 reference (ContainerList, ImageHistory); record 0069, *Context*; every list fixture of `DockerInstanceClientTests.cs` | confirmed | +| 10 | Records 0069 and 0074 are unreleased, so they are edited in place | `git ls-remote --tags origin` lists `v1.3.0`–`v1.3.10`; `git ls-tree -r docs/decisions` holds neither file in any of them | confirmed | +| 11 | No architecture or project text names the root rules | `docs/ARCHITECTURE.md:515` and `.squad/project.md:106` name `RemoteJsonDocument` only as "where strings must decode" | confirmed | + +## Acceptance criteria + +- AC1: `RemoteJsonDocument.ParseArrayAsync` returns the parsed document for a body whose root is a JSON array (`[]`, + `[ 1, "x", null ]`, `[ {} ]`); for every other root (`{}`, `{ "a": [] }`, `"x"`, `7`, `1.5`, `true`, `false`, + `null`) it throws exactly `JsonException` with the message `The remote response is not a JSON array` and no inner + exception; for an array body with a string that does not decode it throws exactly `JsonException` whose inner + exception is the `InvalidOperationException` of the decoding check, as `ParseAsync` does. +- AC2: A discovery whose container list body is `{}`, `"text"`, `7`, `true` or `null` answers *failed* with the message + `Docker container discovery failed for 'Production': invalid response`, logs warning 3104 once with a + `JsonException`, and sends no request after the list request (no image inspect). +- AC3: A resource collection whose container list body is `{}`, `"text"`, `7`, `true` or `null` answers *failed* with + the message `Docker container resource sampling failed for 'Production': invalid response` and sends no stats + request. +- AC4: An image history whose body is `{}`, `"text"`, `7`, `true` or `null` answers *failed* with the message + `Docker image history failed for 'Production': invalid response`. + +The reason text comes from `FailureReason.FromException` (fact 3) on the `JsonException` the parse throws; the message +prefixes are the ones of fact 6. + +## Tests per criterion + +| AC | Test(s) | Test file | +| -- | ------- | --------- | +| AC1 | `RemoteJsonDocumentParseArrayAsyncWhenRootIsAnArrayReturnsDocumentAsync`, `RemoteJsonDocumentParseArrayAsyncWhenRootIsNoArrayThrowsJsonExceptionAsync`, `RemoteJsonDocumentParseArrayAsyncWhenAStringDoesNotDecodeThrowsJsonExceptionAsync` | `src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs` | +| AC2 | `DockerInstanceClientDiscoverContainersAsyncWhenListBodyIsNoArrayReturnsInvalidResponseAsync` | `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs` | +| AC3 | `DockerInstanceClientCollectContainerResourceUsageAsyncWhenListBodyIsNoArrayReturnsInvalidResponseAsync` | `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs` | +| AC4 | `DockerInstanceClientGetImageHistoryAsyncWhenBodyIsNoArrayReturnsInvalidResponseAsync` (the existing `…ReturnsUnexpectedErrorAsync` at `:536`, renamed, its category set to `AC4`, rows `true` and `null` added and its expectation changed) | `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs` | + +The AC1 undecodable case reuses `GetUndecodableBodies` only for its array bodies, or wraps each body in an array; the +backslash guard of the existing undecodable tests (`Assert.Contains((byte)Backslash, …)` for an escape case) stays in +front, so a case that lost its backslash fails. AC2 and AC3 read the request count from +`SequenceHttpMessageHandler.Requests` (one request each). + +## Approach + +1. `RemoteJsonDocument` gets `ParseArrayAsync`, the array counterpart of `ParseObjectAsync`, with the constant + `NotAnArrayMessage = "The remote response is not a JSON array"` beside `NotAnObjectMessage`. Both public methods + delegate to one private static helper, `ParseRootAsync(Stream stream, JsonValueKind rootKind, string refusalMessage, + CancellationToken cancellationToken)`, which runs `ParseAsync`, and when the root's `ValueKind` is not `rootKind` + disposes the document and throws `new JsonException(refusalMessage)` — no inner exception, no remote text. The + string check runs first, as in `ParseObjectAsync` today, so an undecodable string of a body with the wrong root + reads the undecodable refusal; both read `invalid response`. `ParseObjectAsync`'s behavior is unchanged (its + tests stay as they are). +2. `DockerInstanceClient`: the three parses of fact 1 call `ParseArrayAsync` instead of `ParseAsync`. No catch block, + log event or message changes: the `JsonException` takes the existing path to `invalid response` (fact 4). The host + info keeps `ParseAsync` (0068). +3. The class summary of `RemoteJsonDocument` names the root checks ("…and refuses a body whose strings do not decode + or, where asked, whose root is not of the expected kind…" — wording free for the Dev). + +No new user-visible output beyond the reason text; no resource bound changes. + +Early draft PR: no + +## Options considered + +1. **`RemoteJsonDocument.ParseArrayAsync` at the three call sites (chosen)** — the object rule of 0073/0074 for the + other root kind, in the one place every remote parse passes. +2. **Keep `unexpected error`** — lost: one malformed Engine answer would read two ways by its root kind (0075, option 2). +3. **Read a non-array root as an empty list (0069's rule for items)** — lost: discovery would succeed without + containers and a history without entries, so a malformed answer would read as an empty Engine (0075, option 3). +4. **A kind check at each call site** — lost: three copies of one check and message (0075, option 4). +5. **Map `InvalidOperationException` to `invalid response` in `FailureReason`** — lost: rejected by 0019 and 0029. + +## Affected projects and types + +| Project | Type / file | Change | +| ------- | ----------- | ------ | +| DockerUpdateGuard | `Infrastructure/RemoteJsonDocument.cs` | `ParseArrayAsync`, `NotAnArrayMessage`, private `ParseRootAsync` shared with `ParseObjectAsync`; summary | +| DockerUpdateGuard | `Docker/DockerInstanceClient.cs` | three `ParseAsync` calls become `ParseArrayAsync` (`:922`, `:1218`, `:1285`) | +| DockerUpdateGuard.Tests | `RemoteJsonDocumentTests.cs`, `DockerInstanceClientListItemsTests.cs` | tests of *Tests per criterion* | + +## Signatures (for the Dev's skeleton) + +In `internal static class RemoteJsonDocument` (`Infrastructure/RemoteJsonDocument.cs`), region *Static methods*, +after `ParseObjectAsync`: + +- `public static async Task ParseArrayAsync(Stream stream, CancellationToken cancellationToken)` + +The skeleton's body returns `await ParseAsync(stream, cancellationToken).ConfigureAwait(false)` (no root check), so +AC1's refusal tests fail and its accepting test passes; the private helper and the constant are the implementation's. +Name and parameters follow `ParseObjectAsync`, which passes the *Analyzer gate*. `RemoteJsonDocument.cs` and +`DockerInstanceClient.cs` were read; no other file needs rewriting for the skeleton. The three call-site swaps are the +implementation (step 6), not the skeleton, so AC2–AC4 fail on the skeleton. + +## Test files + +- `src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs` (AC1) +- `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs` (AC2–AC4) + +Existing test code that calls a changed signature: none (`ParseAsync` and `ParseObjectAsync` keep theirs). Existing +tests with an input a criterion handles differently: only +`DockerInstanceClientGetImageHistoryAsyncWhenBodyIsNoArrayReturnsUnexpectedErrorAsync` (`:536`), adapted by the +Tester in step 5 (AC4). Every other list fixture of the Docker Engine tests has an array root and stays unchanged. + +Files of the change no unit test can cover: none. + +## Areas + +- `docs/areas/docker-instances.md` (3381 words now, +70 words): *Container discovery*, first bullet — a container list + whose root is not a JSON array fails discovery with `invalid response`; *Image inspection and history*, first + bullet — a history whose root is not a JSON array answers *failed* with `invalid response`; the resource-collection + failure bullet (`A resource collection fails for an instance when the list request fails or times out, …`) — also + when the list's root is not a JSON array (`invalid response`); *Related decisions* — the 0075 entry. +- `docs/areas/integration-failures.md` (2467 words now, +15 words): *Fixed failure reasons*, the `invalid response` + bullet — add a Docker Engine container list or image history whose root is not a JSON array. +- `docs/areas/telemetry.md` (1639 words now, +30 words): *Credentials and external data*, the JSON parse failure + bullet — the refusal of a Docker Engine container list or image history whose root is not a JSON array carries the + fixed message `The remote response is not a JSON array` and no inner exception. + +## Documentation updates + +All by the Dev, once the code is green, against that code: + +- `docs/areas/docker-instances.md`, `docs/areas/integration-failures.md`, `docs/areas/telemetry.md`: as *Areas*. +- `docs/ARCHITECTURE.md`, `README.md`, `.squad/project.md`: none (fact 11); no changelog file exists, and the PR + template asks for none beyond the area documents and the record. + +Sweep: the hits for "not a JSON object", "JSON array", "unexpected error" and `RemoteJsonDocument` in `docs/areas/` +and `docs/ARCHITECTURE.md` are the three areas above (`docker-instances.md:95`, `:123`, `:166-167`, `:230`, +`:254-259`; `integration-failures.md:34`; `telemetry.md:125`), `ARCHITECTURE.md:515` (no change) and +`scan-engine.md:89`, `:202-203` (about unexpected errors of a run, no change). + +## Architecture check + +The fixed-reason guarantee (0009, `docs/ARCHITECTURE.md` *Security posture*) holds: the reason stays one of the fixed +set, the new exception message is fixed text without remote content, and the parse still goes through `ExternalJson` +(0045). Error isolation is unchanged: the calls fail as before, only their reason changes. + +## Security considerations + +- [x] No limits: no byte or length bound is added or changed. +- [x] The new `JsonException("The remote response is not a JSON array")` reaches the user only as `invalid response` + through `FailureReason.FromException`, in the three messages of AC2–AC4; its own message reaches only the log + entries 3104, 3107, 3109 as their exception. The `InvalidOperationException` of the runtime no longer reaches these + calls for a wrong root. + +## Decision records + +- `docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md` + (Proposed, indexed). +- Edited in place (unreleased, fact 10): 0069 *Consequences* (a non-array root fails with `invalid response`, linking + 0075, as the issue asks); 0074 option 4 and its second consequence now point to 0075. + +## Out of scope / follow-ups + +- The host info's non-object root stays read as no total memory (0068). +- Record 0071 still says a history that is not a JSON array keeps failing the call, which stays true; no edit. \ No newline at end of file From f8a53665e78d051a6ac591c3e626c2970186cdef Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 15:57:16 +0000 Subject: [PATCH 03/14] Log plan security review for issue 585 --- specs/issue-585/log.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index 9965b368..7729ae8c 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -7,3 +7,4 @@ are quoted in full. | ---- | ---- | ------ | ------ | | 2026-11-28 15:51 | 1 Intake | Orchestrator | Bug #585 (label bug, open, milestone v1.3.11): non-array root of Engine container list / image history reads unexpected error; branch claude/happy-wozniak-73m7oe off main 0261f5d | | 2026-11-28 15:56 | 2 Plan | Lead | RESULT: DONE. Tier standard; plan.md, decision record 0075 (Proposed), 0069/0074 amended; ParseArrayAsync for container list, sampling, image history (opus/medium · 133,205 tokens · 41 tool uses · 311 s · 72 in · 28,039 out · 3,248,907 cache read · 131,104 cache write · 933,185 weighted) | +| 2026-11-28 15:57 | 3 Plan security | Security | VERDICT: APPROVED. No findings; tier standard confirmed (opus/medium · 39,615 tokens · 6 tool uses · 33 s · 12 in · 2,801 out · 153,179 cache read · 38,268 cache write · 139,022 weighted) | From c3594ca78117c8b278d8340ef398f6687d69e5af Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 15:58:08 +0000 Subject: [PATCH 04/14] Add challenge notes to plan for issue 585 --- specs/issue-585/log.md | 2 ++ specs/issue-585/plan.md | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index 7729ae8c..6852618d 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -8,3 +8,5 @@ are quoted in full. | 2026-11-28 15:51 | 1 Intake | Orchestrator | Bug #585 (label bug, open, milestone v1.3.11): non-array root of Engine container list / image history reads unexpected error; branch claude/happy-wozniak-73m7oe off main 0261f5d | | 2026-11-28 15:56 | 2 Plan | Lead | RESULT: DONE. Tier standard; plan.md, decision record 0075 (Proposed), 0069/0074 amended; ParseArrayAsync for container list, sampling, image history (opus/medium · 133,205 tokens · 41 tool uses · 311 s · 72 in · 28,039 out · 3,248,907 cache read · 131,104 cache write · 933,185 weighted) | | 2026-11-28 15:57 | 3 Plan security | Security | VERDICT: APPROVED. No findings; tier standard confirmed (opus/medium · 39,615 tokens · 6 tool uses · 33 s · 12 in · 2,801 out · 153,179 cache read · 38,268 cache write · 139,022 weighted) | +| 2026-11-28 15:57 | 2 Plan challenge | Devil's Advocate | VERDICT: OBJECTIONS 0 major, 2 minor. (1) AC1 undecodable test needs array-wrapped bodies of GetUndecodableBodies and an order test for object root; (2) DotNetReleaseMetadataService.cs:155-158 has the same defect for a non-object root (opus/medium · 60,001 tokens · 16 tool uses · 77 s · 28 in · 6,466 out · 565,628 cache read · 58,581 cache write · 267,731 weighted) | +| 2026-11-28 15:58 | 2 Challenge notes | Orchestrator | minor objections appended verbatim to plan.md; follow-up #587 linked under Out of scope | diff --git a/specs/issue-585/plan.md b/specs/issue-585/plan.md index e2edf99d..da9b2c1a 100644 --- a/specs/issue-585/plan.md +++ b/specs/issue-585/plan.md @@ -181,4 +181,34 @@ set, the new exception message is fixed text without remote content, and the par ## Out of scope / follow-ups - The host info's non-object root stays read as no total memory (0068). -- Record 0071 still says a history that is not a JSON array keeps failing the call, which stays true; no edit. \ No newline at end of file +- Record 0071 still says a history that is not a JSON array keeps failing the call, which stays true; no edit. +- `DotNetReleaseMetadataService.cs` reads a release index whose root is not an object as `unexpected error`; a different client, tracked in #587. + +## Challenge notes + +The plan holds up. I found two minor objections and nothing that needs a plan change before the build. + +**Claims I checked against the code** +- All three array parses still use `RemoteJsonDocument.ParseAsync`: + - history at `src/DockerUpdateGuard/Docker/DockerInstanceClient.cs:922`, enumerated at `:926` + - discovery at `:1218`, enumerated in `ParseContainers` at `:958` + - sampling at `:1285`, enumerated in `ReadContainerSamplesAsync` at `:1137` +- Each call has a catch-all (`:1242`, `:1302`, `:1380`) that logs the exception and returns `FailureReason.FromException`, so a `JsonException` takes the existing path to `invalid response`. +- `ParseObjectAsync` (`src/DockerUpdateGuard/Infrastructure/RemoteJsonDocument.cs:56-68`) is the pattern the new method copies. It runs the string check first and then throws a `JsonException` with no inner exception. +- After the swap, the only production `ParseAsync` caller left is the host info at `:1423`, as fact 8 says. +- **Sibling paths:** every other `EnumerateArray` in production code checks the kind first or is only called after its caller checked: + - `DockerInstanceClient.cs:530-532` + - `DockerHubClient.cs:237/467/517`, and `:656` before `ManifestPlatformSelector` + - `OciRegistryClient.cs:826-832` + - `JsonStringListReader.cs:21-26` +- **Request counts in AC2/AC3:** with `ParseArrayAsync` the throw comes before `PopulateRepositoryDigestsAsync` and before any stats request, so one request is right. `SequenceHttpMessageHandler.Requests` exists, and `TestLogger` records the exception, so "3104 once with a `JsonException`" can be asserted. +- The only existing test whose input changes meaning is the one at `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs:536`, as the plan says. +- Need, alternatives and tier: option 1 is the least invasive choice, and 0075's options cover the alternatives. Standard tier fits. + +**Objections** + +1. `minor` — The AC1 undecodable test has no array bodies to reuse. All ten rows of `GetUndecodableBodies` (`src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs:224-234`) have an object root, so "only for its array bodies" gives an empty data source. Instruction for the Tester: + - Wrap each body of `GetUndecodableBodies` in `[` … `]` (for example a `GetUndecodableArrayBodies` source built from it), keeping the backslash guard in front. + - Also pin the order the plan states in Approach step 1: an undecodable body with an object root passed to `ParseArrayAsync` throws a `JsonException` whose inner exception is the `InvalidOperationException`, not the root refusal. + +2. `minor` — The same defect remains outside the Docker Engine, and the plan does not mention it. `src/DockerUpdateGuard/Images/DotNetReleaseMetadataService.cs:155-158` parses the .NET release index with `ExternalJson.ParseAsync` and calls `RootElement.TryGetProperty` with no root-kind check. A root that is not an object throws `InvalidOperationException`, and the catch at `:193-197` reports `unexpected error`. Instruction for the Lead or orchestrator: add it under *Out of scope / follow-ups* and open a linked issue. Do not widen this change: it is a different client, and `docs/areas/integration-failures.md:37` already documents `unexpected error` for the release feeds' undecodable strings. From bd0497f344ad02a7d891f18375321ceebc04bf08 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:00:35 +0000 Subject: [PATCH 05/14] Add skeleton for issue 585 --- specs/issue-585/log.md | 1 + .../Infrastructure/RemoteJsonDocument.cs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index 6852618d..68b15f8a 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -10,3 +10,4 @@ are quoted in full. | 2026-11-28 15:57 | 3 Plan security | Security | VERDICT: APPROVED. No findings; tier standard confirmed (opus/medium · 39,615 tokens · 6 tool uses · 33 s · 12 in · 2,801 out · 153,179 cache read · 38,268 cache write · 139,022 weighted) | | 2026-11-28 15:57 | 2 Plan challenge | Devil's Advocate | VERDICT: OBJECTIONS 0 major, 2 minor. (1) AC1 undecodable test needs array-wrapped bodies of GetUndecodableBodies and an order test for object root; (2) DotNetReleaseMetadataService.cs:155-158 has the same defect for a non-object root (opus/medium · 60,001 tokens · 16 tool uses · 77 s · 28 in · 6,466 out · 565,628 cache read · 58,581 cache write · 267,731 weighted) | | 2026-11-28 15:58 | 2 Challenge notes | Orchestrator | minor objections appended verbatim to plan.md; follow-up #587 linked under Out of scope | +| 2026-11-28 16:00 | 4 Skeleton | Dev | RESULT: skeleton done. ParseArrayAsync throws Skeleton body; deviation: no async modifier (CS1998); no pragmas; build 0 warnings (sonnet/medium · 84,848 tokens · 8 tool uses · 137 s · 14 in · 2,658 out · 485,746 cache read · 84,136 cache write · 167,049 weighted) | diff --git a/src/DockerUpdateGuard/Infrastructure/RemoteJsonDocument.cs b/src/DockerUpdateGuard/Infrastructure/RemoteJsonDocument.cs index f2f260d3..3da7620b 100644 --- a/src/DockerUpdateGuard/Infrastructure/RemoteJsonDocument.cs +++ b/src/DockerUpdateGuard/Infrastructure/RemoteJsonDocument.cs @@ -67,6 +67,17 @@ public static async Task ParseObjectAsync(Stream stream, Cancellat return document; } + /// + /// Parse a stream into a JSON document whose root is an array and verify that every string decodes + /// + /// Stream to parse + /// Cancellation token + /// Parsed document + public static Task ParseArrayAsync(Stream stream, CancellationToken cancellationToken) + { + throw new InvalidOperationException("Skeleton: not implemented"); + } + /// /// Verify that every string value and property name of an element decodes /// From 9309765aebecbd8670d3b0edc5e4e88eea1ac0e0 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:02:45 +0000 Subject: [PATCH 06/14] Add failing tests for issue 585 --- specs/issue-585/log.md | 1 + .../DockerInstanceClientListItemsTests.cs | 73 +++++++++++- .../RemoteJsonDocumentTests.cs | 112 ++++++++++++++++++ 3 files changed, 183 insertions(+), 3 deletions(-) diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index 68b15f8a..5718968e 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -11,3 +11,4 @@ are quoted in full. | 2026-11-28 15:57 | 2 Plan challenge | Devil's Advocate | VERDICT: OBJECTIONS 0 major, 2 minor. (1) AC1 undecodable test needs array-wrapped bodies of GetUndecodableBodies and an order test for object root; (2) DotNetReleaseMetadataService.cs:155-158 has the same defect for a non-object root (opus/medium · 60,001 tokens · 16 tool uses · 77 s · 28 in · 6,466 out · 565,628 cache read · 58,581 cache write · 267,731 weighted) | | 2026-11-28 15:58 | 2 Challenge notes | Orchestrator | minor objections appended verbatim to plan.md; follow-up #587 linked under Out of scope | | 2026-11-28 16:00 | 4 Skeleton | Dev | RESULT: skeleton done. ParseArrayAsync throws Skeleton body; deviation: no async modifier (CS1998); no pragmas; build 0 warnings (sonnet/medium · 84,848 tokens · 8 tool uses · 137 s · 14 in · 2,658 out · 485,746 cache read · 84,136 cache write · 167,049 weighted) | +| 2026-11-28 16:02 | 5 Tests first | Tester | RESULT: tests-first complete; 46 new/adapted cases compile and fail on skeleton (confirmed by orchestrator: 46 failed, 105 passed). Deferred: none (sonnet/medium · 111,356 tokens · 11 tool uses · 91 s · 18 in · 9,377 out · 827,861 cache read · 56,311 cache write · 200,078 weighted) | diff --git a/src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs b/src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs index dab6fc7a..b22104d7 100644 --- a/src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs +++ b/src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs @@ -1,3 +1,5 @@ +using System.Text.Json; + using DockerUpdateGuard.Configuration; using DockerUpdateGuard.Docker; using DockerUpdateGuard.Infrastructure; @@ -524,7 +526,7 @@ public async Task DockerInstanceClientInspectImageAsyncWhenBodyIsNoObjectReturns } /// - /// Verify an image history answer that is not a JSON array still fails with the fixed unexpected-error reason + /// Verify an image history answer that is not a JSON array fails with the fixed invalid-response reason /// /// JSON of the answer /// Task @@ -533,7 +535,9 @@ public async Task DockerInstanceClientInspectImageAsyncWhenBodyIsNoObjectReturns [DataRow("{}")] [DataRow("\"text\"")] [DataRow("7")] - public async Task DockerInstanceClientGetImageHistoryAsyncWhenBodyIsNoArrayReturnsUnexpectedErrorAsync(string bodyJson) + [DataRow("true")] + [DataRow("null")] + public async Task DockerInstanceClientGetImageHistoryAsyncWhenBodyIsNoArrayReturnsInvalidResponseAsync(string bodyJson) { using var handler = new SequenceHttpMessageHandler(); using var httpClient = CreateHttpClient(handler); @@ -545,7 +549,70 @@ public async Task DockerInstanceClientGetImageHistoryAsyncWhenBodyIsNoArrayRetur var result = await client.GetImageHistoryAsync(CreateInstanceOptions(), "sha256:local-image", TestContext.CancellationToken).ConfigureAwait(false); Assert.AreEqual(ExternalOperationStatus.Failed, result.Status, $"An answer {bodyJson} that is no array must fail the history"); - Assert.AreEqual("Docker image history failed for 'Production': unexpected error", result.Message, "The failure must carry the fixed reason"); + Assert.AreEqual("Docker image history failed for 'Production': invalid response", result.Message, "The failure must carry the fixed reason"); + } + + /// + /// Verify a container list that is not a JSON array fails the discovery with the fixed invalid-response reason, logs it once and sends no further request + /// + /// JSON of the answer + /// Task + [TestMethod] + [TestCategory("AC2")] + [DataRow("{}")] + [DataRow("\"text\"")] + [DataRow("7")] + [DataRow("true")] + [DataRow("null")] + public async Task DockerInstanceClientDiscoverContainersAsyncWhenListBodyIsNoArrayReturnsInvalidResponseAsync(string bodyJson) + { + using var handler = new SequenceHttpMessageHandler(); + using var httpClient = CreateHttpClient(handler); + + handler.AddJsonResponse("https://docker.example.test/v1.41/containers/json?all=1", bodyJson); + + var logger = new TestLogger(); + var client = new DockerInstanceClient(logger, (_, _) => httpClient); + + var result = await client.DiscoverContainersAsync(CreateInstanceOptions(), TestContext.CancellationToken).ConfigureAwait(false); + + Assert.AreEqual(ExternalOperationStatus.Failed, result.Status, $"A list {bodyJson} that is no array must fail the discovery"); + Assert.AreEqual("Docker container discovery failed for 'Production': invalid response", result.Message, "The failure must carry the fixed reason"); + + var entry = Assert.ContainsSingle(logger.Entries.Where(logEntry => logEntry.EventId.Id == 3104).ToList(), "The failed discovery must be logged once"); + + Assert.IsInstanceOfType(entry.Exception, "The log entry must carry the JSON exception of the refusal"); + Assert.HasCount(1, handler.Requests, "No request after the list request may be sent"); + } + + /// + /// Verify a container list that is not a JSON array fails the resource collection with the fixed invalid-response reason and sends no stats request + /// + /// JSON of the answer + /// Task + [TestMethod] + [TestCategory("AC3")] + [DataRow("{}")] + [DataRow("\"text\"")] + [DataRow("7")] + [DataRow("true")] + [DataRow("null")] + public async Task DockerInstanceClientCollectContainerResourceUsageAsyncWhenListBodyIsNoArrayReturnsInvalidResponseAsync(string bodyJson) + { + using var handler = new SequenceHttpMessageHandler(); + using var httpClient = CreateHttpClient(handler); + + handler.AddJsonResponse("https://docker.example.test/v1.41/containers/json", bodyJson); + + var client = new DockerInstanceClient(new TestLogger(), (_, _) => httpClient); + + var result = await client.CollectContainerResourceUsageAsync(CreateInstanceOptions(), TestContext.CancellationToken).ConfigureAwait(false); + + Assert.AreEqual(ExternalOperationStatus.Failed, result.Status, $"A list {bodyJson} that is no array must fail the sampling"); + Assert.AreEqual("Docker container resource sampling failed for 'Production': invalid response", result.Message, "The failure must carry the fixed reason"); + Assert.DoesNotContain(request => request.RequestUri.Contains("/stats", StringComparison.Ordinal), + handler.Requests, + "No stats request must be sent"); } /// diff --git a/src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs b/src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs index 074d957b..4316d1fd 100644 --- a/src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs +++ b/src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs @@ -201,6 +201,104 @@ public async Task RemoteJsonDocumentParseObjectAsyncWhenAStringDoesNotDecodeThro Assert.IsInstanceOfType(exception.InnerException, $"The refusal of case '{label}' must keep the decoding error as inner exception"); } + /// + /// Verify a body whose root is an array is returned as a parsed document + /// + /// Response body + /// Task + [TestMethod] + [TestCategory("AC1")] + [DataRow("[]")] + [DataRow("[ 1, \"x\", null ]")] + [DataRow("[ {} ]")] + public async Task RemoteJsonDocumentParseArrayAsyncWhenRootIsAnArrayReturnsDocumentAsync(string json) + { + using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); + + using var document = await RemoteJsonDocument.ParseArrayAsync(stream, TestContext.CancellationToken).ConfigureAwait(false); + + Assert.AreEqual(JsonValueKind.Array, document.RootElement.ValueKind, $"The document of '{json}' must be returned with its root array"); + } + + /// + /// Verify a body whose root is not an array is refused as a JSON exception with the fixed message and no inner exception + /// + /// Response body + /// Task + [TestMethod] + [TestCategory("AC1")] + [DataRow("{}")] + [DataRow("""{ "a": [] }""")] + [DataRow("\"x\"")] + [DataRow("7")] + [DataRow("1.5")] + [DataRow("true")] + [DataRow("false")] + [DataRow("null")] + public async Task RemoteJsonDocumentParseArrayAsyncWhenRootIsNoArrayThrowsJsonExceptionAsync(string json) + { + using var stream = new MemoryStream(Encoding.UTF8.GetBytes(json)); + + var exception = await Assert.ThrowsExactlyAsync(() => RemoteJsonDocument.ParseArrayAsync(stream, TestContext.CancellationToken), + $"The root '{json}' must be refused as a JSON exception") + .ConfigureAwait(false); + + Assert.AreEqual("The remote response is not a JSON array", exception.Message, $"The refusal of '{json}' must carry the fixed message"); + Assert.IsNull(exception.InnerException, $"The refusal of '{json}' must carry no inner exception"); + } + + /// + /// Verify an array body with one string that does not decode is refused by the array parse as by the plain parse + /// + /// Name of the case + /// Response body + /// Whether the case is a JSON escape that must keep its backslash + /// Task + [TestMethod] + [TestCategory("AC1")] + [DynamicData(nameof(GetUndecodableArrayBodies))] + public async Task RemoteJsonDocumentParseArrayAsyncWhenAStringDoesNotDecodeThrowsJsonExceptionAsync(string label, byte[] body, bool isEscape) + { + if (isEscape) + { + Assert.Contains((byte)Backslash, body, $"The input of case '{label}' must still carry the backslash of its escape"); + } + + using var stream = new MemoryStream(body); + + var exception = await Assert.ThrowsExactlyAsync(() => RemoteJsonDocument.ParseArrayAsync(stream, TestContext.CancellationToken), + $"Case '{label}' must be refused as a JSON exception") + .ConfigureAwait(false); + + Assert.IsInstanceOfType(exception.InnerException, $"The refusal of case '{label}' must keep the decoding error as inner exception"); + } + + /// + /// Verify an undecodable string is refused before the root kind is checked, so a body with an object root reads the decoding refusal + /// + /// Name of the case + /// Response body with an object root + /// Whether the case is a JSON escape that must keep its backslash + /// Task + [TestMethod] + [TestCategory("AC1")] + [DynamicData(nameof(GetUndecodableBodies))] + public async Task RemoteJsonDocumentParseArrayAsyncWhenObjectRootHasUndecodableStringThrowsDecodingRefusalAsync(string label, byte[] body, bool isEscape) + { + if (isEscape) + { + Assert.Contains((byte)Backslash, body, $"The input of case '{label}' must still carry the backslash of its escape"); + } + + using var stream = new MemoryStream(body); + + var exception = await Assert.ThrowsExactlyAsync(() => RemoteJsonDocument.ParseArrayAsync(stream, TestContext.CancellationToken), + $"Case '{label}' must be refused as a JSON exception") + .ConfigureAwait(false); + + Assert.IsInstanceOfType(exception.InnerException, $"Case '{label}' must read the decoding refusal, not the root refusal"); + } + #endregion // Methods #region Static methods @@ -235,6 +333,20 @@ public static IEnumerable GetUndecodableBodies() yield return ["raw encoded surrogate", CreateBody([(byte)'{', (byte)'"', (byte)'a', (byte)'"', (byte)':', (byte)'"', 0xED, 0xA0, 0x80, (byte)'"', (byte)'}']), false]; } + /// + /// Bodies with one string that does not decode, each wrapped in an array + /// + /// Rows of case name, body and whether the case is an escape + public static IEnumerable GetUndecodableArrayBodies() + { + foreach (var row in GetUndecodableBodies()) + { + var body = (byte[])row[1]; + + yield return [row[0], CreateBody([(byte)'[', .. body, (byte)']']), row[2]]; + } + } + /// /// Create a body from bytes /// From be41239c7437d1ab0c45f74b985de79af7b2a8a1 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:05:51 +0000 Subject: [PATCH 07/14] Parse Docker Engine array answers with ParseArrayAsync --- specs/issue-585/log.md | 1 + .../Docker/DockerInstanceClient.cs | 6 +-- .../Infrastructure/RemoteJsonDocument.cs | 44 +++++++++++++------ 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index 5718968e..42e50d97 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -12,3 +12,4 @@ are quoted in full. | 2026-11-28 15:58 | 2 Challenge notes | Orchestrator | minor objections appended verbatim to plan.md; follow-up #587 linked under Out of scope | | 2026-11-28 16:00 | 4 Skeleton | Dev | RESULT: skeleton done. ParseArrayAsync throws Skeleton body; deviation: no async modifier (CS1998); no pragmas; build 0 warnings (sonnet/medium · 84,848 tokens · 8 tool uses · 137 s · 14 in · 2,658 out · 485,746 cache read · 84,136 cache write · 167,049 weighted) | | 2026-11-28 16:02 | 5 Tests first | Tester | RESULT: tests-first complete; 46 new/adapted cases compile and fail on skeleton (confirmed by orchestrator: 46 failed, 105 passed). Deferred: none (sonnet/medium · 111,356 tokens · 11 tool uses · 91 s · 18 in · 9,377 out · 827,861 cache read · 56,311 cache write · 200,078 weighted) | +| 2026-11-28 16:05 | 6 Implement | Dev | RESULT: green. ParseArrayAsync + ParseRootAsync, three call sites swapped; deviation: public methods not async; orchestrator confirmed build, 2365+39 tests, coverage gate PASS (100% new code) (sonnet/medium · 93,450 tokens · 6 tool uses · 105 s · 12 in · 3,331 out · 488,103 cache read · 38,003 cache write · 112,981 weighted) | diff --git a/src/DockerUpdateGuard/Docker/DockerInstanceClient.cs b/src/DockerUpdateGuard/Docker/DockerInstanceClient.cs index 4ef7f340..54a3eaa5 100644 --- a/src/DockerUpdateGuard/Docker/DockerInstanceClient.cs +++ b/src/DockerUpdateGuard/Docker/DockerInstanceClient.cs @@ -919,7 +919,7 @@ private static async Task(); @@ -1215,7 +1215,7 @@ public async Task -/// Parses a remote JSON response and refuses a body whose strings do not decode as Unicode text; a parse failure carries no remote text +/// Parses a remote JSON response and refuses a body whose strings do not decode as Unicode text or, where asked, whose root is not of the expected kind; a parse failure carries no remote text /// internal static class RemoteJsonDocument { @@ -19,6 +19,11 @@ internal static class RemoteJsonDocument /// private const string NotAnObjectMessage = "The remote response is not a JSON object"; + /// + /// Message of the exception for a response whose root is not a JSON array + /// + private const string NotAnArrayMessage = "The remote response is not a JSON array"; + #endregion // Constants #region Static methods @@ -53,18 +58,9 @@ public static async Task ParseAsync(Stream stream, CancellationTok /// Stream to parse /// Cancellation token /// Parsed document - public static async Task ParseObjectAsync(Stream stream, CancellationToken cancellationToken) + public static Task ParseObjectAsync(Stream stream, CancellationToken cancellationToken) { - var document = await ParseAsync(stream, cancellationToken).ConfigureAwait(false); - - if (document.RootElement.ValueKind != JsonValueKind.Object) - { - document.Dispose(); - - throw new JsonException(NotAnObjectMessage); - } - - return document; + return ParseRootAsync(stream, JsonValueKind.Object, NotAnObjectMessage, cancellationToken); } /// @@ -75,7 +71,29 @@ public static async Task ParseObjectAsync(Stream stream, Cancellat /// Parsed document public static Task ParseArrayAsync(Stream stream, CancellationToken cancellationToken) { - throw new InvalidOperationException("Skeleton: not implemented"); + return ParseRootAsync(stream, JsonValueKind.Array, NotAnArrayMessage, cancellationToken); + } + + /// + /// Parse a stream into a JSON document, verify that every string decodes and that the root is of the expected kind + /// + /// Stream to parse + /// Expected kind of the root + /// Message of the exception for a root of another kind + /// Cancellation token + /// Parsed document + private static async Task ParseRootAsync(Stream stream, JsonValueKind rootKind, string refusalMessage, CancellationToken cancellationToken) + { + var document = await ParseAsync(stream, cancellationToken).ConfigureAwait(false); + + if (document.RootElement.ValueKind != rootKind) + { + document.Dispose(); + + throw new JsonException(refusalMessage); + } + + return document; } /// From 7219591e96426508389c601935d8be3f6a820aaf Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:05:56 +0000 Subject: [PATCH 08/14] Log coverage for issue 585 --- specs/issue-585/log.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index 42e50d97..9d871a9f 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -13,3 +13,4 @@ are quoted in full. | 2026-11-28 16:00 | 4 Skeleton | Dev | RESULT: skeleton done. ParseArrayAsync throws Skeleton body; deviation: no async modifier (CS1998); no pragmas; build 0 warnings (sonnet/medium · 84,848 tokens · 8 tool uses · 137 s · 14 in · 2,658 out · 485,746 cache read · 84,136 cache write · 167,049 weighted) | | 2026-11-28 16:02 | 5 Tests first | Tester | RESULT: tests-first complete; 46 new/adapted cases compile and fail on skeleton (confirmed by orchestrator: 46 failed, 105 passed). Deferred: none (sonnet/medium · 111,356 tokens · 11 tool uses · 91 s · 18 in · 9,377 out · 827,861 cache read · 56,311 cache write · 200,078 weighted) | | 2026-11-28 16:05 | 6 Implement | Dev | RESULT: green. ParseArrayAsync + ParseRootAsync, three call sites swapped; deviation: public methods not async; orchestrator confirmed build, 2365+39 tests, coverage gate PASS (100% new code) (sonnet/medium · 93,450 tokens · 6 tool uses · 105 s · 12 in · 3,331 out · 488,103 cache read · 38,003 cache write · 112,981 weighted) | +| 2026-11-28 16:05 | 6 Coverage skipped | Orchestrator | skipped — gate passes (new code 100%, overall 94.9%), no deferred tests, no unbounded resource, no open test documentation | From b504b86c576b1da135550a404bf42206234452e7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:06:59 +0000 Subject: [PATCH 09/14] Document array root refusal for issue 585 --- docs/areas/docker-instances.md | 8 ++++++-- docs/areas/integration-failures.md | 2 +- docs/areas/telemetry.md | 2 +- specs/issue-585/log.md | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/areas/docker-instances.md b/docs/areas/docker-instances.md index 617c543a..3d62c9e6 100644 --- a/docs/areas/docker-instances.md +++ b/docs/areas/docker-instances.md @@ -93,6 +93,7 @@ on the snapshots and samples it produces. - Discovery lists **all** containers of an instance, including stopped ones. A container without an ID, with an empty or blank ID, or with an ID longer than 200 characters, and an item of the list that is not a JSON object, is left out. + A container list whose root is not a JSON array fails discovery with `invalid response`, and no image is inspected. - Per container it records: the container ID; the name (the first listed name that is a string, without its leading `/`, or the container ID when it has none); the image reference as the Engine reports it; the local image ID; the compose project (`com.docker.compose.project` label), the stack name (`com.docker.stack.namespace`) and the swarm service @@ -121,7 +122,7 @@ on the snapshots and samples it produces. control characters replaced by spaces ([Integration failures](integration-failures.md#remote-text-fields)). The creation time of a history entry is the Engine's Unix time in seconds, read as UTC; `0`, a negative, an out-of-range or an unreadable value is unknown. A history entry that is not a JSON object is left out and the other entries are - still read. + still read. A history whose root is not a JSON array answers *failed* with `invalid response`. An item of the repo tags, repo digests, environment variables, root file-system layers or of a history entry's tags that is not a JSON string (a number, `true`/`false`, `null`, an object, an array) is left out and the other items are still read ([0071](../decisions/0071-a-docker-engine-string-list-item-that-is-not-a-json-string-is-left-out.md)). @@ -227,7 +228,8 @@ on the snapshots and samples it produces. shown in the UI. - A message or log entry that names an endpoint shows its URL with the user info replaced by `***`; connecting still uses the configured URL. -- A resource collection fails for an instance when the list request fails or times out, or when stats were requested +- A resource collection fails for an instance when the list request fails or times out, when the list's root is not a JSON + array (`invalid response`, no stats request), or when stats were requested and no container could be sampled (`Docker container resource sampling failed for '': no container stats could be read`); it records **no** samples for that instance in that round and logs the failure once as warning 2103, besides warning 3107 for a list request that broke and warning 3111 for each container left out; other instances are not @@ -257,6 +259,8 @@ on the snapshots and samples it produces. Docker Engine container without an ID. - [0074](../decisions/0074-a-docker-engine-stats-or-image-inspect-answer-that-is-not-a-json-object-is-an-invalid-response.md): a Docker Engine stats or image inspect answer that is not a JSON object is an invalid response. +- [0075](../decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md): + a Docker Engine container list or image history that is not a JSON array is an invalid response. ## Not here diff --git a/docs/areas/integration-failures.md b/docs/areas/integration-failures.md index cbcfbfe2..3f9b3258 100644 --- a/docs/areas/integration-failures.md +++ b/docs/areas/integration-failures.md @@ -31,7 +31,7 @@ operator's logs rely on it; each integration area states only what it adds. failed` (transport failures and responses that break off), `invalid response` or `unexpected error`. The error itself is logged with the failure (a JSON parse failure with a fixed message, [Telemetry](telemetry.md#credentials-and-external-data)). - `invalid response` covers malformed JSON and a JSON string that does not decode as Unicode text, such as a lone - surrogate escape like `\ud800` or bytes that are not UTF-8, a registry answer, or a Docker Engine stats or image inspect answer, whose root is not a JSON object, and a Docker Hub access token whose payload segment is not + surrogate escape like `\ud800` or bytes that are not UTF-8, a registry answer, or a Docker Engine stats or image inspect answer, whose root is not a JSON object, a Docker Engine container list or image history whose root is not a JSON array, and a Docker Hub access token whose payload segment is not base64url. The Docker Hub, OCI and Docker Engine clients refuse the whole body for one in any string value or property name; the Portainer client and the vulnerability providers for one in a field they read; the release feeds report it as `unexpected error`. diff --git a/docs/areas/telemetry.md b/docs/areas/telemetry.md index d42a687a..8aa05a6e 100644 --- a/docs/areas/telemetry.md +++ b/docs/areas/telemetry.md @@ -122,7 +122,7 @@ Every exported signal carries the same resource: - A JSON parse failure of a remote answer, a token payload, the .NET release index or Trivy's report is logged with a fixed message, never the parser's: `Remote JSON is not valid at line , byte (counted from 0)`, with the parser's line and byte position in invariant digits, or `Remote JSON is not valid` when the position is unknown. The - exception has no path and no inner exception, so it carries no remote text; the refusal of a string that does not decode ([Integration failures](integration-failures.md#fixed-failure-reasons)) keeps its own fixed message and its decoding error, which carries no remote text either; the refusal of a registry answer, or of a Docker Engine stats or image inspect answer, whose root is not a JSON object carries the fixed message `The remote response is not a JSON object` and no inner exception. Every parse of external JSON goes through + exception has no path and no inner exception, so it carries no remote text; the refusal of a string that does not decode ([Integration failures](integration-failures.md#fixed-failure-reasons)) keeps its own fixed message and its decoding error, which carries no remote text either; the refusal of a registry answer, or of a Docker Engine stats or image inspect answer, whose root is not a JSON object carries the fixed message `The remote response is not a JSON object` and no inner exception; the refusal of a Docker Engine container list or image history whose root is not a JSON array carries `The remote response is not a JSON array` and no inner exception. Every parse of external JSON goes through `Infrastructure\ExternalJson`. A `Content-Type` charset that cannot be used is refused with the fixed message `The character set of the remote response is not valid` and no inner exception. Decision: [0045](../decisions/0045-json-parse-failures-of-external-data-carry-a-fixed-message-with-their-position.md). diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index 9d871a9f..bb95458a 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -14,3 +14,4 @@ are quoted in full. | 2026-11-28 16:02 | 5 Tests first | Tester | RESULT: tests-first complete; 46 new/adapted cases compile and fail on skeleton (confirmed by orchestrator: 46 failed, 105 passed). Deferred: none (sonnet/medium · 111,356 tokens · 11 tool uses · 91 s · 18 in · 9,377 out · 827,861 cache read · 56,311 cache write · 200,078 weighted) | | 2026-11-28 16:05 | 6 Implement | Dev | RESULT: green. ParseArrayAsync + ParseRootAsync, three call sites swapped; deviation: public methods not async; orchestrator confirmed build, 2365+39 tests, coverage gate PASS (100% new code) (sonnet/medium · 93,450 tokens · 6 tool uses · 105 s · 12 in · 3,331 out · 488,103 cache read · 38,003 cache write · 112,981 weighted) | | 2026-11-28 16:05 | 6 Coverage skipped | Orchestrator | skipped — gate passes (new code 100%, overall 94.9%), no deferred tests, no unbounded resource, no open test documentation | +| 2026-11-28 16:06 | 6 Documentation | Dev | RESULT: done, docs written (docker-instances, integration-failures, telemetry), checks pass; tests re-run green (sonnet/medium · 5,535 tokens · 4 tool uses · 16 s · 10 in · 2,126 out · 378,009 cache read · 5,780 cache write · 55,666 weighted · continued) | From 9f8642140662041235c888a9a84cc6fccc40563e Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:08:34 +0000 Subject: [PATCH 10/14] Stamp gates for issue 585 --- specs/issue-585/log.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index bb95458a..0bd83be2 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -15,3 +15,4 @@ are quoted in full. | 2026-11-28 16:05 | 6 Implement | Dev | RESULT: green. ParseArrayAsync + ParseRootAsync, three call sites swapped; deviation: public methods not async; orchestrator confirmed build, 2365+39 tests, coverage gate PASS (100% new code) (sonnet/medium · 93,450 tokens · 6 tool uses · 105 s · 12 in · 3,331 out · 488,103 cache read · 38,003 cache write · 112,981 weighted) | | 2026-11-28 16:05 | 6 Coverage skipped | Orchestrator | skipped — gate passes (new code 100%, overall 94.9%), no deferred tests, no unbounded resource, no open test documentation | | 2026-11-28 16:06 | 6 Documentation | Dev | RESULT: done, docs written (docker-instances, integration-failures, telemetry), checks pass; tests re-run green (sonnet/medium · 5,535 tokens · 4 tool uses · 16 s · 10 in · 2,126 out · 378,009 cache read · 5,780 cache write · 55,666 weighted · continued) | +| 2026-11-28 16:08 | 7 Gate stamp | Orchestrator | PASS on b504b86c576b1da135550a404bf42206234452e7 (tier standard): Format check pass; Analyzer gate pass; Test with coverage pass; Coverage gate pass; decision-check.py pass; scope-check.py pass · figure-check.py 0 hit(s) | From 001df793390f598256b2e8418351e1e54cb7035a Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:09:22 +0000 Subject: [PATCH 11/14] Log review for issue 585 --- specs/issue-585/log.md | 1 + 1 file changed, 1 insertion(+) diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index 0bd83be2..f219fe99 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -16,3 +16,4 @@ are quoted in full. | 2026-11-28 16:05 | 6 Coverage skipped | Orchestrator | skipped — gate passes (new code 100%, overall 94.9%), no deferred tests, no unbounded resource, no open test documentation | | 2026-11-28 16:06 | 6 Documentation | Dev | RESULT: done, docs written (docker-instances, integration-failures, telemetry), checks pass; tests re-run green (sonnet/medium · 5,535 tokens · 4 tool uses · 16 s · 10 in · 2,126 out · 378,009 cache read · 5,780 cache write · 55,666 weighted · continued) | | 2026-11-28 16:08 | 7 Gate stamp | Orchestrator | PASS on b504b86c576b1da135550a404bf42206234452e7 (tier standard): Format check pass; Analyzer gate pass; Test with coverage pass; Coverage gate pass; decision-check.py pass; scope-check.py pass · figure-check.py 0 hit(s) | +| 2026-11-28 16:09 | 8 Review | Reviewer | VERDICT: APPROVE on b504b86c576b1da135550a404bf42206234452e7. No findings (opus/medium · 57,463 tokens · 7 tool uses · 41 s · 14 in · 3,425 out · 254,694 cache read · 55,786 cache write · 199,212 weighted) | From 8df3b5a433a6533cea0eb97dd83beae4092ab0ab Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:09:31 +0000 Subject: [PATCH 12/14] Accept decision record 0075 --- ...e-history-that-is-not-a-json-array-is-an-invalid-response.md | 2 +- docs/decisions/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md b/docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md index d223e84e..9c26d7cf 100644 --- a/docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md +++ b/docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md @@ -1,6 +1,6 @@ # 0075: A Docker Engine container list or image history that is not a JSON array is an invalid response -- **Status:** Proposed +- **Status:** Accepted - **Date:** 2026-11-28 - **Area:** Docker instances - **Source:** Issue #585 diff --git a/docs/decisions/README.md b/docs/decisions/README.md index 69b3439a..f696fdea 100644 --- a/docs/decisions/README.md +++ b/docs/decisions/README.md @@ -135,5 +135,5 @@ once in the [area document](../areas/README.md) of the record's area, and the re | [0072](0072-a-registry-string-list-item-that-is-not-a-json-string-is-left-out.md) | A registry string list item that is not a JSON string is left out | Accepted | 2026-11-28 | | [0073](0073-a-registry-answer-that-is-not-a-json-object-is-an-invalid-response-and-an-entry-that-is-not-one-is-left-out.md) | A registry answer that is not a JSON object is an invalid response, and an entry that is not one is left out | Accepted | 2026-11-28 | | [0074](0074-a-docker-engine-stats-or-image-inspect-answer-that-is-not-a-json-object-is-an-invalid-response.md) | A Docker Engine stats or image inspect answer that is not a JSON object is an invalid response | Accepted | 2026-11-28 | -| [0075](0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md) | A Docker Engine container list or image history that is not a JSON array is an invalid response | Proposed | 2026-11-28 | +| [0075](0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md) | A Docker Engine container list or image history that is not a JSON array is an invalid response | Accepted | 2026-11-28 | \ No newline at end of file From a362abb6ab9b24ba8744d173d43c3d8f6c6959a1 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:09:47 +0000 Subject: [PATCH 13/14] Approve pull request for issue 585 --- specs/issue-585/log.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md index f219fe99..cd69ed09 100644 --- a/specs/issue-585/log.md +++ b/specs/issue-585/log.md @@ -17,3 +17,5 @@ are quoted in full. | 2026-11-28 16:06 | 6 Documentation | Dev | RESULT: done, docs written (docker-instances, integration-failures, telemetry), checks pass; tests re-run green (sonnet/medium · 5,535 tokens · 4 tool uses · 16 s · 10 in · 2,126 out · 378,009 cache read · 5,780 cache write · 55,666 weighted · continued) | | 2026-11-28 16:08 | 7 Gate stamp | Orchestrator | PASS on b504b86c576b1da135550a404bf42206234452e7 (tier standard): Format check pass; Analyzer gate pass; Test with coverage pass; Coverage gate pass; decision-check.py pass; scope-check.py pass · figure-check.py 0 hit(s) | | 2026-11-28 16:09 | 8 Review | Reviewer | VERDICT: APPROVE on b504b86c576b1da135550a404bf42206234452e7. No findings (opus/medium · 57,463 tokens · 7 tool uses · 41 s · 14 in · 3,425 out · 254,694 cache read · 55,786 cache write · 199,212 weighted) | +| 2026-11-28 16:09 | 7 Gate stamp | Orchestrator | PASS on 8df3b5a433a6533cea0eb97dd83beae4092ab0ab (tier standard, verbatim): Format check pass; decision-check.py pass; scope-check.py pass | +| 2026-11-28 16:09 | 9 PR approval | Orchestrator | approved by checklist; record 0075 Accepted; the async-modifier deviation was reviewed without findings | From d9d806726082a339c49312b540a3d48140839a00 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 28 Nov 2026 16:10:18 +0000 Subject: [PATCH 14/14] Remove squad working record --- specs/issue-585/log.md | 21 ---- specs/issue-585/plan.md | 214 ---------------------------------------- 2 files changed, 235 deletions(-) delete mode 100644 specs/issue-585/log.md delete mode 100644 specs/issue-585/plan.md diff --git a/specs/issue-585/log.md b/specs/issue-585/log.md deleted file mode 100644 index cd69ed09..00000000 --- a/specs/issue-585/log.md +++ /dev/null @@ -1,21 +0,0 @@ -# Log: issue #585 - -One line per pipeline step: date and time of day (UTC), step, member, result. Lead decisions and escalations -are quoted in full. - -| Date | Step | Member | Result | -| ---- | ---- | ------ | ------ | -| 2026-11-28 15:51 | 1 Intake | Orchestrator | Bug #585 (label bug, open, milestone v1.3.11): non-array root of Engine container list / image history reads unexpected error; branch claude/happy-wozniak-73m7oe off main 0261f5d | -| 2026-11-28 15:56 | 2 Plan | Lead | RESULT: DONE. Tier standard; plan.md, decision record 0075 (Proposed), 0069/0074 amended; ParseArrayAsync for container list, sampling, image history (opus/medium · 133,205 tokens · 41 tool uses · 311 s · 72 in · 28,039 out · 3,248,907 cache read · 131,104 cache write · 933,185 weighted) | -| 2026-11-28 15:57 | 3 Plan security | Security | VERDICT: APPROVED. No findings; tier standard confirmed (opus/medium · 39,615 tokens · 6 tool uses · 33 s · 12 in · 2,801 out · 153,179 cache read · 38,268 cache write · 139,022 weighted) | -| 2026-11-28 15:57 | 2 Plan challenge | Devil's Advocate | VERDICT: OBJECTIONS 0 major, 2 minor. (1) AC1 undecodable test needs array-wrapped bodies of GetUndecodableBodies and an order test for object root; (2) DotNetReleaseMetadataService.cs:155-158 has the same defect for a non-object root (opus/medium · 60,001 tokens · 16 tool uses · 77 s · 28 in · 6,466 out · 565,628 cache read · 58,581 cache write · 267,731 weighted) | -| 2026-11-28 15:58 | 2 Challenge notes | Orchestrator | minor objections appended verbatim to plan.md; follow-up #587 linked under Out of scope | -| 2026-11-28 16:00 | 4 Skeleton | Dev | RESULT: skeleton done. ParseArrayAsync throws Skeleton body; deviation: no async modifier (CS1998); no pragmas; build 0 warnings (sonnet/medium · 84,848 tokens · 8 tool uses · 137 s · 14 in · 2,658 out · 485,746 cache read · 84,136 cache write · 167,049 weighted) | -| 2026-11-28 16:02 | 5 Tests first | Tester | RESULT: tests-first complete; 46 new/adapted cases compile and fail on skeleton (confirmed by orchestrator: 46 failed, 105 passed). Deferred: none (sonnet/medium · 111,356 tokens · 11 tool uses · 91 s · 18 in · 9,377 out · 827,861 cache read · 56,311 cache write · 200,078 weighted) | -| 2026-11-28 16:05 | 6 Implement | Dev | RESULT: green. ParseArrayAsync + ParseRootAsync, three call sites swapped; deviation: public methods not async; orchestrator confirmed build, 2365+39 tests, coverage gate PASS (100% new code) (sonnet/medium · 93,450 tokens · 6 tool uses · 105 s · 12 in · 3,331 out · 488,103 cache read · 38,003 cache write · 112,981 weighted) | -| 2026-11-28 16:05 | 6 Coverage skipped | Orchestrator | skipped — gate passes (new code 100%, overall 94.9%), no deferred tests, no unbounded resource, no open test documentation | -| 2026-11-28 16:06 | 6 Documentation | Dev | RESULT: done, docs written (docker-instances, integration-failures, telemetry), checks pass; tests re-run green (sonnet/medium · 5,535 tokens · 4 tool uses · 16 s · 10 in · 2,126 out · 378,009 cache read · 5,780 cache write · 55,666 weighted · continued) | -| 2026-11-28 16:08 | 7 Gate stamp | Orchestrator | PASS on b504b86c576b1da135550a404bf42206234452e7 (tier standard): Format check pass; Analyzer gate pass; Test with coverage pass; Coverage gate pass; decision-check.py pass; scope-check.py pass · figure-check.py 0 hit(s) | -| 2026-11-28 16:09 | 8 Review | Reviewer | VERDICT: APPROVE on b504b86c576b1da135550a404bf42206234452e7. No findings (opus/medium · 57,463 tokens · 7 tool uses · 41 s · 14 in · 3,425 out · 254,694 cache read · 55,786 cache write · 199,212 weighted) | -| 2026-11-28 16:09 | 7 Gate stamp | Orchestrator | PASS on 8df3b5a433a6533cea0eb97dd83beae4092ab0ab (tier standard, verbatim): Format check pass; decision-check.py pass; scope-check.py pass | -| 2026-11-28 16:09 | 9 PR approval | Orchestrator | approved by checklist; record 0075 Accepted; the async-modifier deviation was reviewed without findings | diff --git a/specs/issue-585/plan.md b/specs/issue-585/plan.md deleted file mode 100644 index da9b2c1a..00000000 --- a/specs/issue-585/plan.md +++ /dev/null @@ -1,214 +0,0 @@ -# Plan: A Docker Engine container list or image history body that is not a JSON array reads `unexpected error` - -Source: Issue #585 -Tier: standard — the fixed failure reason of three Engine calls changes for a malformed body (a behavior change), and no security control is created, changed or removed: a parser's root-kind check is input handling. -Security areas touched: Docker Engine access (`Docker/DockerInstanceClient.cs`: how the Engine's container list and image history answers are parsed); Registry and Docker Scout calls (`Infrastructure/RemoteJsonDocument.cs`, the shared remote JSON parser, gains a method; its existing methods keep their behavior) - -## Problem / root cause - -`DockerInstanceClient` parses three array answers with `RemoteJsonDocument.ParseAsync`, which accepts any root, and -then calls `JsonElement.EnumerateArray()` on the root: - -- discovery: `DiscoverContainersAsync` parses at `DockerInstanceClient.cs:1218`, `ParseContainers` enumerates at `:958`; -- resource sampling: `CollectContainerResourceUsageAsync` parses at `:1285`, `ReadContainerSamplesAsync` enumerates at `:1137`; -- image history: `ReadImageHistoryAsync` parses at `:922` and enumerates at `:926`. - -For a root that is not an array `EnumerateArray` throws `InvalidOperationException`; the call's catch-all -(`:1242`, `:1302`, `:1380`) turns it into *failed* with `FailureReason.FromException`, which maps only `JsonException` -to `invalid response` and everything else to `unexpected error` (`Infrastructure/FailureReason.cs:78-83`). Since #583 -the stats body and the image inspect answer are parsed with `ParseObjectAsync` (`:499`, `:869`) and read -`invalid response` for the wrong root kind; the array answers have no counterpart. - -## Verified facts - -| # | Claim | Evidence | Status | -| - | ----- | -------- | ------ | -| 1 | The three array answers are parsed with `ParseAsync` and enumerated without a kind check | `DockerInstanceClient.cs:1218`/`:958`, `:1285`/`:1137`, `:922`/`:926` | confirmed | -| 2 | A root that is not an array reads `unexpected error` today | `JsonElement.EnumerateArray` throws `InvalidOperationException` for another `ValueKind` (.NET API reference); `DockerInstanceClientGetImageHistoryAsyncWhenBodyIsNoArrayReturnsUnexpectedErrorAsync` (`DockerInstanceClientListItemsTests.cs:536`) pins it for the history with `{}`, `"text"`, `7` | confirmed | -| 3 | `FailureReason.FromException` maps `JsonException` to `invalid response`, any other exception (after cancellation, timeout, transport) to `unexpected error` | `Infrastructure/FailureReason.cs:78-83` | confirmed | -| 4 | A `JsonException` thrown by the parse reaches the call's catch-all in all three calls: `ReadImageHistoryAsync` catches only `OperationCanceledException` (`:939-946`), the outer `GetImageHistoryAsync` catches `Exception` (`:1380`); discovery and sampling parse inside their own `try` (`:1196-1247`, `:1265-1307`) | code | confirmed | -| 5 | The failures are logged as warnings 3104, 3107 and 3109 with the exception; their message templates carry no reason | `DockerInstanceClientLogging.cs:65-68`, `:101-104`, `:127-130` | confirmed | -| 6 | The failure messages are `Docker container discovery failed for '': `, `Docker container resource sampling failed for '': `, `Docker image history failed for '': ` | `DockerInstanceClient.cs:1246`, `:1306`, `:1384` | confirmed | -| 7 | The object rule sits in one place: `RemoteJsonDocument.ParseObjectAsync` runs `ParseAsync`, disposes the document and throws `JsonException("The remote response is not a JSON object")` without inner exception for another root | `Infrastructure/RemoteJsonDocument.cs:56-68`; `RemoteJsonDocumentTests.cs:166-176` | confirmed | -| 8 | After the change `ParseAsync` is called in production only by the host info (`:1423`), whose non-object root reads as no total memory (0068) | `grep RemoteJsonDocument.ParseAsync src/DockerUpdateGuard` | confirmed | -| 9 | The Engine answers `GET /containers/json` and `GET /images/{name}/history` with a JSON array | Docker Engine API v1.41 reference (ContainerList, ImageHistory); record 0069, *Context*; every list fixture of `DockerInstanceClientTests.cs` | confirmed | -| 10 | Records 0069 and 0074 are unreleased, so they are edited in place | `git ls-remote --tags origin` lists `v1.3.0`–`v1.3.10`; `git ls-tree -r docs/decisions` holds neither file in any of them | confirmed | -| 11 | No architecture or project text names the root rules | `docs/ARCHITECTURE.md:515` and `.squad/project.md:106` name `RemoteJsonDocument` only as "where strings must decode" | confirmed | - -## Acceptance criteria - -- AC1: `RemoteJsonDocument.ParseArrayAsync` returns the parsed document for a body whose root is a JSON array (`[]`, - `[ 1, "x", null ]`, `[ {} ]`); for every other root (`{}`, `{ "a": [] }`, `"x"`, `7`, `1.5`, `true`, `false`, - `null`) it throws exactly `JsonException` with the message `The remote response is not a JSON array` and no inner - exception; for an array body with a string that does not decode it throws exactly `JsonException` whose inner - exception is the `InvalidOperationException` of the decoding check, as `ParseAsync` does. -- AC2: A discovery whose container list body is `{}`, `"text"`, `7`, `true` or `null` answers *failed* with the message - `Docker container discovery failed for 'Production': invalid response`, logs warning 3104 once with a - `JsonException`, and sends no request after the list request (no image inspect). -- AC3: A resource collection whose container list body is `{}`, `"text"`, `7`, `true` or `null` answers *failed* with - the message `Docker container resource sampling failed for 'Production': invalid response` and sends no stats - request. -- AC4: An image history whose body is `{}`, `"text"`, `7`, `true` or `null` answers *failed* with the message - `Docker image history failed for 'Production': invalid response`. - -The reason text comes from `FailureReason.FromException` (fact 3) on the `JsonException` the parse throws; the message -prefixes are the ones of fact 6. - -## Tests per criterion - -| AC | Test(s) | Test file | -| -- | ------- | --------- | -| AC1 | `RemoteJsonDocumentParseArrayAsyncWhenRootIsAnArrayReturnsDocumentAsync`, `RemoteJsonDocumentParseArrayAsyncWhenRootIsNoArrayThrowsJsonExceptionAsync`, `RemoteJsonDocumentParseArrayAsyncWhenAStringDoesNotDecodeThrowsJsonExceptionAsync` | `src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs` | -| AC2 | `DockerInstanceClientDiscoverContainersAsyncWhenListBodyIsNoArrayReturnsInvalidResponseAsync` | `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs` | -| AC3 | `DockerInstanceClientCollectContainerResourceUsageAsyncWhenListBodyIsNoArrayReturnsInvalidResponseAsync` | `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs` | -| AC4 | `DockerInstanceClientGetImageHistoryAsyncWhenBodyIsNoArrayReturnsInvalidResponseAsync` (the existing `…ReturnsUnexpectedErrorAsync` at `:536`, renamed, its category set to `AC4`, rows `true` and `null` added and its expectation changed) | `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs` | - -The AC1 undecodable case reuses `GetUndecodableBodies` only for its array bodies, or wraps each body in an array; the -backslash guard of the existing undecodable tests (`Assert.Contains((byte)Backslash, …)` for an escape case) stays in -front, so a case that lost its backslash fails. AC2 and AC3 read the request count from -`SequenceHttpMessageHandler.Requests` (one request each). - -## Approach - -1. `RemoteJsonDocument` gets `ParseArrayAsync`, the array counterpart of `ParseObjectAsync`, with the constant - `NotAnArrayMessage = "The remote response is not a JSON array"` beside `NotAnObjectMessage`. Both public methods - delegate to one private static helper, `ParseRootAsync(Stream stream, JsonValueKind rootKind, string refusalMessage, - CancellationToken cancellationToken)`, which runs `ParseAsync`, and when the root's `ValueKind` is not `rootKind` - disposes the document and throws `new JsonException(refusalMessage)` — no inner exception, no remote text. The - string check runs first, as in `ParseObjectAsync` today, so an undecodable string of a body with the wrong root - reads the undecodable refusal; both read `invalid response`. `ParseObjectAsync`'s behavior is unchanged (its - tests stay as they are). -2. `DockerInstanceClient`: the three parses of fact 1 call `ParseArrayAsync` instead of `ParseAsync`. No catch block, - log event or message changes: the `JsonException` takes the existing path to `invalid response` (fact 4). The host - info keeps `ParseAsync` (0068). -3. The class summary of `RemoteJsonDocument` names the root checks ("…and refuses a body whose strings do not decode - or, where asked, whose root is not of the expected kind…" — wording free for the Dev). - -No new user-visible output beyond the reason text; no resource bound changes. - -Early draft PR: no - -## Options considered - -1. **`RemoteJsonDocument.ParseArrayAsync` at the three call sites (chosen)** — the object rule of 0073/0074 for the - other root kind, in the one place every remote parse passes. -2. **Keep `unexpected error`** — lost: one malformed Engine answer would read two ways by its root kind (0075, option 2). -3. **Read a non-array root as an empty list (0069's rule for items)** — lost: discovery would succeed without - containers and a history without entries, so a malformed answer would read as an empty Engine (0075, option 3). -4. **A kind check at each call site** — lost: three copies of one check and message (0075, option 4). -5. **Map `InvalidOperationException` to `invalid response` in `FailureReason`** — lost: rejected by 0019 and 0029. - -## Affected projects and types - -| Project | Type / file | Change | -| ------- | ----------- | ------ | -| DockerUpdateGuard | `Infrastructure/RemoteJsonDocument.cs` | `ParseArrayAsync`, `NotAnArrayMessage`, private `ParseRootAsync` shared with `ParseObjectAsync`; summary | -| DockerUpdateGuard | `Docker/DockerInstanceClient.cs` | three `ParseAsync` calls become `ParseArrayAsync` (`:922`, `:1218`, `:1285`) | -| DockerUpdateGuard.Tests | `RemoteJsonDocumentTests.cs`, `DockerInstanceClientListItemsTests.cs` | tests of *Tests per criterion* | - -## Signatures (for the Dev's skeleton) - -In `internal static class RemoteJsonDocument` (`Infrastructure/RemoteJsonDocument.cs`), region *Static methods*, -after `ParseObjectAsync`: - -- `public static async Task ParseArrayAsync(Stream stream, CancellationToken cancellationToken)` - -The skeleton's body returns `await ParseAsync(stream, cancellationToken).ConfigureAwait(false)` (no root check), so -AC1's refusal tests fail and its accepting test passes; the private helper and the constant are the implementation's. -Name and parameters follow `ParseObjectAsync`, which passes the *Analyzer gate*. `RemoteJsonDocument.cs` and -`DockerInstanceClient.cs` were read; no other file needs rewriting for the skeleton. The three call-site swaps are the -implementation (step 6), not the skeleton, so AC2–AC4 fail on the skeleton. - -## Test files - -- `src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs` (AC1) -- `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs` (AC2–AC4) - -Existing test code that calls a changed signature: none (`ParseAsync` and `ParseObjectAsync` keep theirs). Existing -tests with an input a criterion handles differently: only -`DockerInstanceClientGetImageHistoryAsyncWhenBodyIsNoArrayReturnsUnexpectedErrorAsync` (`:536`), adapted by the -Tester in step 5 (AC4). Every other list fixture of the Docker Engine tests has an array root and stays unchanged. - -Files of the change no unit test can cover: none. - -## Areas - -- `docs/areas/docker-instances.md` (3381 words now, +70 words): *Container discovery*, first bullet — a container list - whose root is not a JSON array fails discovery with `invalid response`; *Image inspection and history*, first - bullet — a history whose root is not a JSON array answers *failed* with `invalid response`; the resource-collection - failure bullet (`A resource collection fails for an instance when the list request fails or times out, …`) — also - when the list's root is not a JSON array (`invalid response`); *Related decisions* — the 0075 entry. -- `docs/areas/integration-failures.md` (2467 words now, +15 words): *Fixed failure reasons*, the `invalid response` - bullet — add a Docker Engine container list or image history whose root is not a JSON array. -- `docs/areas/telemetry.md` (1639 words now, +30 words): *Credentials and external data*, the JSON parse failure - bullet — the refusal of a Docker Engine container list or image history whose root is not a JSON array carries the - fixed message `The remote response is not a JSON array` and no inner exception. - -## Documentation updates - -All by the Dev, once the code is green, against that code: - -- `docs/areas/docker-instances.md`, `docs/areas/integration-failures.md`, `docs/areas/telemetry.md`: as *Areas*. -- `docs/ARCHITECTURE.md`, `README.md`, `.squad/project.md`: none (fact 11); no changelog file exists, and the PR - template asks for none beyond the area documents and the record. - -Sweep: the hits for "not a JSON object", "JSON array", "unexpected error" and `RemoteJsonDocument` in `docs/areas/` -and `docs/ARCHITECTURE.md` are the three areas above (`docker-instances.md:95`, `:123`, `:166-167`, `:230`, -`:254-259`; `integration-failures.md:34`; `telemetry.md:125`), `ARCHITECTURE.md:515` (no change) and -`scan-engine.md:89`, `:202-203` (about unexpected errors of a run, no change). - -## Architecture check - -The fixed-reason guarantee (0009, `docs/ARCHITECTURE.md` *Security posture*) holds: the reason stays one of the fixed -set, the new exception message is fixed text without remote content, and the parse still goes through `ExternalJson` -(0045). Error isolation is unchanged: the calls fail as before, only their reason changes. - -## Security considerations - -- [x] No limits: no byte or length bound is added or changed. -- [x] The new `JsonException("The remote response is not a JSON array")` reaches the user only as `invalid response` - through `FailureReason.FromException`, in the three messages of AC2–AC4; its own message reaches only the log - entries 3104, 3107, 3109 as their exception. The `InvalidOperationException` of the runtime no longer reaches these - calls for a wrong root. - -## Decision records - -- `docs/decisions/0075-a-docker-engine-container-list-or-image-history-that-is-not-a-json-array-is-an-invalid-response.md` - (Proposed, indexed). -- Edited in place (unreleased, fact 10): 0069 *Consequences* (a non-array root fails with `invalid response`, linking - 0075, as the issue asks); 0074 option 4 and its second consequence now point to 0075. - -## Out of scope / follow-ups - -- The host info's non-object root stays read as no total memory (0068). -- Record 0071 still says a history that is not a JSON array keeps failing the call, which stays true; no edit. -- `DotNetReleaseMetadataService.cs` reads a release index whose root is not an object as `unexpected error`; a different client, tracked in #587. - -## Challenge notes - -The plan holds up. I found two minor objections and nothing that needs a plan change before the build. - -**Claims I checked against the code** -- All three array parses still use `RemoteJsonDocument.ParseAsync`: - - history at `src/DockerUpdateGuard/Docker/DockerInstanceClient.cs:922`, enumerated at `:926` - - discovery at `:1218`, enumerated in `ParseContainers` at `:958` - - sampling at `:1285`, enumerated in `ReadContainerSamplesAsync` at `:1137` -- Each call has a catch-all (`:1242`, `:1302`, `:1380`) that logs the exception and returns `FailureReason.FromException`, so a `JsonException` takes the existing path to `invalid response`. -- `ParseObjectAsync` (`src/DockerUpdateGuard/Infrastructure/RemoteJsonDocument.cs:56-68`) is the pattern the new method copies. It runs the string check first and then throws a `JsonException` with no inner exception. -- After the swap, the only production `ParseAsync` caller left is the host info at `:1423`, as fact 8 says. -- **Sibling paths:** every other `EnumerateArray` in production code checks the kind first or is only called after its caller checked: - - `DockerInstanceClient.cs:530-532` - - `DockerHubClient.cs:237/467/517`, and `:656` before `ManifestPlatformSelector` - - `OciRegistryClient.cs:826-832` - - `JsonStringListReader.cs:21-26` -- **Request counts in AC2/AC3:** with `ParseArrayAsync` the throw comes before `PopulateRepositoryDigestsAsync` and before any stats request, so one request is right. `SequenceHttpMessageHandler.Requests` exists, and `TestLogger` records the exception, so "3104 once with a `JsonException`" can be asserted. -- The only existing test whose input changes meaning is the one at `src/Tests/DockerUpdateGuard.Tests/DockerInstanceClientListItemsTests.cs:536`, as the plan says. -- Need, alternatives and tier: option 1 is the least invasive choice, and 0075's options cover the alternatives. Standard tier fits. - -**Objections** - -1. `minor` — The AC1 undecodable test has no array bodies to reuse. All ten rows of `GetUndecodableBodies` (`src/Tests/DockerUpdateGuard.Tests/RemoteJsonDocumentTests.cs:224-234`) have an object root, so "only for its array bodies" gives an empty data source. Instruction for the Tester: - - Wrap each body of `GetUndecodableBodies` in `[` … `]` (for example a `GetUndecodableArrayBodies` source built from it), keeping the backslash guard in front. - - Also pin the order the plan states in Approach step 1: an undecodable body with an object root passed to `ParseArrayAsync` throws a `JsonException` whose inner exception is the `InvalidOperationException`, not the root refusal. - -2. `minor` — The same defect remains outside the Docker Engine, and the plan does not mention it. `src/DockerUpdateGuard/Images/DotNetReleaseMetadataService.cs:155-158` parses the .NET release index with `ExternalJson.ParseAsync` and calls `RootElement.TryGetProperty` with no root-kind check. A root that is not an object throws `InvalidOperationException`, and the catch at `:193-197` reports `unexpected error`. Instruction for the Lead or orchestrator: add it under *Out of scope / follow-ups* and open a linked issue. Do not widen this change: it is a different client, and `docs/areas/integration-failures.md:37` already documents `unexpected error` for the release feeds' undecodable strings.