Skip to content

✨ feat(wire): edge log correlation, options, and terminal-reject reconnect - #57

Merged
scttbnsn merged 1 commit into
mainfrom
feat/edge-wire-protocol-p2
Jul 10, 2026
Merged

scttbnsn merged 1 commit into
mainfrom
feat/edge-wire-protocol-p2

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

What

Additive edge wire-protocol build-out on the portwing agent side. No compatibility bump — every field is omitempty and the agent stays backward-compatible with a controller that doesn't send them.

Three P2 items from the roadmap:

  1. requestId correlation — echo requestId on dd:container_log_response and dd:container_delete_response so the controller can match responses to concurrent in-flight requests. Drydock already puts requestId on the wire; this closes the loop by reflecting it back. Also adds a timestamps field to dd:container_log_request.

  2. Log options — the handler now actually reads msg.Follow (was hardcoded false) and msg.Timestamps. Because a dd:container_log_response carries a single buffered Logs string and can't stream, follow is served as a bounded live window: portwing overrides until with now + 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.

  3. Reconnect classification — a revoked key currently reconnect-loops forever. internal/edge/hello_reject.go classifies 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

  • Corrupted log output (internal/docker/logs.go): the old path io.ReadAll'd the raw Docker stream, which leaves the 8-byte multiplex frame headers embedded in non-TTY container logs. DecodeContainerLogs strips 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 /logs route returns for the same container.

Notes

  • The requestId / timestamps / follow fields are agent-side enablement. They're inert on the wire until drydock echoes the requestId back to its own callers and starts sending the options — that's the companion drydock change.
  • The terminal-code list mirrors drydock's app/api/portwing-ws.ts and is not a versioned wire contract; hello_reject.go and COMPATIBILITY.md document 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-follow until (Unix seconds within tolerance), non-follow until passthrough, 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, -race test, govulncheck, fuzz). Docs synced: SPEC, drydock-integration, ROADMAP, CHANGELOG, COMPATIBILITY, both security-model docs.

Changelog

  • ✨ Added additive requestId correlation for container log/delete requests and responses.
  • ✨ Added log timestamps support and bounded follow windows.
  • ✨ Added Docker multiplexed-log decoding while preserving TTY output.
  • ✨ Added terminal/transient hello-rejection classification and retry behavior.
  • ✨ Added comprehensive protocol, adapter, decoder, reconnect, and integration tests.
  • 🔧 Updated protocol, compatibility, roadmap, security, and integration documentation.
  • 🔒 Added payload-size and follow-duration resource limits.
  • ⚠️ No compatibility bump; new fields remain optional with omitempty.

Concerns

  • Controller support is still required to send log options and echo request IDs.
  • follow remains bounded rather than a continuous live tail.
  • Hello-rejection code maps must remain synchronized with drydock.

…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.
@coderabbitai

coderabbitai Bot commented Jul 10, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds optional requestId correlation to DD container log and delete messages. Docker log responses now support bounded decoding, timestamps, bounded follow windows, partial output, and TTY pass-through. Delete and log handlers echo request identifiers. Edge hello rejection codes are classified into terminal and retryable sets, with malformed and unknown codes defaulting to retry. Tests and protocol, compatibility, roadmap, integration, and resource-cap documentation cover these behaviors.

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/edge-wire-protocol-p2

Comment @coderabbitai help to get the list of available commands.

Comment thread internal/adapter/drydock/adapter.go Dismissed
Comment thread internal/edge/client.go Dismissed
Comment thread internal/edge/client.go Dismissed
Comment thread internal/edge/client.go Dismissed
Comment thread internal/edge/client.go Dismissed
Comment thread internal/edge/client.go Dismissed
Comment thread internal/edge/client.go Dismissed
Comment thread internal/edge/client.go Dismissed

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (2)
internal/adapter/drydock/adapter.go (1)

30-33: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

100 MiB per-request log cap is large for a single buffered JSON string.

maxContainerLogBytes bounds one dd:container_log_response payload at 100 MiB. Combined with defaultMessageHandlerConcurrency concurrent handlers, worst case is concurrency × 100 MiB held in memory as both raw bytes and a decoded string (roughly doubling for the string(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 win

Add 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

📥 Commits

Reviewing files that changed from the base of the PR and between 0894b5e and 66facd1.

⛔ Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
📒 Files selected for processing (18)
  • COMPATIBILITY.md
  • ROADMAP.md
  • SPEC.md
  • docs/content/docs/drydock-integration.mdx
  • docs/content/docs/security-model.mdx
  • docs/security-model.md
  • internal/adapter/drydock/adapter.go
  • internal/adapter/drydock/adapter_test.go
  • internal/adapter/drydock/coverage_test.go
  • internal/adapter/drydock/handle_message_test.go
  • internal/adapter/drydock/routes_test.go
  • internal/docker/logs.go
  • internal/docker/logs_test.go
  • internal/edge/client.go
  • internal/edge/hello_reject.go
  • internal/edge/hello_reject_test.go
  • internal/protocol/messages.go
  • internal/protocol/messages_test.go

Comment thread docs/content/docs/security-model.mdx Resolved
Comment thread internal/docker/logs.go Resolved
Comment thread internal/docker/logs.go Resolved
Comment thread internal/docker/logs.go Resolved
Comment thread SPEC.md Resolved

@biggest-littlest biggest-littlest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ALARGECOMPANY left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants