fix: bind experimental rechecks to recovery transaction hooks
An isolated SHA-verified replay reproduces exit 78 at managed_experimental_recovery.go:148 with the nested required-hooks guard at managed_transaction.go:69. The production recheck closure retained the adapter path-only transaction instead of the job-bound transaction. Pass the current transaction explicitly without weakening ownership, Lua, runtime or reconciliation guards. Regression starts recovery with path-only hooks and checks bound ownership for cold/adaptive rechecks. Full native Go tests, affected race tests, go vet and diff checks passed. Corrected image replay and production restoration remain unverified. Co-authored-by: GPT-6 <gpt-6@openai.com>
This commit is contained in:
1 parent
1afee7d3bd
commit
fd25cb8939
4 files changed
+49
-36
No files matched your search
@@ -70,7 +70,7 @@ func TestExperimentalProductionProbeCollectorClassification(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
calls := 0
|
calls := 0
|
||||||
d.recheckExperimental = func(_ context.Context, c storedCandidate, r mediaResource) error {
|
d.recheckExperimental = func(_ context.Context, c storedCandidate, r mediaResource, _ *managedTransaction) error {
|
||||||
if c.ID != id || !freshExperimentalMedia(r) {
|
if c.ID != id || !freshExperimentalMedia(r) {
|
||||||
t.Fatal("recovery changed candidate or lost fresh media")
|
t.Fatal("recovery changed candidate or lost fresh media")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ func recoverManagedExperimental(ctx context.Context, d managedRecoveryDeps) (int
|
|||||||
if experimentalGooglevideo(j.Scope, c) {
|
if experimentalGooglevideo(j.Scope, c) {
|
||||||
r, err := experimentalMedia(ctx, d)
|
r, err := experimentalMedia(ctx, d)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
err = d.recheckExperimental(ctx, c, r)
|
err = d.recheckExperimental(ctx, c, r, d.transaction)
|
||||||
}
|
}
|
||||||
return id, managedRecoveryContextError(ctx, err)
|
return id, managedRecoveryContextError(ctx, err)
|
||||||
}
|
}
|
||||||
@@ -68,42 +68,46 @@ func recoverManagedExperimental(ctx context.Context, d managedRecoveryDeps) (int
|
|||||||
return 0, &managedRecoveryFatal{Err: errors.New("owned experimental candidate missing")}
|
return 0, &managedRecoveryFatal{Err: errors.New("owned experimental candidate missing")}
|
||||||
}
|
}
|
||||||
|
|
||||||
func newManagedExperimentalRecheck(target managedDeps, d managedRecoveryDeps) func(context.Context, storedCandidate, mediaResource) error {
|
func newManagedExperimentalRecheck(target managedDeps, d managedRecoveryDeps) func(context.Context, storedCandidate, mediaResource, *managedTransaction) error {
|
||||||
runtime := newManagedAssetRuntime(target)
|
runtime := newManagedAssetRuntime(target)
|
||||||
guard := func() error {
|
return func(ctx context.Context, c storedCandidate, resource mediaResource, transaction *managedTransaction) error {
|
||||||
if err := runtime.guard(); err != nil {
|
// The adapter is constructed with path-only dependencies. Use this job's
|
||||||
return err
|
// bound hooks for ownership checks and reconciliation, not that stale copy.
|
||||||
}
|
d := d
|
||||||
lua, err := os.ReadFile("/opt/zapret2/lua/zapret-auto.lua")
|
d.transaction = transaction
|
||||||
if err != nil || fmt.Sprintf("%x", sha256.Sum256(lua)) != managedGooglevideoLuaHash {
|
guard := func() error {
|
||||||
return errors.New("unverified native automation Lua source")
|
if err := runtime.guard(); err != nil {
|
||||||
}
|
return err
|
||||||
_, err = d.transaction.ActiveCandidates(d.db)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
restart := func(ctx context.Context) (err error) {
|
|
||||||
// Existing daemon protocol stops/joins before starting the same full set.
|
|
||||||
// Never activate a pending or drifted deployment after a partial stop.
|
|
||||||
defer func() {
|
|
||||||
if err != nil {
|
|
||||||
cleanup, cancel := context.WithTimeout(context.WithoutCancel(ctx), 30*time.Second)
|
|
||||||
defer cancel()
|
|
||||||
if e := d.transaction.Reconcile(d.db); e != nil {
|
|
||||||
err = errors.Join(err, e)
|
|
||||||
} else {
|
|
||||||
err = errors.Join(err, d.run(cleanup, managedZapretScript, "start"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}()
|
lua, err := os.ReadFile("/opt/zapret2/lua/zapret-auto.lua")
|
||||||
if err = d.run(ctx, managedZapretScript, "stop"); err != nil {
|
if err != nil || fmt.Sprintf("%x", sha256.Sum256(lua)) != managedGooglevideoLuaHash {
|
||||||
|
return errors.New("unverified native automation Lua source")
|
||||||
|
}
|
||||||
|
_, err = d.transaction.ActiveCandidates(d.db)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err = d.transaction.Reconcile(d.db); err != nil {
|
restart := func(ctx context.Context) (err error) {
|
||||||
return err
|
// Existing daemon protocol stops/joins before starting the same full set.
|
||||||
|
// Never activate a pending or drifted deployment after a partial stop.
|
||||||
|
defer func() {
|
||||||
|
if err != nil {
|
||||||
|
cleanup, cancel := context.WithTimeout(context.WithoutCancel(ctx), 30*time.Second)
|
||||||
|
defer cancel()
|
||||||
|
if e := d.transaction.Reconcile(d.db); e != nil {
|
||||||
|
err = errors.Join(err, e)
|
||||||
|
} else {
|
||||||
|
err = errors.Join(err, d.run(cleanup, managedZapretScript, "start"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
if err = d.run(ctx, managedZapretScript, "stop"); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err = d.transaction.Reconcile(d.db); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return d.run(ctx, managedZapretScript, "start")
|
||||||
}
|
}
|
||||||
return d.run(ctx, managedZapretScript, "start")
|
|
||||||
}
|
|
||||||
return func(ctx context.Context, c storedCandidate, resource mediaResource) error {
|
|
||||||
if !experimentalGooglevideo(GooglevideoScopeExperimental, c) {
|
if !experimentalGooglevideo(GooglevideoScopeExperimental, c) {
|
||||||
return &managedRecoveryFatal{Err: errors.New("unaudited experimental candidate")}
|
return &managedRecoveryFatal{Err: errors.New("unaudited experimental candidate")}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,13 +96,22 @@ func TestExperimentalServiceRecoveryPreservesOwnership(t *testing.T) {
|
|||||||
return managedServiceInventory{media: experimentalResourceFixture()}, &managedResourceFailure{"avatar", "yt3.ggpht.com", nil}
|
return managedServiceInventory{media: experimentalResourceFixture()}, &managedResourceFailure{"avatar", "yt3.ggpht.com", nil}
|
||||||
}
|
}
|
||||||
calls := 0
|
calls := 0
|
||||||
d.recheckExperimental = func(_ context.Context, c storedCandidate, r mediaResource) error {
|
var boundTransaction *managedTransaction
|
||||||
|
d.recheckExperimental = func(_ context.Context, c storedCandidate, r mediaResource, transaction *managedTransaction) error {
|
||||||
calls++
|
calls++
|
||||||
|
boundTransaction = transaction
|
||||||
|
if transaction.Reload == nil || transaction.Health == nil {
|
||||||
|
t.Fatal("recheck retained path-only adapter transaction")
|
||||||
|
}
|
||||||
|
assertActiveCandidates(t, transaction, d.db, ids)
|
||||||
if c.ID != id || !freshExperimentalMedia(r) {
|
if c.ID != id || !freshExperimentalMedia(r) {
|
||||||
t.Fatal("wrong committed candidate/resource")
|
t.Fatal("wrong committed candidate/resource")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// Production adapters carry paths only until recoverManagedTarget binds the
|
||||||
|
// job's reload/health hooks. The recheck must receive that bound transaction.
|
||||||
|
d.transaction.Reload, d.transaction.Health = nil, nil
|
||||||
for _, adaptive := range []bool{false, true} {
|
for _, adaptive := range []bool{false, true} {
|
||||||
d.adaptive = adaptive
|
d.adaptive = adaptive
|
||||||
result, err := recoverManagedTarget(context.Background(), d)
|
result, err := recoverManagedTarget(context.Background(), d)
|
||||||
@@ -130,7 +139,7 @@ func TestExperimentalServiceRecoveryPreservesOwnership(t *testing.T) {
|
|||||||
if err := monitor.probe(context.Background()); err != nil || reports != 1 {
|
if err := monitor.probe(context.Background()); err != nil || reports != 1 {
|
||||||
t.Fatalf("operational probe: %v reports=%d", err, reports)
|
t.Fatalf("operational probe: %v reports=%d", err, reports)
|
||||||
}
|
}
|
||||||
assertActiveCandidates(t, d.transaction, d.db, ids)
|
assertActiveCandidates(t, boundTransaction, d.db, ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestExperimentalRefreshAndMixedFatalPrecedence(t *testing.T) {
|
func TestExperimentalRefreshAndMixedFatalPrecedence(t *testing.T) {
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ type managedRecoveryDeps struct {
|
|||||||
adaptive bool
|
adaptive bool
|
||||||
mediaSamples func(context.Context) ([]mediaResource, error)
|
mediaSamples func(context.Context) ([]mediaResource, error)
|
||||||
verifyGooglevideo func(context.Context, storedCandidate, []mediaResource) (GooglevideoQualificationProof, error)
|
verifyGooglevideo func(context.Context, storedCandidate, []mediaResource) (GooglevideoQualificationProof, error)
|
||||||
recheckExperimental func(context.Context, storedCandidate, mediaResource) error
|
recheckExperimental func(context.Context, storedCandidate, mediaResource, *managedTransaction) error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Target-local adapter: reuses bounded Player requests without invoking a CLI.
|
// Target-local adapter: reuses bounded Player requests without invoking a CLI.
|
||||||
|
|||||||
Reference in new issue
Block a user