Repository navigation
✨ feat(wire): edge log correlation, options, and terminal-reject reconnect - #57
Conversation
…nnect Additive wire-protocol build-out on the portwing agent side (no compat bump): - ✨ feat(protocol): echo requestId on dd:container_log_response and dd:container_delete_response so drydock can correlate concurrent requests; add a timestamps field to dd:container_log_request - ✨ feat(logs): honor msg.Follow as a bounded live window (now+5s via a Unix `until`, the grammar the daemon actually parses) and pass msg.Timestamps through to the daemon - 🐛 fix(logs): decode container logs to plain text — strip Docker's 8-byte multiplex frame headers for a non-TTY container, pass a TTY container's raw stream through unchanged (demuxing a raw TTY stream corrupts it) - ✨ feat(edge): classify hello-rejection codes and stop retrying terminal ones (revoked key, bad signature, protocol mismatch) instead of reconnecting forever; unknown and transient codes still retry - 🧪 test: cover demux/decode, TTY passthrough, bounded-follow deadline, requestId echo, and terminal-vs-retry reconnect - 📝 docs: sync SPEC, drydock-integration, ROADMAP, CHANGELOG, COMPATIBILITY, and both security-model docs The requestId/timestamps/follow fields are agent-side enablement; they stay inert on the wire until drydock echoes the requestId back and starts sending the options.
📝 WalkthroughWalkthroughAdds optional 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🧹 Nitpick comments (2)
internal/adapter/drydock/adapter.go (1)
30-33: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win100 MiB per-request log cap is large for a single buffered JSON string.
maxContainerLogBytesbounds onedd:container_log_responsepayload at 100 MiB. Combined withdefaultMessageHandlerConcurrencyconcurrent handlers, worst case isconcurrency × 100 MiBheld in memory as both raw bytes and a decoded string (roughly doubling for thestring(data)conversion at the response). Given this is a deliberate, documented cap already in this PR, just flagging for awareness — a materially smaller cap (e.g., single-digit MiB) would reduce memory-pressure risk without much practical loss for a log viewer use case.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/adapter/drydock/adapter.go` around lines 30 - 33, Reduce maxContainerLogBytes from 100 MiB to a materially smaller single-digit MiB limit, such as 5–10 MiB, to constrain aggregate memory usage across concurrent handlers while retaining a practical log viewer payload size.internal/docker/logs_test.go (1)
164-210: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winAdd the raw-TTY collision regression case.
The tests cover a raw stream with a non-header prefix, but not raw bytes that satisfy
looksMultiplexed. Add a case such as[1,0,0,0,0,0,0,5,"hello"]and assert pass-through once the decoder receives explicit stream-mode information.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@internal/docker/logs_test.go` around lines 164 - 210, Add a table case in TestDecodeContainerLogs for raw TTY bytes matching looksMultiplexed, such as [1, 0, 0, 0, 0, 0, 0, 5, "hello"], and assert the bytes pass through unchanged when the decoder receives explicit stream-mode information. Update the test invocation and relevant decoder API setup to provide that explicit mode.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/content/docs/security-model.mdx`:
- Around line 234-235: Rename the “Edge log-request payload” cap label in
security-model.mdx to “Edge log-response payload” or “Docker log response body”
to match the bounded Docker response body and dd:container_log_response purpose,
then apply the same correction in docs/security-model.md.
In `@internal/docker/logs.go`:
- Around line 31-35: The log parser currently infers multiplexed mode from the
first eight bytes, which can corrupt valid raw TTY output. Update the relevant
log-reading function and its callers to pass the known TTY/multiplexed mode
explicitly, or rely on a reliable Docker response signal; only call
DemuxLogStream when that mode confirms multiplexing, otherwise read the stream
unchanged.
- Around line 63-67: The log header reading logic should only treat an empty
stream ending with io.EOF as successful. Update the io.ReadFull call in the log
parsing function to capture n, return clean EOF only when n == 0 and
errors.Is(err, io.EOF), and otherwise wrap and return the read error, including
io.ErrUnexpectedEOF for truncated headers.
- Around line 75-79: Handle oversized log frames as an explicit failure instead
of returning partial data: update the log decoding flow around the
oversized-frame handling and the drydock adapter’s DDContainerLogResponseMessage
response path to propagate the truncation error and avoid sending a normal
successful response with incomplete Logs, or extend the wire message with a
clearly populated truncation/error field and update consumers accordingly.
In `@SPEC.md`:
- Around line 159-163: The HTTP /logs route description does not specify the
bounded follow timing. Update the follow-window text in SPEC.md to explicitly
state that the daemon receives an `until` deadline 5 seconds ahead, with the
handler allowing an additional 2-second grace period for a total 7-second
window, while retaining the distinction from continuous
request/stream/stream_end tailing.
---
Nitpick comments:
In `@internal/adapter/drydock/adapter.go`:
- Around line 30-33: Reduce maxContainerLogBytes from 100 MiB to a materially
smaller single-digit MiB limit, such as 5–10 MiB, to constrain aggregate memory
usage across concurrent handlers while retaining a practical log viewer payload
size.
In `@internal/docker/logs_test.go`:
- Around line 164-210: Add a table case in TestDecodeContainerLogs for raw TTY
bytes matching looksMultiplexed, such as [1, 0, 0, 0, 0, 0, 0, 5, "hello"], and
assert the bytes pass through unchanged when the decoder receives explicit
stream-mode information. Update the test invocation and relevant decoder API
setup to provide that explicit mode.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 9f03da0c-6123-423c-a5a2-90ae53f47b9f
⛔ Files ignored due to path filters (1)
CHANGELOG.mdis excluded by!CHANGELOG.md
📒 Files selected for processing (18)
COMPATIBILITY.mdROADMAP.mdSPEC.mddocs/content/docs/drydock-integration.mdxdocs/content/docs/security-model.mdxdocs/security-model.mdinternal/adapter/drydock/adapter.gointernal/adapter/drydock/adapter_test.gointernal/adapter/drydock/coverage_test.gointernal/adapter/drydock/handle_message_test.gointernal/adapter/drydock/routes_test.gointernal/docker/logs.gointernal/docker/logs_test.gointernal/edge/client.gointernal/edge/hello_reject.gointernal/edge/hello_reject_test.gointernal/protocol/messages.gointernal/protocol/messages_test.go
biggest-littlest
left a comment
There was a problem hiding this comment.
Agent-side wire additions are all omitempty so an old controller is unaffected. The until fix (Unix seconds, not RFC3339) matches what the daemon actually parses, the TTY-vs-multiplex decode split is correct, and the terminal-reject classifier defaults unknown codes to retry so a novel drydock code can't crash-loop the fleet. Tests cover the new paths. LGTM.
ALARGECOMPANY
left a comment
There was a problem hiding this comment.
Confirmed the follow path is bounded (now+window via Unix until plus a context-deadline backstop) so a follow request can't pin a handler slot, and the requestId echo is a pure additive field drydock already puts on the wire. Docs and both security-model files are in sync. LGTM.
What
Additive edge wire-protocol build-out on the portwing agent side. No compatibility bump — every field is
omitemptyand the agent stays backward-compatible with a controller that doesn't send them.Three P2 items from the roadmap:
requestId correlation — echo
requestIdondd:container_log_responseanddd:container_delete_responseso the controller can match responses to concurrent in-flight requests. Drydock already putsrequestIdon the wire; this closes the loop by reflecting it back. Also adds atimestampsfield todd:container_log_request.Log options — the handler now actually reads
msg.Follow(was hardcodedfalse) andmsg.Timestamps. Because add:container_log_responsecarries a single bufferedLogsstring and can't stream,followis served as a bounded live window: portwing overridesuntilwithnow + 5s(as Unix seconds — the grammar the Docker daemon parses; RFC3339 is rejected on the wire param) and sets a context deadline as a backstop so the handler can never hold a message-handler semaphore slot indefinitely. Continuous tailing still belongs on the streaming request/stream/stream_end path, not this message pair.Reconnect classification — a revoked key currently reconnect-loops forever.
internal/edge/hello_reject.goclassifies hello-rejection codes; terminal ones (revoked key, bad signature, protocol mismatch, ...) now fail fast (errFatal) instead of retrying. Unknown and transient codes still retry, so a future drydock deploy adding a novel transient code won't crash-loop the fleet.Also fixed
internal/docker/logs.go): the old pathio.ReadAll'd the raw Docker stream, which leaves the 8-byte multiplex frame headers embedded in non-TTY container logs.DecodeContainerLogsstrips those headers for non-TTY streams and passes a TTY container's raw stream through unchanged (demuxing a raw TTY stream would corrupt it), matching what the HTTP/logsroute returns for the same container.Notes
requestId/timestamps/followfields are agent-side enablement. They're inert on the wire until drydock echoes therequestIdback to its own callers and starts sending the options — that's the companion drydock change.app/api/portwing-ws.tsand is not a versioned wire contract;hello_reject.goandCOMPATIBILITY.mddocument that it must be updated in lockstep. Unknown codes default to retry, so drift degrades to "retries a permanent failure," never "drops a fixable one."Tests
internal/docker/logs_test.go— demux framing, truncated header/payload, oversized-frame skip, TTY passthrough, short/empty.internal/adapter/drydock/*_test.go— requestId echo on success + docker error, timestamps forwarding, bounded-followuntil(Unix seconds within tolerance), non-followuntilpassthrough, raw TTY passthrough, follow-deadline partial logs.internal/edge/hello_reject_test.go— full terminal/transient/unknown table;connect()fatal-vs-retry;Run()makes exactly one attempt on a terminal code.Full pre-push gate green (goreleaser snapshot, lint,
-racetest, govulncheck, fuzz). Docs synced: SPEC, drydock-integration, ROADMAP, CHANGELOG, COMPATIBILITY, both security-model docs.Changelog
requestIdcorrelation for container log/delete requests and responses.timestampssupport and boundedfollowwindows.omitempty.Concerns
followremains bounded rather than a continuous live tail.