Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
08. OKX marketplace chat bot: get it off the codespace
Read 00-INDEX.md first.
Commit gate. Content here references a marketplace outside the
$THREEecosystem. Get owner approval before committing anything that names it.
What is wrong
Chat for the marketplace listing (agent #2632, "three.ws 3D Studio") is delivered
by a local okx-a2a daemon plus a wallet session, both outside this repo. It
goes offline on its own: a codespace rebuild wipes the CLIs and an idle nap kills
the daemon (observed alive at 21:09, stale pid by 03:13). The marketplace's own
tests then report "timeout, no delivery in 30 min", which is what got the listing
flagged offline once already.
State on 2026-09-09, measured. The durable host exists and this order is mostly done.
Cloud Run service okx-chat-bot, revision okx-chat-bot-00001-926, booted
2026-09-05T00:33Z and beating every 30s with loggedIn: true, activeClients: 1,
daemonRestarts: 0. What is left is one reply lane: the AI provider refuses this
project's credential (Lightning dunning decision is deny, a GCP billing hold), so chat
arrives and no reply is authored. Both remaining steps are the owner's, and they are listed
at the bottom of this file.
Do NOT start a local daemon (read this before running anything)
The codespace stopgap is retired and must stay stopped. The bot's identity, the
onchainos wallet keyring plus the XMTP client database, is a single state object with
exactly one writer, which is what --max-instances=1 protects on Cloud Run. Starting a
second daemon anywhere puts a second writer on it, and a torn identity costs a human email
OTP to recover.
An earlier version of this file opened with "Immediate revive (do this first)" and
npm run okx:bot. Following it on 2026-09-09 started exactly that rival daemon. The
command now refuses while any other host is beating (exit 3, --force to override), so the
trap is closed mechanically as well as here, but the rule stands: run nothing local while
the deployed host is up.
Read the deployed host's state instead. This read needs no gcloud and no credential:
curl -s https://three.ws/api/healthz | jq '.subsystems.subsystems[]|select(.name=="okx_chat_bot")'
The durable fix
A codespace cannot stay up on its own, so the real deliverable is an always-on host. Build it:
Containerize the daemon and its session state. The daemon spawns the AI CLI in
~/.okx-agent-task/workspace, and that directory'sCLAUDE.mdand.claude/skillsare the only context chat answers have. It is empty by default, which means a naive host ships an agent that knows nothing about three.ws. Bake real context in.Do not replace the adapter with a one-shot responder. The adapter does not read a reply out of the CLI's stdout; the AI subsession sends the reply itself via the
okx-a2aCLI. A simple LLM responder would break the task lifecycle, not just chat. Custom hosts are supported throughOKX_A2A_AI_<PROVIDER>_COMMANDand..._EXEC_ARGS_JSON, but whatever runs there must be genuinely agentic.Deploy to Cloud Run in
aerial-vehicle-466722-p5, pinning thethree-ws-build@build service account and thethree-ws@runtime service account (the default compute SA was deleted). Config-only env updates are pre-approved; the deploy itself is owner-gated, so prepare it to one command.Add a liveness signal. The listing goes offline silently today. Expose a health endpoint and wire it into the same monitoring that watches the rest of the fleet, so "the bot is logged out" becomes an alert instead of a discovery.
Session renewal. The wallet session expires and needs a human OTP. Make the host detect an expired session and emit an actionable alert naming the exact command, rather than failing chat silently.
State on 2026-09-29, re-measured: deployed, online, ok; only a real inbound message is left
Full measurements: okx-ai-PROGRESS.md, entry 2026-09-29.
- Owner step 2 is done.
npm run okx:bot:deployexit 0 after one fix it needed: onchainos releases from v4.6.0 on ship noinstall.sh/installer-checksums.txt, so the Dockerfile now installs the checksummed release binary (0b1335882). Lane provisioned (metering agent55479fa8-13c6-44b3-a245-3156f2c836e5, key inokx-chat-bot-llm-gateway-token), Cloud Buildea753445SUCCESS, revisionokx-chat-bot-00002-s4s. - Lease handoff clean. The new instance waited on the pre-lease
00001-926until its beat was 90 s quiet, the old one snapshotted on SIGTERM and exited, the new one acquired the lease at 06:42:43Z, restored that exact snapshot (7,121,505 bytes), electedanthropic-gatewayoververtex=unauthorized, and wentonlineat 06:42:58Z withloggedIn: trueand no OTP. - Owner step 3 is done.
/api/healthzokx_chat_botisokonokx-chat-bot-00002-s4s; the beat carriesproviderLane: anthropic-gatewayandleaseHolder;npm run okx:bot:gateway -- --verify --cliexit 0 (claude -pthrough the lane, 2 turns, tool call, 6.9 s)./readyzis not readable from this workspace's gcloud identity (401 on the token audience); the beat reportsready: truefrom the same verdict. - What remains: DoD lines 1 and 3 need a real buyer message answered on the host. No inbound has
arrived since 2026-09-03 (daemon offline replay
newest=2026-09-03T10:28:06Z). Inbound chat is job-scoped and must come from a counterparty agent in a different OKX account (an agent on[email protected]would be a second writer on #2632's identity). Owner-held sources: OKX's own chat test when 911 resubmits, or a buyer agent on a second account opening a task naming #2632. When one lands, readgcloud logging read 'resource.labels.service_name="okx-chat-bot" jsonPayload.line:"ai-dispatch"' --freshness=1hand confirm the reply, then retire this order.
State on 2026-09-25, re-measured: gcloud is back, the deploy is one approval away
- Bot host: unchanged.
/api/healthzstill reportsokx_chat_botdegradedoncloudrun:okx-chat-bot (okx-chat-bot-00001-926), same Vertex403 Lightning dunning decision is deny. Live API stillc8f10f437(three-ws-api-00458-njs). - Owner step 0 is done.
gcloudis installed and authenticated (projectaerial-vehicle-466722-p5);npm run okx:bot:deploy -- --dry-runpasses step [1]. - Fresh-clone fix. This workspace has no
.env.local, so step [3] died onDATABASE_URL is not set.scripts/okx-bot-llm-gateway.mjsnow falls back to the API service'sDATABASE_URL(requireServiceEnvValue, the same pathrug-signature.mjsuses). Measured after the change, with no local env: step [3] reads production and reports service account, metering agent, key and secret allmissing, which is exactly what--applycreates. Steps [1] and [4] green. - Why the bot is not deployed yet: the real run refuses while
scripts/okx-bot-llm-gateway.mjshas uncommitted edits, and committing a file that names the marketplace needs owner approval (commit gate). Owner: approve the commit of that file plus this order, then runnpm run okx:bot:deploy, then step 3 below.
State on 2026-09-24, re-measured: the API half has shipped, only the bot deploy is left
- API deploy: DONE. Live API
c8f10f437(three-ws-api-00458-njs) contains53687d994,d3074c1c8andf7f7da9b6. The agent-scoped path is served: a POST to/api/llm/anthropic/agents/<unknown id>/v1/messagesanswers404 agent not found, where it answeredNo API route matcheson 2026-09-18. Owner action 1 below is complete. - Bot host: unchanged revision, still beating.
bot_heartbeatrowokx-chat-botwas 20 s old at 06:33 UTC,host cloudrun:okx-chat-bot (okx-chat-bot-00001-926),loggedIn: true,activeClients: 1,agentCount: 1,daemonRestarts: 0, instancebootAt2026-09-22T13:44Z. NoproviderLane/leaseHolderin the beat, so it is still the pre-lane, pre-lease code, pinned to Vertex, which still answers403 Lightning dunning decision is deny./api/healthzreportsokx_chat_botdegradedfor exactly that reason. npm run okx:bot:deploy -- --dry-runreaches step [4] green ("live API c8f10f437 contains d3074c1c8") and stops at steps [1] and [3] because this workspace has nogcloudbinary at all (spawn gcloud ENOENT), not just an expired login. The metering service account[email protected]does not exist yet, as expected:--applycreates it.- What remains is owner step 2 below, preceded by installing and authenticating
gcloud.
State on 2026-09-18, and the one command left
The payment-free reply lane is built and proven, the rollout overlap is closed, and the deploy is one command. Full measurements: okx-ai-PROGRESS.md, entry 2026-09-18.
- Reply lane. The bot's
anthropic-gatewaylane now points at three.ws's own proxy at the agent-scoped base URLhttps://three.ws/api/llm/anthropic/agents/<agent>(the path theclaudeCLI builds by appending/v1/messages), modelnvidia/nemotron-3-super-120b-a12b, on the free chain. The proxy changes that make the CLI's default request acceptable (53687d994,d3074c1c8, plusf7f7da9b6) are committed and not live yet: live API4291900c7. Proven on production: the bot's probe body answers200on the free NVIDIA rung, and the realclaude -pagentic request made a Bash tool call and answered through the live proxy (via a shim applying exactly those server-side adaptations, until the API deploy lands). - Metering. A dedicated service account
[email protected]owning one unpublished agent, with a key minted straight into Secret Manager (okx-chat-bot-llm-gateway-token). Never someone else's agent, and a leaked key is worth one agent's AI budget.npm run okx:bot:gatewayprovisions and proves it; not run yet (Secret Manager writes are the owner's). - Single writer.
max-instancesis per revision, so a rollout overlapped two daemons on one identity. workers/okx-chat-bot/lease.js sequences it: the new instance waits for the old one's final snapshot and lease release (or, for the pre-lease00001-926, for its heartbeat to go 90 s quiet) before restoring and starting its daemon.
Owner actions, in order (either deploy may go first)
# 0. As of 2026-09-24 this workspace has no gcloud binary at all (install the Google Cloud CLI
# first), and any earlier login is gone with it.
gcloud auth login && gcloud auth application-default login
# 1. DONE by 2026-09-24 (live API c8f10f437 serves the agent-scoped path). Kept for the record:
# approve and commit the gated files, then ship the API:
npm run clean:worktrees -- --apply
npm run prep:worktree -- --apply
(cd /workspaces/.deploy-wt && npm run deploy:gcp:full)
git worktree remove --force /workspaces/.deploy-wt
# 2. Ship the bot: provisions the gateway lane (agent, key, secret, IAM), builds a clean
# worktree of HEAD, submits cloudbuild.yaml, and waits for the new revision to take the lease.
npm run okx:bot:deploy # preview first with: npm run okx:bot:deploy -- --dry-run
# 3. Verify.
npm run okx:bot:gateway -- --verify --cli
curl -s https://three.ws/api/healthz | jq '.subsystems.subsystems[]|select(.name=="okx_chat_bot")'
Clearing the GCP billing hold is no longer required for replies, but it is still worth doing: Vertex leads the chain, so the next election moves the bot back to Claude on Vertex by itself.
Definition of done
- Chat delivery verified end to end with a real inbound message. Both deploys
have landed (2026-09-29:
okx-chat-bot-00002-s4s,online, laneanthropic-gateway,activeClients: 1, healthzok) and the realclaudeCLI answers through the lane on production. Still missing: an actual buyer message and the host's reply to it (owner-held, see the 2026-09-29 state section). The original wording of this line, "npm run okx:botexits 0", is retired: that command is the codespace stopgap and must not run while the deployed host is up. - The daemon runs on an always-on host, not this codespace. Cloud Run
okx-chat-bot-00001-926, 4.8 days of continuous 30s beats. - Its workspace carries real three.ws context. The mechanical half is done and
tested:
buildChatBriefing()renders 10,069 bytes from the live catalog module and is rebuilt on every boot. On 2026-09-29 the real CLI, in a workspace staged by the bot's ownbuildWorkspace()and run through the production lane, answered a buyer question with the exact listed prices and endpoints. That was off-host; the same answer from the deployed host needs the inbound message in line 1. - A health endpoint exists and an offline session raises an alert.
/readyzis strict,/api/healthzcarries theokx_chat_botsubsystem (now naming itshostandhostDurableas fields), andsendOpsAlertfires on every transition into a bad state. - ../okx-ai/PROGRESS.md updated with the host details.
Retire this prompt when it is done (required)
Verify every Definition of done line against actual command output in front of you. Never claim a line you did not verify.
Record the outcome in this campaign's PROGRESS or INDEX file if it has one.
Commit with explicit paths and a subject that describes the diff (house style: type(scope): what changed and why a reader cares), and delete this prompt file in that same commit:
git rm prompts/finish/907-backlog-08-okx-chat-bot-always-on.mdA finished order left on disk reads as open work to the next agent, so the shrinking directory is the campaign's progress ledger.
If a line genuinely cannot pass inside this session (an external party must respond, or an owner-gated action is the final step), finish everything else, leave this file in place, and state exactly which line remains and who owns it. Never delete this file on a partial.