This repository was archived by the owner on Jun 8, 2026. It is now read-only.
Commit 8db7ef9
Andrew Eye
FEA-1444: Add Codex hook event dedup + renderer opt-in toggle
Layer 2 — Event-level dedup against rollout-tail:
- New filterEventsAlreadyCapturedByHooks in codex-import.js. Runs before
importSession in importCodexSession; queries existing events for rows
matching (session_id, event_type, COALESCE(tool_name, ''), created_at
truncated to whole seconds) and drops duplicates. Hook-handler-inserted
rows land first (real-time); the ~5s-later rollout-tail no-ops on match.
- The dedup statement is cached per-dbModule via WeakMap so a batch of
many changed sessions compiles the SQL once, not once per session.
- Best-effort: any prepare/query failure is swallowed and the event is
kept. False negatives (cosmetic duplicates) are preferred over false
positives (silently dropped events). Sub-second timestamp drift handled
by the substr(?, 1, 19) match.
Layer 3 — Renderer opt-in toggle:
- apps/desktop/src/main/app.ts: new IPC handlers
desktop:{get,set}-agent-monitor-codex-hooks-opt-in that call the
already-exported isAgentMonitorCodexHooksOptIn /
setAgentMonitorCodexHooksOptIn. Gated on the master Agent Dashboard
flag, matching the Claude pair shape exactly.
- apps/desktop/src/main/preload.ts: mirror bridge methods exposing the
two channels to the renderer.
- apps/desktop/src/renderer/index.html: new #codexDashConsent toggle row
directly below the existing #claudeDashConsent. Same visibility
semantics (shown only on agent-settings route), same disabled-when-
master-off behavior, same hint text reset on master flag re-enable
(Codex hint reset now mirrors Claude's after a review-flagged gap).
refreshCodexHooksToggle is called when the user toggles the Claude
hooks toggle so the sibling's on/off badge stays in sync.
Test:
- apps/desktop/test/agent-session-event-dedup.test.ts (new): 4 unit
tests on the filter against a sandbox SQLite DB. Covers (1) duplicate
filter with sub-second drift, (2) non-duplicate survival across
mixed events, (3) best-effort behavior on DB errors, (4) empty-events
no-op. Uses the conditional-skip pattern (skipReason ? { skip: ... }
: undefined) because Node test runner treats skip: null as "skip with
no reason" rather than "don't skip" — gotcha learned during debugging.
Independent code review (second pass on the cumulative diff) surfaced:
- Medium: Codex hint stale after master flag re-enable (Claude hint was
reset in the else branch, Codex hint wasn't). Fixed.
- Low: Comment inaccuracy about which toggle "unblocks the master flag"
in wireClaudeHooksToggle. Rewritten.
- Low: Dedup statement prepared once per session inside the batch loop
instead of once per process. Cached via WeakMap.
All three addressed in this commit.
Testing:
- pnpm -C apps/desktop typecheck: clean
- pnpm -C apps/desktop lint: clean
- pnpm -C apps/desktop build:agent-monitor: clean (Layer 1 hard-gates
+ sidecar SQLite gate continue to pass)
- pnpm -C apps/desktop test (full suite): 1945/1945 pass, 0 fail
- New agent-session-event-dedup.test.ts: 4/4 pass
- agent-monitor-hooks-core.test.ts (from Layer 1): 10/10 pass (no
regression)
Risks:
- Cross-second timestamp drift between hook and rollout-tail can defeat
dedup. Documented design tradeoff: false negatives are cosmetic
duplicates; false positives would silently drop events. Will revisit
with a content-hash dedup key in a follow-up if cosmetic duplication
becomes visible in practice.
- IPC handler test coverage deferred. Both new handlers are shallow
plumbing that call already-tested functions (covered by Layer 1's
agent-monitor-hooks-core.test.ts). Typecheck validates the signatures
+ preload bridge types.
- Renderer JS duplicates the Claude/Codex toggle pattern. Per CLAUDE.md
this is the kind of duplication worth extracting, but inline renderer
JS makes a shared helper awkward; deferred to a separate cleanup
ticket if the pattern repeats with a third harness.1 parent 87a601c commit 8db7ef9
5 files changed
Lines changed: 421 additions & 3 deletions
File tree
- apps/desktop
- scripts/agent-monitor-codex
- src
- main
- renderer
- test
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
33 | 43 | | |
34 | 44 | | |
35 | 45 | | |
| |||
42 | 52 | | |
43 | 53 | | |
44 | 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 | + | |
45 | 122 | | |
46 | 123 | | |
47 | 124 | | |
| |||
107 | 184 | | |
108 | 185 | | |
109 | 186 | | |
110 | | - | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
| 74 | + | |
73 | 75 | | |
74 | 76 | | |
75 | 77 | | |
| |||
2499 | 2501 | | |
2500 | 2502 | | |
2501 | 2503 | | |
| 2504 | + | |
| 2505 | + | |
| 2506 | + | |
| 2507 | + | |
| 2508 | + | |
| 2509 | + | |
| 2510 | + | |
| 2511 | + | |
| 2512 | + | |
| 2513 | + | |
| 2514 | + | |
| 2515 | + | |
| 2516 | + | |
| 2517 | + | |
| 2518 | + | |
| 2519 | + | |
| 2520 | + | |
| 2521 | + | |
| 2522 | + | |
| 2523 | + | |
2502 | 2524 | | |
2503 | 2525 | | |
2504 | 2526 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
139 | 149 | | |
140 | 150 | | |
141 | 151 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3404 | 3404 | | |
3405 | 3405 | | |
3406 | 3406 | | |
| 3407 | + | |
| 3408 | + | |
| 3409 | + | |
| 3410 | + | |
| 3411 | + | |
| 3412 | + | |
| 3413 | + | |
| 3414 | + | |
| 3415 | + | |
| 3416 | + | |
| 3417 | + | |
3407 | 3418 | | |
3408 | 3419 | | |
3409 | 3420 | | |
| |||
3971 | 3982 | | |
3972 | 3983 | | |
3973 | 3984 | | |
| 3985 | + | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
3974 | 3990 | | |
3975 | 3991 | | |
3976 | 3992 | | |
| |||
4030 | 4046 | | |
4031 | 4047 | | |
4032 | 4048 | | |
| 4049 | + | |
| 4050 | + | |
| 4051 | + | |
4033 | 4052 | | |
4034 | 4053 | | |
4035 | 4054 | | |
4036 | 4055 | | |
4037 | 4056 | | |
4038 | 4057 | | |
4039 | 4058 | | |
| 4059 | + | |
| 4060 | + | |
| 4061 | + | |
| 4062 | + | |
| 4063 | + | |
| 4064 | + | |
| 4065 | + | |
| 4066 | + | |
| 4067 | + | |
| 4068 | + | |
4040 | 4069 | | |
4041 | 4070 | | |
4042 | 4071 | | |
| |||
4059 | 4088 | | |
4060 | 4089 | | |
4061 | 4090 | | |
4062 | | - | |
4063 | | - | |
| 4091 | + | |
| 4092 | + | |
| 4093 | + | |
| 4094 | + | |
| 4095 | + | |
| 4096 | + | |
| 4097 | + | |
| 4098 | + | |
| 4099 | + | |
| 4100 | + | |
4064 | 4101 | | |
4065 | 4102 | | |
4066 | 4103 | | |
| |||
4110 | 4147 | | |
4111 | 4148 | | |
4112 | 4149 | | |
| 4150 | + | |
| 4151 | + | |
| 4152 | + | |
| 4153 | + | |
| 4154 | + | |
| 4155 | + | |
| 4156 | + | |
| 4157 | + | |
| 4158 | + | |
| 4159 | + | |
| 4160 | + | |
| 4161 | + | |
| 4162 | + | |
| 4163 | + | |
| 4164 | + | |
| 4165 | + | |
| 4166 | + | |
| 4167 | + | |
| 4168 | + | |
| 4169 | + | |
| 4170 | + | |
| 4171 | + | |
| 4172 | + | |
| 4173 | + | |
| 4174 | + | |
| 4175 | + | |
| 4176 | + | |
| 4177 | + | |
| 4178 | + | |
| 4179 | + | |
| 4180 | + | |
| 4181 | + | |
| 4182 | + | |
| 4183 | + | |
| 4184 | + | |
| 4185 | + | |
| 4186 | + | |
| 4187 | + | |
| 4188 | + | |
| 4189 | + | |
| 4190 | + | |
| 4191 | + | |
| 4192 | + | |
| 4193 | + | |
| 4194 | + | |
| 4195 | + | |
| 4196 | + | |
| 4197 | + | |
| 4198 | + | |
| 4199 | + | |
| 4200 | + | |
| 4201 | + | |
| 4202 | + | |
| 4203 | + | |
| 4204 | + | |
| 4205 | + | |
4113 | 4206 | | |
4114 | 4207 | | |
4115 | 4208 | | |
| |||
4125 | 4218 | | |
4126 | 4219 | | |
4127 | 4220 | | |
| 4221 | + | |
| 4222 | + | |
| 4223 | + | |
| 4224 | + | |
| 4225 | + | |
4128 | 4226 | | |
4129 | 4227 | | |
4130 | 4228 | | |
| |||
4161 | 4259 | | |
4162 | 4260 | | |
4163 | 4261 | | |
| 4262 | + | |
| 4263 | + | |
| 4264 | + | |
4164 | 4265 | | |
4165 | 4266 | | |
4166 | 4267 | | |
| |||
0 commit comments