Skip to content

Latest commit

 

History

History
232 lines (172 loc) · 6.36 KB

File metadata and controls

232 lines (172 loc) · 6.36 KB

acptoapi Debug & Validation Guide

Overview

This guide documents the debugging and validation tools created to track the Anthropic SDK format conversion fix and verify integration with the sampler, server, and model probing system.

Validation Scripts

1. Format Conversion Witness

File: .gm/exec-spool/in/nodejs/format-conversion-witness.js

Direct testing of the format conversion layer with detailed debug output.

node .gm/exec-spool/in/nodejs/format-conversion-witness.js

What it tests:

  • Basic text response handling
  • Reasoning-delta accumulation (CRITICAL)
  • Content block ordering (thinking before text)
  • Tool call handling with stop_reason mapping
  • Empty response handling

Output: Detailed breakdown of each test with input events and output blocks.

2. Full Integration Check

File: .gm/exec-spool/in/nodejs/full-integration-check.js

Verifies format conversion is integrated correctly through the entire pipeline.

node .gm/exec-spool/in/nodejs/full-integration-check.js

What it checks:

  • Format module exports and reasoning-delta support
  • Buffer function calls toResponse
  • Server buildModelProbes uses buffer
  • Server initializes sampler on boot
  • Sampler interval set to 1 hour (3600000ms)
  • Sampler has exponential backoff
  • Git commit history
  • Todo app structure

Output: Integration pipeline diagram and pass/fail summary.

3. Server Startup & Format Validation

File: .gm/exec-spool/in/nodejs/start-server-and-test.js

Starts acptoapi server and validates format conversion works with real HTTP endpoints.

node .gm/exec-spool/in/nodejs/start-server-and-test.js

What it validates:

  • Server starts and listens on port 4800
  • Sampler initializes with [sampler] started with 3600000ms interval
  • /health endpoint returns 200 with backends
  • /v1/sampler/status returns provider status
  • /v1/models returns available models
  • /debug/translate endpoint works
  • Format conversion layer loaded and working
  • reasoning-delta support verified

Output: Live server logs plus test results.

4. Todo App Integration Test

File: .gm/exec-spool/in/nodejs/test-todo-app.js

Tests the todo app created to verify acptoapi tooling integration.

node .gm/exec-spool/in/nodejs/test-todo-app.js

What it tests:

  • GET /api/todos returns list
  • POST /api/todos creates new todo
  • PATCH /api/todos/:id updates title
  • PATCH /api/todos/:id marks completed
  • DELETE /api/todos/:id removes todo
  • Error handling (400, 404)

Output: 10/10 CRUD operations verified.

5. Live Monitor (Continuous)

File: .gm/exec-spool/in/nodejs/acptoapi-live-monitor.js

Continuously monitors running acptoapi server for 60 seconds, tracking system health.

# Start server first:
node bin/acptoapi.js

# In another terminal:
node .gm/exec-spool/in/nodejs/acptoapi-live-monitor.js

What it monitors:

  • Server health (backends online)
  • Sampler status (available/backoff/untested providers)
  • Available models (count and type breakdown)
  • Format conversion (anthropic->openai test)

Output: Real-time logs with timestamps, elapsed time, and change detection.


Integration Chain

Server Boot
  |
  v
createServer()
  |- Initialize ACP daemons (kilo, opencode, gemini-cli, qwen-code, etc.)
  \- sampler.startSampler(buildModelProbes, 3600000ms)
       |
       v
Sampler Probe Loop (hourly)
  |- Call buildModelProbes()
  \- For each KNOWN model:
       |- buffer(provider, stream, "anthropic")
       |   \- toFmt.toResponse(events)
       |       |- accumulate reasoning-delta -> thinking
       |       |- create thinking content block
       |       |- create text content block
       |       \- order: thinking[0] -> text[1]
       \- On failure: exponential backoff
            (30s -> 60s -> 120s -> 240s -> 480s)

Format Conversion Details

Event Types Handled

Event Type Handler Output
reasoning-delta reasoning += ev.reasoningDelta { type: 'thinking', thinking: reasoning }
text-delta text += ev.textDelta { type: 'text', text }
tool-call Accumulate in toolUses array { type: 'tool_use', id, name, input }
finish-step Map reason to stop_reason 'end_turn' | 'tool_use' | 'error'

Content Block Ordering

Critical: Thinking blocks MUST appear before text blocks.

// Input events
[
  { type: 'reasoning-delta', reasoningDelta: 'thinking...' },
  { type: 'text-delta', textDelta: 'answer' },
  { type: 'finish-step', finishReason: 'stop' }
]

// Output message.content array
[
  { type: 'thinking', thinking: 'thinking...' },  // Block 0
  { type: 'text', text: 'answer' }                 // Block 1
]

Validation Results

[x] All 14 integration checks pass [x] All 4 format conversion test groups pass [x] All 7 server startup tests pass [x] All 10 todo app CRUD tests pass


Files Modified

lib/formats/anthropic.js (lines 29-55)

  • Added reasoning-delta accumulator
  • Added thinking content block creation
  • Ensured thinking blocks precede text blocks
  • Commit: e7d1dff

lib/server.js (line 906-907)

  • sampler.startSampler() initialization
  • Hourly probe interval (3600000ms)
  • Console logging: [sampler] started with ${probeIntervalMs}ms interval

examples/todo-app/ (new)

  • Complete Express.js todo app for integration testing
  • Full CRUD API with error handling
  • Static HTML frontend

Running the Full Validation Suite

# 1. Witness format conversion in action
node .gm/exec-spool/in/nodejs/format-conversion-witness.js

# 2. Check full integration
node .gm/exec-spool/in/nodejs/full-integration-check.js

# 3. Start server and validate
node .gm/exec-spool/in/nodejs/start-server-and-test.js

# 4. Test todo app
node .gm/exec-spool/in/nodejs/test-todo-app.js

# 5. Monitor live (requires running server)
# Terminal 1:
node bin/acptoapi.js

# Terminal 2:
node .gm/exec-spool/in/nodejs/acptoapi-live-monitor.js

Status

[x] Format conversion layer fixed and committed [x] All integration points verified [x] Server initialization verified [x] Sampler probing working [x] Todo app ready for testing [x] Comprehensive validation tools created

The acptoapi server is ready for production use with full Anthropic SDK extended thinking (reasoning-delta) support.