fix(server): handle action_input JSONB-string shape + write JSONB objects for new runs#877
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthroughThis PR fixes the runs queue to properly store ChangesAction input JSONB shape fixes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…ects for new runs Live prod bug — third in the Phase 5 chain. Snapshot mode is default, worker correctly POSTs to /worker/transcript/snapshot with the right runId (PR #874), but the gateway's isRunOwnedByJwtScope verifier rejects with 403 on every call because `runs.action_input` is stored as a JSONB **string** (double-encoded), not a JSONB object. The verifier's `->> 'agentId'` returns NULL on a JSONB string, so the scope comparison fails. Root cause traced to runs-queue.ts:309 — `JSON.stringify(data)` was bound to a `$4::jsonb` parameter, which Postgres ingested as a JSONB string scalar. Fixed by passing the object through postgres-js's `sql.json()` helper so the driver sends a proper JSONB object. Two-part fix: - Verifier (transcript-routes.ts): CASE jsonb_typeof to handle both shapes — object rows use direct `->>`, string rows unwrap via `(action_input #>> '{}')::jsonb`. New rows post fix always take the 'object' branch; legacy in-flight string rows authorize correctly during the deploy crossover window. - Dispatch (runs-queue.ts): write JSONB objects directly via sql.json going forward. New chat_message / task rows store proper objects. Tests cover both shapes in the verifier and the new dispatch shape.
368a398 to
4adff11
Compare
Summary
Third bug in the Phase 5 chain. Workers correctly POST snapshots (post PR #874), but the gateway's verifier 403's every one because
runs.action_inputis stored as a JSONB string (double-encoded) —action_input ->> 'agentId'returns NULL.Root cause
runs-queue.ts:309:JSON.stringify(data)bound to a$4::jsonbparameter → Postgres stored the JSONB as a string scalar, not a JSONB object. Every chat_message run since the dawn of time has been wrong-shape.Fix
transcript-routes.ts):CASE jsonb_typeof(action_input)handles both shapes. String rows unwrap via(action_input #>> '{}')::jsonbfirst; object rows use direct->>. Crossover-safe.runs-queue.ts):sql.json(data)replacesJSON.stringifyso postgres-js sends a real JSONB object going forward.Verification
After merge + image roll, Telegram message via
@embeddedlobu2botshould produce a row inagent_transcript_snapshot(currently 0 rows since Phase 5).Test plan
Summary by CodeRabbit
Bug Fixes
Tests