Skip to content

feat(insights): derive session objective posture from open obligations - #3226

Merged
Sinity merged 4 commits into
masterfrom
feature/insights/objective-posture-projection
Jul 20, 2026
Merged

Sinity merged 4 commits into
masterfrom
feature/insights/objective-posture-projection

Conversation

@Sinity

@Sinity Sinity commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

Adds a session-level objective-posture projection — whether a
session's underlying goal remains open — derived from authority-bearing
evidence instead of process-termination text. It is separate from
SessionInferencePayload.terminal_state (how the process ended) and is
wired into the existing INSIGHT_REGISTRY session_profiles entry so
profiles, blocker extraction, resume ranking, and the context preamble
consume the same projection.

Problem

terminal_state describes structural tool/turn evidence at the end of a
session, not whether its objective was resolved. Since polylogue-ve9z
(#2960, landed after this bead was filed) deleted the prose-derived
clean_finish heuristic — measured at 50.5% agreement (a coin flip) with
structural truth — most well-behaved endings now collapse to
terminal_state="unknown": silence, not a completion claim. Two
downstream consumers still effectively read that silence as "probably
done":

  • Blocker-text extraction gated on a _UNRESOLVED_BLOCKER_TERMINAL_STATES
    allowlist that never included "unknown", so a session ending on a
    normal reply with an earlier user-reported blocker had that blocker
    text silently suppressed.
  • Resume ranking's _terminal_weight("unknown") == 0.25 (low), with a
    dead terminal_state == "clean_finish" exclusion filter that could
    never fire anymore.

Solution

New polylogue.insights.objective_posture module defines
ObjectivePosture / ObjectivePostureAuthority and an explicit
authority order: goal_graph (polylogue-7yk5) > work_evidence
(polylogue-1vpm.6) > assertion > structural_inference > none. The
top two tiers are not yet built (both are open epics), so this PR lands
the two that are:

  • structural_objective_posture — a bounded terminal_state mapping,
    index.db-only inputs, never emits "completed" (no structural
    signal available today observes a satisfied effect).
  • derive_objective_posture — overlays durable decision/blocker/
    handoff AssertionKind rows (user.db), which outrank structural
    inference. Multiple simultaneous assertion kinds are preserved as
    contradictions, not silently collapsed.

The assertion tier is a read-time overlay
(resolve_session_objective_posture), not baked into the materialized
session_profiles row, so index.db stays independently rebuildable
from source.db without a user.db dependency.

Wiring:

  • enrichment.objective_posture field on SessionProfileInsight
    (reconciled onto the native terminal_state column at read time —
    found and fixed in both existing reconciliation sites:
    insights.archive.SessionProfileInsight.from_record and the live
    SQL-backed _session_profile_components_from_archive_row).
  • Blocker-text extraction now gates on the shared posture mapping
    instead of the old parallel allowlist.
  • Resume ranking adds a posture-weighted score component and replaces
    the dead clean_finish exclusion with objective_posture != "completed".
  • resume_brief overlays the full assertion tier for its single session
    and surfaces a durably-declared obligation as the first next-step.
  • The context preamble surfaces posture per related session.
  • INSIGHT_REGISTRY session_profiles entry gains posture /
    posture_authority display fields; FTS enrichment search text
    includes the posture label.

Scope discrepancy vs. the bead text (honest disclosure)

The bead's AC1 example text ("terminal_state=clean_finish and
objective_posture=awaiting_operator simultaneously") references
clean_finish, which PR #2960 deleted the same day the bead was last
updated — that exact literal state no longer exists. The underlying
intent (a session with no structural error/pending signal must not be
silently treated as resolved) is fully addressed via the
terminal_state="unknown" case instead, and is directly covered by an
integration test (test_session_enrichment_payload_reuses_text_band_outputs).

The goal_graph (polylogue-7yk5) and work_evidence (polylogue-1vpm.6)
authority tiers are reserved slots only — both are open epics with no
storage substrate yet. Wiring them in is a bounded follow-on: the
precedence order and ObjectivePosturePayload shape do not need to
change.

AC matrix

  1. Partially satisfied / reframed. A session with terminal_state="unknown"
    (the honest post-refactor(insights): delete prose-keyword heuristics for terminal state and activity labels #2960 equivalent of the bead's clean_finish example)
    gets objective_posture.posture="ambiguous", and an active decision/
    handoff assertion on that session elevates it to "awaiting_operator"
    — both simultaneously present, and resume ranking includes it
    (objective_posture != "completed" filter, plus the posture-weighted
    score term). Verified in test_objective_posture.py::TestDeriveObjectivePosture::test_assertion_tier_outranks_structural_inference.
  2. Satisfied for the two available tiers. Typed evidence_refs,
    authority, as_of, and contradictions are all present on
    ObjectivePosturePayload and exercised by tests. completed,
    blocked, abandoned_inactive, awaiting_operator, awaiting_effect,
    ambiguous, unknown are all in the ObjectivePosture vocabulary;
    only abandoned_inactive/completed are not reachable from the two
    currently-wired tiers (deferred to goal_graph/work_evidence).
  3. Satisfied. derive_objective_posture always prefers the assertion
    tier over structural inference; test_self_reported_assertion_value_cannot_force_completed
    proves a freeform assertion value claiming resolution cannot force
    "completed".
  4. Satisfied. structural_objective_posture never maps any
    terminal_state to "completed"; test_never_emits_completed
    parametrizes every known state. Removing the authority-order check in
    derive_objective_posture (returning structural whenever assertions
    exist) would make test_assertion_tier_outranks_structural_inference
    fail — the anti-vacuity anchor for this AC.
  5. Satisfied for the wired consumers (profiles, blocker extraction,
    resume ranking, context preamble) — one shared function, no parallel
    terminal-state completion heuristic; the old
    _UNRESOLVED_BLOCKER_TERMINAL_STATES allowlist is deleted.
  6. Deferred. No labeled live-sample precision/coverage run — out of
    scope for a single-lane PR without live archive access in this
    sandboxed worktree. Recorded as residual risk below.

Verification

  • devtools test tests/unit/insights/test_objective_posture.py tests/unit/storage/test_session_insight_profiles.py tests/unit/core/test_resume.py tests/unit/mcp/test_context_resume_intent.py tests/unit/cli/test_context_view.py tests/unit/api/test_facade_contracts.py tests/unit/insights/test_rigor_audit.py → 381 passed.
  • devtools test over a broader plausibly-affected set (CLI insights/check/query-exec-laws, core pricing/registry/readiness, cost contract suite, devtools rigor-honesty, daemon web reader, storage archive-tiers/user-state/session-profile-consistency/status-descriptors, insights registry/no-metadata-cost-reads) → 601 passed, 1 xfailed, 3 pre-existing failures (test_check_runtime_only_skips_archive_readiness, test_exact_session_action_count_bounds_pairing_before_global_ranking, test_operational_web_payloads_redact_configured_archive_paths) — reproduced identically on a pristine origin/master worktree with none of this PR's changes present, confirming they are unrelated pre-existing/environment failures, not regressions from this diff.
  • /realm/project/polylogue/.venv/bin/mypy on every touched source + test file → no issues.
  • /realm/project/polylogue/.venv/bin/ruff check / ruff format --check on every touched file → clean.
  • devtools render topology-projection && devtools render topology-status (new module) and devtools render all --check → sync OK, no drift.
  • devtools verify --quick (format + lint + mypy + render-all-check + topology/layering/closure-matrix/schema-roundtrip/manifests/ci-workflows/doc-commands/docs-coverage/test-infra-currency/test-clock-hygiene/pytest-timeout-overrides/degrade-loudly) → exit 0, ran automatically via the pre-push hook too.
  • Not run: devtools verify --all (full non-integration suite) — testmon was unseeded in this worktree; seeding was judged out of scope for a single-lane PR. Not run: devtools verify --seed-testmon.

Ref polylogue-37t.23

Sinity added 4 commits July 20, 2026 21:38
Problem: SessionInferencePayload.terminal_state describes how a session's
process ended (structural tool/turn evidence), not whether its underlying
objective was resolved. Since polylogue-ve9z deleted the prose-derived
clean_finish heuristic (measured 50.5% agreement with structural truth),
most well-behaved endings now collapse to terminal_state="unknown" --
silence, not a completion claim -- which resume ranking and blocker
extraction still effectively read as "probably done". polylogue-37t.23
asks for a separate resumability projection over authority-bearing open
obligations instead.

Solution: new polylogue.insights.objective_posture module defines
ObjectivePosture/ObjectivePostureAuthority and an explicit authority
order (goal_graph > work_evidence > assertion > structural_inference >
none). The top two tiers (polylogue-7yk5 goal graph, polylogue-1vpm.6
work-evidence graph) are not yet built, so this lands the two tiers that
are: structural_objective_posture (bounded terminal_state mapping,
index.db-only, never emits "completed") and derive_objective_posture
(overlays durable decision/blocker/handoff assertions, which outrank
structural inference). The assertion tier is a read-time overlay
(resolve_session_objective_posture), not baked into the materialized
profile row, so index.db stays independently rebuildable from source.db
without a user.db dependency.

Wired into the existing INSIGHT_REGISTRY session_profiles entry via a new
enrichment.objective_posture field (reconciled onto the native
terminal_state column the same way inference.terminal_state already is).
Consumers: blocker-text extraction now gates on the shared posture
mapping instead of a parallel _UNRESOLVED_BLOCKER_TERMINAL_STATES
allowlist (which never covered "unknown" -- the exact false-negative case
this bead targets); resume ranking adds a posture-weighted score
component and replaces the dead terminal_state == "clean_finish"
exclusion filter with objective_posture != "completed"; resume_brief
overlays the full assertion tier for its single session; the context
preamble surfaces posture per related session.

Ref polylogue-37t.23
… paths

Adds focused unit tests for polylogue.insights.objective_posture
(structural_objective_posture never emits "completed"; assertion tier
outranks structural inference; multiple simultaneous obligations surface
as contradictions rather than collapsing; self-reported assertion values
cannot force "completed") plus the resolve_session_objective_posture
async wrapper.

Fixes a second reconciliation gap the tests caught:
_session_profile_components_from_archive_row
(storage/sqlite/archive_tiers/archive.py) is the live SQL-backed read
path used by list_session_profile_insights/resume ranking -- distinct
from insights.archive.SessionProfileInsight.from_record (used by
daemon/http.py) -- and needed the same native-column reconciliation for
objective_posture that from_record already got. Existing
_UNRESOLVED_BLOCKER_TERMINAL_STATES / resume-ranking / context-preamble
tests updated for the new field and behavior (blocker text is no longer
silently suppressed for terminal_state="unknown").

Ref polylogue-37t.23
verify-degrade-loudly requires a log call or re-raise on any bare
except Exception. build_resume_brief already surfaces the failure via
ResumeUncertainty; add the matching logger.warning (same pattern as
context/preamble.py's component-failure handling) so the fallback is
never silent.

Ref polylogue-37t.23
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@Sinity, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 5 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 309c0704-314d-46fd-9a37-df38879cc36b

📥 Commits

Reviewing files that changed from the base of the PR and between c6b7f3d and f7f2e5e.

📒 Files selected for processing (16)
  • docs/plans/topology-target.yaml
  • docs/topology-status.md
  • polylogue/context/preamble.py
  • polylogue/insights/archive.py
  • polylogue/insights/archive_models.py
  • polylogue/insights/objective_posture.py
  • polylogue/insights/registry.py
  • polylogue/insights/resume.py
  • polylogue/insights/rigor.py
  • polylogue/storage/insights/session/profiles.py
  • polylogue/storage/sqlite/archive_tiers/archive.py
  • polylogue/surfaces/payloads.py
  • tests/unit/core/test_resume.py
  • tests/unit/insights/test_objective_posture.py
  • tests/unit/mcp/test_context_resume_intent.py
  • tests/unit/storage/test_session_insight_profiles.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/insights/objective-posture-projection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f7f2e5ef90

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread polylogue/insights/objective_posture.py Resolved
@Sinity

Sinity commented Jul 20, 2026

Copy link
Copy Markdown
Owner Author

Coordinator review stand-in (CodeRabbit rate-limited — no findings produced).

Read the full diff. Assessment:

  • Sound authority model: goal_graph > work_evidence > assertion > structural_inference > none, with only the two buildable tiers wired (structural + assertion overlay); reserved slots for the unbuilt 7yk5/1vpm.6 epics need no shape change later. structural_objective_posture can never emit completed, and a self-reported assertion cannot force completed — both anti-vacuity-tested.
  • Materialization discipline is right: only the structural tier (index.db-only inputs) is baked into the profile row, preserving the derived-tier rebuild-from-source invariant; the assertion tier is a read-time overlay. The structural tier is recomputed onto the reconciled native terminal_state at BOTH read sites (insights/archive.py and the SQL-backed archive.py row path) rather than trusted from possibly-stale enrichment JSON — the second site was found by a test catching drift.
  • Honest AC reframe: AC1's literal clean_finish text was obsoleted by refactor(insights): delete prose-keyword heuristics for terminal state and activity labels #2960 (deleted the same day the bead was last touched); implemented the post-refactor(insights): delete prose-keyword heuristics for terminal state and activity labels #2960 equivalent and killed the old parallel _UNRESOLVED_BLOCKER_TERMINAL_STATES allowlist that never covered unknown (the false-negative the bead targets).
  • Verification is unusually thorough for a lane: 381 focused + 601 broader-sweep tests green; the 3 sweep failures reproduce identically on a pristine origin/master worktree (classified pre-existing, not regressions); mypy/ruff clean; topology regenerated for the new module.
  • Known limits, acceptable: assertion overlay is per-physical-session (not lineage-composed); bulk resume ranking uses structural tier only (avoids N-query fan-out); live-sample precision run deferred (needs live archive).

Quick-gate green. Merging.

@Sinity
Sinity merged commit 4799d24 into master Jul 20, 2026
2 of 3 checks passed
@Sinity
Sinity deleted the feature/insights/objective-posture-projection branch July 20, 2026 20:03
Sinity added a commit that referenced this pull request Jul 20, 2026
Problem: master gained #3226 (objective-posture insight, new module +
topology regen) and #3227 (hermes_verification.py profile-qualified
identity: verification:<id>[@PROfile-<key>], hermes_verification_session_id_for
now PRESERVES the qualifier instead of stripping it) since this branch's
last rebase. Rebasing surfaced one real conflict and one silent cross-file
break the rebase's textual merge did not flag:

- polylogue/sources/parsers/hermes_verification.py: conflicting docstring
  edits (both #3227 and this branch's earlier commit touched the same
  observer_session_provider_id/hermes_verification_session_id_for
  docstrings) -- resolved to describe the composed state: profile-qualified
  AND correctly referencing hermes_spans's renamed
  atif_session_provider_id/atof_session_provider_id (this branch) instead
  of the retired shared observer_session_provider_id.
- tests/unit/sources/parsers/test_hermes_verification.py (added by #3227,
  never touched by this branch's commits, so the rebase reported no
  conflict): test_verification_family_prefix_stays_distinguishable_from_atif_atof_observer_family
  imported hermes_spans.observer_session_provider_id, a name this branch
  retired in favor of atif_session_provider_id/atof_session_provider_id --
  an ImportError, not a merge conflict, so it only surfaced by actually
  running the suite. Fixed to import and assert against both renamed
  functions (verification: stays distinguishable from BOTH observer:atif:
  and observer:atof:, not just the old single observer: family).

Semantic composition check (per coordinator request): hermes_topology_projection.py
never hardcodes a session-id shape itself -- callers resolve each artifact's
session_id (see HermesArtifactInput docstring) via
hermes_spans.atif_session_provider_id/atof_session_provider_id or
hermes_verification.hermes_verification_session_id_for -- so the module is
scheme-agnostic by construction and needed no code change. Added
test_composes_with_profile_qualified_verification_ids_like_atif_and_atof in
tests/unit/insights/test_hermes_topology_projection.py, which drives the
REAL hermes_verification_session_id_for/hermes_identity helpers (not a
hand-typed "verification:<id>" string) from a profile-qualified
conversational session id and proves: the resolved verification id
preserves the qualifier (not stripped, matching #3227's fix), and two
different profiles resolve to two distinct, non-colliding verification
session ids for the same raw Hermes session id -- exactly the guarantee
ATIF/ATOF already have.

docs/hermes-operators.md: "Session identity" section and item 1 updated --
previously (written before #3227 merged) claimed hermes_verification's
helper "still strips" the profile qualifier and was "explicitly left out of
this fix's scope"; now correctly describes it as fixed separately
(polylogue-y9zx, PR #3227) using the same shared hermes_identity.py scheme.

docs/plans/topology-target.yaml, docs/topology-status.md: regenerated
(devtools render topology-projection && render topology-status) to reflect
#3226's new objective-posture insight module -- no textual conflict during
rebase, but genuinely stale without regen.

Verification:
- devtools test tests/unit/insights/test_hermes_topology_projection.py
  tests/unit/sources/parsers/test_hermes_spans.py
  tests/unit/sources/test_dispatch_payloads.py
  tests/unit/sources/test_live_watcher.py
  tests/unit/sources/parsers/test_hermes_verification.py -- 151 passed.
- devtools verify --quick -- exit 0.

Ref polylogue-fs1.14

Co-Authored-By: Claude <[email protected]>
@Sinity

Sinity commented Sep 30, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

@Sinity

Sinity commented Oct 1, 2026

Copy link
Copy Markdown
Owner Author

Historical Codex triage: evidence checked at 5ebcfe5. This records that source revision; it does not claim a fresh review of current master.

Only the rows listed above are dispositioned. Held findings remain open.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant