Commit graph

144 commits

Author SHA1 Message Date
3fcdb9b88c
fix(CI): No CD, yet
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 5m11s
CI Go Verification / build_and_test (push) Successful in 1m56s
2026-09-13 22:58:13 +00:00
7a21437120
docs: tidy stale comments in analytics, cache version, and style profile test
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 6m33s
CI/CD Go Verification / build_and_test (push) Successful in 1m32s
2026-09-13 22:24:45 +00:00
d1b7805162
test(server): sort fake store analytics posts ascending
GetAnalyticsPostsInRange now returns posts oldest-first to match the real store
implementation.
2026-09-13 22:24:45 +00:00
e66900dc75
fix(server): abort webhook retry backoff when context is cancelled
Replace time.Sleep with a select on time.After and ctx.Done so webhook retries
stop promptly when the request context is cancelled.
2026-09-13 22:24:45 +00:00
0db85ee650
fix(server): add 5-minute timeout to prewarm profile builds
Bound prewarmOne with a context timeout so a hung backend can't stall the
prewarm scheduler.
2026-09-13 22:24:43 +00:00
c965eb51d3
refactor(server): type CDP private key as crypto.Signer
Store the CDP auth key as a crypto.Signer interface so ECDSA and Ed25519 keys
share one signing path, and detect raw base64 Ed25519 keys inline instead of a
separate helper.
2026-09-13 22:24:43 +00:00
19ae0d781a
fix(server): bound post cache size with earliest-expiry eviction
Cap the post TTL cache at 10000 entries; once full, evict the entry with the
earliest expiry instead of growing without bound.
2026-09-13 22:24:42 +00:00
9825c45350
fix(server): surface and log settlement persistence errors
persistSettlement now returns the write error instead of swallowing it, and
both the HTTP and MCP settlement hooks log failures instead of silently
dropping them. Also remove the dead function_runtime_ms webhook field and a
stale log value.
2026-09-13 22:24:37 +00:00
f4ae7d9c9f
refactor(x402): fold resolver into AddPayableTool and honor per-tool timeouts
Simplify the payable-tool registration API by merging
AddPayableToolWithResolver into AddPayableTool, and thread a configurable
MaxTimeoutSeconds plus Extra through the payment options. getStyleProfile
keeps its 600s advertise timeout.
2026-09-13 22:24:34 +00:00
c96447e3e0
fix(activitypub): harden client, add outbox fallback and throttled GTS warming
Extract ActivityPub outbox walk into internal/activitypub/outbox.go with
webfinger/actor resolution, Create/Note filtering and IRI dereferencing.
Fix searchStatus returning wrong post, nil-account panic in SearchActors,
@local handle resolution, empty Author via noteToInternalPost, protocol-
relative URL handling, pagination loops, limit clamping (200) and cacheErr
masking. Add per-host token-bucket throttle (1/s, cross-host concurrency)
in throttle.go and background GTS warming via search?resolve for outbox-
fetched posts without following remotes. Align AGENTS.md.

Co-Authored-By: internal-model
2026-09-10 09:59:44 +00:00
98a6bed466
fix: eliminate Bluesky session-refresh data race
read/write race on xrpc.Client.Auth: Do() reads client.Auth unlocked while
refreshSession mutated AccessJwt/RefreshJwt in place (only refreshMu serialized
refreshes, not concurrent request readers).

- add authMu RWMutex; every request now uses a clientSnapshot() copy that pins
  the current AuthInfo under the read lock, so requests never touch Auth directly
- refreshSession replaces client.Auth with a fresh immutable AuthInfo under the
  exclusive lock instead of mutating the old one in place
- remove the now-obsolete 'benign race' comment; lock order refreshMu -> authMu
2026-09-10 09:54:56 +00:00
84fbad705d
fix: harden Twitter API client timeout, retries, and authors
- replace http.DefaultClient with a 60s-timeout client and send a
  User-Agent header
- retry 5xx and transport errors with the same ctx-aware backoff used
  for 429s; drop the unreachable trailing return and defer-in-loop body
- resolveUser returns the username; posts carry the handle (was numeric
  ID), error on 200-with-empty-data, and skip empty-ID tweets
- remove the lower limit floor so small limits pass through
- AGENTS.md: refresh the stale twitter clamp/backoff gotcha
2026-09-09 23:18:34 +00:00
67d35a0a2f
fix: harden Ollama client embeddings, truncation, and retries
- embed posts in a bounded worker pool while preserving index order,
  with per-post error context and transient (429/5xx) retry backoff
- SummarizeStyle errors when the stream ends before a done chunk or the
  model truncates at its context limit (done_reason length) instead of
  returning a partial summary for a payable tool
- New() drops the unused ctx param and names its model params; callers
  in main.go updated
2026-09-09 23:18:01 +00:00
4f107da9ee
fix: harden Nostr client relay handling and error propagation
- budget relay queries across a shared 20s deadline (5s per relay) and
  dedupe events by ID across relays
- surface 'could not connect to any relay' when no query succeeded and
  abort early on relay-connect and stream-cancel errors
- guard zero/negative limits across all fetchers
- GetActor falls through relays and rejects empty profile metadata;
  SearchActors propagates relay errors instead of silently returning none
- NewNostrClient validates relay ws://wss:// schemes, trims, and dedupes
2026-09-09 23:17:56 +00:00
f7b3cd886b
fix: harden Bluesky client caching, auth refresh, and limits
- TTL-cache DID/actor lookups (24h) under a dedicated mutex, with a
  separate refresh lock so auth refreshes never fight the cache
- clamp zero/excessive limits (maxBskyFeedLimit, maxAuthorFeedPages)
  and stop timeline pagination early once a bound or applimit is hit
- restrict feed URIs to http(s) and validate AT-URIs in GetPost
- derive the profile URL from the handle instead of the raw URI
2026-09-09 23:17:51 +00:00
4df3967cab
fix: harden ActivityPub client pagination and response bounds
- paginate GetLatestNPosts up to the requested limit (40/page, the
  Mastodon API cap) instead of relying on silent server clamping
- cap GetPostsInTimeframe at maxTimeframePages to stop runaway paging
- bound response bodies with a 1 MB LimitReader
- short-circuit on a canceled ctx between pages and guard limit <= 0
2026-09-09 23:17:43 +00:00
2fd4a4ec90
refactor: finish activitypub post migration from Text to Content
Drop the redundant Post.Text/internalPost.Text fields and complete the
rename in server converters and test fixtures so the tree builds again.

- types.go: remove Text from Post and internalPost; toPost only writes
  Author when the account acct is present
- posts_convert.go: apPostsPtrToItems / apPostsToAnalyticsItems read Content
- server tests: drop duplicate Text literal fields (values identical to Content)
2026-09-09 23:17:35 +00:00
b27108467e
fix: harden main entrypoint — graceful shutdown, context handling, readyz binding
- Add Server.Shutdown() method delegating to X402Server
- Wire main-server graceful shutdown with 15s bounded timeout
- Derive long-lived clients (bluesky, ollama) from backgroundCtx instead of
  signal context to prevent poisoned sessions on SIGTERM during startup
- Remove empty errgroup goroutine that only logged on cancellation
- Bind readyz sidecar to configurable READYZ_ADDRESS (default 127.0.0.1)
  instead of 0.0.0.0
- Validate port strings (ReadyzPort, MetricsPort, ListenPort) at config load
- Fix ready-check Ollama probe: use defer for body drain, guard nil resp
2026-09-09 15:07:27 +00:00
1640fae6be
fix: surface relay-connect and stream-cancel errors
- nostr GetPost: track whether any relay was reached so an unreachable
  relay set surfaces 'could not connect to any relay' (consistent with
  GetLatestNPosts/GetPostsInTimeframe) instead of a misleading
  'post not found'.
- ollama SummarizeStyle: surface ctx cancellation after Generate when
  the Ollama stream reader closes cleanly on a canceled context,
  instead of returning a truncated summary.
2026-09-09 14:42:10 +00:00
e68e02bf20
feat: data-driven upto scheme registration for twitter-enabled tools
Extend x402 actual-cost settlement beyond getStyleProfile to every
Twitter-capable tool (findSimilarUsers, getEngagementMetrics,
getPostingPatterns, getTopicModeling, getSentimentTrends,
getEngagementDrivers). Each carries a twitterPostCount (or source
platform + post count) in its response so settlement passes on the
realized Twitter API lookup and per-post costs.

- tools: payableDef uses UsesTwitter + TwitterPostCap instead of a
  fixed Scheme; registerTools advertises upto at the cap-derived
  maximum when Twitter is enabled, otherwise exact at the flat base
  price.
- x402: export pricing constants and MaxTwitterCostMicro /
  FormatPriceMicro / MicroFromPriceString helpers; add
  AddPayableToolWithResolver and a per-tool settleResolvers map used
  by both the MCP wrapper and REST override; buildSchemeConfigs
  registers only the schemes declared in a tool's requirements.
- analytics: default aggregates include Twitter only when enabled;
  result count recorded before caching and returned as twitterPostCount.
- server/twitterEnabled gates the upto switch (config bearer token).
2026-09-09 13:27:17 +00:00
9a45dbc2c6
refactor: complete pointer-ify in remaining test fakes and analytics converter 2026-09-08 01:44:36 +00:00
1e32bb752f
chore: remove dead post-pruner goroutine and rescueFunds.py script 2026-09-08 01:35:55 +00:00
8c561a83a2
chore: idempotent migrations (IF NOT EXISTS) + systemd binary name fix 2026-09-08 01:31:50 +00:00
debd49d6f6
chore: quiet errcheck/staticcheck across server, platform, and test clients 2026-09-08 01:29:28 +00:00
5cd1d128d6
test: expand Ollama client tests and store integration coverage 2026-09-08 01:25:44 +00:00
22b92cb6cd
fix: skip empty embeddings/text posts; 1-month profile refresh window 2026-09-08 01:23:08 +00:00
7aee2fe88c
feat: x402 actual-cost settlement for getStyleProfile + custom MCP wrapper 2026-09-08 01:15:31 +00:00
3b443eff36
refactor: harden HTTP clients with timeouts, per-relay ctx, rate-limit handling 2026-09-08 01:11:13 +00:00
ee2829b818
refactor: pointer-ify profile/post slices across backends, converters, and tests 2026-09-08 01:08:28 +00:00
d06ade2172
chore: switch golangci-lint config to v2 format 2026-09-08 00:32:29 +00:00
a5a4ccd972
chore: bump nacorid/logger and promote x/sync to direct dep 2026-09-08 00:31:59 +00:00
76d337f54c
fix: bump MaxTimeoutSeconds for upto scheme
All checks were successful
Test Every Endpoint on Base Sepolia / test_endpoints (push) Successful in 6m39s
CI/CD Go Verification / build_and_test (push) Successful in 1m18s
2026-09-06 22:44:59 +00:00
9c26886957
Self-heal MCP facilitator init so no restart is needed
Some checks failed
CI/CD Go Verification / build_and_test (push) Successful in 1m18s
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 5m43s
The MCP PaymentWrapper verifies against the low-level x402 resource server,
whose facilitatorClients map is only populated by Initialize(), which was
never called - paid MCP calls failed with no_facilitator_for_network once
the amount fix let clients reach server-side verification. INITIALIZE the
resource server at construction (best-effort, warn-only) and retry on every
inbound request via receiving middleware until it succeeds once. 10s bounded
timeout per attempt; after first success the map persists for the process
lifetime so later facilitator outages self-heal without a restart.
2026-09-06 21:32:39 +00:00
9059be5027
Convert MCP Accepts prices to smallest units in AddPayableTool
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 1m31s
CI/CD Go Verification / build_and_test (push) Successful in 1m18s
MCP clients failed to create payments with invalid_exact_evm_client_amount:
0.01 because the PaymentWrapper advertised raw dollar prices as amounts,
while REST re-runs prices through BuildPaymentRequirementsFromOptions.
Mirror that conversion for the MCP Accepts at registration time; keep the
REST PaymentOption with the raw price to avoid double conversion.
2026-09-06 21:12:05 +00:00
4798fa6732
Debug: Add settlement tracing and register only upto for getStyleProfile
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 1m29s
CI/CD Go Verification / build_and_test (push) Successful in 1m16s
- Register only upto scheme for getStyleProfile (variable pricing)
- Add debug logging to settlement handler (scheme, override amount)
- Add debug logging to error handler (settlement overrides header)
- Add debug logging to verifyErrorCapture (payment signature, overrides)
- Add debug logging to handleRESTCall (actual cost override)

This will help trace why the facilitator returns 'invalid_exact_evm_payload_authorization_value'
when upto scheme is configured for getStyleProfile
2026-09-06 18:46:20 +00:00
2c8f09fdbf
Split test clients into REST and MCP, add MCP endpoint tests
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 1m32s
CI/CD Go Verification / build_and_test (push) Successful in 1m14s
Rename testClient/main.go into testClient/rest/test-rest-endpoints.go and add
testClient/mcp/test-mcp-endpoints.go which tests the /mcp Streamable HTTP
endpoint via an x402-aware MCP client. Update the test-endpoints workflow to
run the MCP tests first, and decode/print the 402 challenge when a paid REST
retry is rejected.
2026-09-06 18:27:09 +00:00
78ec4af4ee
Use upto scheme for getStyleProfile variable pricing
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 5m31s
CI/CD Go Verification / build_and_test (push) Successful in 1m15s
- Added Scheme field to payableDef struct in tools.go
- getStyleProfile now uses 'upto' scheme (variable pricing: base + per-post)
- Modified buildRequirements in settlement.go to accept scheme parameter
- Default scheme is 'exact' for backwards compatibility
- getStyleProfile uses 'upto' scheme to match its variable pricing model
  (base /bin/bash.10 + /bin/bash.01 user lookup + /bin/bash.005 per post)
- This fixes 'invalid_exact_evm_payload_authorization_value' error from facilitator
  which expected upto scheme for variable pricing
2026-09-05 10:27:19 +00:00
6e0a57063c
Increase all timeouts to 600s for CPU-only Ollama
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 5m31s
CI/CD Go Verification / build_and_test (push) Successful in 1m15s
- internal/x402/x402.go: x402 middleware timeout 240s -> 600s; facilitator client timeout 30s default -> 600s
- testClient/main.go: test client HTTP timeout 240s -> 600s
- cmd/server/main.go: Ollama HTTP client timeout 120s -> 600s

All timeouts increased to 10 minutes to accommodate CPU-only Ollama inference.
Calls return as soon as possible; timeouts only act as safety net.
2026-09-05 08:52:06 +00:00
6c75d869b2
Increase timeouts to 240s for settlement and test client
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 4m5s
CI/CD Go Verification / build_and_test (push) Successful in 1m14s
- internal/x402/x402.go: x402 middleware Timeout 120s -> 240s
  (covers payment verification + handler execution + settlement)
- testClient/main.go: test client HTTP timeout 180s -> 240s
  (matches server-side timeout for end-to-end payment + handler + settlement)

Provides adequate buffer for slow facilitator /settle responses during
getStyleProfile and findSimilarUsers tool execution.
2026-09-05 02:42:55 +00:00
9e12c6cac8
Align schemaExtra input fields with actual request structs
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 4m3s
CI/CD Go Verification / build_and_test (push) Successful in 1m13s
- Changed 'actor' to 'author' in schemaExtra input BodyFields for:
  - getPost
  - getLatestPosts
  - getPostsInTime
  - getStyleProfile
  - findSimilarUsers
- These now match the actual request struct field names (Author)
- Output BodyFields remain unchanged (still use 'actor' for response)
2026-09-05 02:09:00 +00:00
79e2a2348c
Fix getPost test client field name: actor -> author
- testClient/main.go:139: Changed JSON field from 'actor' to 'author' to match GetPostRequest schema
- The handler expects 'author' field, test client was sending 'actor' causing validation error
2026-09-05 01:59:29 +00:00
9609f68b6c
Increase test client timeout to 180s for slow Ollama embeddings
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 3m56s
CI/CD Go Verification / build_and_test (push) Successful in 1m12s
- testClient/main.go:120: Timeout 60s -> 180s to accommodate
  server-side Ollama embedding generation (~60s) after payment retry
- Matches server-side 120s x402 middleware timeout + 120s Ollama HTTP client timeout
- Allows getStyleProfile and findSimilarUsers to complete after payment
2026-09-05 01:43:01 +00:00
f1a2a2c827
Increase timeout for Ollama embedding generation
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 3m43s
CI/CD Go Verification / build_and_test (push) Successful in 1m14s
- internal/x402/x402.go: Added 120s timeout to nethttp.Config for payment middleware
  (was defaulting to 30s, which was too short for Ollama embeddings)
- cmd/server/main.go: Created custom HTTP client with 120s timeout for Ollama client
- Both changes ensure slow tools (getStyleProfile, findSimilarUsers) complete without timeout
2026-09-05 01:23:38 +00:00
57a9c43890
fix: interface{} -> any, +goose up -> +goose up
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 3m52s
CI/CD Go Verification / build_and_test (push) Successful in 1m21s
2026-09-05 01:01:07 +00:00
fe22a9779f
Add comprehensive debugging for CDP auth 401 issue
Some checks failed
CI/CD Go Verification / build_and_test (push) Successful in 1m11s
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 1m40s
- Workflow: Debug CDP Secret Format step prints secret characteristics (length, newlines, first/last chars)
- check-facilitator: Added extensive debug logging:
  - Key name, secret length, first 80 chars
  - Literal vs actual newline detection
  - PEM block parsing (SEC1 vs PKCS8 detection)
  - Signing method used
  - JWT claims decoded from generated tokens
  - Full request/response logging
- auth.go: Added GetSigningMethod() for debugging
- All tests pass, gofmt/go vet clean
2026-09-05 00:25:59 +00:00
f0b1e7a777
Fix YAML indentation for X402_FACILITATOR_URL in facilitator check step
Some checks failed
CI/CD Go Verification / build_and_test (push) Successful in 1m9s
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 1m19s
2026-09-04 23:44:01 +00:00
60d18beda2
Switch CI and defaults back to CDP facilitator (auth fixed)
Some checks failed
test-endpoints.yaml / Switch CI and defaults back to CDP facilitator (auth fixed) (push) Failing after 0s
CI/CD Go Verification / build_and_test (push) Successful in 1m10s
- test-endpoints.yaml: X402_FACILITATOR_URL -> https://api.cdp.coinbase.com/platform/v2/x402 (2 locations)
- start-test-server.sh: X402_FACILITATOR_URL -> https://api.cdp.coinbase.com/platform/v2/x402
- config.go default: https://api.cdp.coinbase.com/platform/v2/x402
- x402.go fallback: https://api.cdp.coinbase.com/platform/v2/x402
- CDP auth now matches official SDK (fixes 401 Unauthorized)
2026-09-04 23:42:22 +00:00
3287e15ac0
Fix CDP auth to match official SDK implementation
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 1m31s
CI/CD Go Verification / build_and_test (push) Successful in 1m10s
- Proper key type detection: Ed25519 (base64, 64 bytes) vs EC (PEM)
- Fixed PKCS8 fallback - removed incorrect PKCS8->EdDSA path for EC keys
- Added 'iat' claim to match official SDK
- Added base64 import for Ed25519 key decoding
- Return proper errors instead of ignoring them in GetAuthHeaders
- Added unit tests for EC/Ed25519 keys, token generation, and auth headers
2026-09-04 23:37:00 +00:00
8e55922baf
Fix YAML indentation for X402_FACILITATOR_URL
Some checks failed
Test Every Endpoint on Base Sepolia / test_endpoints (push) Failing after 1m30s
CI/CD Go Verification / build_and_test (push) Successful in 1m8s
2026-09-04 23:07:55 +00:00
bf7a91ca89
Switch CI to PayAI facilitator (supports exact + upto)
Some checks failed
test-endpoints.yaml / Switch CI to PayAI facilitator (supports exact + upto) (push) Failing after 0s
CI/CD Go Verification / build_and_test (push) Has been cancelled
- PayAI facilitator supports both exact and upto schemes on Base Sepolia
- Workflow and start-test-server.sh: X402_FACILITATOR_URL -> https://facilitator.payai.network
- check-facilitator: handles payai.network as no-auth facilitator like Mogami
2026-09-04 23:06:42 +00:00