1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
//! Mention-polling capability for `AgentOrchestrator`: scanning Gitea
//! comments for agent mentions, per-project mention polling, and resolving
//! the mention chain for nested conversations. Split from lib.rs as part of
//! the Gitea #1910 god-file decomposition; behaviour unchanged.
#![allow(clippy::too_many_lines)]
use tracing::{info, warn};
use crate::{
AgentOrchestrator, ScheduleEvent, agent_key, config, dispatcher, mention, mention_chain,
};
impl AgentOrchestrator {
/// Uses repo-wide comments endpoint with `since` cursor. On first run
/// (no persisted cursor), cursor is set to `now` to skip all historical
/// mentions — preventing the mention replay storm.
pub(crate) async fn poll_mentions(&mut self) {
// Build the list of (project_id, gitea_cfg, mention_cfg) targets.
//
// - Legacy mode (no `[[projects]]`): one pass under the synthetic
// `__global__` id using the top-level `gitea` and `mentions`.
// - Multi-project mode: one pass per configured project that
// declares a `gitea` block. Per-project `mentions` override the
// top-level `mentions`, which in turn falls back to
// `MentionConfig::default()` so operators need not repeat caps
// in every project.
let targets: Vec<(String, config::GiteaOutputConfig, config::MentionConfig)> =
if self.config.projects.is_empty() {
match (self.config.mentions.clone(), self.config.gitea.clone()) {
(Some(m), Some(g)) => {
vec![(dispatcher::LEGACY_PROJECT_ID.to_string(), g, m)]
}
_ => {
tracing::debug!(
"mention polling skipped: legacy mode but no Gitea/mentions config"
);
return;
}
}
} else {
let global_mentions = self.config.mentions.clone();
self.config
.projects
.iter()
.filter_map(|project| {
if project.gitea.is_none() {
tracing::debug!(
project = project.id.as_str(),
"skipping mention poll: project has no gitea config"
);
}
let gitea = project.gitea.clone()?;
let mentions = project
.mentions
.clone()
.or_else(|| global_mentions.clone())
.unwrap_or_default();
Some((project.id.clone(), gitea, mentions))
})
.collect()
};
if targets.is_empty() {
tracing::debug!("mention polling skipped: no projects with Gitea config");
return;
}
for (project_id, gitea_cfg, mention_cfg) in targets {
self.poll_mentions_for_project(&project_id, &gitea_cfg, &mention_cfg)
.await;
}
}
/// Run a single mention-poll pass for one project.
///
/// Invoked by [`AgentOrchestrator::poll_mentions`] for each configured
/// project (or once for legacy single-project mode under
/// `__global__`). Loads/persists the project's cursor, honours the
/// project's `MentionConfig`, and threads `project_id` onto every
/// dispatched mention.
async fn poll_mentions_for_project(
&mut self,
project_id: &str,
gitea_cfg: &config::GiteaOutputConfig,
mention_cfg: &config::MentionConfig,
) {
// Respect poll_modulo to reduce API traffic.
if !self.tick_count.is_multiple_of(mention_cfg.poll_modulo) {
return;
}
// Count currently active mention-spawned agents for this project.
//
// We filter by the agent definition's project field so one noisy
// project cannot exhaust the fleet-wide mention budget for others.
// In legacy mode (project_id == "__global__") every agent
// contributes because project binding isn't meaningful there.
let active_mention_agents = if project_id == dispatcher::LEGACY_PROJECT_ID {
self.active_agents
.values()
.filter(|a| a.spawned_by_mention)
.count() as u32
} else {
self.active_agents
.values()
.filter(|a| {
a.spawned_by_mention && a.definition.project.as_deref() == Some(project_id)
})
.count() as u32
};
if active_mention_agents >= mention_cfg.max_concurrent_mention_agents {
tracing::debug!(
project = project_id,
active = active_mention_agents,
max = mention_cfg.max_concurrent_mention_agents,
"mention agents at capacity, skipping poll"
);
return;
}
// Lazy-load the project's cursor.
let mut cursor = match self.mention_cursors.remove(project_id) {
Some(c) => c,
None => mention::MentionCursor::load_or_now(project_id).await,
};
cursor.dispatches_this_tick = 0;
// Create Gitea tracker for repo-wide comment polling
let tracker_cfg = terraphim_tracker::GiteaConfig {
base_url: gitea_cfg.base_url.clone(),
token: gitea_cfg.token.clone(),
owner: gitea_cfg.owner.clone(),
repo: gitea_cfg.repo.clone(),
active_states: vec!["open".to_string()],
terminal_states: vec!["closed".to_string()],
use_robot_api: false,
robot_path: std::path::PathBuf::from("/home/alex/go/bin/gitea-robot"),
claim_strategy: terraphim_tracker::gitea::ClaimStrategy::PreferRobot,
};
let tracker = match terraphim_tracker::GiteaTracker::new(tracker_cfg) {
Ok(t) => t,
Err(e) => {
tracing::warn!(
project = project_id,
error = %e,
"failed to create GiteaTracker for mention polling"
);
self.mention_cursors.insert(project_id.to_string(), cursor);
return;
}
};
// Single API call: all comments since cursor
let comments = match tracker
.fetch_repo_comments(Some(&cursor.last_seen_at), Some(50))
.await
{
Ok(c) => c,
Err(e) => {
tracing::warn!(
project = project_id,
error = %e,
"failed to fetch repo comments for mention polling"
);
self.mention_cursors.insert(project_id.to_string(), cursor);
return;
}
};
if comments.is_empty() {
cursor.save(project_id).await;
self.mention_cursors.insert(project_id.to_string(), cursor);
return;
}
let agents = self.config.agents.clone();
let persona_registry = self.persona_registry.clone();
let max_dispatches = mention_cfg.max_dispatches_per_tick;
// Build ADF command parser with known agents and personas
let agent_names: Vec<String> = agents.iter().map(|a| a.name.clone()).collect();
let persona_names: Vec<String> = persona_registry
.persona_names()
.into_iter()
.map(|s| s.to_string())
.collect();
let command_parser =
crate::adf_commands::AdfCommandParser::new(&agent_names, &persona_names);
let max_mention_depth = mention_cfg.max_mention_depth;
for comment in &comments {
if cursor.dispatches_this_tick >= max_dispatches {
tracing::debug!(
dispatched = cursor.dispatches_this_tick,
max = max_dispatches,
"max dispatches per tick reached"
);
break;
}
// Skip already-processed comments (persisted dedup across restarts)
if cursor.is_processed(comment.id) {
tracing::debug!(
comment_id = comment.id,
issue = comment.issue_number,
"skipping already-processed comment"
);
cursor.advance_to(&comment.created_at);
continue;
}
// Parse ADF commands using terraphim-automata Aho-Corasick
let commands =
command_parser.parse_commands(&comment.body, comment.issue_number, comment.id);
// Handle qualified `@adf:project/name` mentions that AdfCommandParser cannot
// see (its patterns are `@adf:{name}`; a `project/` prefix is not a substring).
for token in mention::parse_mention_tokens(&comment.body) {
if cursor.dispatches_this_tick >= max_dispatches {
break;
}
let proj = match token.project.as_deref() {
Some(p) => p,
None => continue, // unqualified mentions are handled by parse_commands below
};
match mention::resolve_mention(Some(proj), project_id, &token.agent, &agents) {
Some(def) => {
info!(
agent = %token.agent,
project = proj,
issue = comment.issue_number,
comment_id = comment.id,
"dispatching qualified mention-driven agent"
);
// Event-only agents (e.g. build-runner) must not be dispatched
// from comment mentions. Reject before any spawn-related work.
if def.event_only {
info!(
agent = %token.agent,
issue = comment.issue_number,
comment_id = comment.id,
"poll mention dispatch rejected: agent is event-only (push/event-driven), not mention-dispatchable"
);
cursor.dispatches_this_tick += 1;
continue;
}
if self
.should_skip_dispatch(&token.agent, comment.issue_number)
.await
{
cursor.dispatches_this_tick += 1;
continue;
}
let (chain_id, depth, parent_agent) = self.resolve_mention_chain(
&comment.user.login,
&agent_names,
max_mention_depth,
);
if let Err(e) = mention_chain::MentionChainTracker::check(
depth,
&parent_agent,
&token.agent,
max_mention_depth,
) {
warn!(
agent = %token.agent,
chain_id = %chain_id,
depth,
error = %e,
"mention chain check rejected dispatch"
);
if let Some(ref poster) = self.output_poster {
let body = format!(
"## Mention Dispatch Blocked\n\n\
Agent `{}` was not spawned: {}.\n\n\
_Chain `{}` at depth {} exceeds the configured limit._",
token.agent, e, chain_id, depth
);
if let Err(pe) = poster
.post_raw_for_project(project_id, comment.issue_number, &body)
.await
{
warn!(error = %pe, "failed to post chain rejection comment");
}
}
cursor.dispatches_this_tick += 1;
continue;
}
let ctx_args = mention_chain::MentionContextArgs {
parent_agent: parent_agent.clone(),
issue_number: comment.issue_number,
comment_body: comment.body.clone(),
depth,
chain_id: chain_id.clone(),
available_agents: agent_names
.iter()
.filter(|n| *n != &token.agent)
.cloned()
.collect(),
};
let chain_ctx = mention_chain::MentionChainTracker::build_context(
&ctx_args,
max_mention_depth,
);
let mut mention_def = def.clone();
mention_def.task = format!("{}\n\n{}", def.task, chain_ctx);
mention_def.gitea_issue = Some(comment.issue_number);
if let Err(e) = self.spawn_agent(&mention_def).await {
tracing::error!(
agent = %token.agent,
project = proj,
issue = comment.issue_number,
error = %e,
"failed to spawn agent for qualified mention"
);
} else if let Some(active) =
self.active_agents.get_mut(&agent_key(&mention_def))
{
active.spawned_by_mention = true;
active.mention_chain_id = Some(chain_id);
active.mention_depth = Some(depth);
active.mention_parent_agent = if parent_agent.is_empty() {
None
} else {
Some(parent_agent)
};
}
cursor.dispatches_this_tick += 1;
}
None => {
tracing::warn!(
mention = format!("@adf:{}/{}", proj, token.agent),
project = project_id,
issue = comment.issue_number,
"qualified mention matched no agent"
);
}
}
}
for cmd in commands {
if cursor.dispatches_this_tick >= max_dispatches {
break;
}
match cmd {
crate::adf_commands::AdfCommand::CompoundReview {
issue_number,
comment_id,
} => {
info!(
issue = issue_number,
comment_id = comment_id,
"compound review triggered via @adf:compound-review mention"
);
// Trigger compound review
self.handle_schedule_event(ScheduleEvent::CompoundReview)
.await;
// Post acknowledgment
if let Some(ref poster) = self.output_poster {
let ack_body = format!(
"## 🔍 Compound Review Triggered\n\n\
Manual trigger received from issue #{} comment {}.\n\
Running 6-agent review swarm now...\n\n\
_Results will be posted to issue #{} when complete._",
issue_number,
comment_id,
self.config.compound_review.gitea_issue.unwrap_or(108)
);
if let Err(e) = poster.post_raw(issue_number, &ack_body).await {
warn!(error = %e, "failed to post compound review acknowledgment");
}
}
cursor.dispatches_this_tick += 1;
}
crate::adf_commands::AdfCommand::SpawnAgent {
agent_name,
issue_number,
comment_id,
context,
} => {
info!(
agent = %agent_name,
issue = issue_number,
comment_id = comment_id,
"dispatching mention-driven agent via terraphim-automata parser"
);
if let Some(def) =
mention::resolve_mention(None, project_id, &agent_name, &agents)
{
// Event-only agents (e.g. build-runner) must not be dispatched
// from comment mentions. Reject before any spawn-related work.
if def.event_only {
info!(
agent = %agent_name,
issue = issue_number,
comment_id = comment_id,
"poll mention dispatch rejected: agent is event-only (push/event-driven), not mention-dispatchable"
);
cursor.dispatches_this_tick += 1;
continue;
}
if self.should_skip_dispatch(&agent_name, issue_number).await {
cursor.dispatches_this_tick += 1;
continue;
}
let (chain_id, depth, parent_agent) = self.resolve_mention_chain(
&comment.user.login,
&agent_names,
max_mention_depth,
);
if let Err(e) = mention_chain::MentionChainTracker::check(
depth,
&parent_agent,
&agent_name,
max_mention_depth,
) {
warn!(
agent = %agent_name,
chain_id = %chain_id,
depth,
error = %e,
"mention chain check rejected dispatch"
);
if let Some(ref poster) = self.output_poster {
let body = format!(
"## Mention Dispatch Blocked\n\n\
Agent `{}` was not spawned: {}.\n\n\
_Chain `{}` at depth {} exceeds the configured limit._",
agent_name, e, chain_id, depth
);
if let Err(pe) = poster
.post_raw_for_project(project_id, issue_number, &body)
.await
{
warn!(error = %pe, "failed to post chain rejection comment");
}
}
cursor.dispatches_this_tick += 1;
continue;
}
let ctx_args = mention_chain::MentionContextArgs {
parent_agent: parent_agent.clone(),
issue_number,
comment_body: context.clone(),
depth,
chain_id: chain_id.clone(),
available_agents: agent_names
.iter()
.filter(|n| *n != &agent_name)
.cloned()
.collect(),
};
let chain_ctx = mention_chain::MentionChainTracker::build_context(
&ctx_args,
max_mention_depth,
);
let mut mention_def = def.clone();
mention_def.task = format!("{}\n\n{}", def.task, chain_ctx);
mention_def.gitea_issue = Some(issue_number);
if let Err(e) = self.spawn_agent(&mention_def).await {
tracing::error!(agent = %agent_name, issue = issue_number, error = %e, "failed to spawn agent");
} else if let Some(agent) =
self.active_agents.get_mut(&agent_key(&mention_def))
{
agent.spawned_by_mention = true;
agent.mention_chain_id = Some(chain_id);
agent.mention_depth = Some(depth);
agent.mention_parent_agent = if parent_agent.is_empty() {
None
} else {
Some(parent_agent)
};
}
cursor.dispatches_this_tick += 1;
}
}
crate::adf_commands::AdfCommand::SpawnPersona {
persona_name,
issue_number,
comment_id: _,
context,
} => {
// Resolve persona to agent
if let Some((agent_name, _)) = mention::resolve_persona_mention(
&persona_name,
&agents,
&persona_registry,
&context,
) {
info!(
persona = %persona_name,
agent = %agent_name,
issue = issue_number,
"dispatching persona-resolved agent via terraphim-automata parser"
);
if let Some(def) = agents.iter().find(|a| a.name == agent_name).cloned()
{
// Event-only agents (e.g. build-runner) must not be dispatched
// from persona mentions. Reject before any spawn-related work.
if def.event_only {
info!(
persona = %persona_name,
agent = %agent_name,
issue = issue_number,
"poll mention dispatch rejected: persona-resolved agent is event-only (push/event-driven), not mention-dispatchable"
);
cursor.dispatches_this_tick += 1;
continue;
}
// Dedup: check Gitea assignment + active_agents before spawning
if self.should_skip_dispatch(&agent_name, issue_number).await {
cursor.dispatches_this_tick += 1;
continue;
}
let (chain_id, depth, parent_agent) = self.resolve_mention_chain(
&comment.user.login,
&agent_names,
max_mention_depth,
);
if let Err(e) = mention_chain::MentionChainTracker::check(
depth,
&parent_agent,
&agent_name,
max_mention_depth,
) {
warn!(
agent = %agent_name,
chain_id = %chain_id,
depth,
error = %e,
"mention chain check rejected persona dispatch"
);
if let Some(ref poster) = self.output_poster {
let body = format!(
"## Mention Dispatch Blocked\n\n\
Agent `{}` (via persona) was not spawned: {}.\n\n\
_Chain `{}` at depth {} exceeds the configured limit._",
agent_name, e, chain_id, depth
);
if let Err(pe) = poster
.post_raw_for_project(project_id, issue_number, &body)
.await
{
warn!(error = %pe, "failed to post chain rejection comment");
}
}
cursor.dispatches_this_tick += 1;
continue;
}
let ctx_args = mention_chain::MentionContextArgs {
parent_agent: parent_agent.clone(),
issue_number,
comment_body: context.clone(),
depth,
chain_id: chain_id.clone(),
available_agents: agent_names
.iter()
.filter(|n| *n != &agent_name)
.cloned()
.collect(),
};
let chain_ctx = mention_chain::MentionChainTracker::build_context(
&ctx_args,
max_mention_depth,
);
let mut mention_def = def.clone();
mention_def.task = format!("{}\n\n{}", def.task, chain_ctx);
mention_def.gitea_issue = Some(issue_number);
if let Err(e) = self.spawn_agent(&mention_def).await {
tracing::error!(agent = %agent_name, issue = issue_number, error = %e, "failed to spawn agent");
} else if let Some(agent) =
self.active_agents.get_mut(&agent_key(&mention_def))
{
agent.spawned_by_mention = true;
agent.mention_chain_id = Some(chain_id);
agent.mention_depth = Some(depth);
agent.mention_parent_agent = if parent_agent.is_empty() {
None
} else {
Some(parent_agent)
};
}
cursor.dispatches_this_tick += 1;
}
}
}
crate::adf_commands::AdfCommand::Unknown { raw } => {
warn!(raw = %raw, "unknown ADF command");
}
}
}
// Mark comment as processed and advance cursor
cursor.mark_processed(comment.id);
cursor.advance_to(&comment.created_at);
}
// Persist cursor for next poll / restart
cursor.save(project_id).await;
self.mention_cursors.insert(project_id.to_string(), cursor);
}
/// Check if an agent is already assigned to this issue and currently active.
///
/// Returns `true` if dispatch should be **skipped** (duplicate), `false` if
/// dispatch should proceed. When dispatch proceeds, the issue is assigned
/// to the agent as a side-effect.
///
/// The dedup logic:
/// - If the issue is already assigned to the agent AND the agent is currently
/// in `active_agents` -> skip (duplicate dispatch).
/// - If assigned but agent is NOT active -> allow (agent crashed, re-dispatch).
/// - If not assigned -> allow (first dispatch) and assign.
pub(crate) async fn should_skip_dispatch(&self, agent_name: &str, issue_number: u64) -> bool {
if issue_number == 0 {
return false;
}
// Fast local check: if agent is already running, skip immediately.
// This prevents races where the Gitea API returns stale assignee data
// because a concurrent dispatch path just assigned the issue milliseconds ago.
if self.is_agent_active_by_name(agent_name) {
warn!(
agent = %agent_name,
issue = issue_number,
"skipping dispatch: agent already active (local guard)"
);
return true;
}
let Some(ref poster) = self.output_poster else {
return false;
};
// Resolve the agent's owning project so the tracker uses the
// correct owner/repo (multi-project) or falls back to legacy.
let project = self
.config
.agents
.iter()
.find(|a| a.name == agent_name)
.and_then(|a| a.project.clone())
.unwrap_or_else(|| crate::dispatcher::LEGACY_PROJECT_ID.to_string());
let Some(tracker) = poster.tracker_for(&project, agent_name) else {
warn!(
agent = %agent_name,
project = %project,
"no Gitea tracker for project; treating dispatch as not-duplicate"
);
return false;
};
// Remote check: if agent is assigned in Gitea but not active (crash recovery)
match tracker.fetch_issue_assignees(issue_number).await {
Ok(assignees) => {
if assignees.iter().any(|a| a == agent_name) {
// Already assigned -- check if agent is actively running
if self.is_agent_active_by_name(agent_name) {
warn!(
agent = %agent_name,
issue = issue_number,
"skipping duplicate dispatch: agent already assigned and active"
);
return true;
}
// Assigned but not active (crashed or completed) -- allow re-dispatch
info!(
agent = %agent_name,
issue = issue_number,
"agent assigned but not active, allowing re-dispatch"
);
}
}
Err(e) => {
// Fail open: if we can't check assignees, allow dispatch
warn!(
agent = %agent_name,
issue = issue_number,
error = %e,
"failed to fetch assignees, allowing dispatch (fail-open)"
);
}
}
// Assign the issue to the agent
if let Err(e) = tracker.assign_issue(issue_number, &[agent_name]).await {
warn!(
agent = %agent_name,
issue = issue_number,
error = %e,
"failed to assign issue to agent"
);
} else {
info!(
agent = %agent_name,
issue = issue_number,
"assigned issue to agent"
);
}
false
}
/// Resolve mention chain metadata from the comment author.
///
/// If the comment was posted by a known agent, this is a nested mention:
/// inherit the chain_id from the agent's current run and increment depth.
/// If posted by a human, start a fresh chain with depth 0.
fn resolve_mention_chain(
&self,
comment_author: &str,
agent_names: &[String],
_max_depth: u32,
) -> (String, u32, String) {
if agent_names.iter().any(|n| n == comment_author) {
if let Some(active) = self.active_agent_by_name(comment_author) {
let parent_chain_id = active
.mention_chain_id
.clone()
.unwrap_or_else(|| ulid::Ulid::new().to_string());
let parent_depth = active.mention_depth.unwrap_or(0).saturating_add(1);
(parent_chain_id, parent_depth, comment_author.to_string())
} else {
let chain_id = ulid::Ulid::new().to_string();
(chain_id, 1, comment_author.to_string())
}
} else {
let chain_id = ulid::Ulid::new().to_string();
(chain_id, 0, String::new())
}
}
}