Skip to content

Commit f859fd6

Browse files
committed
feat: add sync and data debug workflows
1 parent 1a5d555 commit f859fd6

2 files changed

Lines changed: 100 additions & 11 deletions

File tree

‎docs/DEBUG_WORKFLOWS.md‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ Standard debugging workflows for Tero CLI. These workflows are task-driven and e
1313

1414
Default debug environment is `dev`.
1515

16-
1. `task debug:*` defaults to `TERO_ENV=dev`.
16+
1. `task debug:*` defaults to `DEBUG_ENV=dev`.
1717
2. `prd` is blocked unless `ALLOW_PRD=1` is explicitly set.
1818

1919
Example:
2020

2121
```bash
2222
task debug:ui:logs:slow
23-
task debug:ui:logs:slow TERO_ENV=prd ALLOW_PRD=1
23+
task debug:ui:logs:slow DEBUG_ENV=prd ALLOW_PRD=1
2424
```
2525

2626
## Command Map
@@ -46,6 +46,19 @@ Onboarding:
4646
task debug:onboarding:trace
4747
```
4848

49+
Sync:
50+
51+
```bash
52+
task debug:sync:trace
53+
task debug:sync:health
54+
```
55+
56+
Data:
57+
58+
```bash
59+
task debug:data:snapshot
60+
```
61+
4962
## Slow UI Diagnostics
5063

5164
Slow-loop telemetry logs:
@@ -80,3 +93,17 @@ Use `debug:<area>:<action>`:
8093

8194
Add new debug tasks in `taskfiles/debug.yml`.
8295

96+
## Triage Matrix
97+
98+
Use this when debugging quickly:
99+
100+
1. UI lag, key delay, drawer jitter:
101+
1. `task debug:ui:logs:slow`
102+
2. `task debug:ui:smoke`
103+
2. Onboarding stuck or unclear gate transitions:
104+
1. `task debug:onboarding:trace`
105+
3. Sync stuck, reconnect loops, upload confusion:
106+
1. `task debug:sync:trace`
107+
2. `task debug:sync:health`
108+
4. Data mismatch (UI vs expected local state):
109+
1. `task debug:data:snapshot`

‎taskfiles/debug.yml‎

Lines changed: 71 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,38 @@
11
version: "3"
22

33
vars:
4-
TERO_ENV: '{{.TERO_ENV | default "dev"}}'
4+
DEBUG_ENV: '{{.DEBUG_ENV | default "dev"}}'
55
ENV_PREFIX:
66
sh: |
7-
if [ "{{.TERO_ENV}}" = "local" ]; then
7+
if [ "{{.DEBUG_ENV}}" = "local" ]; then
88
echo ""
99
else
10-
echo "doppler run -c {{.TERO_ENV}} --"
10+
echo "doppler run -c {{.DEBUG_ENV}} --"
1111
fi
1212
1313
tasks:
1414
list:
1515
desc: List debug workflows
1616
cmds:
1717
- |
18-
echo "Debug workflows (default TERO_ENV=dev):"
18+
echo "Debug workflows (default DEBUG_ENV=dev):"
1919
echo " task debug:ui:run"
2020
echo " task debug:ui:logs:slow"
2121
echo " task debug:ui:logs:all"
2222
echo " task debug:ui:smoke"
2323
echo " task debug:onboarding:trace"
24+
echo " task debug:sync:trace"
25+
echo " task debug:sync:health"
26+
echo " task debug:data:snapshot"
2427
echo ""
2528
echo "To target prd explicitly (discouraged):"
26-
echo " task debug:ui:logs:slow TERO_ENV=prd ALLOW_PRD=1"
29+
echo " task debug:ui:logs:slow DEBUG_ENV=prd ALLOW_PRD=1"
2730
2831
guard:non-prd:
2932
internal: true
3033
cmds:
3134
- |
32-
if [ "{{.TERO_ENV}}" = "prd" ] && [ "{{.ALLOW_PRD}}" != "1" ]; then
35+
if [ "{{.DEBUG_ENV}}" = "prd" ] && [ "{{.ALLOW_PRD}}" != "1" ]; then
3336
echo "Refusing to run debug workflow against prd without explicit override."
3437
echo "Set ALLOW_PRD=1 if you intentionally need prd."
3538
exit 1
@@ -52,7 +55,7 @@ tasks:
5255
deps: [guard:non-prd]
5356
cmds:
5457
- |
55-
LOG_FILE="$HOME/.tero/environments/{{.TERO_ENV}}/tero.log"
58+
LOG_FILE="$HOME/.tero/environments/{{.DEBUG_ENV}}/tero.log"
5659
echo "Tailing slow UI logs from $LOG_FILE"
5760
tail -n 200 -f "$LOG_FILE" | rg --line-buffered "slow app update|slow app render|SESSION START"
5861
@@ -61,7 +64,7 @@ tasks:
6164
deps: [guard:non-prd]
6265
cmds:
6366
- |
64-
LOG_FILE="$HOME/.tero/environments/{{.TERO_ENV}}/tero.log"
67+
LOG_FILE="$HOME/.tero/environments/{{.DEBUG_ENV}}/tero.log"
6568
echo "Tailing app logs from $LOG_FILE"
6669
tail -n 200 -f "$LOG_FILE"
6770
@@ -70,7 +73,66 @@ tasks:
7073
deps: [guard:non-prd]
7174
cmds:
7275
- |
73-
LOG_FILE="$HOME/.tero/environments/{{.TERO_ENV}}/tero.log"
76+
LOG_FILE="$HOME/.tero/environments/{{.DEBUG_ENV}}/tero.log"
7477
echo "Tailing onboarding trace from $LOG_FILE"
7578
tail -n 200 -f "$LOG_FILE" | rg --line-buffered "onboarding gate transition|preflight|runtime initialized|datadog|workspace|sync completed|onboarding complete|slow app update|slow app render|SESSION START"
7679
80+
sync:trace:
81+
desc: Tail syncer/uploader activity with slow-loop context
82+
deps: [guard:non-prd]
83+
cmds:
84+
- |
85+
LOG_FILE="$HOME/.tero/environments/{{.DEBUG_ENV}}/tero.log"
86+
echo "Tailing sync trace from $LOG_FILE"
87+
tail -n 300 -f "$LOG_FILE" | rg --line-buffered "scope=powersync|scope=app/upload|sync progress|sync complete|transient error|slow app update|slow app render|SESSION START"
88+
89+
sync:health:
90+
desc: Show recent sync/uploader health snapshot from logs
91+
deps: [guard:non-prd]
92+
cmds:
93+
- |
94+
LOG_FILE="$HOME/.tero/environments/{{.DEBUG_ENV}}/tero.log"
95+
if [ ! -f "$LOG_FILE" ]; then
96+
echo "No log file found at $LOG_FILE"
97+
exit 1
98+
fi
99+
echo "Recent sync health ($LOG_FILE):"
100+
echo ""
101+
echo "Latest sync + upload lines:"
102+
tail -n 800 "$LOG_FILE" | rg "scope=powersync|scope=app/upload|sync complete|transient error|upload loop started|completed batch" | tail -n 40 || true
103+
echo ""
104+
echo "Latest slow-loop lines:"
105+
tail -n 800 "$LOG_FILE" | rg "slow app update|slow app render" | tail -n 20 || true
106+
echo ""
107+
echo "Latest error lines:"
108+
tail -n 800 "$LOG_FILE" | rg " level=ERROR " | tail -n 20 || true
109+
110+
data:snapshot:
111+
desc: Show local SQLite snapshot (counts + pending upload rows)
112+
deps: [guard:non-prd]
113+
cmds:
114+
- |
115+
if ! command -v sqlite3 >/dev/null 2>&1; then
116+
echo "sqlite3 not installed; install sqlite3 to use debug:data:snapshot"
117+
exit 1
118+
fi
119+
DB_PATH=$(find "$HOME/.tero/environments/{{.DEBUG_ENV}}/orgs" -type f -name "*.sqlite" 2>/dev/null | head -n 1)
120+
if [ -z "$DB_PATH" ]; then
121+
echo "No SQLite database found under ~/.tero/environments/{{.DEBUG_ENV}}/orgs"
122+
exit 1
123+
fi
124+
echo "SQLite snapshot: $DB_PATH"
125+
echo ""
126+
sqlite3 "$DB_PATH" <<'SQL'
127+
.mode column
128+
.headers on
129+
SELECT 'services' AS table_name, COUNT(*) AS row_count FROM services
130+
UNION ALL
131+
SELECT 'log_event_statuses', COUNT(*) FROM log_event_statuses
132+
UNION ALL
133+
SELECT 'messages', COUNT(*) FROM messages
134+
UNION ALL
135+
SELECT 'conversations', COUNT(*) FROM conversations
136+
UNION ALL
137+
SELECT 'ps_crud_pending', COUNT(*) FROM ps_crud;
138+
SQL

0 commit comments

Comments
 (0)