Skip to content

🐛 fix(edge): finish the portwing edge integration (punch-list criticals + races) - #471

Merged
scttbnsn merged 7 commits into
dev/v1.6from
fix/portwing-edge-punchlist
Jul 4, 2026
Merged

scttbnsn merged 7 commits into
dev/v1.6from
fix/portwing-edge-punchlist

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

What

Closes every item in .planning/portwing-edge-punchlist.md — the adversarially-verified gaps left by the #470 WIP checkpoint. The edge feature is now actually finished.

Fixes

  1. [critical] Process crash on non-string agentName — validateAgentNameField() rejects malformed hellos up front ('invalid-agent-name' error frame + 1008 close) instead of throwing an unhandled rejection; computeAgentName() is type-safe as defense in depth.
  2. [critical] Name squatting across Ed25519 keys — nameToKeyId binds display name → pubKeyId on first use; a hello reusing a name under a different key is rejected ('agent-name-claimed'). Binding releases on key revocation so re-provisioned agents reclaim their name. Review hardening: the map is capped at 10,000 with 24h-idle pruning that never evicts a live agent's binding (a single valid key could otherwise grow it unboundedly via fresh names — ~288k/day within the nonce-admission limit).
  3. [major] Double onDisconnect / name-keyed eviction — idempotency guard, listeners detached before forced close, and instance-checked removal (a stale connection's delayed cleanup can no longer evict a reconnected agent with the same name).
  4. [major] pendingRequests collision — unique uuidv7 requestId per call + per-container FIFO correlation. Portwing's response frames carry only containerId today (verified against internal/protocol/messages.go — no request-id echo), so this is FIFO correlation with the wire limitation documented, not silently pretended away.
  5. [minor] timestamps flag on the edge log path — documentation-only by design: portwing's wire schema has no timestamps field and hardcodes timestamps/follow to false server-side, so a drydock-side field would be forwarded into a void. Commented at the forwarding site + user-facing Callout in the agents doc. Real support = joint protocol work (tracked).
  6. CHANGELOG — [Unreleased] entries for the full ✨ feat(edge): tri-repo integration — edge dispatch fix, WS liveness, agent identity #470 edge scope, added now that the feature is finished.

Wire format unchanged; SERVER_COMPAT_LEVEL stays 1.4.0.

Item 7 (API reference) is on docs/edge-endpoint (3ce7d02): lookout.mdx → portwing.mdx, rewritten against current dev/v1.6 code, stays unmerged until DD_EXPERIMENTAL_PORTWING graduates per house rule.

Verification

  • EdgeAgentAdapter.ts at 100% stmt/branch/func/line coverage (119 tests); portwing-ws suite +409 lines covering non-string agentName and squat-proofing; full agent/ dir 868 tests green.
  • biome, tsc, qlty gates, script tests (83), workflow tests (248), sharded coverage gates (app+ui, 100% met), build shards — all clean.
  • Two independent adversarial reviews (deep + Codex); the one major finding (unbounded binding map) fixed in c3ed9b8 and re-verified.

scttbnsn added 7 commits July 4, 2026 10:02
…uth key

Punch list items #1 and #2 (both critical, .planning/portwing-edge-punchlist.md):

- computeAgentName() called hello.agentName?.trim() with no type check; a
  number/boolean/array/object agentName in the hello frame threw a TypeError,
  an unhandled promise rejection that could take down the whole process.
  A new validateAgentNameField() step rejects malformed hellos up front with
  an 'invalid-agent-name' error frame + 1008 close, and computeAgentName()
  itself is now type-safe as defense in depth (never throws even if that
  invariant is ever violated).

- The sanitized/fallback agentName was the sole registry/display identity
  with zero binding to the Ed25519 pubKeyId that authenticated the
  connection: any holder of ANY valid registered key could squat or steal
  another agent's name. Added nameToKeyId, binding name -> pubKeyId on first
  use; a later hello reusing a name is only admitted under the SAME key
  (rejected as 'agent-name-claimed' otherwise). The binding is released in
  disconnectByKeyId when its owning key is revoked, so a legitimately
  re-provisioned agent can reclaim its old display name.

Wire format (hello/welcome frames) is unchanged; SERVER_COMPAT_LEVEL stays
1.4.0.
…-proofing

Bug 1 (crash on non-string agentName): number/boolean/array/object and
overlong agentName values are all rejected with invalid-agent-name instead
of throwing; null/undefined still fall back to portwing-edge-<agentId>
without crashing (covers both the new validateAgentNameField() step and
computeAgentName()'s defensive typeof check).

Bug 2 (name not bound to authenticating key): the same key reconnecting
under its own bound name is admitted (welcome); a different key claiming an
in-use name is rejected (agent-name-claimed); revoking the owning key frees
only that key's bindings, leaving other agents' names intact (exercises both
branches of the disconnectByKeyId purge loop).

100% line/branch/function coverage on app/api/portwing-ws.ts.
…ue per-request ids

- 🐛 checkLivenessAndPing() force-closes then runs onDisconnect() synchronously,
  but the real 'close'/'error' listeners were never detached — a delayed real
  close event ran onDisconnect() a second time. Add a `disconnected` guard so
  onDisconnect() is a no-op after the first run.
- 🐛 detach the 'close'/'error' listeners before forcing a close, so a
  WebSocketLike that still fires them afterwards can't trigger a second run
  even without the guard.
- 🐛 manager.removeAgent() matches purely by name and removes every entry with
  that name — a stale adapter's delayed cleanup could evict a different,
  newly-reconnected agent sharing the name. Only remove when the registry's
  current entry for the name is still this adapter's own client instance.
- 🐛 pendingRequests keyed log:/delete:${containerId} only, so a second
  concurrent request for the same container clobbered the first's entry and
  its timer then deleted the second's entry, dropping the real response.
  Give each call a unique requestId (embedded in the key and sent on the
  wire); correlate responses via a per-containerId FIFO queue since
  portwing's dd:container_log_response/dd:container_delete_response frames
  don't echo back a request id today (cross-checked against
  internal/adapter/drydock/adapter.go and internal/protocol/messages.go in
  the portwing repo) — noted as a wire-format limitation in the doc comments.
…nt per-container requests

- 🧪 double-onDisconnect idempotency, including the forced-close listener
  detachment path (Bug 3 legs 1+2)
- 🧪 a stale adapter's delayed onDisconnect must not evict a reconnected agent
  sharing the same name (Bug 3 leg 3) — updates the shared manager.js mock to
  track a single "current" registered client so the instance check is
  exercised realistically instead of always short-circuiting on a stubbed
  getAgent
- 🧪 two concurrent requestContainerLogs()/deleteContainer() calls for the same
  container both resolve, including a timeout/concurrent-request interleaving
  (Bug 4)
- 🧪 fixes the pre-existing "called twice" test that had asserted the old
  double-removeAgent behavior as correct — it now asserts idempotency
- 🧪 defensive-branch coverage for the new FIFO-queue helpers to hold the
  100% coverage gate
Punch-list #5: AgentClient.getContainerLogs() doesn't forward the caller's
`timestamps` flag to edgeAdapter.requestContainerLogs(), unlike the SSE/axios
fallback which sends `&timestamps=`. Checked portwing's wire schema
read-only: protocol.DDContainerLogRequestMessage has no `timestamps` field,
and handleContainerLogRequest always calls GetContainerLogs with
follow=false, timestamps=false regardless of input — so there's no field to
thread the flag into today. Rather than invent an unsupported wire field,
document the gap:

- Code comment at the AgentClient.ts forwarding site and on
  EdgeAgentAdapter.requestContainerLogs() explaining why timestamps is
  dropped, and that `until`/`follow` are accepted by portwing's message type
  but never populated by any drydock caller (and `follow` is ignored
  server-side too).
- User-facing Callout in
  content/docs/current/configuration/agents/index.mdx noting edge-agent log
  downloads never include timestamps and don't support until/follow.
- Existing edgeAdapter-delegation test comment clarifies the dropped flag is
  documented, intentional current behavior, not an oversight.

Threading timestamps/until/follow through properly needs a wire protocol
addition on portwing's side — separate coordinated work, not done here.
- Added: edge dispatch for logs/delete over the WS tunnel, ping-liveness
  dead-connection detection, hello.agentName display-name support bound to
  the authenticating Ed25519 key
- Fixed: memoryGb GiB (not decimal GB) reporting, bidirectional
  drydockCompat mismatch warnings, the malformed-agentName crash, the
  stale-connection eviction race, and the concurrent per-container
  request-correlation bug — all closed on this branch since #470 merged
nameToKeyId (added to bind an agent's display name to the Ed25519 key
that first claimed it, closing the squat/theft hole) had no size cap
or eviction — bindings were released only on explicit key revocation,
never on disconnect. A single already-authenticated, never-revoked key
could grow it without bound by reconnecting under a fresh agentName
each time (the 200/60s per-key nonce-admission limit still allows
~288k new bindings/day/key), a memory-exhaustion vector introduced by
the fix meant to harden this exact path.

- Cap the map at MAX_NAME_BINDINGS (10,000, mirroring nonceCache) and
  reject brand-new names once full with a new 'registry-full' error
  code; reconnects under an already-owned name are exempt since they
  reuse their existing entry rather than growing the map
- Add pruneStaleNameBindings: evicts bindings idle past
  NAME_BINDING_STALE_MS (24h) that aren't backing a live agent
  (checked via getAgent so active connections are never evicted),
  run both opportunistically at the cap and every periodic 60s cycle
  alongside nonce pruning
- Add fillNameBindingsForTesting/nameBindingsSizeForTesting test hooks
  and cover the cap-rejection, eviction, live-binding-protection, and
  at-cap-reconnect paths
@vercel

vercel Bot commented Jul 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drydock-website Ready Ready Preview, Comment Jul 4, 2026 3:04pm
drydockdemo-website Ready Ready Preview, Comment Jul 4, 2026 3:04pm

@scttbnsn
scttbnsn merged commit 06e5570 into dev/v1.6 Jul 4, 2026
4 checks passed
@scttbnsn
scttbnsn deleted the fix/portwing-edge-punchlist branch July 4, 2026 15:04
scttbnsn added a commit that referenced this pull request Jul 4, 2026
…ror codes

- Add invalid-agent-name (bad agentName type/length), agent-name-claimed
  (name bound to a different key), and registry-full (10k binding cap)
  to the hello error-code list
- Document the name→key identity binding: bound on first hello, reused
  only by the same key, released on key revocation
- Note revocation also frees any agent-name it owned
scttbnsn added a commit that referenced this pull request Jul 11, 2026
…nnection race

Post-review fixes for the #470/#471 edge identity work. Closes a critical
restart hole in the name-squat protection and narrows the zombie-connection
race in the edge adapter.

- 🐛 fix(edge): persist the name→pubKeyId binding in a durable LokiJS
  `name-bindings` collection (mirrors agent-keys.ts). The anti-squat binding
  previously lived only in an in-memory Map, so a restart — including the one
  that deploys this protection — wiped it and reopened the squat window until
  every agent reconnected. Every mutation (bind on hello, stale-prune, revoke
  release) is write-through'd; the Map is rehydrated on gateway startup with an
  immediate stale-prune so reloaded bindings don't get a fresh 24h lease.
  Revoke purges the durable store before the Map so a crash between them leaves
  the persisted view no more locked-down than memory.
- 🐛 fix(edge): stop a force-closed EdgeAgentAdapter from resurrecting itself —
  detach the `message` listener on forced close, guard onMessage() on
  `disconnected` so a frame buffered in the close window is inert, and re-check
  `disconnected` after the container-sync await before flipping connected back
  on / re-emitting agentConnected.
- 📝 docs(changelog): note the name binding now holds across a server restart,
  not just for the lifetime of one process.

Adversarially verified: restart-closure ordering, write-through completeness,
revoke ordering, stale-lease eviction, and upsert key-change all confirmed. The
guard's scope comment was corrected to not overclaim — the residual mid-await
container-store write is same-owner, self-correcting, and pre-existing.

This branch was successfully deployed

2 active deployments
Preview – drydock-website — c3ed9b8b Deployed Jul 4, 2026 by vercel[bot]
Preview – drydockdemo-website — c3ed9b8b Deployed Jul 4, 2026 by vercel[bot]
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.

1 participant