Skip to content

[Spec 1967] Tower-to-Tower messaging, stage 2: between my own Towers through Codev Cloud - #2007

Merged
waleedkadous merged 174 commits into
mainfrom
builder/spir-1967
Nov 28, 2026
Merged

waleedkadous merged 174 commits into
mainfrom
builder/spir-1967

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Tower half of Tower-to-Tower messaging, stage 2: an agent on one of my Towers sends afx send afx://<tower>/<workspace>:<agent> "…" to an agent on another of my Towers, both behind NAT, through Codev Cloud. The cloud half is codev-cloud #22 (the relay, the attested statement and the cloud's limits).

  • The receiving Tower takes the sending Tower only from the cloud's MAC-verified statement (current tunnel session's secret, once only, within 5 minutes). It accepts nothing until the owner grants that peer, and writes a frame no body can counterfeit.
  • The sending Tower runs its checks before any call, in a fixed order. It holds what cannot go now, visibly, in afx inbox, and sends in order with one relay call at a time per peer, for up to 30 days.
  • Remote messaging is off on a fresh install and on an upgraded one. afx peer on/off/grant/revoke/list/show/log and the dashboard's Peers panel manage it. The held-mail indicator gains its three counts.

Closes #1967

Changes

  • packages/codev/src/agent-farm/peer/, new: the wire contract (the only module that speaks it), the sender and outbox, the cloud client and peer list, the receiver, discovery, grants, the switch, records and surfaces.
  • The tunnel's verified entry point for /__tower/peer (lib/tunnel-client.ts). The handshake states the protocol and the switch. The session secret is taken only over wss: and kept in memory only.
  • Migration v21 (additive only): remote mailbox columns, peer_outbox, peer_accepted, peer_towers, peer_tower_names, peer_grants, peer_records, peer_answer_runs and peer_settings.
  • afx send across Towers (route, SDK, CLI), afx peer …, afx inbox (three groups, release), lines in afx status and afx tower status.
  • The dashboard's Peers panel and the three-count held-mail indicator, with an isolated Playwright config (playwright.peers.config.ts).
  • Test layers: a stand-in relay that implements the contract, a two-Tower harness, a seeded generator for the frame-invariant property test, and the shared contract vectors (packages/types/fixtures/peer-contract-vectors.json, posted to codev-cloud I Built a Conversational Todo Manager with Codev! #22).
  • Docs in both codev/ and codev-skeleton/: the afx skill, agent-farm.md, overview.md, the architect and builder roles, the CLAUDE.md and AGENTS.md templates, and arch.md section 10.
  • Fixed in place: bugfix-1871-cloud-identity.test.ts now closes global.db. Once auth read the switch, that suite left the database open and failed teardown on Windows with EBUSY.

For the reviewer at the pr gate

  • The origin/main merge (9f2048c78, bringing in issue Tower: a cheap liveness route with the version; /health is too heavy to probe under load #1977's /health/live liveness route and issue VSCode Agents view hides task builders whose id contains - or _ #1992's fix for task builders hidden in the VS Code Agents view) had four conflicts, each kept from both sides: send.ts, the SDK's tower-client.ts, server-utils.ts and tower-routes.ts. The resolutions are listed in the thread's phase 13 entry. The branch is 0 commits behind main today.
  • Four phases were closed by porch's force-advance (5, 7, 9, 12), so their last fix had no consult round: c21f5b932, 3cd856ef1, 10e5fe397 and a38f0f2b0. The review document's "Phases closed by porch's force-advance" says who read each, and what they ran.
  • Gap 2, the builder footer's reply round trip, is closed in layer A by the architect's ruling (de2263971). One table-driven test frames each builder footer row with the receiver's own code and hands the printed command to the real sender as the builder. The named-architect row prints afx send architect, a local send the remote sender never sees, and the test asserts exactly that.

Testing

  • Layer A (porch's tests check; unit tests, in process): 11 028 passed, 116 skipped, in 244 s on a2f660715, after npm run build succeeded. Before the review phase it was 11 022 passed, in 242 s.
  • Layer B (on demand; two built Towers against the stand-in over loopback), the seven *.e2e.test.ts two-Tower files: 63/63 in 59 s.
  • Layer C (on demand; playwright.peers.config.ts, port 14102): 17/17 in 5.5 s.
  • Layer D, Windows:
    • Run 46009240887 on 914765b38: every job green. The afx:// probe passed in Git Bash, PowerShell and cmd, on windows-latest and windows-11-arm, and 10 712 unit tests passed.
    • Since that run:
      • b95f451a8: test-only, removes the temporary timing.
      • 09ea39d00: the review document.
      • 370dd788e: the thread.
      • 4fc7b20ef: the phase 13 review round, with test rows and doc rows.
      • de2263971: the layer A gap 2 test.
      • a3ce47bd3: the review document, lessons and the thread.
      • a2f660715: the PR review round. One line of production code (errorKind in peer/outbox.ts logs an error's class, not its message; not platform code), a doc comment, and Gap 7's named tests.
      • 963c50b75 and the thread commit after it: the review document and the thread.
      • 653191119: three test files spell paths they never open without /tmp (the Unit Tests job's residue check).
      • d02bea6f4: stage 1's cross-workspace-addressing.e2e.test.ts expects stage 2's remote-off refusal (the architect's word).
      • Porch's own commits.
    • The architect ruled that b95f451a8 and 09ea39d00 need no third run, and that a2f660715 (one line of logging in peer/outbox.ts, a comment in peer/contract.ts) needs none either. Every other commit after the run touches only tests and documents.
    • The earlier run, 46006429938, was red on two new test files. Both were fixed; the review document has the cause of each.
  • CI on the head d02bea6f4: all 8 checks pass (Tests run 46018493820, CLI Integration run 46018493837).
    • Until 653191119, the Unit Tests job stopped at its /tmp residue check, so the unit suite first ran on Linux there.
    • The Tower Integration Tests job ran the whole e2e suite against this branch for the first time; porch skips e2e_tests here. It found one stage 1 test still pinning stage 1's refusal, fixed in d02bea6f4.
  • Flaky tests: none encountered.

PR review (codex COMMENT, claude APPROVE)

Fixed in place in a2f660715:

  • the outbox logs an error's class;
  • Gap 7 (a payload claiming another sending Tower) has named tests: refused as malformed, with nothing stored;
  • readRelayRequestHeaders is documented as the cloud's check.

One point was rebutted: codex's duplicate mailboxId is two different interfaces. The responses are in codev/projects/1967-tower-to-tower-messaging-stage/1967-review-iter1-rebuttals.md.

Waiting for the real cloud (verify-approval)

These are checked here only against the stand-in, or with a mocked answer:

  • the same Tower name on another account;
  • the cloud's refusal of a relay request through /t/;
  • the cloud's per-peer limit;
  • both Towers behind NAT;
  • a recipient's terminal that itself survived a Tower restart;
  • the Peers panel's no-relay state;
  • the full afx status in a workspace on a real Tower;
  • what the real cloud stores of a relayed message;
  • a real builder messaged under --all sending its footer's command back, and the message arriving.

Spec

codev/specs/1967-tower-to-tower-messaging-stage.md

Review

codev/reviews/1967-tower-to-tower-messaging-stage.md

…round 2

Contract revision 2: slug as the Tower's protocol name; HTTP 200 alone
means the receiver decided; exact field rules for statement and payload;
literal-UTF-8 serialisation; sender refusal precedence; how the sender
resolves its row; rate-limited held mail held for either source; wrong-clock
surface; shared vector location, format and a worked case; cloud costs
K1-K6 as departures; test-plan constraint; cost of a slipped cloud half in
Open Question 1.
C's order of checks as a table; per-pair counting only after the recipient
check; excluded code points for the email written into the contract;
media-type-only check of R's answer; a run of cloud-error surfaced (G15).
…dings stated

[r3-1] 600 calls a minute per Tower across every /api/peer route, checked
at step 4; a query 429 is refused and never held, a message 429 is handled
like any other. [r3-2] 'C never answers 200 itself' is about the relay call
only; PUT /api/peer/state answers 400 malformed for a bad body. Current
State dates cloud PR #18 (merged 2026-11-17); C6 names the ceiling.
…t vectors

- packages/types/src/peer-wire.ts: the contract's shapes and the protocol-v1
  constants (codev-types stays free of runtime dependencies).
- packages/codev/src/agent-farm/peer/contract.ts: the one production module that
  speaks the contract: relay headers, strict base64url, the MAC in constant time,
  R's steps 1-7, the section 5 field rules as one table with the excluded code
  points as data, Decision 7's normalisation, payload encode/read and hash,
  answers in both directions with the status-to-outcome mapping and the
  "relay stated" distinction, and S's refusal order. Architect-read file.
- packages/types/fixtures/peer-contract-vectors.json: 140 shared vectors in the
  section 11 format, generated with node:crypto independently of contract.ts;
  every case's HMAC and SHA-256 cross-checked once in Python (stdlib, -I).
- Tests: the vectors through node:crypto then contract.ts (each failing case at
  its named step); layer-A unit tests for every rule; a structural grep that no
  other production file holds a contract header name or a status mapping.

Checks: npm run build and npm test -- --exclude='**/e2e/**' (461 files,
10236 tests) pass; core and artifact-canvas boundary tests pass.
…with the cloud

- Spec (Wire Contract): "integer" is judged on the parsed value (1.0 and
  1.7641e12 are integers); an unpaired surrogate in fromOwnerEmail is
  not-verified. Both already what the vectors and contract.ts do; no change of
  behaviour, so no revision number (codev-cloud #22, comment 7204918145).
- Vectors: two cases appended (v written as 1.0, issuedAt written as
  1.7641e12, both verified); the first 140 cases are unchanged. HMAC and
  SHA-256 of all 142 cross-checked again in Python (stdlib, -I).
…istered Tower with the switch off

The architect's ruling at phase 12 close: the section is hidden when this
Tower has no Codev Cloud registration (towerName null, which is
readCloudConfig() null, as tower_name is a required field) and remote
messaging is off; it is shown in every other case, and appears on the next
poll once the Tower is connected or the switch is on. An earlier shown
section is cleared.

- templates/tower.html: peersPanelShown(panel), used by renderPeers.
- peer-panel-template.test.ts (new, 2): the template's own functions,
  each side of the condition; fails with the condition removed.
- e2e/peers-panel.test.ts: the unmocked case is now the browser check
  that the section is absent on a fresh throwaway Tower.
- Screenshot: peers-hidden-unregistered.png.

Verified: build 17 s; layer C through playwright.peers.config.ts on port
14102, 17/17 in 5.6 s, nothing left in tmp, port free.
Found by grepping both trees for the addressing forms, afx peer, afx inbox
and the stage 1 refusal text (overview.md was found that way).

- CLAUDE.md and AGENTS.md (byte-identical): the afx://<tower>/... row.
- Templates, CLAUDE.md and AGENTS.md in codev/ and codev-skeleton/: the
  afx:// row, and what a REMOTE header means, the send outcomes across
  Towers, and that afx peer on, afx peer grant and afx inbox release are
  a human's decisions. Each pair differs only by its two lines that differ
  on main by design (title, the AGENTS.md note).
- The afx skill, four identical copies: the afx:// row and outcomes, the
  REMOTE frame, afx inbox's three groups and release, a new afx peer
  section (hold wins, human-only acts), status and tower status lines.
  Hashes regenerated (generate-skill-hashes: skills and root docs).
- agent-farm.md in both trees: afx:// in send's arguments, outcomes and
  refusals across Towers, the remote frame, inbox groups/show/release/
  dismiss, a new afx peer section with the walkthrough and the Peers
  section (it appears once the Tower is connected or the switch is on),
  the status and tower status lines, and the peer limits config. The
  stage 1 sentence (messaging between Towers not available yet) is gone.
- overview.md in both trees: afx peer, and release under afx inbox.
- Roles, architect and builder in both trees: a new Other Towers section:
  the REMOTE header, only the Tower part of the address is verified
  (Decision 7), and the three human-only acts with the carve-out (run on
  a human's decision relayed by the architect / on the human's word).
- arch.md: section 10, cross-Tower messaging (the relay, the contract
  module, provenance, receiver, sender, peer list, switch and grants, the
  v21 peer tables, records, surfaces, tests); the stale stage 1 refusal
  sentence (CROSS_TOWER_UNAVAILABLE no longer exists) corrected; two
  glossary terms. The hot tier is not grown.

Verified: diff CLAUDE.md AGENTS.md empty; skill copies identical; the 34
unit test files that read these docs, 809 passed.
…, with its skipped steps and a secrets check

peer-walkthrough.e2e.test.ts (new, layer B, on demand): two built Towers,
mbp and devvm, on the stand-in over loopback, both registered with their
tunnels up and remote messaging off, as a fresh install is.

- Steps 1 to 9 of the approved spec's walkthrough, in order, each as its
  own command line through the CLI's parser (runAgentFarm), as the agent
  the walkthrough names, with each printed line asserted as written.
  Delivery goes through the real render gate to claude echo terminals;
  step 8 reads the frame back from the recipient terminal's output.
- Each row of the skipped-step table, at step 7: the step taken back with
  afx peer off or afx peer revoke, step 7 run, the step done again with
  the walkthrough's own command. Skipped step 2: no relay call and no
  outbox row. Steps 3 and 4: nothing left on devvm. Step 5: step 7
  delivers and step 9 is refused naming the command for mbp. devvm
  asleep (the stand-in reporting it offline): held with its mailbox id,
  then delivered once.
- Secrets and bodies: every tunnel session's secret (raw, base64url,
  base64, hex; every session accounted for), every forward's statement
  (header, JSON, statementId) and MAC (header, raw, hex) are absent from
  each Tower's database files, every other file it wrote (cloud-config.json
  among them), its log and peer_records. Bodies are absent from all of
  them but the database and the PTY session log (#1238) of the one
  terminal each was delivered to, where each is shown present.

A runner detail: a refused afx send exits inside send(); in-process the
command's own catch logs that thrown exit as [error] exit 1, which a real
process never prints, so that one trailing line is dropped.

Verified: 7/7 in 16 s at load 0.8. A negative run with a secret and a MAC
planted in a Tower's directory failed on exactly that file; the copy was
removed and nothing was left in tmp.
… waits for the real-cloud run

- Phases closed by porch's force-advance: phase 12, with the architect's
  reading of a38f0f2 (main, 2026-11-27T12:54Z), beside phases 5, 7, 9.
- New: for the real-cloud run at verify-approval: the plan's four, the
  restart-surviving terminal, and the Peers panel's no-relay state, so
  far browser-checked only with a mocked answer.
Brings in #1977 (cheap /health/live liveness route) and #1992 (task
builders in the agents view).

Conflicts resolved, keeping both sides:
- send.ts: main's explainNotFound now asks the liveness route and takes
  three arguments; this branch's explainMalformed (the afx:// hint) and
  the receiving Tower's detail are kept around main's call.
- tower-client.ts (sdk): import union (TowerLiveness with the peer
  types); main's liveness helpers and this branch's request and peer
  route result types are independent declarations, both kept.
- server-utils.ts, tower-routes.ts: import unions.

Build passes; layer A 11022 passed, 116 skipped, 242 s.
…the liveness route

After merging #1977 the CLI asks /health/live first and falls back to
/health only on a Tower without it. peer-send-cli.test.ts's fake stands
for a Tower of this version, so it now answers /health/live (and no
longer /health), and the hint test's exact path list begins with it.
19/19; layer A 11022 passed, 116 skipped, 242 s.
…es as a Tower stores them

On the Windows run (46006429938) five peer-inbox.test.ts cases failed:
the test's workspace was the POSIX literal /work/codev, which /api/inbox
normalizes to a drive-letter path on Windows, so the mailbox rows stored
under the literal never matched and only the outbox group listed (the
outbox query normalizes both sides). Production mailbox rows are stored
canonical, so this is the test's literal, not the code (the architect
checked the queries, 2026-11-27T13:35Z).

WS and OTHER now go through resolve(), as inbox-routes.test.ts does; the
holder's workspace is WS before each test (its hoisted value runs before
resolve is imported, so it starts empty); the remaining /work literals in
the overview-count case use OTHER and resolve(). Test-only. 24/24 here.
…t, and temporary per-message timing

On the Windows run (46006429938) peer-pipeline.test.ts took 172 s for 15
tests against 1.9 s here, and the first 50-message backlog passed its 30 s
limit. In one commit, so one Windows run answers it (the architect's word,
2026-11-27T13:35Z):

- Windows only: each test in this file gets 120 s (vi.setConfig, and the
  four explicit limits through TEST_TIMEOUT). POSIX keeps 30 s.
- TEMPORARY timing in the two 50-message tests, test-side only: the two
  test databases' statements and transactions, the cloud client's fetch
  (an option it already takes) and the receiver this file hands the
  tunnel are wrapped and timed. Per message it prints, prefixed
  [pipeline-timing], each send's time and S's SQLite; each drain relay
  call's HTTP time, R's receiver and R's SQLite inside it, and S's SQLite
  until the next call; then totals, the set-up time and the test's time.
  No shipped code changes. Removed in a follow-up commit once the run has
  answered.

Here: 15/15; a relay call is about 3.8 ms over HTTP, of which R's receiver
about 1.5 ms (mostly SQLite); S's SQLite about 0.7 ms per message. With
--reporter=default under CI=true (as the workflow runs it) all 206 lines
print.
…scenario-to-test table, and two more real-cloud items

- The finished branch: layer A, layer B (seven two-Tower files, 63/63),
  layer C (17/17), and the first Windows run on 63624ca: probes green,
  6 unit failures in two of this spec's files on their first Windows run,
  sent to the architect before any rerun. The second run follows.
- Scenarios and their tests: every scenario in Spec 1967 and every
  inherited stage 2 scenario of Spec 1940 beside its tests and layer;
  the five that wait for the real cloud or real Towers are marked. Eleven
  partial gaps, each named with what was searched.
- For the real-cloud run: the full afx status in a real workspace (Tower
  leaves temp-directory workspaces out of what it reports, so layer B
  cannot run it), and what the real cloud stores of a relayed message.
…ming; the Windows limit stays

The Windows run on 914765b (46009240887) passed every job: unit 10712
passed, none failed; peer-pipeline 15/15 in 145 s under the 120 s limit.
Its per-message timing put the cost in SQLite commits, which wait on a
sync to disk on the Windows runner: per message about 120 ms in R's
writes, 70 ms in S's outbox writes, 45 ms in the send, and 5 ms in the
stand-in's loopback HTTP. These test databases use SQLite's default
rollback journal; production's global.db is WAL. About 0.25 s a message,
R's part 0.12 s against its 5 s deadline: under the second a message the
architect set as the point at which it would be a product matter. As the
architect laid out (2026-11-27T13:35Z): the Windows limit stays, with the
cause in its comment, and the timing is removed. Test-only; 15/15 here.
…e the pipeline's time goes there

Layer D now records both runs: the first's six failures and their causes,
the second all green, and the per-message timing that names SQLite commits
on the runner as the cost, under the line the architect set.
…al exit rows, peer show lists running workspaces)

Codex APPROVE (HIGH, no issues); claude APPROVE (HIGH, six non-blocking
comments). Dispositions in 1967-phase_13-iter1-rebuttals.md.

- Gap 1 closed: peer-send-cli.test.ts's refusal table has a rate-limited
  row for the peer and for Codev Cloud, worded as sender.ts words them;
  a fresh send refused for rate exits non-zero (C4). 21/21.
- agent-farm.md, both trees: afx peer show lists only workspaces running
  on the peer (the phase 10 ruling), and what not live means.
- Review: gap 11 no longer contradicts the verify-approval list; gap 1
  marked closed, and its scenario row names the new rows.
- For the architect at the pr gate: gap 2, the builder-footer round trip
  (a new layer B case in an earlier phase's file).

Tests reading agent-farm.md: 3 files, 51 passed.
… 7's named tests, a note on the cloud's header check)
@waleedkadous
waleedkadous merged commit 10436d0 into main Nov 28, 2026
8 checks passed
waleedkadous added a commit that referenced this pull request Nov 28, 2026
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.

Tower-to-Tower messaging, stage 2: between my own Towers through Codev Cloud

1 participant