Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions .trellis/spec/flowscope-cli/backend/audit-api-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,23 @@ unsupported or unclassified types display `—` in the page.
| Meaningful statements exist | Classify using `AnalyzeResult.sql_type` and `insert_type` |
| Only SET/USE/RESET, or no analyzed statements | `sql_type=null` |
| INSERT variant missing | Retain generic `INSERT`; display `—` rather than guess |
| Legacy row with complete saved classification | Normalize its stored type at audit startup |
| Legacy row with complete saved classification | Normalize its stored type in resumable background batches after binding the listener |
| Missing, malformed, or truncated saved JSON | Leave the legacy type unchanged; unsupported page Type is `—` |
| Audit database opened repeatedly | Normalization is idempotent and only updates changed labels |
| Audit database opened repeatedly | Resume the persisted cursor; completed backfills do not scan JSON again |

Startup only initializes the schema and captures the legacy upper ID through the
primary-key index. Never run JSON extraction or a historical UPDATE before the
listener is bound: production audit JSON can be hundreds of gigabytes, and even
unchanged SELECT rows otherwise get parsed on every restart. A small fixture
proves classification correctness, not acceptable production startup latency.

The audit SQL-type worker reads at most 32 rows by primary key per batch on a
separate connection. It releases the read statement before parsing only the
saved classification fields, then commits changed labels and the resume cursor
together. No audit-writer mutex is held. Lock contention retries without advancing
the cursor; shutdown stops between batches. Rows beyond the initial upper ID use
the current writer classification. Missing, invalid or truncated metadata keeps
its old label. Progress is logged while the HTTP service remains available.

#### 5. Good / Base / Bad Cases

Expand All @@ -211,9 +225,14 @@ unsupported or unclassified types display `—` in the page.
- `audit_query_filter_by_sql_type`: actual analyze/write/list calls cover SELECT,
INTO, and OVERWRITE, each with and without WITH; subtype filters return two
records each, aggregate INSERT returns four, and WITH returns none.
- `startup_normalizes_legacy_sql_types_without_guessing_missing_metadata`:
reopen twice, verify corrected labels, preserve incomplete/invalid metadata,
and verify subtype filtering after correction.
- `startup_defers_sql_type_backfill_and_preserves_missing_metadata`: startup
leaves historical values untouched, explicit batches correct valid metadata,
and reopen/completion do not redo work; subtype filters use corrected labels.
- `sql_type_backfill_is_bounded_resumable_and_cancellable` and
`sql_type_backfill_retries_without_advancing_after_write_contention`: verify
the 32-row bound, persisted cursor, fixed upper ID, cancellation and atomic
retry behavior. Native serve checks must use a substantial large-JSON fixture,
verify health and new audit writes during backfill, and verify restart resume.
- `AuditPage SQL types`: render `ii`, `io`, and `select`; unsupported legacy
values render `—`.

Expand Down
5 changes: 3 additions & 2 deletions .trellis/workspace/wangliang/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<!-- @@@auto:current-status -->
- **Active File**: `journal-1.md`
- **Total Sessions**: 17
- **Total Sessions**: 18
- **Last Active**: 2026-11-26
<!-- @@@/auto:current-status -->

Expand All @@ -19,7 +19,7 @@
<!-- @@@auto:active-documents -->
| File | Lines | Status |
|------|-------|--------|
| `journal-1.md` | ~586 | Active |
| `journal-1.md` | ~619 | Active |
<!-- @@@/auto:active-documents -->

---
Expand All @@ -29,6 +29,7 @@
<!-- @@@auto:session-history -->
| # | Date | Title | Commits | Branch |
|---|------|-------|---------|--------|
| 18 | 2026-11-26 | 修复历史审计类型校正阻塞启动 | `577e0295` | `codex/fix-audit-startup-blocking` |
| 17 | 2026-11-26 | 汇总全部本地分支并验证审计功能 | `fde842be`, `41af81ee` | `codex/fix-audit-table-flicker` |
| 16 | 2026-11-26 | 审计入图状态展示具体原因 | `391384d4` | `codex/audit-status-reasons` |
| 15 | 2026-11-26 | 审计页增加入图状态筛选 | `fc5ab52e4bd3ae41152cc7c9233c7b65b74681c8` | `codex/audit-ingestion-filter` |
Expand Down
33 changes: 33 additions & 0 deletions .trellis/workspace/wangliang/journal-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -584,3 +584,36 @@ Token 管理显示实际凭据,管理员可在刷新和重启后再次读取
### Next Steps

- None - task complete


## Session 18: 修复历史审计类型校正阻塞启动

**Date**: 2026-11-26
**Task**: 修复历史审计类型校正阻塞启动
**Branch**: `codex/fix-audit-startup-blocking`

### Summary

移除监听端口前的历史 JSON 全量校正,改为服务启动后每批 32 行、独立连接、原子游标和可恢复的后台任务,增加阶段与进度日志。补齐延后执行、断点续跑、取消、写锁冲突和历史边界测试;192 单测、92 接口测试、Clippy、18 SQL 回归通过。约 517 MiB 大 JSON 夹具验证健康检查在历史校正前就绪、审计新写入、重启续跑和带 lineage-config 认证访问;测试进程与端口已清理。线上 PID 长时间活跃与缺陷一致,但无 SSH 权限,尚未代替用户完成生产部署验收。

### Main Changes

(Add details)

### Git Commits

| Hash | Message |
|------|---------|
| `577e0295` | (see git log) |

### Testing

- [OK] (Add test results)

### Status

[OK] **Completed**

### Next Steps

- None - task complete
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Audit startup no longer scans historical analysis JSON before listening.
Legacy SQL types are corrected in bounded, resumable background batches with
progress logs, preserving audit writes and health checks during maintenance.
- Audit polling refreshes queued writes without covering the table or disabling
pagination. Audit SQL types consistently show `ii`, `io`, and `select`, including
CTE-prefixed writes and legacy rows with complete saved analyzer metadata.
Expand Down
Loading
Loading