§1 修复代码审查反馈: generateSignalId/TraceId 按当日日期过滤顺序号

Agent-Logs-Url: https://github.com/qinfendebingshuo/guanghulab/sessions/933f67dd-56b2-417f-8162-a5f3d70ce797

Co-authored-by: qinfendebingshuo <207279273+qinfendebingshuo@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-27 07:55:14 +00:00 committed by GitHub
parent 5d12384fc7
commit 3458deebfe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 6 additions and 4 deletions

View File

@ -104,14 +104,15 @@ function generateSignalId() {
const now = new Date();
const date = now.toISOString().split('T')[0].replace(/-/g, '');
// 读取现有 index.json 获取最大顺序号生成下一个顺序ID
// 读取现有 index.json,仅统计当日信号的最大顺序号
let nextSeq = 1;
try {
const indexPath = path.join(SIGNAL_LOG_DIR, 'index.json');
const raw = JSON.parse(fs.readFileSync(indexPath, 'utf8'));
const signals = Array.isArray(raw) ? raw : (raw.signals || []);
const pattern = new RegExp(`^SIG-${date}-(\\d{3})$`);
for (const sig of signals) {
const match = (sig.signal_id || '').match(/^SIG-\d{8}-(\d{3})$/);
const match = (sig.signal_id || '').match(pattern);
if (match) {
const seq = parseInt(match[1], 10);
if (seq >= nextSeq) nextSeq = seq + 1;
@ -126,14 +127,15 @@ function generateTraceId() {
const now = new Date();
const date = now.toISOString().split('T')[0].replace(/-/g, '');
// 读取现有 index.json 获取最大 trace 顺序号
// 读取现有 index.json,仅统计当日 trace 的最大顺序号
let nextSeq = 1;
try {
const indexPath = path.join(SIGNAL_LOG_DIR, 'index.json');
const raw = JSON.parse(fs.readFileSync(indexPath, 'utf8'));
const signals = Array.isArray(raw) ? raw : (raw.signals || []);
const pattern = new RegExp(`^TRC-${date}-(\\d{3})$`);
for (const sig of signals) {
const match = (sig.trace_id || '').match(/^TRC-\d{8}-(\d{3})$/);
const match = (sig.trace_id || '').match(pattern);
if (match) {
const seq = parseInt(match[1], 10);
if (seq >= nextSeq) nextSeq = seq + 1;