Skip to content

fix(ai-path): connect() onProgress no longer fires 'log' duplicates#32

Open
Sentinel-Bluebuilder wants to merge 1 commit into
masterfrom
ai-path/connect-double-log-fix
Open

fix(ai-path): connect() onProgress no longer fires 'log' duplicates#32
Sentinel-Bluebuilder wants to merge 1 commit into
masterfrom
ai-path/connect-double-log-fix

Conversation

@Sentinel-Bluebuilder
Copy link
Copy Markdown
Owner

Summary

connect({ onProgress }) used to fire both the structured stage event AND a sibling 'log' event for the same line, forcing every consumer to filter stage === 'log' to avoid triple-printing. This PR fixes the contract so onProgress only fires for documented stages.

  • ai-path/connect.js: raw SDK logs now route to a new opts.onLog callback. They are NOT forwarded to opts.onProgress. JSDoc updated to make both callbacks explicit and to list the exact stages onProgress emits.
  • ai-path/README.md: options table updated — onProgress, onLog, and silent: true documented separately.
  • ai-path/FAILURES.md: API-CONTRACT entry added with migration note.

Why

From the x402 fresh-test/connect-from-live-docs.mjs consumer harness: every progress line printed three times. Tracing into ai-path/connect.js:509-511 showed the log: callback fanned out to opts.onProgress('log', msg) on top of the structured stage emit. Consumer had to add:

onProgress: (stage, msg) => { if (stage === 'log') return; ... },
silent: true,

…to make output usable. The documented contract was "one event per stage transition" — this fixes the implementation to match.

Consumer-app context

The friction was discovered while building x402's agent E2E test harness. The harness drives the full connect flow from the live published llms.txt docs. With the duplicated events, every progress line printed three times (raw SDK log + duplicated 'log' event + structured stage event). After consumer-side filtering the output became correct — but only because both ends knew the quirk. After this fix, the consumer just sets silent: true and reads onProgress cleanly.

Backward compatibility

  • Consumers that already filtered stage === 'log' continue to work — they just never hit that branch anymore.
  • Consumers that did NOT filter — and relied on the raw log spam — should switch to onLog. The behavior change is "fewer events," never "missing events."
  • No public-API rename, no signature change to connect() beyond a new optional onLog field.

Test plan

  • js-sdk lint/build clean (no test suite changes touched).
  • x402 fresh-test harness (fresh-test/connect-from-live-docs.mjs) — once linked locally to this branch, output shows one event per stage with no 'log' siblings.
  • After merge + npm publish: re-run the same x402 harness against the published blue-js-sdk@next and confirm clean output without consumer-side stage === 'log' filtering.

Previously connect({ onProgress }) received both the structured stage
events (wallet, node-check, validate, session, handshake, tunnel, verify)
AND a sibling 'log' event for the same line, fired from the SDK's internal
raw log forwarder. Consumers had to filter `stage === 'log'` to avoid
triple-printing every line.

The forwarder now routes raw logs to a separate `onLog` callback. The
documented contract for `onProgress` — "one event per stage transition" —
is now what consumers actually observe.

- ai-path/connect.js: split raw `log:` forwarder; route to opts.onLog,
  do NOT forward to opts.onProgress. JSDoc updated.
- ai-path/README.md: options table now lists onProgress + onLog
  separately and documents `silent: true` for suppressing the SDK's
  built-in step output.
- ai-path/FAILURES.md: documented the API-CONTRACT change under
  Pending Integration with a migration note.

Consumer-app context: the x402 fresh-test agent harness saw triple-logged
progress lines on every connect(). After filtering 'log' on the consumer
side the output became correct — but only because both sides knew the
quirk. This fixes the SDK so the documented contract is the actual
contract.

No breaking change for consumers that ignore 'log' or set silent: true.
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