Skip to content

Commit b6cc6ed

Browse files
author
i2cjak
authored
Merge pull request #457 from BackplaneWorks/backplane/settle-fresh-qualified
Reopen settled threads for fresh owned work
2 parents bfc485b + c37de9e commit b6cc6ed

6 files changed

Lines changed: 297 additions & 15 deletions

File tree

‎LAWS.bend‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12522,3 +12522,18 @@ law codex_error_notice_no_effects:
1252212522
for now: Nat
1252312523
for o: J.Json
1252412524
{H.Step.outs_of(H.Codex.error.step(s, th, now, o)) == [] : List<&2, H.Out>}
12525+
12526+
# A distinct owned identity starts new work even while the turn runs.
12527+
law life_fresh_owned_wakes:
12528+
{H.Shelve.step(H.Shelve.demo([M.ThreadSettled{"t1", True{}, 3n}]), [M.WorkSet{"t1", "bg", "new\tx", 4n}]) == [M.ThreadWoke{"t1", 4n}] : List<&2, M.Change>}
12529+
12530+
# Updating that same job is progress, not a new start.
12531+
law life_owned_progress_held:
12532+
{H.Shelve.step(H.Shelve.demo([M.WorkSet{"t1", "bg", "old\tx", 2n}, M.ThreadSettled{"t1", True{}, 3n}]), [M.WorkSet{"t1", "bg", "old\tmore", 4n}]) == [] : List<&2, M.Change>}
12533+
12534+
law life_fresh_child_wakes:
12535+
{H.Shelve.step(H.Shelve.demo([M.ThreadSettled{"t1", True{}, 3n}]), [M.TaskDelegated{"k1", "t1", "child", 1n, "codex", "", 4n}]) == [M.ThreadWoke{"t1", 4n}] : List<&2, M.Change>}
12536+
12537+
# The person's later settle is authoritative within a transaction too.
12538+
law life_later_manual_settle_held:
12539+
{H.Shelve.step(H.Shelve.demo([]), [M.WorkSet{"t1", "bg", "new\tx", 4n}, M.ThreadSettled{"t1", True{}, 4n}]) == [] : List<&2, M.Change>}

‎PROOF.bend‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13294,3 +13294,15 @@ def mail_silent_bot_envelope(s, now, th, text): {==}
1329413294

1329513295
def codex_error_notice_kind(): {==}
1329613296
def codex_error_notice_no_effects(s, th, now, o): {==}
13297+
13298+
def Laws.life_fresh_owned_wakes():
13299+
{==}
13300+
13301+
def Laws.life_owned_progress_held():
13302+
{==}
13303+
13304+
def Laws.life_fresh_child_wakes():
13305+
{==}
13306+
13307+
def Laws.life_later_manual_settle_held():
13308+
{==}

‎scripts/sidebar-draft-inputs.json‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
"src/core/mailview.bend": "e1cac757c5f34457a745f095642f6675befed68d5b87aae30f14b706dff015b1",
7070
"src/core/mech.bend": "79fb3307d0d6868a777924d4b934ac8a1671937e265942467f6c60cc4db82efb",
7171
"src/core/menu.bend": "807668923de70eaabb72ddb760f808cbf6d786b70822ba6a1180776758af7eee",
72-
"src/core/model.bend": "5a67e9bdca81f35c2f151c541277b117600eaf352b38e0b99ccea3f6abe9eadf",
72+
"src/core/model.bend": "3d66f2339799f2dc8c5353f9e45066b79fc5a401cc59a9f6fdf6dfd7916c8c71",
7373
"src/core/msgs.bend": "dfc361d44ee34a12f8ba8628498032f6943668c3428c00db25ef9cb7477f4f3c",
7474
"src/core/notice.bend": "ee87318c1f12fc6cfb23bb5e24e90709e1f9a2eadfd2832581d21590f596e5e0",
7575
"src/core/onboard.bend": "55ccccf20f706a0acad492de20e23aedc751c7e9ce61b6f3430bfd65796e9232",
@@ -239,7 +239,17 @@
239239
"scope": "Only three added catalog keys and deterministic generated lookup-tree repartition. Existing catalog text and named sidebar labels, draft readers, keys and unknown@ retention are unchanged. Conservative source-reference graph is not a compiler AST proof.",
240240
"fullOutputCheck": "test/sidebar_draft_image_test.bend",
241241
"assertions": 24
242+
},
243+
"freshOwnedSettlement": {
244+
"changedClosureFiles": [
245+
"src/core/model.bend"
246+
],
247+
"reachableFunctions": 873,
248+
"changedReachableBodies": [],
249+
"kind": "Conservative source reference graph, not compiler AST proof. New Shelve helpers are outside sidebar projection; model change is comment-only; draft readers/unknown@ policy unchanged.",
250+
"fullOutputAssertions": 24,
251+
"sourceSnapshot": "/home/h/Documents/i2cjak/bp-coord/settle-fresh-work/SOURCE-structural-correction.json"
242252
}
243253
},
244-
"reviewNote": "Image lightbox labels: three catalog additions; unchanged873 sidebar reachable bodies/readers.24 affected full-output checks passed; unknown@ and full-main/picture freshness preserved; fail-closed guard unchanged."
254+
"reviewNote": "Fresh owned-work settlement: new Shelve helpers outside unchanged sidebar projection; model comment only. Conservative graph and24 full-output checks retain draft/unknown@/picture semantics."
245255
}

‎src/core/hub.bend‎

Lines changed: 143 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6493,18 +6493,148 @@ def Shelve.fresh.u(r: M.Role, +t: String, +th: String) -> Bool:
64936493
case _:
64946494
False{}
64956495

6496-
# whether the step brings the thread new input: a message for it (not the
6497-
# agent's own) or one queued for it (Lifecycle.wake.fresh)
6498-
def Shelve.fresh(cs: List<&2, M.Change>, +th: String) -> Bool:
6499-
match cs:
6500-
case Nil{}:
6501-
False{}
6502-
case M.MessagePosted{+t, _, r, _, _} <> rest:
6503-
Bool.or(Shelve.fresh.u(r, t, th), Shelve.fresh(rest, th))
6504-
case M.TurnQueued{+t, _, _, _} <> rest:
6505-
Bool.or(String.eq(t, th), Shelve.fresh(rest, th))
6496+
# These local identity scans return at the first match. The tail calls
6497+
# stay bounded in stack even when a manually settled thread has a long log.
6498+
def Shelve.rows.has.go(xs: List<&2, String>, +id: String, found: Bool) -> Bool:
6499+
match xs:
6500+
case Nil{}: found
6501+
case +l <> rest:
6502+
match found:
6503+
case True{}: True{}
6504+
case False{}: Shelve.rows.has.go(rest, id, M.Bg.is(l, id))
6505+
6506+
def Shelve.rows.has(xs: List<&2, String>, +id: String) -> Bool:
6507+
Shelve.rows.has.go(xs, id, False{})
6508+
6509+
# Snapshot updates count as fresh work only when they introduce a live
6510+
# identity. Progress, launch acknowledgments and completions keep the same
6511+
# identity and do not undo a manual settle, even if the busy count changes.
6512+
def Shelve.rows.fresh.go(xs: List<&2, String>, +old: List<&2, String>, found: Bool) -> Bool:
6513+
match xs:
6514+
case Nil{}: found
6515+
case +l <> rest:
6516+
match found:
6517+
case True{}: True{}
6518+
case False{}:
6519+
Shelve.rows.fresh.go(rest, old, Bool.and(Bool.not(M.Bg.ended(l)), Bool.and(Bool.not(String.is_empty(M.Bg.field(l, 0n))), Bool.not(Shelve.rows.has(old, M.Bg.field(l, 0n))))))
6520+
6521+
def Shelve.rows.fresh(xs: List<&2, String>, +old: List<&2, String>) -> Bool:
6522+
Shelve.rows.fresh.go(xs, old, False{})
6523+
6524+
def Shelve.queue.has.go(qs: List<&2, M.QItem>, +msg: String, found: Bool) -> Bool:
6525+
match qs:
6526+
case Nil{}: found
6527+
case M.QItem{+id, _} <> rest:
6528+
match found:
6529+
case True{}: True{}
6530+
case False{}: Shelve.queue.has.go(rest, msg, String.eq(id, msg))
6531+
6532+
def Shelve.queue.has(qs: List<&2, M.QItem>, +msg: String) -> Bool:
6533+
Shelve.queue.has.go(qs, msg, False{})
6534+
6535+
def Shelve.input.seen.go(es: List<&2, M.Entry>, +msg: String, found: Bool) -> Bool:
6536+
match es:
6537+
case Nil{}: found
6538+
case M.Msg{+id, _, _, _, _} <> rest:
6539+
match found:
6540+
case True{}: True{}
6541+
case False{}: Shelve.input.seen.go(rest, msg, String.eq(id, msg))
65066542
case _ <> rest:
6507-
Shelve.fresh(rest, th)
6543+
match found:
6544+
case True{}: True{}
6545+
case False{}: Shelve.input.seen.go(rest, msg, False{})
6546+
6547+
def Shelve.input.seen(es: List<&2, M.Entry>, +msg: String) -> Bool:
6548+
Shelve.input.seen.go(es, msg, False{})
6549+
6550+
# Check the small queue before consulting the thread's history.
6551+
def Shelve.input.new.k(queued: Bool, +s: M.State, +th: String, +msg: String) -> Bool:
6552+
match queued:
6553+
case True{}: False{}
6554+
case False{}: Bool.not(Shelve.input.seen(M.State.mine(s, th), msg))
6555+
6556+
def Shelve.input.new(+s: M.State, +th: String, +msg: String) -> Bool:
6557+
Shelve.input.new.k(Shelve.queue.has(M.Queue.items(s, th), msg), s, th, msg)
6558+
6559+
# Real activity is accepted at its event boundary, against the state just
6560+
# before it. Older callbacks cannot supersede a later manual settlement.
6561+
def Shelve.recent.k(o: M.Override, +sa: Nat, +at: Nat) -> Bool:
6562+
match o:
6563+
case M.ForcedSettled{}: Nat.is_ge(at, sa)
6564+
case _: True{}
6565+
6566+
def Shelve.recent(+s: M.State, +th: String, +at: Nat) -> Bool:
6567+
Shelve.recent.k(M.Lifecycle.override(M.State.thread.get(s, th)), M.Lifecycle.settled_at(M.State.thread.get(s, th)), at)
6568+
6569+
# Only a recent user message for this thread may read its history.
6570+
def Shelve.input.recent(recent: Bool, +s: M.State, +th: String, +msg: String) -> Bool:
6571+
match recent:
6572+
case False{}: False{}
6573+
case True{}: Shelve.input.new(s, th, msg)
6574+
6575+
def Shelve.input.for(hit: Bool, +s: M.State, +th: String, +msg: String, +at: Nat) -> Bool:
6576+
match hit:
6577+
case False{}: False{}
6578+
case True{}: Shelve.input.recent(Shelve.recent(s, th, at), s, th, msg)
6579+
6580+
def Shelve.input.role(r: M.Role, +s: M.State, +t: String, +th: String, +msg: String, +at: Nat) -> Bool:
6581+
match r:
6582+
case M.User{}: Shelve.input.for(String.eq(t, th), s, th, msg, at)
6583+
case _: False{}
6584+
6585+
def Shelve.fresh.event(+s: M.State, c: M.Change, +th: String) -> Bool:
6586+
match c:
6587+
case M.MessagePosted{+t, +msg, r, _, +at}:
6588+
Shelve.input.role(r, s, t, th, msg, at)
6589+
case M.TurnQueued{+t, +msg, _, +at}:
6590+
Bool.and(String.eq(t, th), Bool.and(Shelve.recent(s, th, at), Bool.not(Shelve.queue.has(M.Queue.items(s, th), msg))))
6591+
case M.WorkSet{+t, +kind, rows, +at}:
6592+
Bool.and(String.eq(t, th), Bool.and(Shelve.recent(s, th, at), Bool.and(Bool.or(String.eq(kind, "bg"), String.eq(kind, "watch")),
6593+
Shelve.rows.fresh(M.Bg.lines(rows), M.Bg.lines(M.Setting.get(s, kind ++ "." ++ th, ""))))))
6594+
case M.TaskDelegated{+id, +parent, _, _, _, _, +at}:
6595+
Bool.and(String.eq(parent, th), Bool.and(Shelve.recent(s, th, at), String.is_empty(M.Lifecycle.task.parent(s, id))))
6596+
case M.TurnChanged{+t, M.Running{}, +at}:
6597+
Bool.and(String.eq(t, th), Bool.and(Shelve.recent(s, th, at), Bool.not(M.State.running.k(M.State.thread.get(s, th)))))
6598+
case _: False{}
6599+
6600+
# A settle later in the same transaction wins over the work before it;
6601+
# work accepted after that settle can wake it, including in the same second.
6602+
def Shelve.hold(c: M.Change, +th: String) -> Bool:
6603+
match c:
6604+
case M.ThreadSettled{+t, _, _}: String.eq(t, th)
6605+
case M.ThreadMerged{+t, _, _}: String.eq(t, th)
6606+
case _: False{}
6607+
6608+
def Shelve.held.go(cs: List<&2, M.Change>, +th: String, found: Bool) -> Bool:
6609+
match cs:
6610+
case Nil{}: found
6611+
case +c <> rest:
6612+
match found:
6613+
case True{}: True{}
6614+
case False{}: Shelve.held.go(rest, th, Shelve.hold(c, th))
6615+
6616+
def Shelve.held(cs: List<&2, M.Change>, +th: String) -> Bool:
6617+
Shelve.held.go(cs, th, False{})
6618+
6619+
def Shelve.fresh.next(hold: Bool, fresh: Bool, +s: M.State, c: M.Change, +th: String) -> Bool:
6620+
match hold:
6621+
case True{}: False{}
6622+
case False{}:
6623+
match fresh:
6624+
case True{}: True{}
6625+
case False{}: Shelve.fresh.event(s, c, th)
6626+
6627+
def Shelve.fresh.go(cs: List<&2, M.Change>, +s: M.State, +th: String, fresh: Bool) -> Bool:
6628+
match cs:
6629+
case Nil{}: fresh
6630+
case +c <> rest:
6631+
Shelve.fresh.go(rest, M.State.apply.go(s, c), th, Shelve.fresh.next(Shelve.hold(c, th), fresh, s, c, th))
6632+
6633+
# Active streaming threads skip the event scan entirely.
6634+
def Shelve.fresh.on(sh: M.Shelf, cs: List<&2, M.Change>, +pre: M.State, +th: String) -> Bool:
6635+
match sh:
6636+
case M.Settled{}: Shelve.fresh.go(cs, pre, th, False{})
6637+
case _: False{}
65086638

65096639
def Shelve.one.k(wake: Bool, done: Bool, +th: String, +at: Nat, +t: M.Thread, rest: List<&2, M.Change>) -> List<&2, M.Change>:
65106640
match wake done:
@@ -6524,7 +6654,8 @@ def Shelve.wake(+pre: M.State, +post: M.State, +k0: Map<&2, Nat>, +k1: Map<&2, N
65246654
Shelve.wake.k(M.Lifecycle.working(k0, pre, M.State.thread.get(pre, th)), M.Lifecycle.working(k1, post, M.State.thread.get(post, th)), fresh, post, th)
65256655

65266656
def Shelve.one(+cs: List<&2, M.Change>, +pre: M.State, +post: M.State, +k0: Map<&2, Nat>, +k1: Map<&2, Nat>, +navs: Map<&2, M.Nav>, +th: String, +at: Nat, rest: List<&2, M.Change>) -> List<&2, M.Change>:
6527-
Shelve.one.k(Shelve.wake(pre, post, k0, k1, th, Shelve.fresh(cs, th)), M.Lifecycle.done(k1, post, M.State.thread.get(post, th), M.Snooze.on(at, M.Nav.until(M.Nav.get(navs, th)))),
6657+
Shelve.one.k(Bool.or(Bool.and(Bool.and(Bool.not(Shelve.held(cs, th)), Shelve.recent(pre, th, at)), Shelve.wake(pre, post, k0, k1, th, False{})),
6658+
M.Lifecycle.wake.fresh(Shelve.fresh.on(M.Shelf.of(M.State.thread.get(post, th)), cs, pre, th), M.Lifecycle.working(k1, post, M.State.thread.get(post, th)), M.Shelf.of(M.State.thread.get(post, th)))), M.Lifecycle.done(k1, post, M.State.thread.get(post, th), M.Snooze.on(at, M.Nav.until(M.Nav.get(navs, th)))),
65286659
th, at, M.State.thread.get(post, th), rest)
65296660

65306661
def Shelve.go(xs: List<&2, SvAt>, +cs: List<&2, M.Change>, +pre: M.State, +post: M.State, +k0: Map<&2, Nat>, +k1: Map<&2, Nat>, +navs: Map<&2, M.Nav>) -> List<&2, M.Change>:

‎src/core/model.bend‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type TurnState is Data:
2727
Interrupted{}
2828
Failed{}
2929

30-
# A manual settle/unsettle pins the thread's shelf until the other is chosen.
30+
# A manual settle/unsettle holds the shelf until fresh real work resumes.
3131
type Override is Data:
3232
NoOverride{}
3333
ForcedSettled{}

0 commit comments

Comments
 (0)