Repository navigation
feat(api): abort signal support for openai, openai-compatible base, zai, kimi-code (round 2) #1311
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
4e1d15f
99decd4
9552368
bec0067
0c85ad7
27e3e8e
87cf26e
8fd7f3b
24f4b49
d53d7eb
9e4a493
e08c03b
66e0e5b
b0bdbb9
9f63250
9109771
75f3eb4
3a0c160
cd6c8b4
bb99287
ffaea4c
90a7c84
266fa34
49f57b0
eb34dcd
a440365
06a9d28
822ed3e
c4ea3f3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| ---- MODULE KimiOAuthRefresh ---- | ||
| EXTENDS Naturals | ||
| \* Models the shared refresh state in src/integrations/kimi-code/oauth.ts. | ||
| \* Source: the caller detach in awaitRefresh. Sink: the credential write in writeCredentials. | ||
| \* Failure 1: a waiter that detaches while the server is answering drops the pair the server issued. | ||
| \* The provider rotated the refresh token, so that pair is the only copy of it. | ||
| \* Failure 2: a sign-out that lands during a refresh still lets that refresh write its pair. | ||
| \* Invariants: IssuedPairKept (failure 1), SignOutWins (failure 2). | ||
| \* Expected before any run: both invariants hold in the model. The sabotage variant fails in 2 states. | ||
| \* Run status: TLC was NOT run for this file. The machine that wrote it has no Java and no TLA+ jar, | ||
| \* so ./check.sh could not be executed. Run it before merging: TLA_JAR=<jar> ./check.sh KimiOAuthRefresh | ||
| \* Cost: 7 actions, 1 constant, 6 variables. The state space is small; expect under a second. | ||
| \* Not modeled: the device-flow polling, the request deadline, and the write chain ordering of two | ||
| \* concurrent saves. Those are covered by the unit rows in __tests__/oauth.spec.ts. | ||
| \* Review: written after the change. It is not an independent first pass. | ||
|
|
||
| CONSTANT Sabotage \* TRUE runs the sabotage variant: a detach during the answer drops the pair | ||
|
|
||
| VARIABLE phase \* "idle", "posted", "answered", "done" | ||
| VARIABLE waiters \* 0..2 callers enrolled in the one shared refresh | ||
| VARIABLE saved \* "old", "new", or "absent": the persisted pair | ||
| VARIABLE signedOut \* TRUE after a sign-out | ||
| VARIABLE gen \* credentials generation, the token a write must still hold | ||
| VARIABLE captured \* the generation the running refresh captured | ||
|
|
||
| vars == <<phase, waiters, saved, signedOut, gen, captured>> | ||
|
|
||
| TypeOK == | ||
| /\ phase \in {"idle", "posted", "answered", "done"} | ||
| /\ waiters \in 0..2 | ||
| /\ saved \in {"old", "new", "absent"} | ||
| /\ signedOut \in BOOLEAN | ||
| /\ gen \in 0..2 | ||
| /\ captured \in 0..2 | ||
|
|
||
| Init == | ||
| /\ phase = "idle" | ||
| /\ waiters = 0 | ||
| /\ saved = "old" | ||
| /\ signedOut = FALSE | ||
| /\ gen = 0 | ||
| /\ captured = 0 | ||
|
|
||
| \* A caller starts the shared refresh and captures the generation it will write under. | ||
| Start == | ||
| /\ phase = "idle" | ||
| /\ phase' = "posted" | ||
| /\ captured' = gen | ||
| /\ waiters' = 1 | ||
| /\ UNCHANGED <<saved, signedOut, gen>> | ||
|
|
||
| \* A second caller joins the same shared POST while another is still enrolled. | ||
| Join == | ||
| /\ phase = "posted" | ||
| /\ waiters >= 1 | ||
| /\ waiters < 2 | ||
| /\ waiters' = waiters + 1 | ||
| /\ UNCHANGED <<phase, saved, signedOut, gen, captured>> | ||
|
|
||
| \* The server answers. The rotated pair now exists in the response body. | ||
| Answer == | ||
| /\ phase = "posted" | ||
| /\ phase' = "answered" | ||
| /\ UNCHANGED <<waiters, saved, signedOut, gen, captured>> | ||
|
|
||
| \* A caller detaches. Cancelling one wait is allowed, and so is cancelling the last one; dropping | ||
| \* the answered pair is not. | ||
| Detach == | ||
| /\ waiters > 0 | ||
| /\ waiters' = waiters - 1 | ||
| /\ IF Sabotage /\ waiters = 1 /\ phase = "answered" | ||
| THEN /\ phase' = "done" | ||
| /\ saved' = "old" | ||
| /\ UNCHANGED <<signedOut, gen, captured>> | ||
| ELSE UNCHANGED <<phase, saved, signedOut, gen, captured>> | ||
|
|
||
| \* The write runs under the ownership check: the captured generation must still be current. | ||
| Store == | ||
| /\ phase = "answered" | ||
| /\ captured = gen | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Model a newer credential install during refresh. Only The implementation advances its generation when it installs credentials. Model this sequence: capture generation 0, install newer credentials, then complete the old refresh. Check that the old refresh preserves the newer credentials. As per coding guidelines, model “The actions and every order of them.”
|
||
| /\ ~signedOut | ||
| /\ phase' = "done" | ||
| /\ saved' = "new" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate retained credentials from persisted credentials. The stated contract permits storage to fail after the server rotates the pair. Memory must retain that pair for the next request.
Add separate memory and storage states. Model storage rejection and check which pair the next request receives. As per coding guidelines, model “The actions and every order of them.”
|
||
| /\ UNCHANGED <<waiters, signedOut, gen, captured>> | ||
|
|
||
| \* A refresh can settle without a write only when a sign-out already took the credentials. | ||
| Settle == | ||
| /\ phase = "answered" | ||
| /\ signedOut | ||
| /\ phase' = "done" | ||
| /\ UNCHANGED <<waiters, saved, signedOut, gen, captured>> | ||
|
|
||
| \* Sign-out advances the generation and deletes the pair, during a refresh or after it. The | ||
| \* post-delete state is "absent": keeping the old pair is not a completed sign-out. | ||
| SignOut == | ||
| /\ ~signedOut | ||
| /\ signedOut' = TRUE | ||
| /\ gen' = gen + 1 | ||
| /\ saved' = "absent" | ||
| /\ UNCHANGED <<phase, waiters, captured>> | ||
|
|
||
| Next == Start \/ Join \/ Answer \/ Detach \/ Store \/ Settle \/ SignOut | ||
|
|
||
| Spec == Init /\ [][Next]_vars | ||
|
|
||
| \* Failure 1: the server answered and nobody signed out, so the persisted pair is the issued one. | ||
| IssuedPairKept == phase = "done" /\ ~signedOut => saved = "new" | ||
|
easonLiangWorldedtech marked this conversation as resolved.
Resolved
|
||
|
|
||
| \* Failure 2: a sign-out during a refresh keeps the store from landing after it. | ||
| SignOutWins == signedOut => saved = "absent" | ||
| ==== | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Uh oh!
There was an error while loading. Please reload this page.