oughtinc / patchwork

Command-line recursive question-answering with immutable contexts and explicit data store
https://ought.org/projects/factored-cognition
MIT License
24 stars 1 forks source link

Empty questions cause misbehaviour/Pointer glitches #11

Open rmoehn opened 6 years ago

rmoehn commented 6 years ago

Exhibit 1:

What is your root question?
> <Enter>
Question: [$1: ]
Scratchpad: [$1: ]
Subquestions:

>

Exhibit 2:

What is your root question?
> What is the capital of Assyria?
Question: [$1: What is the capital of Assyria?]
Scratchpad: [$2: ]
Subquestions:

> ask<Enter>
Question: [$1: What is the capital of Assyria?]
Scratchpad: [$q1: ]
Subquestions:
1.
  [$q1: ]
  $a1
  $w1

> unlock $a1
Question: [$1: ]
Scratchpad: [$1: ]
Subquestions:

>

I could probably fix this easily, but I don't want to switch context now. Besides, this is a good bug to fix for someone who wants to get to know the codebase.

rmoehn commented 6 years ago

Another glitch with the scratchpad:

What is your root question?
> Is [] the empty list?
Question: [$1: Is [$2: ] the empty list?]
Scratchpad: [$2: ]
Subquestions:

>

I guess some implementation detail causes null pointers ([]) to always appear unlocked.

Here is yet another glitch:

What is your root question?
> What is the air-speed velocity of an unladen swallow?
Question: [$1: What is the air-speed velocity of an unladen swallow?]
Scratchpad: [$2: ]
Subquestions:

> ask What is the air-speed velocity of an unladen African swallow?
Question: [$1: What is the air-speed velocity of an unladen swallow?]
Scratchpad: [$2: ]
Subquestions:
1.
  [$q1: What is the air-speed velocity of an unladen African swallow?]
  $a1
  $w1

> unlock $a1
Question: [$1: What is the air-speed velocity of an unladen African swallow?]
Scratchpad: [$2: ]
Subquestions:

> reply []
Question: [$1: What is the air-speed velocity of an unladen swallow?]
Scratchpad: [$2: ]
Subquestions:
1.
  [$q1: What is the air-speed velocity of an unladen African swallow?]
  [$a1: [$2: ]]
  $w1

> scratch []
Question: [$1: What is the air-speed velocity of an unladen swallow?]
Scratchpad: [$a1: [$2: ]]   <===
Subquestions:
1.
  [$q1: What is the air-speed velocity of an unladen African swallow?]
  [$a1: [$2: ]]
  $w1

>

This is caused by the data deduplication and might confuse a user.

rmoehn commented 6 years ago

But since Patchwork is not intended for end users, this issue is probably unimportant.

stuhlmueller commented 6 years ago

I don't think it's obviously unimportant. Identifying pointers (for the purpose of unlocking within a workspace) that have the same contents, but were created independently, feels like a symptom of a design choice that might be incorrect.

rmoehn commented 6 years ago

Okay, here is my analysis, then.

Example:

What is your root question?
> Bat?
Question: [$1: Bat?]
Scratchpad: [$2: ]
Subquestions:

> scratch Bat?
Question: [$1: Bat?]
Scratchpad: [$1: Bat?]
Subquestions:

>

The steps are roughly:

  1. Insert the root question into the database. It gets address A1.
  2. Scratch.act inserts ‘Bat?’ into the database (TransactionAccumulator.insert). The content is already in the database, so new_scratchpad_link will be A1 as well.
  3. Scratch.act constructs a successor workspace with A1 as both the question link and the scratchpad link.
  4. Scratch.act constructs a successor context pointing to that workspace.
  5. The context has to contain a dictionary that maps pointers to addresses and a dictionary that maps addresses to pointers. These mappings are bijective, ie. every pointer is mapped to exactly one address and vice versa. Context.__init__ calls Context._name_pointers to construct these mappings.

In the example above, there is only one address A1, which _name_pointers maps to $1. This is how we end up with the same pointer in the scratchpad and the question, even though they were ‘created independently’.

_name_pointers creates mappings for the sub-question pointers (question, answer, workspace) first, which is how we end up with Scratchpad: [$a1: [$2: ]] in the last example above.

How could we fix this? Options:

I haven't thought through the consequences of these options, yet.