Make boolean column reads and writes work on both storage tiers #62

Merged
weichen merged 2 commits from fix/pg-boolean-columns into main 2026-10-05 05:03:04 +00:00
Owner

Why

Dev 运行时切换 PostgreSQL 档后全部 conversations 接口 500。迁移把 conversations.{pinned,archived,allow_cross_read,cross_private}、users.{must_change_password,is_admin} 在 PG 档建为 BOOLEAN(SQLite 档 INTEGER),store 层用 0/1 字面量、int 扫描与 boolInt() 写入,pgx 下报 42883/42804/bool 编码错误。

改动

  • projects.go:scanConversation/GetConversation 直接扫 bool;ListTasks archived=? 参数化;SetConversationFlags 传 Go bool。
  • auth.go:CreateAccount/SetUserPassword/ClearMustChangePassword 参数化;GetUserAuthState/ListUsersAdmin 直接扫 bool。
  • 双方言通用:pgx 原生 bool;SQLite 走 database/sql 默认转换 0/1。两档均 INTEGER 的列(hitl_cards.resolved 等)不动。

Evidence

  • 红(main 4fd03ee + AGENT_PG_TEST_DSN):TestConversationFlagsAndTaskList / TestAdminAccountsAndSessions FAIL(42804、encode 1 into bool);线上 GET /api/conversations 返回 boolean = integer (42883)。
  • 绿(本分支):./internal/store/ 全量 PG 档 ok;./internal/pgbus/ PG 档 ok;make test-backend SQLite 档全绿;Dev 仓 make test 组合验证通过。
  • 已知先存问题(不属本次):./internal/runmgr/ PG 集成测试在 main 同样失败(gin_trgm_ops 不在 search_path 隔离 schema,42704)。

Impact

两档行为一致;SQLite 档行为不变。Refs: Dev 任务卡 .task/fix-pg-boolean-columns.md

## Why Dev 运行时切换 PostgreSQL 档后全部 conversations 接口 500。迁移把 `conversations.{pinned,archived,allow_cross_read,cross_private}`、`users.{must_change_password,is_admin}` 在 PG 档建为 BOOLEAN(SQLite 档 INTEGER),store 层用 0/1 字面量、int 扫描与 boolInt() 写入,pgx 下报 42883/42804/bool 编码错误。 ## 改动 - projects.go:scanConversation/GetConversation 直接扫 bool;ListTasks `archived=?` 参数化;SetConversationFlags 传 Go bool。 - auth.go:CreateAccount/SetUserPassword/ClearMustChangePassword 参数化;GetUserAuthState/ListUsersAdmin 直接扫 bool。 - 双方言通用:pgx 原生 bool;SQLite 走 database/sql 默认转换 0/1。两档均 INTEGER 的列(hitl_cards.resolved 等)不动。 ## Evidence - 红(main 4fd03ee + AGENT_PG_TEST_DSN):TestConversationFlagsAndTaskList / TestAdminAccountsAndSessions FAIL(42804、encode 1 into bool);线上 GET /api/conversations 返回 boolean = integer (42883)。 - 绿(本分支):`./internal/store/` 全量 PG 档 ok;`./internal/pgbus/` PG 档 ok;`make test-backend` SQLite 档全绿;Dev 仓 `make test` 组合验证通过。 - 已知先存问题(不属本次):`./internal/runmgr/` PG 集成测试在 main 同样失败(gin_trgm_ops 不在 search_path 隔离 schema,42704)。 ## Impact 两档行为一致;SQLite 档行为不变。Refs: Dev 任务卡 .task/fix-pg-boolean-columns.md
weichen added 1 commit 2026-10-04 14:53:16 +00:00
Make boolean column reads and writes work on both storage tiers
ci / vet-and-test (pull_request) Successful in 46s
685bd0d171
Why:
The dev runtime switched to the PostgreSQL tier and every conversation
endpoint started returning 500. Migrations define
conversations.pinned/archived/allow_cross_read/cross_private and
users.must_change_password/is_admin as BOOLEAN on PostgreSQL but
INTEGER on SQLite, while the store layer compared them with 0/1
literals, scanned them into int, and wrote them via boolInt().
Under pgx these fail with 42883 (operator does not exist: boolean =
integer), bool encode errors, or 42804 (column is of type boolean but
expression is of type integer).

Evidence:
- parent-repo main 4fd03ee with AGENT_PG_TEST_DSN:
  TestConversationFlagsAndTaskList and TestAdminAccountsAndSessions
  fail with the errors above; live GET /api/conversations returned
  "operator does not exist: boolean = integer (SQLSTATE 42883)".
- this branch: full ./internal/store suite green on the PostgreSQL
  tier (AGENT_PG_TEST_DSN against a scratch database), pgbus green,
  make test-backend green on the SQLite tier.
- scan into *bool and Go bool parameters are cross-dialect: pgx encodes
  bool natively; database/sql converts bool<->0/1 for SQLite.
- pre-existing and out of scope: ./internal/runmgr PG integration tests
  fail on main too (gin_trgm_ops invisible inside the search_path
  isolation schema, 42704).

Impact:
Conversations list/detail/flags and user auth-state reads/writes now
work identically on both storage tiers; SQLite behavior is unchanged.

Refs: Dev task .task/fix-pg-boolean-columns.md
weichen added 1 commit 2026-10-05 05:02:37 +00:00
# Conflicts:
#	internal/store/auth.go
#	internal/store/projects.go
weichen merged commit 3f438b9e80 into main 2026-10-05 05:03:04 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: weichen/Agent-System-Backend#62