Skip to content

feat(engine): port /v1/bus/* and /v1/sessions to engine (Track 5 Phase 3)#39

Merged
chazmaniandinkle merged 1 commit intocogos-dev:mainfrom
chazmaniandinkle:feat/bus-routes-to-engine
Apr 22, 2026
Merged

feat(engine): port /v1/bus/* and /v1/sessions to engine (Track 5 Phase 3)#39
chazmaniandinkle merged 1 commit intocogos-dev:mainfrom
chazmaniandinkle:feat/bus-routes-to-engine

Conversation

@chazmaniandinkle
Copy link
Copy Markdown
Contributor

Phase 3 of the Track 5 migration plan (Agent I2).

What this lands

  • 9 /v1/bus/* routes + 2 /v1/sessions routes now implemented in engine
  • busSessionManager ported verbatim (~376 LoC)
  • Bus SSE broker ported (distinct from PR feat(engine): event bus with MCP tools, real SSE stream + cogos#10 fix #16's ledger broker)
  • Consumer cursor registry ported (ADR-061)
  • Byte-compat JSON shape preserved (CogBlock {v:2, seq, ts, from, type, payload, prev_hash, hash} — tested against live fixtures from cogos-v3 :6931)
  • ~2,463 LoC new engine code + tests

Additive-only

Root still serves these routes. Installed binary (per Makefile:44) remains root-backed until Phase 4 flips the build target. No user-visible change.

Shape verification

Captured live responses from cogos-v3 :6931 into /tmp/phase3-fixture-*.json, then ran the engine server through httptest and diff'd the top-level key sets:

  • POST /v1/bus/send — MATCH (ok, seq, hash)
  • GET /v1/bus/{id}/events — MATCH (v, bus_id, seq, ts, from, type, payload, hash)
  • GET /v1/bus/list — MATCH (bus_id, state, participants, transport, endpoint, created_at, last_event_seq, last_event_at, event_count)
  • GET /v1/bus/{id}/stats — MATCH (bus_id, event_count, first_event_at, last_event_at, types, senders)
  • GET /v1/bus/consumers — MATCH outer + inner ConsumerCursor shape (consumer_id, bus_id, last_acked_seq, connected_at, last_ack_at, stale)

Unblocks

Phase 4 Makefile cutover. After Phase 4 lands, running `cogos serve` from the installed binary will serve these routes via engine; rebuilding cogos-v3 will no longer break cog-sandbox-mcp bridge.

Not in scope

Test plan

  • byte-compat diff against captured cogos-v3 :6931 responses (fixture-diff probe, described above)
  • hash chain continuity (TestBusSessionHashChainRecompute)
  • bus isolation (TestBusSessionIsolation)
  • consumer cursors (TestConsumerRegistryAckAndList + TestBusConsumers)
  • SSE subscribe (TestBusStreamBrokerPublishSubscribe)
  • session list + detail (TestSessionsListAndDetail)
  • engine test suite green -race -count=1 (ok 3.093s)
  • build + vet silent (full repo)
  • TestServeBusAckRemoved regression — still passes (no ack route added)

…e 3)

Ports 9 bus routes + 2 session routes from root package to engine,
preserving byte-compat JSON shape for cog-sandbox-mcp bridge consumption.
Storage path unchanged (.cog/.state/buses/{bus_id}/events.jsonl).

Additive-only: root serve.go still registers these routes; after Phase 4
Makefile switch, the installed binary will serve them via engine instead.

Follows the Phase 1 / PR cogos-dev#23 and Phase 2 / PR cogos-dev#37 migration pattern.
@chazmaniandinkle chazmaniandinkle merged commit 9ae40ad into cogos-dev:main Apr 22, 2026
5 checks passed
chazmaniandinkle pushed a commit that referenced this pull request Apr 22, 2026
The installed cogos binary now builds from cmd/cogos/main.go (engine)
rather than from root package. Root package still builds for tests +
comparison, but the default `make build` / `make install` targets
produce an engine-based binary.

Prerequisites (all on main):
- Phase 1 (#23): cogos emit migrated to engine
- Phase 2 (#37): cogos mcp serve migrated to engine
- Phase 3 (#39): /v1/bus/* + /v1/sessions migrated to engine

Changes:
- Makefile: default build target, all per-platform cross-compile
  targets (darwin/linux/android), and LDFLAGS -X path flip to
  github.com/cogos-dev/cogos/internal/engine.BuildTime. Smoke-test
  target drops `help` and `coherence check` subcommands which engine
  does not expose.
- Dockerfile: multi-stage build updates matching Makefile (path +
  LDFLAGS). Dockerfile.e2e was already correct.
- CHANGELOG: document cutover, subcommands gained / lost.

Preserves the CLI entry point name (`cogos`) so hooks + .mcp.json
continue to work without changes. Subcommands that only existed in
root (dormant subcommands + anything not yet migrated) are no longer
available in the installed binary — Phase 5 audits these for final
deletion.

Smoke-tested: engine binary serves /health, /v1/bus/send, /v1/bus/{id}/events
in the shape the cog-sandbox-mcp bridge consumes.
chazmaniandinkle pushed a commit that referenced this pull request Apr 22, 2026
Deletes the serveServer type and all files that reference it as a
method receiver, plus helpers that went orphan when the web was cut.

Prerequisites (all on main):
- Phase 1 (#23): cogos emit in engine
- Phase 2 (#37): cogos mcp serve in engine
- Phase 3 (#39): /v1/bus/* + /v1/sessions in engine
- Phase 4 (#40): Makefile flipped to cmd/cogos build
- Phase 5 (#41): 25 dormant subcommands pruned from root

With all migrations + prunes landed, the root serveServer is
unreachable from any live code path: the installed binary has been
cmd/cogos since Phase 4, the cogos-sandbox-mcp bridge consumes
engine's ported /v1/bus/* routes, and hooks invoke engine's ported
subcommands.

Deleted, production (serveServer method receivers):
- serve.go, serve_bus.go, serve_context.go, serve_context_build.go,
  serve_inference.go, serve_research.go, serve_messages.go,
  serve_providers.go, serve_dashboard.go, serve_daemon.go,
  serve_agents.go
- bus_api.go, bus_stream.go
- cogfield.go, cogfield_sessions.go, cogfield_documents.go,
  cogfield_buses.go, cogfield_adapters.go,
  cogfield_components.go, cogfield_conditions.go,
  cogfield_reconcile.go, cogfield_signals.go
- modality_serve.go, modality_tools.go, modality_pipeline.go
- agent_serve.go, agent_decompose.go, agent_observation.go
- mcp.go, mcp_http.go, mcp_mod3.go
- reconcile_serve.go
- event_discord_bridge.go, events_webhook_config.go

Deleted, tests whose fixtures lived in deleted production files:
- foveated_test.go, serve_agents_test.go, serve_context_build_test.go,
  serve_messages_test.go, mcp_http_test.go, bus_stream_test.go,
  modality_pipeline_test.go, agent_user_turn_reply_test.go

cog.go dispatch cleanup:
- Dropped `case "serve":` and `case "mcp":` — both are engine-backed now
- Removed `cog serve` help block

Surviving-file trims:
- decompose_test.go: removed two cycle-memory tests that exercised
  agent_decompose.go's ServeAgent-scoped helpers
- agent_tools_respond_test.go: inlined capturedReply /
  sessionIDsOf / sameStringSet helpers that used to live in the
  deleted agent_user_turn_reply_test.go

New consolidation files (replacing deleted-file type aliases the
rest of the root package still relies on):
- types_shared.go: CogBlock, BusEventData, busRegistryEntry,
  busSendRequest, busSendResponse, busEventEnvelope, defaultServePort,
  claudeCommand, codexCommand
- openclaw_bridge.go: OpenClawBridge + MCPTool* types, lifted out of
  mcp.go because bus_tool_router.go and reconcile_mcp_tools.go still
  call into the bridge
- bus_event_format.go: formatBusEvent + helpers, extracted from
  event_discord_bridge.go because bus_watch.go's line-format mode
  still calls into it

Tally: 45 files deleted, 3 consolidation files added.
45 files changed, 652 insertions(+), 19,926 deletions(-).
Net: ~19,274 LoC root-package contraction.

Verification:
- go build ./... clean
- go vet ./... clean
- go test ./... -short -race -count=1 green
- cmd/cogos binary builds + serves /health, /v1/bus/send,
  /v1/bus/{id}/events with historical response shapes

Closes the Agent I2 revised dead-code plan (Track 5).
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