Add a frame-hold verification skill and TLA+ model shared by Claude Code and Codex

- Add GVFG_SDK/sdk/gvfg/formal: a TLA+ model of one channel's frame-hold protocol (read, release, stop, start and signal-change recovery) and six TLC configs: the shipped code with the reader joined before stop/start and with it running across them, and four mutations that must fail.
- Add .agents/skills/verify-gvfg-frame-hold: check.ps1 runs every config against its expected result, prints counterexamples with -Trace, and reports when the covered code moves past the sync commit; f1-hardware-repro.ps1 stages a stop and start during a read on a real card.
- Add a Claude Code entry in .claude/skills that points to the shared copy, and notes on which steps must run outside the Codex Windows sandbox.

Validation: git diff --cached --check passed. check.ps1 met all six expectations and reported the model in step with 1d89392. f1-hardware-repro.ps1 reproduced the stuck channel against b47f27b and passed against 1d89392 on a GIGABYTE SDI VFG100. TLC needs Java 17+ and tla2tools 1.7.4; check.ps1 -Install fetches the jar into the git-ignored formal/tools. Not yet run from Codex.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 16:46:15 +08:00
co-authored by Claude Opus 5.5
parent 1d89392cef
commit 208fb6c811
13 changed files with 983 additions and 0 deletions
@@ -0,0 +1,193 @@
// F1 on real hardware, deterministically: stop + start while a read sits between
// capture and delivery. A frame processor (the hook OSD uses) parks the reader in
// exactly that window, so no timing luck is needed.
//
// Exit 0: fixed behaviour (the read is rejected, the next read works).
// Exit 1: F1 reproduced (stale frame delivered, release rejected or channel stuck).
// Exit 2: not verifiable here (no device / no signal). Exit 3: unexpected result.
#include <windows.h>
#include <chrono>
#include <condition_variable>
#include <cstdio>
#include <mutex>
#include <thread>
#include "gvfg_capture.h"
#include "gvfg_frame_processor.h"
namespace
{
std::mutex g_mutex;
std::condition_variable g_cv;
bool g_armed = false;
bool g_parked = false;
bool g_resume = false;
gvfg_status_t parkerCreate(void **context)
{
*context = nullptr;
return GVFG_OK;
}
void parkerDestroy(void *) {}
gvfg_status_t parkerProcess(void *, const gvfg_frame_t &in, gvfg_frame_t &out, bool &applied,
gvfg_debug_osd_frame_timing_t *, uint8_t *, bool *inPlace)
{
out = in;
applied = false; // keep the backend hold, like OSD off / in-place OSD
if (inPlace)
*inPlace = false;
std::unique_lock<std::mutex> lock(g_mutex);
if (g_armed)
{
g_armed = false;
g_parked = true;
g_cv.notify_all();
g_cv.wait(lock, [] { return g_resume; });
}
return GVFG_OK;
}
gvfg_status_t parkerControl(void *, const void *) { return GVFG_OK; }
const gvfg_frame_processor kParker{parkerCreate, parkerDestroy, parkerProcess};
const char *name(gvfg_status_t status) { return gvfg_strerror(status); }
void lastError(gvfg_handle handle, const char *label)
{
char message[512] = {};
gvfg_get_channel_last_sdk_error_detail(handle, GVFG_CHANNEL_0, message, sizeof(message));
std::printf(" %-16s last SDK error: %s\n", label, message[0] ? message : "(none)");
}
}
int main()
{
std::printf("GVFG SDK %s\n", gvfg_get_version());
if (gvfg_enumerate_devices(nullptr, 0) < 1)
{
std::puts("NOT VERIFIED: no GVFG device");
return 2;
}
gvfg_handle handle = nullptr;
if (gvfg_create(&handle) != GVFG_OK || gvfg_open_channel(handle, 0, GVFG_CHANNEL_0) != GVFG_OK)
{
std::puts("NOT VERIFIED: cannot open device 0 channel 0");
return 2;
}
gvfg_status_t st = gvfg_start_channel(handle, GVFG_CHANNEL_0);
if (st != GVFG_OK)
{
std::printf("NOT VERIFIED: start failed (%s); is a signal connected?\n", name(st));
gvfg_destroy(handle);
return 2;
}
st = gvfg_control_frame_processor(handle, GVFG_CHANNEL_0, &kParker, true, parkerControl, nullptr,
"attach parker failed");
if (st != GVFG_OK)
{
std::printf("UNEXPECTED: cannot attach frame processor (%s)\n", name(st));
gvfg_destroy(handle);
return 3;
}
// Warm up: capture really flows before the race.
int warm = 0;
for (int i = 0; i < 20 && warm < 5; ++i)
{
gvfg_frame_t frame{};
if (gvfg_read_channel_frame(handle, GVFG_CHANNEL_0, &frame, 1000) == GVFG_OK)
{
++warm;
gvfg_release_channel_frame(handle, GVFG_CHANNEL_0, &frame);
}
}
if (warm < 5)
{
std::puts("NOT VERIFIED: frames are not flowing");
gvfg_destroy(handle);
return 2;
}
{
std::lock_guard<std::mutex> lock(g_mutex);
g_armed = true;
}
gvfg_status_t readStatus = GVFG_ETIMEOUT;
gvfg_status_t releaseStatus = GVFG_ETIMEOUT;
bool released = false;
std::thread reader([&] {
gvfg_frame_t frame{};
readStatus = gvfg_read_channel_frame(handle, GVFG_CHANNEL_0, &frame, 2000);
if (readStatus == GVFG_OK)
{
released = true;
releaseStatus = gvfg_release_channel_frame(handle, GVFG_CHANNEL_0, &frame);
}
});
bool parked = false;
{
std::unique_lock<std::mutex> lock(g_mutex);
parked = g_cv.wait_for(lock, std::chrono::seconds(5), [] { return g_parked; });
}
gvfg_status_t stopStatus = GVFG_ETIMEOUT;
gvfg_status_t startStatus = GVFG_ETIMEOUT;
if (parked)
{
stopStatus = gvfg_stop_channel(handle, GVFG_CHANNEL_0);
startStatus = gvfg_start_channel(handle, GVFG_CHANNEL_0);
}
{
std::lock_guard<std::mutex> lock(g_mutex);
g_resume = true;
}
g_cv.notify_all();
reader.join();
lastError(handle, "after race:");
gvfg_status_t nextRead = GVFG_ETIMEOUT;
gvfg_status_t nextRelease = GVFG_ETIMEOUT;
for (int i = 0; i < 5 && nextRead != GVFG_OK; ++i)
{
gvfg_frame_t frame{};
nextRead = gvfg_read_channel_frame(handle, GVFG_CHANNEL_0, &frame, 1000);
if (nextRead == GVFG_OK)
nextRelease = gvfg_release_channel_frame(handle, GVFG_CHANNEL_0, &frame);
else if (nextRead == GVFG_ESTATE)
break; // ESTATE here means the channel is stuck; retrying will not help
}
lastError(handle, "after next read:");
std::printf("parked in window : %s\n", parked ? "yes" : "no");
std::printf("stop / start : %s / %s\n", name(stopStatus), name(startStatus));
std::printf("racing read : %s\n", name(readStatus));
std::printf("its release : %s\n", released ? name(releaseStatus) : "(not called: no frame)");
std::printf("next read : %s (release %s)\n", name(nextRead),
nextRead == GVFG_OK ? name(nextRelease) : "-");
gvfg_stop_channel(handle, GVFG_CHANNEL_0);
gvfg_destroy(handle);
if (!parked || stopStatus != GVFG_OK || startStatus != GVFG_OK)
{
std::puts("RESULT: UNEXPECTED (race not staged)");
return 3;
}
if (readStatus == GVFG_OK && (releaseStatus != GVFG_OK || nextRead != GVFG_OK))
{
std::puts("RESULT: F1 REPRODUCED (stale frame delivered after stop->start)");
return 1;
}
if (readStatus != GVFG_OK && nextRead == GVFG_OK && nextRelease == GVFG_OK)
{
std::puts("RESULT: FIXED (racing read rejected, channel keeps working)");
return 0;
}
std::puts("RESULT: UNEXPECTED");
return 3;
}