docs/superpowers/plans/2026-04-16-query-session-stability-phase1.md
For agentic workers: REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (
- [ ]) syntax for tracking.
Goal: Make launcher first-flush behavior stable enough that weak early partial results do not visibly take over top1 before stronger results arrive, while keeping query response latency bounded.
Architecture: Leave the existing fuzzy scoring and final snapshot ranking in place for now. Add deterministic backend smoke coverage around the WebSocket query pipeline, instrument first-flush corrections in ui_impl.go, then change first-flush commit from a pure timer gate to a confidence gate: commit immediately for done, otherwise wait until the snapshot is competitive enough or a bounded max-wait expires.
Tech Stack: Go backend, existing wox.core/test integration harness, WebSocket UI bridge, current launcher query snapshot pipeline
Operator rule: Do not change fuzzy ranking or plugin-specific scoring rules in this phase. This plan only covers instrumentation and first-flush commit policy.
/mnt/c/dev/Wox/wox.core/test/query_session_stability_test.go
Purpose: deterministic end-to-end smoke coverage for first-flush instability using test-only plugins and the existing WebSocket UI bridge/mnt/c/dev/Wox/wox.core/ui/ui_impl.go
Purpose: first-flush instrumentation, confidence gating, and bounded max-wait behavior/mnt/c/dev/Wox/wox.core/plugin/manager.go
Purpose: snapshot summary helpers and any minimal delay-policy plumbing needed by ui_impl.goNo Flutter file changes are planned in this phase. The backend should stop emitting visibly wrong early snapshots before any frontend reconciliation work is added.
Files:
Create: /mnt/c/dev/Wox/wox.core/test/query_session_stability_test.go
Use: /mnt/c/dev/Wox/wox.core/test/test_base.go
Use: /mnt/c/dev/Wox/wox.core/test/plugin_test.go
Step 1: Add test-only system plugins in query_session_stability_test.go before service initialization
Define two minimal test-only plugins in the test package and register them in init() by appending to plugin.AllSystemPlugin:
stabilityEarlyWeakPlugin
ignoreAutoScore"Open Stability Portfolio Settings"5ms before returning"stability-portfolio"stabilityLateStrongPlugin
ignoreAutoScore"stability-portfolio"70msKeep titles unique so existing real plugins do not interfere with assertions.
ui_impl.go, not Manager.Query(...) directlyIn the same file, add a helper that:
ensureTestUIWebsocket(t)Query request matching the launcher protocolQuery response message for the active queryIdisFinalDo not use runQuery(...) for these tests, because it bypasses handleWebsocketQuery(...), first flush delay, and the debouncer path.
Add:
func TestQueryFirstFlushWaitsForCompetitiveSnapshot(t *testing.T)
Assertions:
"stability-portfolio"Query responses"stability-portfolio", not the weak settings-like resultCurrent expected failure before implementation:
the first non-final response contains only the weak early result
the second response corrects top1 after the strong result arrives
Step 4: Add the bounded-latency smoke test for single-result queries
Add:
func TestQueryFirstFlushMaxWaitStillShowsSingleResult(t *testing.T)
Use one additional test-only plugin or a branch in the existing weak plugin so that:
"stability-single"Assertions:
doneThis test protects the fix from becoming "wait for everything" instead of "wait until confidence or max-wait".
Run:
cmd.exe /c "cd /d C:\dev\Wox\wox.core && go test ./test -run TestQueryFirstFlush -count=1 -v"
Expected before implementation:
TestQueryFirstFlushWaitsForCompetitiveSnapshot fails because the first visible non-final response contains only the weak early resultTestQueryFirstFlushMaxWaitStillShowsSingleResult can fail or remain pending depending on how the helper is wired, but the first test must clearly prove the current instabilityFiles:
Modify: /mnt/c/dev/Wox/wox.core/ui/ui_impl.go
Modify: /mnt/c/dev/Wox/wox.core/plugin/manager.go
Step 1: Add a compact snapshot summary helper in manager.go
Add a small internal helper that can summarize a built snapshot for logging:
Keep the helper internal to the backend; do not change public plugin APIs in this phase.
ui_impl.goEnhance handleWebsocketQuery(...) so the query bridge logs:
donecompetitive_snapshotmax_wait120msUse one log line per event, keeping it concise and comparable to the existing:
first flush delayresult flushed (reason: first|tick|done)logs already emitted today.
Run:
cmd.exe /c "cd /d C:\dev\Wox\wox.core && go test ./test -run TestQueryFirstFlushWaitsForCompetitiveSnapshot -count=1 -v"
Expected before the real fix:
This task is complete only when the instrumentation makes the failure measurable, not anecdotal.
Files:
Modify: /mnt/c/dev/Wox/wox.core/ui/ui_impl.go
Modify: /mnt/c/dev/Wox/wox.core/plugin/manager.go
Step 1: Add an explicit first-flush policy in ui_impl.go
Implement a small policy in the query bridge closure, not in the generic debouncer:
done always commits immediately2firstFlushMaxWaitFor this phase, do not add semantic-role heuristics yet.
Do not change the contract of /mnt/c/dev/Wox/wox.core/util/debounce.go.
Instead:
ui_impl.goThis preserves existing generic debounce behavior for other call sites.
Add a small constant such as:
const firstFlushMaxWaitMs = 96
Policy rules:
firstFlushMaxWaitMs expiresDo not increase the existing tick interval in this phase.
After the first visible snapshot has been committed:
This phase is intentionally narrow: first visible snapshot quality only.
Run:
cmd.exe /c "cd /d C:\dev\Wox\wox.core && go test ./test -run TestQueryFirstFlush -count=1 -v"
Expected:
TestQueryFirstFlushWaitsForCompetitiveSnapshot passes because the first visible non-final response already contains the strong top1TestQueryFirstFlushMaxWaitStillShowsSingleResult passes because single-result queries still paint before final completionFiles:
Modify as needed: /mnt/c/dev/Wox/wox.core/ui/ui_impl.go
Modify as needed: /mnt/c/dev/Wox/wox.core/plugin/manager.go
Modify as needed: /mnt/c/dev/Wox/wox.core/test/query_session_stability_test.go
Step 1: Run the full backend build verification required by repo rules
Run:
cmd.exe /c "cd /d C:\dev\Wox\wox.core && go build ./..."
cd /mnt/c/dev/Wox/wox.core && make build
Expected:
go build ./... succeeds
make build succeeds in a correctly provisioned backend environment
Step 2: Re-run one existing smoke slice to ensure no unrelated query regression
Run:
cmd.exe /c "cd /d C:\dev\Wox\wox.core && go test ./test -run TestSystemPlugin -count=1"
Expected:
existing query smoke coverage still passes
Step 3: Record Phase 2 boundary in code comments where needed
If a short comment is necessary, clarify that this phase only gates first visible commit quality and intentionally does not yet implement:
Keep comments concise and in English.
After verification, stop. Do not continue into session-aware ranking in the same branch without a separate plan. The next phase should target: