Align the svc.sh startup precheck with binary auth semantics and keep the reused DSN #317

Merged
weichen merged 12 commits from fix/svc-dsn-reuse-dbref into main 2026-10-11 08:55:14 +00:00
Owner

修复 G1-7 引入的 svc.sh 三处缺陷(任务卡:.task/fix-svc-dsn-reuse-dbref.md,本 PR 为任务主记录)。

Why: 2026-10-10 ./scripts/svc.sh update dev 非回环复用启动被预检误拒(当时以 --auth on 应急解锁,记忆 svc-g17-precheck-dsn-bug)。根因:

  1. 预检 agent_args_authed 只看参数串,不认 AGENT_SYSTEM_DSN 环境变量;二进制 AuthEnabled = on‖(非off && DSN非空)(config.go:301,env 为合法 DSN 来源,默认 auto)——「非回环 + auto + env DSN」被误判认证关。
  2. G1-7 后 exec= 不再含 DSN,dbref 兜底只在重建分支:纯 start/restart 复用会静默回落 SQLite,数据库绑定丢失(2026-10-05 事故教训在 reuse 路径回归)。
  3. DSN_ENV 全局且每次启动不重置:update --all 同进程连续启动时前一个服务的 DSN 泄漏进后一个的 AGENT_SYSTEM_DSN(跨服务串库)。

变更(scripts/svc.sh + tests/test_svc_precheck.py):

  • agent_args_authed ARGS [DSN_ENV]:显式 off 优先;否则命令行 --dsn 或环境 DSN 任一非空即认证开,与二进制同口径。
  • 预检判定抽成 agent_listen_rejected EXEC DEFAULT_ADDR INSECURE DSN_ENV(回环/显式放行/认证开均不拦)。
  • 复用分支抽成 agent_reuse_exec EXEC OUT_VAR(nameref 回写;不得在 $() 中调用,DSN_ENV 赋值会留子壳):G1-7 迁移剥离后,DSN_ENV 为空且 dbref= 在案时经 dsn_from_dbref 重建。
  • agent_do_start 内 local DSN_ENV="" 隔离;文件尾 main "$@" 加 source 守卫供测试 source。
  • 新增 tests/test_svc_precheck.py:19 用例(认证矩阵、预检判定、复用迁移/重建/优先级/缺登记、隔离棘轮)。

Evidence: (SELF,任务卡收据)tests/test_svc_precheck.py 19/19;make test-governance 123/123 exit=0;make test 全量 exit=0(HEAD 8d73075,含 worktree/governance/boundaries/pins/libs/core/backend/frontend/ui/agentcmd);事故场景重放:非回环+auto+dbref → 放行且 DSN 随守卫环境传递。GATE 待 CI 在 PR HEAD 运行 make test+make build。

Impact: 仅 svc.sh 预检与复用启动 DSN 处理;不改二进制、不改持久化格式(dbref= 已是既有登记)。

Refs: .task/fix-svc-dsn-reuse-dbref.md;G1-7 变更 a6d434e;modules/backend/internal/config/config.go AuthEnabled。

修复 G1-7 引入的 svc.sh 三处缺陷(任务卡:.task/fix-svc-dsn-reuse-dbref.md,本 PR 为任务主记录)。 Why: 2026-10-10 `./scripts/svc.sh update dev` 非回环复用启动被预检误拒(当时以 `--auth on` 应急解锁,记忆 svc-g17-precheck-dsn-bug)。根因: 1. 预检 `agent_args_authed` 只看参数串,不认 `AGENT_SYSTEM_DSN` 环境变量;二进制 `AuthEnabled = on‖(非off && DSN非空)`(config.go:301,env 为合法 DSN 来源,默认 auto)——「非回环 + auto + env DSN」被误判认证关。 2. G1-7 后 exec= 不再含 DSN,dbref 兜底只在重建分支:纯 start/restart 复用会静默回落 SQLite,数据库绑定丢失(2026-10-05 事故教训在 reuse 路径回归)。 3. `DSN_ENV` 全局且每次启动不重置:`update --all` 同进程连续启动时前一个服务的 DSN 泄漏进后一个的 `AGENT_SYSTEM_DSN`(跨服务串库)。 变更(scripts/svc.sh + tests/test_svc_precheck.py): - `agent_args_authed ARGS [DSN_ENV]`:显式 off 优先;否则命令行 `--dsn` 或环境 DSN 任一非空即认证开,与二进制同口径。 - 预检判定抽成 `agent_listen_rejected EXEC DEFAULT_ADDR INSECURE DSN_ENV`(回环/显式放行/认证开均不拦)。 - 复用分支抽成 `agent_reuse_exec EXEC OUT_VAR`(nameref 回写;不得在 $() 中调用,DSN_ENV 赋值会留子壳):G1-7 迁移剥离后,DSN_ENV 为空且 dbref= 在案时经 `dsn_from_dbref` 重建。 - `agent_do_start` 内 `local DSN_ENV=""` 隔离;文件尾 `main "$@"` 加 source 守卫供测试 source。 - 新增 tests/test_svc_precheck.py:19 用例(认证矩阵、预检判定、复用迁移/重建/优先级/缺登记、隔离棘轮)。 Evidence: (SELF,任务卡收据)tests/test_svc_precheck.py 19/19;make test-governance 123/123 exit=0;make test 全量 exit=0(HEAD 8d73075,含 worktree/governance/boundaries/pins/libs/core/backend/frontend/ui/agentcmd);事故场景重放:非回环+auto+dbref → 放行且 DSN 随守卫环境传递。GATE 待 CI 在 PR HEAD 运行 make test+make build。 Impact: 仅 svc.sh 预检与复用启动 DSN 处理;不改二进制、不改持久化格式(dbref= 已是既有登记)。 Refs: .task/fix-svc-dsn-reuse-dbref.md;G1-7 变更 a6d434e;modules/backend/internal/config/config.go AuthEnabled。
weichen added 6 commits 2026-10-11 02:13:53 +00:00
Why: establish the authorized task workspace and its initial baseline.

Evidence: preserved precheck receipt in .task/fix-svc-dsn-reuse-dbref.md; R0=890b9b2bf2e9b356351d373a21f358ea04ca958b.

Impact: task metadata only; the feature workspace starts at 890b9b2bf2.

Refs: .task/fix-svc-dsn-reuse-dbref.md
Why: Resume the pre-started task with the defect analysis (G1-7 precheck
mismatch, reuse-path DSN loss, DSN_ENV leakage) recorded per delivery policy.
Evidence: make precheck receipt (SELF) imported via make evidence.
Impact: Task card only; no code change yet.
Refs: .task/fix-svc-dsn-reuse-dbref.md
Why: G1-7 moved the DSN into AGENT_SYSTEM_DSN, but the precheck only read
the arg string, so a non-loopback restart with auth auto was wrongly
rejected (2026-10-10 dev incident); the reuse path no longer restored the
dbref-bound DSN and would silently fall back to SQLite; and DSN_ENV leaked
across same-process starts (update --all) into other services' env.
Evidence: tests/test_svc_precheck.py 19 cases green (auth matrix vs
config.go AuthEnabled, reuse migration/dbref restore, scope isolation);
full governance suite 123 green; incident-scenario replay allowed + DSN
carried. Recorded via make evidence.
Impact: scripts/svc.sh precheck and reuse-start DSN handling only; no
binary change, no persistence-format change.
Refs: .task/fix-svc-dsn-reuse-dbref.md; config.go AuthEnabled (on || (not
off && DSN non-empty), env DSN counts).
Why: include the current integration baseline before verification.

Evidence: fetched origin/main=73c901fa341a3653d6e0826d0da3497507995482.

Impact: integrate upstream changes without rewriting task history.

Refs: task-sync
Why: bind the task validation checkpoint to the latest integration baseline.

Evidence: SELF recursive component checks; sync_base=73c901fa341a3653d6e0826d0da3497507995482; candidate=51bce59d282ccb6f33e9cfd61b03ea5f353e18be.

Impact: task metadata only.

Refs: .task/fix-svc-dsn-reuse-dbref.md
Record the test evidence and backfill the self-check results
ci / test (pull_request) Successful in 2m18s
9e1b3c601f
Why: Complete the three-stage evidence (precheck/task-sync/tests) and the
self-check stage row per the evidence and delivery gates.
Evidence: make test exit=0 and make test-governance exit=0 receipts written
by make evidence at HEAD 8d73075.
Impact: Task card only.
Refs: .task/fix-svc-dsn-reuse-dbref.md
weichen added 1 commit 2026-10-11 02:14:06 +00:00
Fill the task record PR link (PR #317)
ci / test (pull_request) Successful in 2m19s
cd05692e80
Why: The card's primary record must point at the real PR per the delivery gate.
Evidence: PR #317 open (API verified).
Impact: Task card only.
Refs: .task/fix-svc-dsn-reuse-dbref.md
weichen added 4 commits 2026-10-11 08:15:05 +00:00
Why: include the current integration baseline before verification.

Evidence: fetched origin/main=95992d751f0a6ea8e345109dbb6b9367d9055e92.

Impact: integrate upstream changes without rewriting task history.

Refs: task-sync
Why: bind the task validation checkpoint to the latest integration baseline.

Evidence: SELF recursive component checks; sync_base=95992d751f0a6ea8e345109dbb6b9367d9055e92; candidate=da5b92c3a168c913e60900b814c27d809eca4e0e.

Impact: task metadata only.

Refs: .task/fix-svc-dsn-reuse-dbref.md
Why: Fold the card close into PR #317 per the post-merge cleanup instruction.
Evidence: make test exit=0 re-run at the synced head 0303040 (receipt in card).
Impact: Task card only.
Refs: .task/fix-svc-dsn-reuse-dbref.md
Close 1 merged task card(s) and archive them
ci / test (pull_request) Successful in 2m17s
ci / test-pg (pull_request) Successful in 1m10s
e734de9c6b
Why: branches merged into main had left their task cards open; backfill status and archive to prevent bookkeeping debt.
Evidence: fix-svc-dsn-reuse-dbref.md(already-complete) — merges verified via git log --merges against origin/main.
Impact: .task/*.md moved to .task/archive/ with status backfilled; no code or submodule change.
Refs: task.sh close (card-autoclose-r1)
weichen added 1 commit 2026-10-11 08:29:15 +00:00
Merge authoritative main into the task branch
ci / test (pull_request) Successful in 2m21s
ci / test-pg (pull_request) Successful in 58s
66962a517c
Why: include the current integration baseline before verification.

Evidence: fetched origin/main=80a518628c526fd6ddece4abeb707ab4bb0b5618.

Impact: integrate upstream changes without rewriting task history.

Refs: task-sync
weichen merged commit b3b48f5efa into main 2026-10-11 08:55:14 +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-Dev#317